KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xalan > internal > xsltc > compiler > LangCall


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: LangCall.java,v 1.5 2004/02/16 22:24:29 minchau Exp $
18  */

19
20 package com.sun.org.apache.xalan.internal.xsltc.compiler;
21
22 import java.util.Vector JavaDoc;
23
24 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
25 import com.sun.org.apache.bcel.internal.generic.ILOAD;
26 import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
27 import com.sun.org.apache.bcel.internal.generic.InstructionList;
28 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.FilterGenerator;
30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.StringType;
32 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
33 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
34
35 /**
36  * @author Morten Jorgensen
37  */

38 final class LangCall extends FunctionCall {
39     private Expression _lang;
40     private Type _langType;
41
42     /**
43      * Get the parameters passed to function:
44      * lang(string)
45      */

46     public LangCall(QName fname, Vector JavaDoc arguments) {
47     super(fname, arguments);
48     _lang = argument(0);
49     }
50
51     /**
52      *
53      */

54     public Type typeCheck(SymbolTable stable) throws TypeCheckError {
55     _langType = _lang.typeCheck(stable);
56     if (!(_langType instanceof StringType)) {
57         _lang = new CastExpr(_lang, Type.String);
58     }
59     return Type.Boolean;
60     }
61
62     /**
63      *
64      */

65     public Type getType() {
66     return(Type.Boolean);
67     }
68
69     /**
70      * This method is called when the constructor is compiled in
71      * Stylesheet.compileConstructor() and not as the syntax tree is traversed.
72      */

73     public void translate(ClassGenerator classGen,
74               MethodGenerator methodGen) {
75     final ConstantPoolGen cpg = classGen.getConstantPool();
76     final InstructionList il = methodGen.getInstructionList();
77
78     final int tst = cpg.addMethodref(BASIS_LIBRARY_CLASS,
79                      "testLanguage",
80                      "("+STRING_SIG+DOM_INTF_SIG+"I)Z");
81     _lang.translate(classGen,methodGen);
82     il.append(methodGen.loadDOM());
83     if (classGen instanceof FilterGenerator)
84         il.append(new ILOAD(1));
85     else
86         il.append(methodGen.loadContextNode());
87     il.append(new INVOKESTATIC(tst));
88     }
89 }
90
Popular Tags