View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /*
6    * Copyright 2001-2004 The Apache Software Foundation.
7    *
8    * Licensed under the Apache License, Version 2.0 (the "License");
9    * you may not use this file except in compliance with the License.
10   * You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  /*
21   * $Id: LangCall.java,v 1.2.4.1 2005/09/01 15:54:25 pvedula Exp $
22   */
23  
24  package com.sun.org.apache.xalan.internal.xsltc.compiler;
25  
26  import java.util.Vector;
27  
28  import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
29  import com.sun.org.apache.bcel.internal.generic.ILOAD;
30  import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
31  import com.sun.org.apache.bcel.internal.generic.InstructionList;
32  import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
33  import com.sun.org.apache.xalan.internal.xsltc.compiler.util.FilterGenerator;
34  import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
35  import com.sun.org.apache.xalan.internal.xsltc.compiler.util.StringType;
36  import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
37  import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
38  
39  /**
40   * @author Morten Jorgensen
41   */
42  final class LangCall extends FunctionCall {
43      private Expression _lang;
44      private Type _langType;
45  
46      /**
47       * Get the parameters passed to function:
48       *   lang(string)
49       */
50      public LangCall(QName fname, Vector arguments) {
51          super(fname, arguments);
52          _lang = argument(0);
53      }
54  
55      /**
56       *
57       */
58      public Type typeCheck(SymbolTable stable) throws TypeCheckError {
59          _langType = _lang.typeCheck(stable);
60          if (!(_langType instanceof StringType)) {
61              _lang = new CastExpr(_lang, Type.String);
62          }
63          return Type.Boolean;
64      }
65  
66      /**
67       *
68       */
69      public Type getType() {
70          return(Type.Boolean);
71      }
72  
73      /**
74       * This method is called when the constructor is compiled in
75       * Stylesheet.compileConstructor() and not as the syntax tree is traversed.
76       */
77      public void translate(ClassGenerator classGen,
78                            MethodGenerator methodGen) {
79          final ConstantPoolGen cpg = classGen.getConstantPool();
80          final InstructionList il = methodGen.getInstructionList();
81  
82          final int tst = cpg.addMethodref(BASIS_LIBRARY_CLASS,
83                                           "testLanguage",
84                                           "("+STRING_SIG+DOM_INTF_SIG+"I)Z");
85          _lang.translate(classGen,methodGen);
86          il.append(methodGen.loadDOM());
87          if (classGen instanceof FilterGenerator)
88              il.append(new ILOAD(1));
89          else
90              il.append(methodGen.loadContextNode());
91          il.append(new INVOKESTATIC(tst));
92      }
93  }