1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import org.apache.xalan.xsltc.compiler.util.BooleanType; 23 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 24 import org.apache.xalan.xsltc.compiler.util.ErrorMsg; 25 import org.apache.xalan.xsltc.compiler.util.MethodGenerator; 26 import org.apache.xalan.xsltc.compiler.util.Type; 27 import org.apache.xalan.xsltc.compiler.util.TypeCheckError; 28 import org.apache.xalan.xsltc.compiler.util.Util; 29 30 35 final class When extends Instruction { 36 37 private Expression _test; 38 private boolean _ignore = false; 39 40 public void display(int indent) { 41 indent(indent); 42 Util.println("When"); 43 indent(indent + IndentIncrement); 44 System.out.print("test "); 45 Util.println(_test.toString()); 46 displayContents(indent + IndentIncrement); 47 } 48 49 public Expression getTest() { 50 return _test; 51 } 52 53 public boolean ignore() { 54 return(_ignore); 55 } 56 57 public void parseContents(Parser parser) { 58 _test = parser.parseExpression(this, "test", null); 59 60 Object result = _test.evaluateAtCompileTime(); 63 if (result != null && result instanceof Boolean ) { 64 _ignore = !((Boolean ) result).booleanValue(); 65 } 66 67 parseChildren(parser); 68 69 if (_test.isDummy()) { 71 reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "test"); 72 } 73 } 74 75 82 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 83 if (_test.typeCheck(stable) instanceof BooleanType == false) { 85 _test = new CastExpr(_test, Type.Boolean); 86 } 87 if (!_ignore) { 89 typeCheckContents(stable); 90 } 91 92 return Type.Void; 93 } 94 95 99 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 100 final ErrorMsg msg = new ErrorMsg(ErrorMsg.STRAY_WHEN_ERR, this); 101 getParser().reportError(Constants.ERROR, msg); 102 } 103 } 104 | Popular Tags |