KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > xsltc > compiler > UnresolvedRef


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: UnresolvedRef.java,v 1.6 2004/02/16 22:25:10 minchau Exp $
18  */

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 /**
29  * @author Morten Jorgensen
30  */

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     // At this point the AST is already built and we should be able to
57
// find any declared global variable or parameter
58
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     // Insert the referenced variable as something the parent variable
66
// is dependent of (this class should only be used under variables)
67
if ((_var = findParentVariable()) != null) _var.addDependency(ref);
68
69     // Instanciate a true variable/parameter ref
70
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 JavaDoc 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 JavaDoc toString() {
98     return "unresolved-ref()";
99     }
100
101 }
102
Popular Tags