1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import org.apache.bcel.generic.InstructionHandle; 23 import org.apache.bcel.generic.InstructionList; 24 import org.apache.xalan.xsltc.compiler.util.BooleanType; 25 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 26 import org.apache.xalan.xsltc.compiler.util.ErrorMsg; 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 import org.apache.xalan.xsltc.compiler.util.Util; 31 32 37 final class If extends Instruction { 38 39 private Expression _test; 40 private boolean _ignore = false; 41 42 45 public void display(int indent) { 46 indent(indent); 47 Util.println("If"); 48 indent(indent + IndentIncrement); 49 System.out.print("test "); 50 Util.println(_test.toString()); 51 displayContents(indent + IndentIncrement); 52 } 53 54 57 public void parseContents(Parser parser) { 58 _test = parser.parseExpression(this, "test", null); 60 61 if (_test.isDummy()) { 63 reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "test"); 64 return; 65 } 66 67 Object result = _test.evaluateAtCompileTime(); 70 if (result != null && result instanceof Boolean ) { 71 _ignore = !((Boolean ) result).booleanValue(); 72 } 73 74 parseChildren(parser); 75 } 76 77 81 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 82 if (_test.typeCheck(stable) instanceof BooleanType == false) { 84 _test = new CastExpr(_test, Type.Boolean); 85 } 86 if (!_ignore) { 88 typeCheckContents(stable); 89 } 90 return Type.Void; 91 } 92 93 97 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 98 final InstructionList il = methodGen.getInstructionList(); 99 _test.translateDesynthesized(classGen, methodGen); 100 final InstructionHandle truec = il.getEnd(); 102 if (!_ignore) { 103 translateContents(classGen, methodGen); 104 } 105 _test.backPatchFalseList(il.append(NOP)); 106 _test.backPatchTrueList(truec.getNext()); 107 } 108 } 109 | Popular Tags |