~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/xalan-j_2_7_1/src/org/apache/xalan/xsltc/compiler/LangCall.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

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