KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xalan > internal > 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 com.sun.org.apache.xalan.internal.xsltc.compiler;
21
22 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
23 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
24 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
25 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
26 import com.sun.org.apache.xalan.internal.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
36     public UnresolvedRef(QName name) {
37     super();
38     _variableName = name;
39     }
40
41     public QName getName() {
42     return(_variableName);
43     }
44
45     private ErrorMsg reportError() {
46     ErrorMsg err = new ErrorMsg(ErrorMsg.VARIABLE_UNDEF_ERR,
47                     _variableName, this);
48     getParser().reportError(Constants.ERROR, err);
49     return(err);
50     }
51
52     private VariableRefBase resolve(Parser parser, SymbolTable stable) {
53     // At this point the AST is already built and we should be able to
54
// find any declared global variable or parameter
55
VariableBase ref = parser.lookupVariable(_variableName);
56     if (ref == null) {
57         ref = (VariableBase)stable.lookupName(_variableName);
58     }
59     if (ref == null) {
60         reportError();
61         return null;
62     }
63
64     // If in a top-level element, create dependency to the referenced var
65
_variable = ref;
66     addParentDependency();
67
68     if (ref instanceof Variable) {
69         return new VariableRef((Variable) ref);
70     }
71     else if (ref instanceof Param) {
72         return new ParameterRef((Param)ref);
73     }
74     return null;
75     }
76
77     public Type typeCheck(SymbolTable stable) throws TypeCheckError {
78     if (_ref != null) {
79         final String JavaDoc name = _variableName.toString();
80         ErrorMsg err = new ErrorMsg(ErrorMsg.CIRCULAR_VARIABLE_ERR,
81                     name, this);
82     }
83     if ((_ref = resolve(getParser(), stable)) != null) {
84         return (_type = _ref.typeCheck(stable));
85     }
86     throw new TypeCheckError(reportError());
87     }
88
89     public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
90     if (_ref != null)
91         _ref.translate(classGen, methodGen);
92     else
93         reportError();
94     }
95
96     public String JavaDoc toString() {
97     return "unresolved-ref()";
98     }
99
100 }
101
Popular Tags