jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/VariableBase.java
changeset 36486 b84e564d2358
parent 25868 686eef1e7a79
child 44797 8b3b3b911b8a
equal deleted inserted replaced
36280:c870cb782aca 36486:b84e564d2358
     1 /*
     1 /*
     2  * reserved comment block
     2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT REMOVE OR ALTER!
       
     4  */
     3  */
     5 /*
     4 /*
     6  * Copyright 2001-2004 The Apache Software Foundation.
     5  * Copyright 2001-2004 The Apache Software Foundation.
     7  *
     6  *
     8  * Licensed under the Apache License, Version 2.0 (the "License");
     7  * Licensed under the Apache License, Version 2.0 (the "License");
    15  * distributed under the License is distributed on an "AS IS" BASIS,
    14  * distributed under the License is distributed on an "AS IS" BASIS,
    16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    17  * See the License for the specific language governing permissions and
    16  * See the License for the specific language governing permissions and
    18  * limitations under the License.
    17  * limitations under the License.
    19  */
    18  */
    20 /*
       
    21  * $Id: VariableBase.java,v 1.5 2005/09/28 13:48:18 pvedula Exp $
       
    22  */
       
    23 
    19 
    24 package com.sun.org.apache.xalan.internal.xsltc.compiler;
    20 package com.sun.org.apache.xalan.internal.xsltc.compiler;
    25 
    21 
    26 import java.util.Vector;
    22 import java.util.Vector;
    27 
    23 
       
    24 import com.sun.org.apache.bcel.internal.generic.CHECKCAST;
    28 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
    25 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
    29 import com.sun.org.apache.bcel.internal.generic.Instruction;
    26 import com.sun.org.apache.bcel.internal.generic.Instruction;
    30 import com.sun.org.apache.bcel.internal.generic.InstructionList;
    27 import com.sun.org.apache.bcel.internal.generic.InstructionList;
       
    28 import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
    31 import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
    29 import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
       
    30 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
    32 import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
    31 import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
    33 import com.sun.org.apache.bcel.internal.generic.NEW;
    32 import com.sun.org.apache.bcel.internal.generic.NEW;
    34 import com.sun.org.apache.bcel.internal.generic.PUSH;
    33 import com.sun.org.apache.bcel.internal.generic.PUSH;
    35 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
    34 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
    36 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
    35 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
    37 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
    36 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
    38 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeSetType;
    37 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.NodeSetType;
       
    38 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ResultTreeType;
    39 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
    39 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
    40 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
    40 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
    41 import com.sun.org.apache.xml.internal.utils.XML11Char;
    41 import com.sun.org.apache.xml.internal.utils.XML11Char;
    42 
    42 
    43 /**
    43 /**
    47  * @author Erwin Bolwidt <ejb@klomp.org>
    47  * @author Erwin Bolwidt <ejb@klomp.org>
    48  * @author John Howard <JohnH@schemasoft.com>
    48  * @author John Howard <JohnH@schemasoft.com>
    49  */
    49  */
    50 class VariableBase extends TopLevelElement {
    50 class VariableBase extends TopLevelElement {
    51 
    51 
    52     protected QName       _name;            // The name of the variable.
    52     protected QName       _name;             // The name of the variable.
    53     protected String      _escapedName;        // The escaped qname of the variable.
    53     protected String      _escapedName;      // The escaped qname of the variable.
    54     protected Type        _type;            // The type of this variable.
    54     protected Type        _type;             // The type of this variable.
    55     protected boolean     _isLocal;         // True if the variable is local.
    55     protected boolean     _isLocal;          // True if the variable is local.
    56     protected LocalVariableGen _local;      // Reference to JVM variable
    56     protected LocalVariableGen _local;       // Reference to JVM variable
    57     protected Instruction _loadInstruction; // Instruction to load JVM variable
    57     protected Instruction _loadInstruction;  // Instruction to load JVM variable
    58     protected Instruction _storeInstruction; // Instruction to load JVM variable
    58     protected Instruction _storeInstruction; // Instruction to load JVM variable
    59     protected Expression  _select;          // Reference to variable expression
    59     protected Expression  _select;           // Reference to variable expression
    60     protected String      select;           // Textual repr. of variable expr.
    60     protected String      select;            // Textual repr. of variable expr.
    61 
    61 
    62     // References to this variable (when local)
    62     // References to this variable (when local)
    63     protected Vector      _refs = new Vector(2);
    63     protected Vector<VariableRefBase> _refs = new Vector<>(2);
    64 
       
    65     // Dependencies to other variables/parameters (for globals only)
       
    66     protected Vector      _dependencies = null;
       
    67 
    64 
    68     // Used to make sure parameter field is not added twice
    65     // Used to make sure parameter field is not added twice
    69     protected boolean    _ignore = false;
    66     protected boolean    _ignore = false;
    70 
    67 
    71     /**
    68     /**
    90      * purpose.
    87      * purpose.
    91      */
    88      */
    92     public void copyReferences(VariableBase var) {
    89     public void copyReferences(VariableBase var) {
    93         final int size = _refs.size();
    90         final int size = _refs.size();
    94         for (int i = 0; i < size; i++) {
    91         for (int i = 0; i < size; i++) {
    95             var.addReference((VariableRefBase) _refs.get(i));
    92             var.addReference(_refs.get(i));
    96         }
    93         }
    97     }
    94     }
    98 
    95 
    99     /**
    96     /**
   100      * Map this variable to a register
    97      * Map this variable to a register
   110 
   107 
   111     /**
   108     /**
   112      * Remove the mapping of this variable to a register.
   109      * Remove the mapping of this variable to a register.
   113      * Called when we leave the AST scope of the variable's declaration
   110      * Called when we leave the AST scope of the variable's declaration
   114      */
   111      */
   115     public void unmapRegister(MethodGenerator methodGen) {
   112     public void unmapRegister(ClassGenerator classGen, MethodGenerator methodGen) {
   116         if (_local != null) {
   113         if (_local != null) {
       
   114             if (_type instanceof ResultTreeType) {
       
   115                 final ConstantPoolGen cpg = classGen.getConstantPool();
       
   116                 final InstructionList il = methodGen.getInstructionList();
       
   117                 if (classGen.getStylesheet().callsNodeset() && classGen.getDOMClass().equals(MULTI_DOM_CLASS)) {
       
   118                     final int removeDA = cpg.addMethodref(MULTI_DOM_CLASS, "removeDOMAdapter", "(" + DOM_ADAPTER_SIG + ")V");
       
   119                     il.append(methodGen.loadDOM());
       
   120                     il.append(new CHECKCAST(cpg.addClass(MULTI_DOM_CLASS)));
       
   121                     il.append(loadInstruction());
       
   122                     il.append(new CHECKCAST(cpg.addClass(DOM_ADAPTER_CLASS)));
       
   123                     il.append(new INVOKEVIRTUAL(removeDA));
       
   124                 }
       
   125                 final int release = cpg.addInterfaceMethodref(DOM_IMPL_CLASS, "release", "()V");
       
   126                 il.append(loadInstruction());
       
   127                 il.append(new INVOKEINTERFACE(release, 1));
       
   128             }
       
   129 
   117             _local.setEnd(methodGen.getInstructionList().getEnd());
   130             _local.setEnd(methodGen.getInstructionList().getEnd());
   118             methodGen.removeLocalVariable(_local);
   131             methodGen.removeLocalVariable(_local);
   119             _refs = null;
   132             _refs = null;
   120             _local = null;
   133             _local = null;
   121         }
   134         }
   124     /**
   137     /**
   125      * Returns an instruction for loading the value of this variable onto
   138      * Returns an instruction for loading the value of this variable onto
   126      * the JVM stack.
   139      * the JVM stack.
   127      */
   140      */
   128     public Instruction loadInstruction() {
   141     public Instruction loadInstruction() {
   129         final Instruction instr = _loadInstruction;
       
   130         if (_loadInstruction == null) {
   142         if (_loadInstruction == null) {
   131             _loadInstruction = _type.LOAD(_local.getIndex());
   143             _loadInstruction = _type.LOAD(_local.getIndex());
   132         }
   144         }
   133         return _loadInstruction;
   145         return _loadInstruction;
   134     }
   146     }
   136     /**
   148     /**
   137      * Returns an instruction for storing a value from the JVM stack
   149      * Returns an instruction for storing a value from the JVM stack
   138      * into this variable.
   150      * into this variable.
   139      */
   151      */
   140     public Instruction storeInstruction() {
   152     public Instruction storeInstruction() {
   141         final Instruction instr = _storeInstruction;
       
   142         if (_storeInstruction == null) {
   153         if (_storeInstruction == null) {
   143             _storeInstruction = _type.STORE(_local.getIndex());
   154             _storeInstruction = _type.STORE(_local.getIndex());
   144         }
   155         }
   145         return _storeInstruction;
   156         return _storeInstruction;
   146     }
   157     }