1 package net.sf.saxon.instruct; 2 import net.sf.saxon.expr.*; 3 import net.sf.saxon.om.NamePool; 4 import net.sf.saxon.style.StandardNames; 5 import net.sf.saxon.trans.XPathException; 6 import net.sf.saxon.type.ItemType; 7 8 import java.io.PrintStream ; 9 import java.util.Iterator ; 10 11 12 17 18 public class While extends Instruction { 19 20 private Expression test; 21 private Expression action; 22 23 public While(Expression test, Expression action) { 24 this.test = test; 25 this.action = action; 26 adoptChildExpression(test); 27 adoptChildExpression(action); 28 } 29 30 34 35 public int getInstructionNameCode() { 36 return StandardNames.SAXON_WHILE; 37 } 38 39 42 43 public Expression getActionExpression() { 44 return action; 45 } 46 47 55 56 public Expression simplify(StaticContext env) throws XPathException { 57 test = test.simplify(env); 58 action = action.simplify(env); 59 return this; 60 } 61 62 public Expression typeCheck(StaticContext env, ItemType contextItemType) throws XPathException { 63 test = test.typeCheck(env, contextItemType); 64 adoptChildExpression(test); 65 action = action.typeCheck(env, contextItemType); 66 adoptChildExpression(action); 67 return this; 68 } 69 70 public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType) throws XPathException { 71 test = test.optimize(opt, env, contextItemType); 72 adoptChildExpression(test); 73 action = action.optimize(opt, env, contextItemType); 74 adoptChildExpression(action); 75 return this; 76 } 77 78 79 84 85 public ItemType getItemType() { 86 return action.getItemType(); 87 } 88 89 94 95 protected void promoteInst(PromotionOffer offer) throws XPathException { 96 test = doPromotion(test, offer); 97 action = doPromotion(action, offer); 98 } 99 100 105 106 public final boolean createsNewNodes() { 107 int props = action.getSpecialProperties(); 108 return ((props & StaticProperty.NON_CREATIVE) == 0); 109 } 110 111 116 117 public Iterator iterateSubExpressions() { 118 return new PairIterator(test, action); 119 } 120 121 public TailCall processLeavingTail(XPathContext context) throws XPathException { 122 while (test.effectiveBooleanValue(context)) { 123 action.process(context); 124 } 125 return null; 126 } 127 128 129 136 137 public void display(int level, NamePool pool, PrintStream out) { 138 out.println(ExpressionTool.indent(level) + "while"); 139 test.display(level+1, pool, out); 140 out.println(ExpressionTool.indent(level) + "do"); 141 action.display(level+1, pool, out); 142 } 143 } 144 145 | Popular Tags |