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 FunctionDef extends stmtType { 8 public String name; 9 public argumentsType args; 10 public stmtType[] body; 11 12 public FunctionDef(String name, argumentsType args, stmtType[] body) { 13 this.name = name; 14 this.args = args; 15 this.body = body; 16 } 17 18 public FunctionDef(String name, argumentsType args, stmtType[] body, 19 SimpleNode parent) { 20 this(name, args, body); 21 this.beginLine = parent.beginLine; 22 this.beginColumn = parent.beginColumn; 23 } 24 25 public String toString() { 26 StringBuffer sb = new StringBuffer ("FunctionDef["); 27 sb.append("name="); 28 sb.append(dumpThis(this.name)); 29 sb.append(", "); 30 sb.append("args="); 31 sb.append(dumpThis(this.args)); 32 sb.append(", "); 33 sb.append("body="); 34 sb.append(dumpThis(this.body)); 35 sb.append("]"); 36 return sb.toString(); 37 } 38 39 public void pickle(DataOutputStream ostream) throws IOException { 40 pickleThis(5, ostream); 41 pickleThis(this.name, ostream); 42 pickleThis(this.args, ostream); 43 pickleThis(this.body, ostream); 44 } 45 46 public Object accept(VisitorIF visitor) throws Exception { 47 return visitor.visitFunctionDef(this); 48 } 49 50 public void traverse(VisitorIF visitor) throws Exception { 51 if (args != null) 52 args.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 } 60 61 } 62 | Popular Tags |