- public static class ArrayBuildingTreeFunctor<T> implements TreeFunctor<T,T[]>, ToJava {
-
- public void toJava(StringBuffer sb) { sb.append("new Tree.ArrayBuildingTreeFunctor()"); }
- public String toString() { return ""; }
-
- public T[] invoke(Iterable<Tree<T>> t) {
- ArrayList ret = new ArrayList();
- for(Tree tc : t) {
- if (tc.head() != null && tc.head() instanceof Functor)
- ret.add(((Functor<Iterable<Tree>,Object>)tc.head()).invoke(tc.children()));
- else if (tc.numChildren() == 0)
- ret.add(tc.head());
- else {
- System.err.println("FIXME: don't know what to do about " + tc);
- ret.add(null);
- }
- }
- return (T[])ret.toArray(new Object[0]);
+ /** 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.head = 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();