1 package org.python.parser.ast; 3 import org.python.parser.SimpleNode; 4 import java.io.DataOutputStream ; 5 import java.io.IOException ; 6 7 public class If extends stmtType { 8 public exprType test; 9 public stmtType[] body; 10 public stmtType[] orelse; 11 12 public If(exprType test, stmtType[] body, stmtType[] orelse) { 13 this.test = test; 14 this.body = body; 15 this.orelse = orelse; 16 } 17 18 public If(exprType test, stmtType[] body, stmtType[] orelse, SimpleNode 19 parent) { 20 this(test, body, orelse); 21 this.beginLine = parent.beginLine; 22 this.beginColumn = parent.beginColumn; 23 } 24 25 public String toString() { 26 StringBuffer sb = new StringBuffer ("If["); 27 sb.append("test="); 28 sb.append(dumpThis(this.test)); 29 sb.append(", "); 30 sb.append("body="); 31 sb.append(dumpThis(this.body)); 32 sb.append(", "); 33 sb.append("orelse="); 34 sb.append(dumpThis(this.orelse)); 35 sb.append("]"); 36 return sb.toString(); 37 } 38 39 public void pickle(DataOutputStream ostream) throws IOException { 40 pickleThis(15, ostream); 41 pickleThis(this.test, ostream); 42 pickleThis(this.body, ostream); 43 pickleThis(this.orelse, ostream); 44 } 45 46 public Object accept(VisitorIF visitor) throws Exception { 47 return visitor.visitIf(this); 48 } 49 50 public void traverse(VisitorIF visitor) throws Exception { 51 if (test != null) 52 test.accept(visitor); 53 if (body != null) { 54 for (int i = 0; i < body.length; i++) { 55 if (body[i] != null) 56 body[i].accept(visitor); 57 } 58 } 59 if (orelse != null) { 60 for (int i = 0; i < orelse.length; i++) { 61 if (orelse[i] != null) 62 orelse[i].accept(visitor); 63 } 64 } 65 } 66 67 } 68 | Popular Tags |