From 93a050e5822f37c512936a00d48a3447b0d33715 Mon Sep 17 00:00:00 2001 From: adam Date: Sun, 22 Jan 2006 04:45:14 -0500 Subject: [PATCH] checkpoint darcs-hash:20060122094514-5007d-875b311678a9b359dd8984e4dd598dbd18ed014a.gz --- src/edu/berkeley/sbp/Forest.java | 48 +++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/edu/berkeley/sbp/Forest.java b/src/edu/berkeley/sbp/Forest.java index 786ffad..378c069 100644 --- a/src/edu/berkeley/sbp/Forest.java +++ b/src/edu/berkeley/sbp/Forest.java @@ -18,8 +18,8 @@ public abstract class Forest /*extends PrintableTree>*/ impl /** expand this forest into a set of trees */ public HashSet> expand(boolean toss) { - TreeMaker ret = new TreeMaker(); - visit(ret, new Boolean(toss), null); + TreeMaker ret = new TreeMaker(toss); + visit(ret, null, null); if (toss && ret.size() > 1) throw new Ambiguous(this); return ret; } @@ -34,17 +34,14 @@ public abstract class Forest /*extends PrintableTree>*/ impl // Body ////////////////////////////////////////////////////////////////////////////// protected static interface Body { - TreeMaker expand(boolean toss, int i, TreeMaker h); + TreeMaker expand(int i, TreeMaker h); } - protected static class MyBody extends Forest implements Body /* extends PrintableTree> implements *//*, Invokable>*/ { + protected static class MyBody extends Forest implements Body /* extends PrintableTree> implements */, Invokable, TreeMaker, Integer> { public void visit(Invokable,B,C> ivbc, B b, C c) { ivbc.invoke(this, b, c); } - public void invoke(Tree ivbc, B b, C c) { - //ivbc.invoke(this, b, c); - } private final Input.Location location; private final T tag; @@ -62,31 +59,41 @@ public abstract class Forest /*extends PrintableTree>*/ impl this.singleton = singleton; } - public TreeMaker expand(boolean toss, int i, TreeMaker h) { + public TreeMaker expand(int i, TreeMaker h) { if (singleton) { - tokens[0].visit(h, toss, i); + tokens[0].visit(h, null, i); } else if (i==tokens.length) { h.add(new Tree(null, tag, h.toks.toArray(tree_hint))); } else if (unwrap && i==tokens.length-1) { if (tokens[i] != null) - tokens[i].visit(h, toss, 0); + tokens[i].visit(h, null, 0); } else { - boolean hit = false; - //tokens[i].visit(this, - for(Tree r : tokens[i].expand(toss)) { - hit = true; + //boolean hit = false; + //tokens[i].visit(this, h, i); + + for(Tree r : tokens[i].expand(h.toss)) { + //hit = true; int old = h.toks.size(); h.toks.add(r); - expand(toss, i+1, h); + expand(i+1, h); while(h.toks.size() > old) h.toks.remove(h.toks.size()-1); } + //if (!hit) throw new Error(); } return h; } + public void invoke(Tree r, TreeMaker h, Integer i) { + //hit = true; + int old = h.toks.size(); + h.toks.add(r); + expand(i+1, h); + while(h.toks.size() > old) h.toks.remove(h.toks.size()-1); + //ivbc.invoke(this, b, c); + } protected String headToString() { return null; } protected String headToJava() { return null; } @@ -109,7 +116,8 @@ public abstract class Forest /*extends PrintableTree>*/ impl public void merge(Forest p) { if (p!=this) hp.add(p, true); } public void visit(Invokable,B,C> ivbc, B b, C c) { if (hp==null) return; - for(Forest f : hp) f.visit(ivbc, b, c); + for(Forest f : hp) + f.visit(ivbc, b, c); } public Forest resolve() { return this; } } @@ -117,14 +125,16 @@ public abstract class Forest /*extends PrintableTree>*/ impl public abstract void visit(Invokable,B,C> ivbc, B b, C c); private static class TreeMaker extends HashSet> implements Invokable,Boolean,Integer> { public ArrayList> toks = new ArrayList>(); - public void invoke(Forest.Body bod, Boolean toss, Integer i) { + private boolean toss; + public TreeMaker(boolean toss) { this.toss = toss; } + public void invoke(Forest.Body bod, Boolean o, Integer i) { if (i==null) { ArrayList> toks = this.toks; this.toks = new ArrayList>(); - bod.expand(toss, 0, this); + bod.expand(0, this); this.toks = toks; } else { - bod.expand(toss, i, this); + bod.expand(i, this); } } } -- 1.7.10.4