1/* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5/* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22package com.sun.org.apache.xalan.internal.xsltc.compiler; 23 24import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; 25import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; 26import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; 27import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; 28import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; 29 30/** 31 * @author Morten Jorgensen 32 */ 33final class UnresolvedRef extends VariableRefBase { 34 35 private QName _variableName = null; 36 private VariableRefBase _ref = null; 37 38 public UnresolvedRef(QName name) { 39 super(); 40 _variableName = name; 41 } 42 43 public QName getName() { 44 return(_variableName); 45 } 46 47 private ErrorMsg reportError() { 48 ErrorMsg err = new ErrorMsg(ErrorMsg.VARIABLE_UNDEF_ERR, 49 _variableName, this); 50 getParser().reportError(Constants.ERROR, err); 51 return(err); 52 } 53 54 private VariableRefBase resolve(Parser parser, SymbolTable stable) { 55 // At this point the AST is already built and we should be able to 56 // find any declared global variable or parameter 57 VariableBase ref = parser.lookupVariable(_variableName); 58 if (ref == null) { 59 ref = (VariableBase)stable.lookupName(_variableName); 60 } 61 if (ref == null) { 62 reportError(); 63 return null; 64 } 65 66 // If in a top-level element, create dependency to the referenced var 67 _variable = ref; 68 addParentDependency(); 69 70 if (ref instanceof Variable) { 71 return new VariableRef((Variable) ref); 72 } 73 else if (ref instanceof Param) { 74 return new ParameterRef((Param)ref); 75 } 76 return null; 77 } 78 79 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 80 if (_ref != null) { 81 final String name = _variableName.toString(); 82 ErrorMsg err = new ErrorMsg(ErrorMsg.CIRCULAR_VARIABLE_ERR, 83 name, this); 84 } 85 if ((_ref = resolve(getParser(), stable)) != null) { 86 return (_type = _ref.typeCheck(stable)); 87 } 88 throw new TypeCheckError(reportError()); 89 } 90 91 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 92 if (_ref != null) 93 _ref.translate(classGen, methodGen); 94 else 95 reportError(); 96 } 97 98 public String toString() { 99 return "unresolved-ref()"; 100 } 101 102} 103