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. package com.sun.org.apache.xalan.internal.xsltc.compiler;
  20. import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
  21. import com.sun.org.apache.bcel.internal.generic.GOTO;
  22. import com.sun.org.apache.bcel.internal.generic.InstructionList;
  23. import com.sun.org.apache.bcel.internal.generic.PUSH;
  24. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
  25. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
  26. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
  27. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
  28. /**
  29. * This class implements inlined calls to the XSLT standard functions
  30. * true() and false().
  31. * @author Jacek Ambroziak
  32. * @author Santiago Pericas-Geertsen
  33. */
  34. final class BooleanExpr extends Expression {
  35. private boolean _value;
  36. public BooleanExpr(boolean value) {
  37. _value = value;
  38. }
  39. public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  40. _type = Type.Boolean;
  41. return _type;
  42. }
  43. public String toString() {
  44. return _value ? "true()" : "false()";
  45. }
  46. public boolean getValue() {
  47. return _value;
  48. }
  49. public boolean contextDependent() {
  50. return false;
  51. }
  52. public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  53. ConstantPoolGen cpg = classGen.getConstantPool();
  54. InstructionList il = methodGen.getInstructionList();
  55. il.append(new PUSH(cpg, _value));
  56. }
  57. public void translateDesynthesized(ClassGenerator classGen,
  58. MethodGenerator methodGen) {
  59. final InstructionList il = methodGen.getInstructionList();
  60. if (_value) {
  61. il.append(NOP); // true list falls through
  62. }
  63. else {
  64. _falseList.add(il.append(new GOTO(null)));
  65. }
  66. }
  67. }