- public String toString() {
- StringBuffer ret = new StringBuffer();
- for(int i=0; i<children.length; i++) {
- String q = children[i]==null ? "null" : children[i].toString();
- if (q.length() > 0) { ret.append(q); ret.append(" "); }
+ /** get the input region that this tree was parsed from */
+ public Input.Region getRegion() { return location; }
+
+ public Tree(Input.Region loc, NodeType head) { this(loc, head, null); }
+ public Tree(Input.Region loc, NodeType head, Tree<NodeType>[] children) { this(loc, head, children, false); }
+
+ /** package-private constructor, allows setting the "lift" bit */
+ Tree(Input.Region loc, NodeType head, Tree<NodeType>[] children, boolean lift) {
+ this.location = loc;
+ this.ihead = head;
+ this.lift = lift && children != null && children.length > 0;
+ this.children = ArrayUtil.clone(children, Tree.class);
+ }
+
+
+ // PrintableTree /////////////////////////////////////////////////////////////////////////////
+
+ protected String headToString() { return head()==null?null:head().toString(); }
+ protected String headToJava() {
+ // FIXME
+ if (head()==null) return null;
+ if (head() instanceof ToJava) {
+ StringBuffer sb = new StringBuffer();
+ ((ToJava)head()).toJava(sb);
+ return sb.toString();