KickJava   Java API By Example, From Geeks To Geeks.

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


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

19
20 package org.apache.xalan.xsltc.compiler;
21
22 import org.apache.bcel.generic.ConstantPoolGen;
23 import org.apache.bcel.generic.GOTO;
24 import org.apache.bcel.generic.InstructionList;
25 import org.apache.bcel.generic.PUSH;
26 import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
27 import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
28 import org.apache.xalan.xsltc.compiler.util.Type;
29 import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
30
31 /**
32  * This class implements inlined calls to the XSLT standard functions
33  * true() and false().
34  * @author Jacek Ambroziak
35  * @author Santiago Pericas-Geertsen
36  */

37 final class BooleanExpr extends Expression {
38     private boolean _value;
39
40     public BooleanExpr(boolean value) {
41     _value = value;
42     }
43
44     public Type typeCheck(SymbolTable stable) throws TypeCheckError {
45     _type = Type.Boolean;
46     return _type;
47     }
48
49     public String JavaDoc toString() {
50     return _value ? "true()" : "false()";
51     }
52
53     public boolean getValue() {
54     return _value;
55     }
56
57     public boolean contextDependent() {
58     return false;
59     }
60
61     public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
62     ConstantPoolGen cpg = classGen.getConstantPool();
63     InstructionList il = methodGen.getInstructionList();
64     il.append(new PUSH(cpg, _value));
65     }
66
67     public void translateDesynthesized(ClassGenerator classGen,
68                        MethodGenerator methodGen) {
69     final InstructionList il = methodGen.getInstructionList();
70     if (_value) {
71         il.append(NOP); // true list falls through
72
}
73     else {
74         _falseList.add(il.append(new GOTO(null)));
75     }
76     }
77 }
78
Popular Tags