public TreeBindable(Bindable b) { this._bindable = b; }
private int[] buildSequence(Production p) {
- Annotation[][] annotations = _bindable.getArgAnnotations();
- Class[] types = _bindable.getArgTypes();
- String[] names = _bindable.getArgNames();
- String name = _bindable.getSimpleName();
- int len = annotations.length;
- int ofs = 0;
- bind.arg[] argtags = new bind.arg[len];
- for(int i=0; i<names.length; i++)
- for(Annotation a : annotations[i+ofs])
- if (a instanceof bind.arg)
- argtags[i+ofs] = (bind.arg)a;
- return TreeBindable.this.buildSequence(p, names, argtags, types);
+ return p.buildSequence(_bindable);
}
public String getName() { return _bindable.getSimpleName(); }
return false;
}
- private int[] buildSequence(Production p, String[] names, bind.arg[] argtags, Class[] types) {
- int argTagged = 0;
- boolean hasloc = types.length>0 && types[0]==Input.Region.class;
- for(int i=0; i<argtags.length; i++) {
- if (i==0 && types[0]==Input.Region.class) continue;
- if (argtags[i] != null)
- argTagged++;
- }
- int numNames = names.length;
- if (hasloc) numNames--;
-
- // FIXME: can be smarter here
- if (argTagged==p.count) {
- int[] ret = new int[argtags.length];
- int j = 0;
- for(int i=0; i<argtags.length; i++) {
- if (i==0 && types[0]==Input.Region.class) continue;
- if (argtags[i]==null) continue;
- if (argtags[i].value().equals(""))
- ret[i] = j++;
- else {
- ret[i] = -1;
- for(int k=0; k<names.length; k++)
- if (argtags[i].value().equals(names[k])){
- ret[i] = k;
- break;
- }
- if (ret[i]==-1) return null;
- }
- }
- return ret;
- } else if (numNames==p.count) {
- int[] ret = new int[p.count];
- for(int i=0; i<p.count; i++) ret[i] = i+(hasloc?1:0);
- return ret;
- } else {
- return null;
- }
- }
public Sequence makeSequence(final Production p) {
if (_bindable.getArgTypes().length > 0 &&
}
}
Object[] o = (Object[])ret.toArray(new Object[0]);
- int max = 0;
- for(int i=0; i<map.length; i++) max = Math.max(map[i], max);
- Object[] o2 = new Object[max+1];
- for(int i=0; i<o.length; i++) o2[map[i]] = o[i];
- return _bindable.impose(o2);
+ return _bindable.createBinding(map).invoke(o);
}
}
if (!drops[i])
count++;
}
+
+ public int[] buildSequence(Bindable _bindable) {
+ Annotation[][] annotations = _bindable.getArgAnnotations();
+ Class[] types = _bindable.getArgTypes();
+ String[] names = _bindable.getArgNames();
+ String name = _bindable.getSimpleName();
+ int len = annotations.length;
+ int ofs = 0;
+ bind.arg[] argtags = new bind.arg[len];
+ for(int i=0; i<names.length; i++)
+ for(Annotation a : annotations[i+ofs])
+ if (a instanceof bind.arg)
+ argtags[i+ofs] = (bind.arg)a;
+
+ int argTagged = 0;
+ boolean hasloc = types.length>0 && types[0]==Input.Region.class;
+ for(int i=0; i<argtags.length; i++) {
+ if (i==0 && types[0]==Input.Region.class) continue;
+ if (argtags[i] != null)
+ argTagged++;
+ }
+ int numNames = names.length;
+ if (hasloc) numNames--;
+
+ // FIXME: can be smarter here
+ if (argTagged==count) {
+ int[] ret = new int[argtags.length];
+ int j = 0;
+ for(int i=0; i<argtags.length; i++) {
+ if (i==0 && types[0]==Input.Region.class) continue;
+ if (argtags[i]==null) continue;
+ if (argtags[i].value().equals(""))
+ ret[i] = j++;
+ else {
+ ret[i] = -1;
+ for(int k=0; k<names.length; k++)
+ if (argtags[i].value().equals(names[k])){
+ ret[i] = k;
+ break;
+ }
+ if (ret[i]==-1) return null;
+ }
+ }
+ return ret;
+ } else if (numNames==count) {
+ int[] ret = new int[count];
+ for(int i=0; i<count; i++) ret[i] = i+(hasloc?1:0);
+ return ret;
+ } else {
+ return null;
+ }
+ }
+
}