jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/VariableRefBase.java

Print this page




   6  * Copyright 2001-2004 The Apache Software Foundation.
   7  *
   8  * Licensed under the Apache License, Version 2.0 (the "License");
   9  * you may not use this file except in compliance with the License.
  10  * You may obtain a copy of the License at
  11  *
  12  *     http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 /*
  21  * $Id: VariableRefBase.java,v 1.5 2005/09/28 13:48:18 pvedula Exp $
  22  */
  23 
  24 package com.sun.org.apache.xalan.internal.xsltc.compiler;
  25 

  26 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
  27 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
  28 
  29 /**
  30  * @author Morten Jorgensen
  31  * @author Santiago Pericas-Geertsen
  32  */
  33 class VariableRefBase extends Expression {
  34 
  35     /**
  36      * A reference to the associated variable.
  37      */
  38     protected VariableBase _variable;
  39 
  40     /**
  41      * A reference to the enclosing expression/instruction for which a
  42      * closure is needed (Predicate, Number or Sort).
  43      */
  44     protected Closure _closure = null;
  45 


  80         TopLevelElement parent = (TopLevelElement) node;
  81         if (parent != null) {
  82             VariableBase var = _variable;
  83             if (_variable._ignore) {
  84                 if (_variable instanceof Variable) {
  85                     var = parent.getSymbolTable()
  86                                 .lookupVariable(_variable._name);
  87                 } else if (_variable instanceof Param) {
  88                     var = parent.getSymbolTable().lookupParam(_variable._name);
  89                 }
  90             }
  91 
  92             parent.addDependency(var);
  93         }
  94     }
  95 
  96     /**
  97      * Two variable references are deemed equal if they refer to the
  98      * same variable.
  99      */

 100     public boolean equals(Object obj) {
 101         try {
 102             return (_variable == ((VariableRefBase) obj)._variable);
 103         }
 104         catch (ClassCastException e) {
 105             return false;
 106         }




 107     }
 108 
 109     /**
 110      * Returns a string representation of this variable reference on the
 111      * format 'variable-ref(<var-name>)'.
 112      * @return Variable reference description
 113      */

 114     public String toString() {
 115         return "variable-ref("+_variable.getName()+'/'+_variable.getType()+')';
 116     }
 117 

 118     public Type typeCheck(SymbolTable stable)
 119         throws TypeCheckError
 120     {
 121         // Returned cached type if available
 122         if (_type != null) return _type;
 123 
 124         // Find nearest closure to add a variable reference
 125         if (_variable.isLocal()) {
 126             SyntaxTreeNode node = getParent();
 127             do {
 128                 if (node instanceof Closure) {
 129                     _closure = (Closure) node;
 130                     break;
 131                 }
 132                 if (node instanceof TopLevelElement) {
 133                     break;      // way up in the tree
 134                 }
 135                 node = node.getParent();
 136             } while (node != null);
 137 




   6  * Copyright 2001-2004 The Apache Software Foundation.
   7  *
   8  * Licensed under the Apache License, Version 2.0 (the "License");
   9  * you may not use this file except in compliance with the License.
  10  * You may obtain a copy of the License at
  11  *
  12  *     http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 /*
  21  * $Id: VariableRefBase.java,v 1.5 2005/09/28 13:48:18 pvedula Exp $
  22  */
  23 
  24 package com.sun.org.apache.xalan.internal.xsltc.compiler;
  25 
  26 import com.sun.org.apache.xalan.internal.utils.Objects;
  27 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
  28 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
  29 
  30 /**
  31  * @author Morten Jorgensen
  32  * @author Santiago Pericas-Geertsen
  33  */
  34 class VariableRefBase extends Expression {
  35 
  36     /**
  37      * A reference to the associated variable.
  38      */
  39     protected VariableBase _variable;
  40 
  41     /**
  42      * A reference to the enclosing expression/instruction for which a
  43      * closure is needed (Predicate, Number or Sort).
  44      */
  45     protected Closure _closure = null;
  46 


  81         TopLevelElement parent = (TopLevelElement) node;
  82         if (parent != null) {
  83             VariableBase var = _variable;
  84             if (_variable._ignore) {
  85                 if (_variable instanceof Variable) {
  86                     var = parent.getSymbolTable()
  87                                 .lookupVariable(_variable._name);
  88                 } else if (_variable instanceof Param) {
  89                     var = parent.getSymbolTable().lookupParam(_variable._name);
  90                 }
  91             }
  92 
  93             parent.addDependency(var);
  94         }
  95     }
  96 
  97     /**
  98      * Two variable references are deemed equal if they refer to the
  99      * same variable.
 100      */
 101     @Override
 102     public boolean equals(Object obj) {
 103         return obj == this || (obj instanceof VariableRefBase)
 104             && (_variable == ((VariableRefBase) obj)._variable);



 105     }
 106 
 107     @Override
 108     public int hashCode() {
 109         return Objects.hashCode(this._variable);
 110     }
 111 
 112     /**
 113      * Returns a string representation of this variable reference on the
 114      * format 'variable-ref(<var-name>)'.
 115      * @return Variable reference description
 116      */
 117     @Override
 118     public String toString() {
 119         return "variable-ref("+_variable.getName()+'/'+_variable.getType()+')';
 120     }
 121 
 122     @Override
 123     public Type typeCheck(SymbolTable stable)
 124         throws TypeCheckError
 125     {
 126         // Returned cached type if available
 127         if (_type != null) return _type;
 128 
 129         // Find nearest closure to add a variable reference
 130         if (_variable.isLocal()) {
 131             SyntaxTreeNode node = getParent();
 132             do {
 133                 if (node instanceof Closure) {
 134                     _closure = (Closure) node;
 135                     break;
 136                 }
 137                 if (node instanceof TopLevelElement) {
 138                     break;      // way up in the tree
 139                 }
 140                 node = node.getParent();
 141             } while (node != null);
 142