1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 23 import org.apache.xalan.xsltc.compiler.util.ErrorMsg; 24 import org.apache.xalan.xsltc.compiler.util.MethodGenerator; 25 import org.apache.xalan.xsltc.compiler.util.Type; 26 import org.apache.xalan.xsltc.compiler.util.TypeCheckError; 27 28 31 final class UnresolvedRef extends VariableRefBase { 32 33 private QName _variableName = null; 34 private VariableRefBase _ref = null; 35 private VariableBase _var = null; 36 private Stylesheet _sheet = null; 37 38 public UnresolvedRef(QName name) { 39 super(); 40 _variableName = name; 41 _sheet = getStylesheet(); 42 } 43 44 public QName getName() { 45 return(_variableName); 46 } 47 48 private ErrorMsg reportError() { 49 ErrorMsg err = new ErrorMsg(ErrorMsg.VARIABLE_UNDEF_ERR, 50 _variableName, this); 51 getParser().reportError(Constants.ERROR, err); 52 return(err); 53 } 54 55 private VariableRefBase resolve(Parser parser, SymbolTable stable) { 56 VariableBase ref = parser.lookupVariable(_variableName); 59 if (ref == null) ref = (VariableBase)stable.lookupName(_variableName); 60 if (ref == null) { 61 reportError(); 62 return null; 63 } 64 65 if ((_var = findParentVariable()) != null) _var.addDependency(ref); 68 69 if (ref instanceof Variable) 71 return(new VariableRef((Variable)ref)); 72 else if (ref instanceof Param) 73 return(new ParameterRef((Param)ref)); 74 else 75 return null; 76 } 77 78 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 79 if (_ref != null) { 80 final String name = _variableName.toString(); 81 ErrorMsg err = new ErrorMsg(ErrorMsg.CIRCULAR_VARIABLE_ERR, 82 name, this); 83 } 84 if ((_ref = resolve(getParser(), stable)) != null) { 85 return (_type = _ref.typeCheck(stable)); 86 } 87 throw new TypeCheckError(reportError()); 88 } 89 90 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 91 if (_ref != null) 92 _ref.translate(classGen, methodGen); 93 else 94 reportError(); 95 } 96 97 public String toString() { 98 return "unresolved-ref()"; 99 } 100 101 } 102 | Popular Tags |