1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import org.apache.xalan.xsltc.compiler.util.Type; 23 import org.apache.xalan.xsltc.compiler.util.TypeCheckError; 24 25 29 class VariableRefBase extends Expression { 30 31 34 protected final VariableBase _variable; 35 36 40 protected Closure _closure = null; 41 42 public VariableRefBase(VariableBase variable) { 43 _variable = variable; 44 variable.addReference(this); 45 } 46 47 public VariableRefBase() { 48 _variable = null; 49 } 50 51 54 public VariableBase getVariable() { 55 return _variable; 56 } 57 58 61 public VariableBase findParentVariable() { 62 SyntaxTreeNode node = this; 63 while (node != null && !(node instanceof VariableBase)) { 64 node = node.getParent(); 65 } 66 return (VariableBase) node; 67 } 68 69 73 public boolean equals(Object obj) { 74 try { 75 return (_variable == ((VariableRefBase) obj)._variable); 76 } 77 catch (ClassCastException e) { 78 return false; 79 } 80 } 81 82 87 public String toString() { 88 return "variable-ref("+_variable.getName()+'/'+_variable.getType()+')'; 89 } 90 91 public Type typeCheck(SymbolTable stable) 92 throws TypeCheckError 93 { 94 if (_type != null) return _type; 96 97 if (_variable.isLocal()) { 99 SyntaxTreeNode node = getParent(); 100 do { 101 if (node instanceof Closure) { 102 _closure = (Closure) node; 103 break; 104 } 105 if (node instanceof TopLevelElement) { 106 break; } 108 node = node.getParent(); 109 } while (node != null); 110 111 if (_closure != null) { 112 _closure.addVariable(this); 113 } 114 } 115 116 VariableBase parent = findParentVariable(); 118 if (parent != null) { 119 VariableBase var = _variable; 120 if (_variable._ignore) { 121 if (_variable instanceof Variable) { 122 var = parent.getSymbolTable() 123 .lookupVariable(_variable._name); 124 } else if (_variable instanceof Param) { 125 var = parent.getSymbolTable().lookupParam(_variable._name); 126 } 127 } 128 parent.addDependency(var); 129 } 130 131 _type = _variable.getType(); 133 134 if (_type == null) { 137 _variable.typeCheck(stable); 138 _type = _variable.getType(); 139 } 140 141 return _type; 143 } 144 145 } 146 | Popular Tags |