1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.xalan.internal.xsltc.compiler; 23 24 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; 25 import com.sun.org.apache.bcel.internal.generic.GOTO; 26 import com.sun.org.apache.bcel.internal.generic.InstructionList; 27 import com.sun.org.apache.bcel.internal.generic.PUSH; 28 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; 29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; 30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; 31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; 32 33 /** 34 * This class implements inlined calls to the XSLT standard functions 35 * true() and false(). 36 * @author Jacek Ambroziak 37 * @author Santiago Pericas-Geertsen 38 */ 39 final class BooleanExpr extends Expression { 40 private boolean _value; 41 42 public BooleanExpr(boolean value) { 43 _value = value; 44 } 45 46 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 47 _type = Type.Boolean; 48 return _type; 49 } 50 51 public String toString() { 52 return _value ? "true()" : "false()"; 53 } 54 55 public boolean getValue() { 56 return _value; 57 } 58 59 public boolean contextDependent() { 60 return false; 61 } 62 63 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 64 ConstantPoolGen cpg = classGen.getConstantPool(); 65 InstructionList il = methodGen.getInstructionList(); 66 il.append(new PUSH(cpg, _value)); 67 } 68 69 public void translateDesynthesized(ClassGenerator classGen, 70 MethodGenerator methodGen) { 71 final InstructionList il = methodGen.getInstructionList(); 72 if (_value) { 73 il.append(NOP); // true list falls through 74 } 75 else { 76 _falseList.add(il.append(new GOTO(null))); 77 } 78 } 79 }