1 package edu.berkeley.sbp.meta;
2 import edu.berkeley.sbp.util.*;
3 import edu.berkeley.sbp.*;
4 import edu.berkeley.sbp.chr.*;
5 import edu.berkeley.sbp.misc.*;
6 import edu.berkeley.sbp.bind.*;
8 import java.lang.annotation.*;
9 import java.lang.reflect.*;
12 public class Production {
14 public boolean[] drops;
15 public Element[] elements;
16 public String nonTerminal;
18 public Production(String tag, Element[] elements, boolean[] drops) { this(tag, tag, elements, drops); }
19 public Production(String tag, String nonTerminal, Element[] elements, boolean[] drops) {
21 this.elements = elements;
23 this.nonTerminal = nonTerminal;
24 for(int i=0; i<drops.length; i++)
29 public int[] buildSequence(Bindable _bindable) {
30 Annotation[][] annotations = _bindable.getArgAnnotations();
31 Class[] types = _bindable.getArgTypes();
32 String[] names = _bindable.getArgNames();
33 String name = _bindable.getSimpleName();
34 int len = annotations.length;
36 bind.arg[] argtags = new bind.arg[len];
37 for(int i=0; i<names.length; i++)
38 for(Annotation a : annotations[i+ofs])
39 if (a instanceof bind.arg)
40 argtags[i+ofs] = (bind.arg)a;
43 boolean hasloc = types.length>0 && types[0]==Input.Region.class;
44 for(int i=0; i<argtags.length; i++) {
45 if (i==0 && types[0]==Input.Region.class) continue;
46 if (argtags[i] != null)
49 int numNames = names.length;
50 if (hasloc) numNames--;
52 // FIXME: can be smarter here
53 if (argTagged==count) {
54 int[] ret = new int[argtags.length];
56 for(int i=0; i<argtags.length; i++) {
57 if (i==0 && types[0]==Input.Region.class) continue;
58 if (argtags[i]==null) continue;
59 if (argtags[i].value().equals(""))
63 for(int k=0; k<names.length; k++)
64 if (argtags[i].value().equals(names[k])){
68 if (ret[i]==-1) return null;
72 } else if (numNames==count) {
73 int[] ret = new int[count];
74 for(int i=0; i<count; i++) ret[i] = i+(hasloc?1:0);