public void buildtree(ParseNode pn, Set toanalyze, String sourcefile) {
parseFile(pn, toanalyze, sourcefile);
-
+
// numering the interfaces
int if_num = 0;
Iterator it_classes = state.getClassSymbolTable().getValueSet().iterator();
while(it_classes.hasNext()) {
ClassDescriptor cd = (ClassDescriptor)it_classes.next();
if(cd.isInterface()) {
- cd.setInterfaceId(if_num++);
+ cd.setInterfaceId(if_num++);
}
}
}
//This is all single imports and a subset of the
- //multi imports that have been resolved.
+ //multi imports that have been resolved.
Hashtable mandatoryImports;
//maps class names in file to full name
- //Note may map a name to an ERROR.
+ //Note may map a name to an ERROR.
Hashtable multiimports;
NameDescriptor packages;
public void parseFile(ParseNode pn, Set toanalyze, String sourcefile) {
mandatoryImports = new Hashtable();
multiimports = new Hashtable();
-
+
if(state.JNI) {
//add java.lang as our default multi-import
this.addMultiImport(sourcefile, "java.lang", false);
}
-
+
ParseNode ipn = pn.getChild("imports").getChild("import_decls_list");
if (ipn != null) {
ParseNodeVector pnv = ipn.getChildren();
for (int i = 0; i < pnv.size(); i++) {
- ParseNode pnimport = pnv.elementAt(i);
- NameDescriptor nd = parseName(pnimport.getChild("name"));
- if (isNode(pnimport, "import_single")) {
- if (!mandatoryImports.containsKey(nd.getIdentifier())) {
- // map name to full name (includes package/directory
- mandatoryImports.put(nd.getIdentifier(), nd.getPathFromRootToHere());
- } else {
- throw new Error("An ambiguous class "+ nd.getIdentifier() +" has been found. It is included for " +
- ((String)mandatoryImports.get(nd.getIdentifier())) + " and " +
- nd.getPathFromRootToHere());
- }
- }
- else {
- addMultiImport(sourcefile, nd.getPathFromRootToHere(), false);
- }
+ ParseNode pnimport = pnv.elementAt(i);
+ NameDescriptor nd = parseName(pnimport.getChild("name"));
+ if (isNode(pnimport, "import_single")) {
+ if (!mandatoryImports.containsKey(nd.getIdentifier())) {
+ // map name to full name (includes package/directory
+ mandatoryImports.put(nd.getIdentifier(), nd.getPathFromRootToHere());
+ } else {
+ throw new Error("An ambiguous class "+ nd.getIdentifier() +" has been found. It is included for " +
+ ((String)mandatoryImports.get(nd.getIdentifier())) + " and " +
+ nd.getPathFromRootToHere());
+ }
+ } else {
+ addMultiImport(sourcefile, nd.getPathFromRootToHere(), false);
+ }
}
}
-
+
ParseNode ppn=pn.getChild("packages").getChild("package");
String packageName = null;
if (ppn!=null) {
NameDescriptor nd = parseClassName(ppn.getChild("name"));
- packageName = nd.getPathFromRootToHere();
- //Trick -> import the package directory as a multi-import and it'll
+ packageName = nd.getPathFromRootToHere();
+ //Trick -> import the package directory as a multi-import and it'll
//automatically recognize files in the same directory.
addMultiImport(sourcefile, packageName, true);
}
-
+
ParseNode tpn=pn.getChild("type_declaration_list");
if (tpn != null) {
ParseNodeVector pnv = tpn.getChildren();
for (int i = 0; i < pnv.size(); i++) {
- ParseNode type_pn = pnv.elementAt(i);
- if (isEmpty(type_pn)) /* Skip the semicolon */
- continue;
- if (isNode(type_pn, "class_declaration")) {
- ClassDescriptor cn = parseTypeDecl(type_pn, packageName);
- cn.setSourceFileName(sourcefile);
- parseInitializers(cn);
- if (toanalyze != null)
- toanalyze.add(cn);
- state.addClass(cn);
- // for inner classes/enum
- HashSet tovisit = new HashSet();
- Iterator it_icds = cn.getInnerClasses();
- while (it_icds.hasNext()) {
- tovisit.add(it_icds.next());
- }
-
- while (!tovisit.isEmpty()) {
- ClassDescriptor cd = (ClassDescriptor) tovisit.iterator().next();
- tovisit.remove(cd);
- parseInitializers(cd);
- if (toanalyze != null) {
- toanalyze.add(cd);
- }
- cd.setSourceFileName(sourcefile);
- state.addClass(cd);
-
- Iterator it_ics = cd.getInnerClasses();
- while (it_ics.hasNext()) {
- tovisit.add(it_ics.next());
- }
-
- Iterator it_ienums = cd.getEnum();
- while (it_ienums.hasNext()) {
- ClassDescriptor iecd = (ClassDescriptor) it_ienums.next();
- if (toanalyze != null) {
- toanalyze.add(iecd);
- }
- iecd.setSourceFileName(sourcefile);
- state.addClass(iecd);
- }
- }
-
- Iterator it_enums = cn.getEnum();
- while (it_enums.hasNext()) {
- ClassDescriptor ecd = (ClassDescriptor) it_enums.next();
- if (toanalyze != null) {
- toanalyze.add(ecd);
- }
- ecd.setSourceFileName(sourcefile);
- state.addClass(ecd);
- }
- } else if (isNode(type_pn, "task_declaration")) {
- TaskDescriptor td = parseTaskDecl(type_pn);
- if (toanalyze != null)
- toanalyze.add(td);
- state.addTask(td);
- } else if (isNode(type_pn, "interface_declaration")) {
- // TODO add version for normal Java later
- ClassDescriptor cn = parseInterfaceDecl(type_pn, packageName);
- if (toanalyze != null)
- toanalyze.add(cn);
- cn.setSourceFileName(sourcefile);
- state.addClass(cn);
-
- // for enum
- Iterator it_enums = cn.getEnum();
- while (it_enums.hasNext()) {
- ClassDescriptor ecd = (ClassDescriptor) it_enums.next();
- if (toanalyze != null) {
- toanalyze.add(ecd);
- }
- ecd.setSourceFileName(sourcefile);
- state.addClass(ecd);
- }
- } else if (isNode(type_pn, "enum_declaration")) {
- // TODO add version for normal Java later
- ClassDescriptor cn = parseEnumDecl(null, type_pn);
- if (toanalyze != null)
- toanalyze.add(cn);
- cn.setSourceFileName(sourcefile);
- state.addClass(cn);
- } else if(isNode(type_pn,"annotation_type_declaration")){
- ClassDescriptor cn=parseAnnotationTypeDecl(type_pn);
- if (toanalyze != null)
- toanalyze.add(cn);
- cn.setSourceFileName(sourcefile);
- state.addClass(cn);
- } else {
- throw new Error(type_pn.getLabel());
- }
+ ParseNode type_pn = pnv.elementAt(i);
+ if (isEmpty(type_pn)) /* Skip the semicolon */
+ continue;
+ if (isNode(type_pn, "class_declaration")) {
+ ClassDescriptor cn = parseTypeDecl(type_pn, packageName);
+ cn.setSourceFileName(sourcefile);
+ parseInitializers(cn);
+ if (toanalyze != null)
+ toanalyze.add(cn);
+ state.addClass(cn);
+ // for inner classes/enum
+ HashSet tovisit = new HashSet();
+ Iterator it_icds = cn.getInnerClasses();
+ while (it_icds.hasNext()) {
+ tovisit.add(it_icds.next());
+ }
+
+ while (!tovisit.isEmpty()) {
+ ClassDescriptor cd = (ClassDescriptor) tovisit.iterator().next();
+ tovisit.remove(cd);
+ parseInitializers(cd);
+ if (toanalyze != null) {
+ toanalyze.add(cd);
+ }
+ cd.setSourceFileName(sourcefile);
+ state.addClass(cd);
+
+ Iterator it_ics = cd.getInnerClasses();
+ while (it_ics.hasNext()) {
+ tovisit.add(it_ics.next());
+ }
+
+ Iterator it_ienums = cd.getEnum();
+ while (it_ienums.hasNext()) {
+ ClassDescriptor iecd = (ClassDescriptor) it_ienums.next();
+ if (toanalyze != null) {
+ toanalyze.add(iecd);
+ }
+ iecd.setSourceFileName(sourcefile);
+ state.addClass(iecd);
+ }
+ }
+
+ Iterator it_enums = cn.getEnum();
+ while (it_enums.hasNext()) {
+ ClassDescriptor ecd = (ClassDescriptor) it_enums.next();
+ if (toanalyze != null) {
+ toanalyze.add(ecd);
+ }
+ ecd.setSourceFileName(sourcefile);
+ state.addClass(ecd);
+ }
+ } else if (isNode(type_pn, "task_declaration")) {
+ TaskDescriptor td = parseTaskDecl(type_pn);
+ if (toanalyze != null)
+ toanalyze.add(td);
+ state.addTask(td);
+ } else if (isNode(type_pn, "interface_declaration")) {
+ // TODO add version for normal Java later
+ ClassDescriptor cn = parseInterfaceDecl(type_pn, packageName);
+ if (toanalyze != null)
+ toanalyze.add(cn);
+ cn.setSourceFileName(sourcefile);
+ state.addClass(cn);
+
+ // for enum
+ Iterator it_enums = cn.getEnum();
+ while (it_enums.hasNext()) {
+ ClassDescriptor ecd = (ClassDescriptor) it_enums.next();
+ if (toanalyze != null) {
+ toanalyze.add(ecd);
+ }
+ ecd.setSourceFileName(sourcefile);
+ state.addClass(ecd);
+ }
+ } else if (isNode(type_pn, "enum_declaration")) {
+ // TODO add version for normal Java later
+ ClassDescriptor cn = parseEnumDecl(null, type_pn);
+ if (toanalyze != null)
+ toanalyze.add(cn);
+ cn.setSourceFileName(sourcefile);
+ state.addClass(cn);
+ } else if(isNode(type_pn,"annotation_type_declaration")) {
+ ClassDescriptor cn=parseAnnotationTypeDecl(type_pn);
+ if (toanalyze != null)
+ toanalyze.add(cn);
+ cn.setSourceFileName(sourcefile);
+ state.addClass(cn);
+ } else {
+ throw new Error(type_pn.getLabel());
+ }
}
}
}
-
-
-
+
+
+
//This kind of breaks away from tradition a little bit by doing the file checks here
// instead of in Semantic check, but doing it here is easier because we have a mapping early on
// if I wait until semantic check, I have to change ALL the type descriptors to match the new
String path = (String) state.classpath.get(j);
File folder = new File(path, importPath.replace('.', '/'));
if (folder.exists()) {
- found = true;
- for (String file : folder.list()) {
- // if the file is of type *.java add to multiImport list.
- if (file.lastIndexOf('.') != -1 && file.substring(file.lastIndexOf('.')).equalsIgnoreCase(".java")) {
- String classname = file.substring(0, file.length() - 5);
- // single imports have precedence over multi-imports
- if (!mandatoryImports.containsKey(classname)) {
- //package files have precedence over multi-imports.
- if (multiimports.containsKey(classname) && !isPackageDirectory) {
- // put error in for later, in case we try to import
- multiimports.put(classname, new Error("Error: class " + classname + " is defined more than once in a multi-import in " + currentSource));
- } else {
- multiimports.put(classname, importPath + "." + classname);
- }
- }
- }
- }
+ found = true;
+ for (String file : folder.list()) {
+ // if the file is of type *.java add to multiImport list.
+ if (file.lastIndexOf('.') != -1 && file.substring(file.lastIndexOf('.')).equalsIgnoreCase(".java")) {
+ String classname = file.substring(0, file.length() - 5);
+ // single imports have precedence over multi-imports
+ if (!mandatoryImports.containsKey(classname)) {
+ //package files have precedence over multi-imports.
+ if (multiimports.containsKey(classname) && !isPackageDirectory) {
+ // put error in for later, in case we try to import
+ multiimports.put(classname, new Error("Error: class " + classname + " is defined more than once in a multi-import in " + currentSource));
+ } else {
+ multiimports.put(classname, importPath + "." + classname);
+ }
+ }
+ }
+ }
}
}
-
-
+
+
if(!found) {
throw new Error("Import package " + importPath + " in " + currentSource
- + " cannot be resolved.");
+ + " cannot be resolved.");
}
}
- public void parseInitializers(ClassDescriptor cn){
+ public void parseInitializers(ClassDescriptor cn) {
Vector fv=cn.getFieldVec();
int pos = 0;
- for(int i=0;i<fv.size();i++) {
+ for(int i=0; i<fv.size(); i++) {
FieldDescriptor fd=(FieldDescriptor)fv.get(i);
if(fd.getExpressionNode()!=null) {
Iterator methodit = cn.getMethods();
- while(methodit.hasNext()){
+ while(methodit.hasNext()) {
MethodDescriptor currmd=(MethodDescriptor)methodit.next();
- if(currmd.isConstructor()){
+ if(currmd.isConstructor()) {
BlockNode bn=state.getMethodBody(currmd);
NameNode nn=new NameNode(new NameDescriptor(fd.getSymbol()));
AssignmentNode an=new AssignmentNode(nn,fd.getExpressionNode(),new AssignOperation(1));
pos++;
}
}
- }
-
+ }
+
private ClassDescriptor parseEnumDecl(ClassDescriptor cn, ParseNode pn) {
ClassDescriptor ecd=new ClassDescriptor(pn.getChild("name").getTerminal(), false);
ecd.setImports(mandatoryImports);
cn.addEnum(ecd);
}
if (!(ecd.getSymbol().equals(TypeUtil.ObjectClass)||
- ecd.getSymbol().equals(TypeUtil.TagClass))) {
+ ecd.getSymbol().equals(TypeUtil.TagClass))) {
ecd.setSuper(TypeUtil.ObjectClass);
}
ecd.setModifiers(parseModifiersList(pn.getChild("modifiers")));
parseEnumBody(ecd, pn.getChild("enumbody"));
return ecd;
}
-
+
private void parseEnumBody(ClassDescriptor cn, ParseNode pn) {
ParseNode decls=pn.getChild("enum_constants_list");
if (decls!=null) {
ParseNodeVector pnv=decls.getChildren();
for(int i=0; i<pnv.size(); i++) {
- ParseNode decl=pnv.elementAt(i);
- if (isNode(decl,"enum_constant")) {
- parseEnumConstant(cn,decl);
- } else throw new Error();
+ ParseNode decl=pnv.elementAt(i);
+ if (isNode(decl,"enum_constant")) {
+ parseEnumConstant(cn,decl);
+ } else throw new Error();
}
}
}
-
+
private void parseEnumConstant(ClassDescriptor cn, ParseNode pn) {
cn.addEnumConstant(pn.getChild("name").getTerminal());
}
-
- private ClassDescriptor parseAnnotationTypeDecl(ParseNode pn){
+
+ private ClassDescriptor parseAnnotationTypeDecl(ParseNode pn) {
ClassDescriptor cn=new ClassDescriptor(pn.getChild("name").getTerminal(), true);
cn.setImports(mandatoryImports);
ParseNode modifiers=pn.getChild("modifiers");
- if(modifiers!=null){
+ if(modifiers!=null) {
cn.setModifiers(parseModifiersList(modifiers));
}
parseAnnotationTypeBody(cn,pn.getChild("body"));
return cn;
}
-
- private void parseAnnotationTypeBody(ClassDescriptor cn, ParseNode pn){
+
+ private void parseAnnotationTypeBody(ClassDescriptor cn, ParseNode pn) {
ParseNode list_node=pn.getChild("annotation_type_element_list");
- if(list_node!=null){
+ if(list_node!=null) {
ParseNodeVector pnv = list_node.getChildren();
for (int i = 0; i < pnv.size(); i++) {
- ParseNode element_node = pnv.elementAt(i);
- if (isNode(element_node, "annotation_type_element_declaration")) {
- ParseNodeVector elementProps = element_node.getChildren();
- String identifier=null;
- TypeDescriptor type=null;
- Modifiers modifiers=new Modifiers();
- for(int eidx=0; eidx<elementProps.size(); eidx++) {
- ParseNode prop_node=elementProps.elementAt(eidx);
- if(isNode(prop_node,"name")){
- identifier=prop_node.getTerminal();
- }else if(isNode(prop_node,"type")){
- type=parseTypeDescriptor(prop_node);
- }else if(isNode(prop_node,"modifier")){
- modifiers=parseModifiersList(prop_node);
- }
- }
- cn.addField(new FieldDescriptor(modifiers, type, identifier, null, false));
- }
+ ParseNode element_node = pnv.elementAt(i);
+ if (isNode(element_node, "annotation_type_element_declaration")) {
+ ParseNodeVector elementProps = element_node.getChildren();
+ String identifier=null;
+ TypeDescriptor type=null;
+ Modifiers modifiers=new Modifiers();
+ for(int eidx=0; eidx<elementProps.size(); eidx++) {
+ ParseNode prop_node=elementProps.elementAt(eidx);
+ if(isNode(prop_node,"name")) {
+ identifier=prop_node.getTerminal();
+ } else if(isNode(prop_node,"type")) {
+ type=parseTypeDescriptor(prop_node);
+ } else if(isNode(prop_node,"modifier")) {
+ modifiers=parseModifiersList(prop_node);
+ }
+ }
+ cn.addField(new FieldDescriptor(modifiers, type, identifier, null, false));
+ }
}
}
}
-
+
public ClassDescriptor parseInterfaceDecl(ParseNode pn, String packageName) {
ClassDescriptor cn;
if(packageName == null) {
- cn=new ClassDescriptor(pn.getChild("name").getTerminal(), true);
+ cn=new ClassDescriptor(pn.getChild("name").getTerminal(), true);
} else {
String newClassname = packageName + "." + pn.getChild("name").getTerminal();
cn= new ClassDescriptor(packageName, newClassname, true);
}
-
+
cn.setImports(mandatoryImports);
//cn.setAsInterface();
if (!isEmpty(pn.getChild("superIF").getTerminal())) {
ParseNode snlist=pn.getChild("superIF").getChild("extend_interface_list");
ParseNodeVector pnv=snlist.getChildren();
for(int i=0; i<pnv.size(); i++) {
- ParseNode decl=pnv.elementAt(i);
- if (isNode(decl,"type")) {
- NameDescriptor nd=parseClassName(decl.getChild("class").getChild("name"));
- cn.addSuperInterface(nd.toString());
- }
+ ParseNode decl=pnv.elementAt(i);
+ if (isNode(decl,"type")) {
+ NameDescriptor nd=parseClassName(decl.getChild("class").getChild("name"));
+ cn.addSuperInterface(nd.toString());
+ }
}
}
cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
parseInterfaceBody(cn, pn.getChild("interfacebody"));
return cn;
}
-
+
private void parseInterfaceBody(ClassDescriptor cn, ParseNode pn) {
assert(cn.isInterface());
ParseNode decls=pn.getChild("interface_member_declaration_list");
if (decls!=null) {
ParseNodeVector pnv=decls.getChildren();
for(int i=0; i<pnv.size(); i++) {
- ParseNode decl=pnv.elementAt(i);
- if (isNode(decl,"constant")) {
- parseInterfaceConstant(cn,decl);
- } else if (isNode(decl,"method")) {
- parseInterfaceMethod(cn,decl.getChild("method_declaration"));
- } else throw new Error();
+ ParseNode decl=pnv.elementAt(i);
+ if (isNode(decl,"constant")) {
+ parseInterfaceConstant(cn,decl);
+ } else if (isNode(decl,"method")) {
+ parseInterfaceMethod(cn,decl.getChild("method_declaration"));
+ } else throw new Error();
}
}
}
-
-
-
+
+
+
private void parseInterfaceConstant(ClassDescriptor cn, ParseNode pn) {
if (pn!=null) {
parseFieldDecl(cn,pn.getChild("field_declaration"));
}
throw new Error();
}
-
+
private void parseInterfaceMethod(ClassDescriptor cn, ParseNode pn) {
ParseNode headern=pn.getChild("header");
ParseNode bodyn=pn.getChild("body");
// at the AST level, someday should evolve into a nice compiler
// option *wink*
//if( cn.getSymbol().equals( ***put a class in here like: "Test" ) &&
- // md.getSymbol().equals( ***put your method in here like: "main" )
+ // md.getSymbol().equals( ***put your method in here like: "main" )
//) {
// bn.setStyle( BlockNode.NORMAL );
// System.out.println( bn.printNode( 0 ) );
paramn = paramn.getChild("optional").getFirstChild();
System.out.println("OPTIONAL FOUND!!!!!!!");
} else { optional = false;
- System.out.println("NOT OPTIONAL");}
-
+ System.out.println("NOT OPTIONAL"); }
+
TypeDescriptor type=parseTypeDescriptor(paramn);
String paramname=paramn.getChild("single").getTerminal();
ParseNode snlist=pn.getChild("superIF").getChild("interface_type_list");
ParseNodeVector pnv=snlist.getChildren();
for(int i=0; i<pnv.size(); i++) {
- ParseNode decl=pnv.elementAt(i);
- if (isNode(decl,"type")) {
- NameDescriptor nd=parseClassName(decl.getChild("class").getChild("name"));
- cn.addSuperInterface(nd.toString());
- }
+ ParseNode decl=pnv.elementAt(i);
+ if (isNode(decl,"type")) {
+ NameDescriptor nd=parseClassName(decl.getChild("class").getChild("name"));
+ cn.addSuperInterface(nd.toString());
+ }
}
}
cn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
parseClassBody(cn, pn.getChild("classbody"));
-
+
boolean hasConstructor = false;
- for(Iterator method_it=cn.getMethods(); method_it.hasNext();) {
+ for(Iterator method_it=cn.getMethods(); method_it.hasNext(); ) {
MethodDescriptor md=(MethodDescriptor)method_it.next();
hasConstructor |= md.isConstructor();
}
if((!hasConstructor) && (!cn.isEnum())) {
// add a default constructor for this class
MethodDescriptor md = new MethodDescriptor(new Modifiers(Modifiers.PUBLIC),
- cn.getSymbol(), false);
+ cn.getSymbol(), false);
BlockNode bn=new BlockNode();
state.addTreeCode(md,bn);
md.setDefaultConstructor();
}
}
}
-
+
private void parseLocationOrder(ClassDescriptor cd, ParseNode pn) {
ParseNodeVector pnv = pn.getChildren();
Lattice<String> locOrder =
- new Lattice<String>("_top_","_bottom_");
+ new Lattice<String>("_top_","_bottom_");
Set<String> spinLocSet=new HashSet<String>();
for (int i = 0; i < pnv.size(); i++) {
ParseNode loc = pnv.elementAt(i);
- if(isNode(loc,"location_property")){
- String spinLoc=loc.getChildren().elementAt(0).getLabel();
- spinLocSet.add(spinLoc);
+ if(isNode(loc,"location_property")) {
+ String spinLoc=loc.getChildren().elementAt(0).getLabel();
+ spinLocSet.add(spinLoc);
} else {
- String lowerLoc=loc.getChildren().elementAt(0).getLabel();
- String higherLoc= loc.getChildren().elementAt(1).getLabel();
- locOrder.put(higherLoc, lowerLoc);
- if (locOrder.isIntroducingCycle(higherLoc)) {
- throw new Error("Error: the order relation " + lowerLoc + " < " + higherLoc
- + " introduces a cycle.");
- }
+ String lowerLoc=loc.getChildren().elementAt(0).getLabel();
+ String higherLoc= loc.getChildren().elementAt(1).getLabel();
+ locOrder.put(higherLoc, lowerLoc);
+ if (locOrder.isIntroducingCycle(higherLoc)) {
+ throw new Error("Error: the order relation " + lowerLoc + " < " + higherLoc
+ + " introduces a cycle.");
+ }
}
}
- if(spinLocSet.size()>0){
+ if(spinLocSet.size()>0) {
//checking if location is actually defined in the hierarchy
- for (Iterator iterator = spinLocSet.iterator(); iterator.hasNext();) {
- String locID = (String) iterator.next();
- if(!locOrder.containsKey(locID)){
- throw new Error("Error: The spinning location '"+
- locID + "' is not defined in the hierarchy of the class '"+cd +"'.");
- }
+ for (Iterator iterator = spinLocSet.iterator(); iterator.hasNext(); ) {
+ String locID = (String) iterator.next();
+ if(!locOrder.containsKey(locID)) {
+ throw new Error("Error: The spinning location '"+
+ locID + "' is not defined in the hierarchy of the class '"+cd +"'.");
+ }
}
state.addLocationPropertySet(cd, spinLocSet);
}
state.addLocationOrder(cd, locOrder);
}
-
+
private void parseClassMember(ClassDescriptor cn, ParseNode pn) {
ParseNode fieldnode=pn.getChild("field");
if (fieldnode!=null) {
}
throw new Error();
}
-
+
private ClassDescriptor parseInnerClassDecl(ClassDescriptor cn, ParseNode pn) {
ClassDescriptor icn=new ClassDescriptor(pn.getChild("name").getTerminal(), false);
icn.setImports(mandatoryImports);
icn.setSuper(nd.toString());
} else {
if (!(icn.getSymbol().equals(TypeUtil.ObjectClass)||
- icn.getSymbol().equals(TypeUtil.TagClass)))
- icn.setSuper(TypeUtil.ObjectClass);
+ icn.getSymbol().equals(TypeUtil.TagClass)))
+ icn.setSuper(TypeUtil.ObjectClass);
}
// check inherited interfaces
if (!isEmpty(pn.getChild("superIF").getTerminal())) {
ParseNode snlist=pn.getChild("superIF").getChild("interface_type_list");
ParseNodeVector pnv=snlist.getChildren();
for(int i=0; i<pnv.size(); i++) {
- ParseNode decl=pnv.elementAt(i);
- if (isNode(decl,"type")) {
- NameDescriptor nd=parseClassName(decl.getChild("class").getChild("name"));
- icn.addSuperInterface(nd.toString());
- }
+ ParseNode decl=pnv.elementAt(i);
+ if (isNode(decl,"type")) {
+ NameDescriptor nd=parseClassName(decl.getChild("class").getChild("name"));
+ icn.addSuperInterface(nd.toString());
+ }
}
}
icn.setModifiers(parseModifiersList(pn.getChild("modifiers")));
if(!icn.isStatic()) {
- throw new Error("Error: inner class " + icn.getSymbol() + " in Class " +
- cn.getSymbol() + " is not a nested class and is not supported yet!");
+ throw new Error("Error: inner class " + icn.getSymbol() + " in Class " +
+ cn.getSymbol() + " is not a nested class and is not supported yet!");
}
parseClassBody(icn, pn.getChild("classbody"));
return icn;
}
}
- //Needed to separate out top level call since if a base exists,
+ //Needed to separate out top level call since if a base exists,
//we do not want to apply our resolveName function (i.e. deal with imports)
- //otherwise, if base == null, we do just want to resolve name.
+ //otherwise, if base == null, we do just want to resolve name.
private NameDescriptor parseClassName(ParseNode nn) {
ParseNode base=nn.getChild("base");
ParseNode id=nn.getChild("identifier");
}
return new NameDescriptor(parseClassNameRecursive(base.getChild("name")),classname);
}
-
+
private NameDescriptor parseClassNameRecursive(ParseNode nn) {
ParseNode base=nn.getChild("base");
ParseNode id=nn.getChild("identifier");
}
return new NameDescriptor(parseClassNameRecursive(base.getChild("name")),classname);
}
-
+
//This will get the mapping of a terminal class name
//to a canonical classname (with imports/package locations in them)
private String resolveName(String terminal) {
if(mandatoryImports.containsKey(terminal)) {
- return (String) mandatoryImports.get(terminal);
+ return (String) mandatoryImports.get(terminal);
} else {
if(multiimports.containsKey(terminal)) {
- //Test for error
- Object o = multiimports.get(terminal);
- if(o instanceof Error) {
- throw new Error("Class " + terminal + " is ambiguous. Cause: more than 1 package import contain the same class.");
- } else {
- //At this point, if we found a unique class
- //we can treat it as a single, mandatory import.
- mandatoryImports.put(terminal, o);
- return (String) o;
- }
+ //Test for error
+ Object o = multiimports.get(terminal);
+ if(o instanceof Error) {
+ throw new Error("Class " + terminal + " is ambiguous. Cause: more than 1 package import contain the same class.");
+ } else {
+ //At this point, if we found a unique class
+ //we can treat it as a single, mandatory import.
+ mandatoryImports.put(terminal, o);
+ return (String) o;
+ }
}
}
-
+
return terminal;
}
-
+
//only function difference between this and parseName() is that this
- //does not look for a import mapping.
+ //does not look for a import mapping.
private NameDescriptor parseName(ParseNode nn) {
ParseNode base=nn.getChild("base");
ParseNode id=nn.getChild("identifier");
if(cn.isInterface()) {
// TODO add version for normal Java later
// Can only be PUBLIC or STATIC or FINAL
- if((m.isAbstract()) || (m.isAtomic()) || (m.isNative())
- || (m.isSynchronized())) {
- throw new Error("Error: field in Interface " + cn.getSymbol() + "can only be PUBLIC or STATIC or FINAL");
+ if((m.isAbstract()) || (m.isAtomic()) || (m.isNative())
+ || (m.isSynchronized())) {
+ throw new Error("Error: field in Interface " + cn.getSymbol() + "can only be PUBLIC or STATIC or FINAL");
}
m.addModifier(Modifiers.PUBLIC);
m.addModifier(Modifiers.STATIC);
ExpressionNode en=null;
if (epn!=null) {
- en=parseExpression(epn.getFirstChild());
- en.setNumLine(epn.getFirstChild().getLine());
- if(m.isStatic()) {
- // for static field, the initializer should be considered as a
- // static block
- boolean isfirst = false;
- MethodDescriptor md = (MethodDescriptor)cn.getMethodTable().getFromSameScope("staticblocks");
- if(md == null) {
- // the first static block for this class
- Modifiers m_i=new Modifiers();
- m_i.addModifier(Modifiers.STATIC);
- md = new MethodDescriptor(m_i, "staticblocks", false);
- md.setAsStaticBlock();
- isfirst = true;
- }
- if(isfirst) {
- cn.addMethod(md);
- }
- cn.incStaticBlocks();
- BlockNode bn=new BlockNode();
- NameNode nn=new NameNode(new NameDescriptor(identifier));
- nn.setNumLine(en.getNumLine());
- AssignmentNode an=new AssignmentNode(nn,en,new AssignOperation(1));
- an.setNumLine(pn.getLine());
- bn.addBlockStatement(new BlockExpressionNode(an));
- if(isfirst) {
- state.addTreeCode(md,bn);
- } else {
- BlockNode obn = state.getMethodBody(md);
- for(int ii = 0; ii < bn.size(); ii++) {
- BlockStatementNode bsn = bn.get(ii);
- obn.addBlockStatement(bsn);
- }
- state.addTreeCode(md, obn);
- bn = null;
- }
- en = null;
- }
+ en=parseExpression(epn.getFirstChild());
+ en.setNumLine(epn.getFirstChild().getLine());
+ if(m.isStatic()) {
+ // for static field, the initializer should be considered as a
+ // static block
+ boolean isfirst = false;
+ MethodDescriptor md = (MethodDescriptor)cn.getMethodTable().getFromSameScope("staticblocks");
+ if(md == null) {
+ // the first static block for this class
+ Modifiers m_i=new Modifiers();
+ m_i.addModifier(Modifiers.STATIC);
+ md = new MethodDescriptor(m_i, "staticblocks", false);
+ md.setAsStaticBlock();
+ isfirst = true;
+ }
+ if(isfirst) {
+ cn.addMethod(md);
+ }
+ cn.incStaticBlocks();
+ BlockNode bn=new BlockNode();
+ NameNode nn=new NameNode(new NameDescriptor(identifier));
+ nn.setNumLine(en.getNumLine());
+ AssignmentNode an=new AssignmentNode(nn,en,new AssignOperation(1));
+ an.setNumLine(pn.getLine());
+ bn.addBlockStatement(new BlockExpressionNode(an));
+ if(isfirst) {
+ state.addTreeCode(md,bn);
+ } else {
+ BlockNode obn = state.getMethodBody(md);
+ for(int ii = 0; ii < bn.size(); ii++) {
+ BlockStatementNode bsn = bn.get(ii);
+ obn.addBlockStatement(bsn);
+ }
+ state.addTreeCode(md, obn);
+ bn = null;
+ }
+ en = null;
+ }
}
cn.addField(new FieldDescriptor(m, arrayt, identifier, en, isglobal));
}
}
-
- private void assignAnnotationsToType(Modifiers modifiers, TypeDescriptor type){
+
+ private void assignAnnotationsToType(Modifiers modifiers, TypeDescriptor type) {
Vector<AnnotationDescriptor> annotations=modifiers.getAnnotations();
for(int i=0; i<annotations.size(); i++) {
// it only supports a marker annotation
AnnotationDescriptor an=annotations.elementAt(i);
- type.addAnnotationMarker(an);
- }
+ type.addAnnotationMarker(an);
+ }
}
int innerCount=0;
} else if (isNode(pn,"preinc")||
isNode(pn,"predec")) {
ParseNode left=pn.getFirstChild();
- AssignOperation op=isNode(pn,"preinc") ? new AssignOperation(AssignOperation.PLUSEQ) : new AssignOperation(AssignOperation.MINUSEQ);
+ AssignOperation op=isNode(pn,"preinc")?new AssignOperation(AssignOperation.PLUSEQ):new AssignOperation(AssignOperation.MINUSEQ);
AssignmentNode an=new AssignmentNode(parseExpression(left),
- new LiteralNode("integer",new Integer(1)),op);
+ new LiteralNode("integer",new Integer(1)),op);
an.setNumLine(pn.getLine());
return an;
} else if (isNode(pn,"literal")) {
String literaltype=pn.getTerminal();
ParseNode literalnode=pn.getChild(literaltype);
- Object literal_obj=literalnode.getLiteral();
+ Object literal_obj=literalnode.getLiteral();
LiteralNode ln=new LiteralNode(literaltype, literal_obj);
ln.setNumLine(pn.getLine());
return ln;
boolean isglobal = pn.getChild("global") != null || pn.getChild("scratch") != null;
String disjointId = null;
if (pn.getChild("disjoint") != null) {
- disjointId = pn.getChild("disjoint").getTerminal();
+ disjointId = pn.getChild("disjoint").getTerminal();
}
CreateObjectNode con = new CreateObjectNode(td, isglobal, disjointId);
con.setNumLine(pn.getLine());
for (int i = 0; i < args.size(); i++) {
- con.addArgument((ExpressionNode) args.get(i));
+ con.addArgument((ExpressionNode) args.get(i));
}
/* Could have flag set or tag added here */
if (pn.getChild("flag_list") != null || pn.getChild("tag_list") != null) {
- FlagEffects fe = new FlagEffects(null);
- if (pn.getChild("flag_list") != null)
- parseFlagEffect(fe, pn.getChild("flag_list"));
+ FlagEffects fe = new FlagEffects(null);
+ if (pn.getChild("flag_list") != null)
+ parseFlagEffect(fe, pn.getChild("flag_list"));
- if (pn.getChild("tag_list") != null)
- parseTagEffect(fe, pn.getChild("tag_list"));
- con.addFlagEffects(fe);
+ if (pn.getChild("tag_list") != null)
+ parseTagEffect(fe, pn.getChild("tag_list"));
+ con.addFlagEffects(fe);
}
return con;
} else if (isNode(pn,"createarray")) {
//System.out.println(pn.PPrint(3,true));
boolean isglobal=pn.getChild("global")!=null||
- pn.getChild("scratch")!=null;
+ pn.getChild("scratch")!=null;
String disjointId=null;
if( pn.getChild("disjoint") != null) {
disjointId = pn.getChild("disjoint").getTerminal();
con.addArgument((ExpressionNode)args.get(i));
}
return con;
- } if (isNode(pn,"createarray2")) {
+ }
+ if (isNode(pn,"createarray2")) {
TypeDescriptor td=parseTypeDescriptor(pn);
int num=0;
if (pn.getChild("dims_opt").getLiteral()!=null)
- num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
+ num=((Integer)pn.getChild("dims_opt").getLiteral()).intValue();
for(int i=0; i<num; i++)
- td=td.makeArray(state);
+ td=td.makeArray(state);
CreateObjectNode con=new CreateObjectNode(td, false, null);
con.setNumLine(pn.getLine());
- ParseNode ipn = pn.getChild("initializer");
+ ParseNode ipn = pn.getChild("initializer");
Vector initializers=parseVariableInitializerList(ipn);
ArrayInitializerNode ain = new ArrayInitializerNode(initializers);
ain.setNumLine(pn.getLine());
} else if (isNode(pn,"fieldaccess")) {
ExpressionNode en=parseExpression(pn.getChild("base").getFirstChild());
String fieldname=pn.getChild("field").getTerminal();
-
+
FieldAccessNode fan=new FieldAccessNode(en,fieldname);
fan.setNumLine(pn.getLine());
return fan;
} else if (isNode(pn,"cast1")) {
try {
CastNode cn=new CastNode(parseTypeDescriptor(pn.getChild("type")),parseExpression(pn.getChild("exp").getFirstChild()));
- cn.setNumLine(pn.getLine());
+ cn.setNumLine(pn.getLine());
return cn;
} catch (Exception e) {
System.out.println(pn.PPrint(1,true));
//System.out.println("Checking the values of: "+ " td.toString()= " + td.toString()+ " fieldname= " + fieldname);
return new OffsetNode(td, fieldname);
} else if (isNode(pn, "tert")) {
-
+
TertiaryNode tn=new TertiaryNode(parseExpression(pn.getChild("cond").getFirstChild()),
- parseExpression(pn.getChild("trueexpr").getFirstChild()),
- parseExpression(pn.getChild("falseexpr").getFirstChild()) );
+ parseExpression(pn.getChild("trueexpr").getFirstChild()),
+ parseExpression(pn.getChild("falseexpr").getFirstChild()) );
tn.setNumLine(pn.getLine());
-
+
return tn;
} else if (isNode(pn, "instanceof")) {
ExpressionNode exp=parseExpression(pn.getChild("exp").getFirstChild());
InstanceOfNode ion=new InstanceOfNode(exp,t);
ion.setNumLine(pn.getLine());
return ion;
- } else if (isNode(pn, "array_initializer")) {
+ } else if (isNode(pn, "array_initializer")) {
Vector initializers=parseVariableInitializerList(pn);
return new ArrayInitializerNode(initializers);
} else if (isNode(pn, "class_type")) {
// at the AST level, someday should evolve into a nice compiler
// option *wink*
//if( cn.getSymbol().equals( ***put a class in here like: "Test" ) &&
- // md.getSymbol().equals( ***put your method in here like: "main" )
+ // md.getSymbol().equals( ***put your method in here like: "main" )
//) {
// bn.setStyle( BlockNode.NORMAL );
// System.out.println( bn.printNode( 0 ) );
}
state.addTreeCode(md,bn);
}
-
+
private void parseStaticBlockDecl(ClassDescriptor cn, ParseNode pn) {
- // Each class maintains one MethodDecscriptor which combines all its
+ // Each class maintains one MethodDecscriptor which combines all its
// static blocks in their declaration order
boolean isfirst = false;
MethodDescriptor md = (MethodDescriptor)cn.getMethodTable().getFromSameScope("staticblocks");
} else {
BlockNode obn = state.getMethodBody(md);
for(int i = 0; i < bn.size(); i++) {
- BlockStatementNode bsn = bn.get(i);
- obn.addBlockStatement(bsn);
+ BlockStatementNode bsn = bn.get(i);
+ obn.addBlockStatement(bsn);
}
state.addTreeCode(md, obn);
bn = null;
TagDeclarationNode tdn=new TagDeclarationNode(name, type);
tdn.setNumLine(pn.getLine());
-
+
blockstatements.add(tdn);
} else if (isNode(pn,"local_variable_declaration")) {
-
- ParseNode mn=pn.getChild("modifiers");
+
+ ParseNode mn=pn.getChild("modifiers");
TypeDescriptor t=parseTypeDescriptor(pn);
- if(mn!=null){
- Modifiers m=parseModifiersList(mn);
- assignAnnotationsToType(m, t);
- }
+ if(mn!=null) {
+ Modifiers m=parseModifiersList(mn);
+ assignAnnotationsToType(m, t);
+ }
ParseNode vn=pn.getChild("variable_declarators_list");
ParseNodeVector pnv=vn.getChildren();
for(int i=0; i<pnv.size(); i++) {
ExpressionNode en=null;
if (epn!=null)
en=parseExpression(epn.getFirstChild());
-
+
DeclarationNode dn=new DeclarationNode(new VarDescriptor(arrayt, identifier),en);
dn.setNumLine(tmp.getLine());
blockstatements.add(ben);
} else if (isNode(pn,"ifstatement")) {
IfStatementNode isn=new IfStatementNode(parseExpression(pn.getChild("condition").getFirstChild()),
- parseSingleBlock(pn.getChild("statement").getFirstChild()),
- pn.getChild("else_statement")!=null ? parseSingleBlock(pn.getChild("else_statement").getFirstChild()) : null);
+ parseSingleBlock(pn.getChild("statement").getFirstChild()),
+ pn.getChild("else_statement")!=null?parseSingleBlock(pn.getChild("else_statement").getFirstChild()):null);
isn.setNumLine(pn.getLine());
-
+
blockstatements.add(isn);
} else if (isNode(pn,"switch_statement")) {
// TODO add version for normal Java later
SwitchStatementNode ssn=new SwitchStatementNode(parseExpression(pn.getChild("condition").getFirstChild()),
- parseSingleBlock(pn.getChild("statement").getFirstChild()));
+ parseSingleBlock(pn.getChild("statement").getFirstChild()));
ssn.setNumLine(pn.getLine());
blockstatements.add(ssn);
} else if (isNode(pn,"switch_block_list")) {
// TODO add version for normal Java later
ParseNodeVector pnv=pn.getChildren();
for(int i=0; i<pnv.size(); i++) {
- ParseNode sblockdecl=pnv.elementAt(i);
-
- if(isNode(sblockdecl, "switch_block")) {
- ParseNode lpn=sblockdecl.getChild("switch_labels").getChild("switch_label_list");
- ParseNodeVector labelv=lpn.getChildren();
- Vector<SwitchLabelNode> slv = new Vector<SwitchLabelNode>();
- for(int j=0; j<labelv.size(); j++) {
- ParseNode labeldecl=labelv.elementAt(j);
- if(isNode(labeldecl, "switch_label")) {
- SwitchLabelNode sln=new SwitchLabelNode(parseExpression(labeldecl.getChild("constant_expression").getFirstChild()), false);
- sln.setNumLine(labeldecl.getLine());
- slv.addElement(sln);
- } else if(isNode(labeldecl, "default_switch_label")) {
- SwitchLabelNode sln=new SwitchLabelNode(null, true);
- sln.setNumLine(labeldecl.getLine());
- slv.addElement(sln);
- }
- }
-
- SwitchBlockNode sbn=new SwitchBlockNode(slv,
- parseSingleBlock(sblockdecl.getChild("switch_statements").getFirstChild()));
- sbn.setNumLine(sblockdecl.getLine());
-
- blockstatements.add(sbn);
-
- }
+ ParseNode sblockdecl=pnv.elementAt(i);
+
+ if(isNode(sblockdecl, "switch_block")) {
+ ParseNode lpn=sblockdecl.getChild("switch_labels").getChild("switch_label_list");
+ ParseNodeVector labelv=lpn.getChildren();
+ Vector<SwitchLabelNode> slv = new Vector<SwitchLabelNode>();
+ for(int j=0; j<labelv.size(); j++) {
+ ParseNode labeldecl=labelv.elementAt(j);
+ if(isNode(labeldecl, "switch_label")) {
+ SwitchLabelNode sln=new SwitchLabelNode(parseExpression(labeldecl.getChild("constant_expression").getFirstChild()), false);
+ sln.setNumLine(labeldecl.getLine());
+ slv.addElement(sln);
+ } else if(isNode(labeldecl, "default_switch_label")) {
+ SwitchLabelNode sln=new SwitchLabelNode(null, true);
+ sln.setNumLine(labeldecl.getLine());
+ slv.addElement(sln);
+ }
+ }
+
+ SwitchBlockNode sbn=new SwitchBlockNode(slv,
+ parseSingleBlock(sblockdecl.getChild("switch_statements").getFirstChild()));
+ sbn.setNumLine(sblockdecl.getLine());
+
+ blockstatements.add(sbn);
+
+ }
}
} else if (isNode(pn, "trycatchstatement")) {
// TODO add version for normal Java later
ParseNode tpn = pn.getChild("tryblock").getFirstChild();
BlockNode bn=parseBlockHelper(tpn);
blockstatements.add(new SubBlockNode(bn));
-
+
ParseNode fbk = pn.getChild("finallyblock");
if(fbk != null) {
- ParseNode fpn = fbk.getFirstChild();
- BlockNode fbn=parseBlockHelper(fpn);
- blockstatements.add(new SubBlockNode(fbn));
+ ParseNode fpn = fbk.getFirstChild();
+ BlockNode fbn=parseBlockHelper(fpn);
+ blockstatements.add(new SubBlockNode(fbn));
}
} else if (isNode(pn, "throwstatement")) {
// TODO Simply return here
ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
if(condition == null) {
- // no condition clause, make a 'true' expression as the condition
- condition = (ExpressionNode)new LiteralNode("boolean", new Boolean(true));
+ // no condition clause, make a 'true' expression as the condition
+ condition = (ExpressionNode) new LiteralNode("boolean", new Boolean(true));
}
LoopNode ln=new LoopNode(init,condition,update,body);
ln.setNumLine(pn.getLine());
ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
if(condition == null) {
- // no condition clause, make a 'true' expression as the condition
- condition = (ExpressionNode)new LiteralNode("boolean", new Boolean(true));
+ // no condition clause, make a 'true' expression as the condition
+ condition = (ExpressionNode) new LiteralNode("boolean", new Boolean(true));
}
blockstatements.add(new LoopNode(condition,body,LoopNode.WHILELOOP));
} else if (isNode(pn,"dowhilestatement")) {
ExpressionNode condition=parseExpression(pn.getChild("condition").getFirstChild());
BlockNode body=parseSingleBlock(pn.getChild("statement").getFirstChild());
if(condition == null) {
- // no condition clause, make a 'true' expression as the condition
- condition = (ExpressionNode)new LiteralNode("boolean", new Boolean(true));
+ // no condition clause, make a 'true' expression as the condition
+ condition = (ExpressionNode) new LiteralNode("boolean", new Boolean(true));
}
blockstatements.add(new LoopNode(condition,body,LoopNode.DOWHILELOOP));
} else if (isNode(pn,"sese")) {
ParseNode pnID=pn.getChild("identifier");
String stID=null;
- if( pnID != null ) { stID=pnID.getFirstChild().getTerminal(); }
+ if( pnID != null ) {
+ stID=pnID.getFirstChild().getTerminal();
+ }
SESENode start=new SESENode(stID);
start.setNumLine(pn.getLine());
SESENode end =new SESENode(stID);
- start.setEnd( end );
- end.setStart( start );
+ start.setEnd(end);
+ end.setStart(start);
blockstatements.add(start);
blockstatements.addAll(parseSESEBlock(blockstatements,pn.getChild("body").getFirstChild()));
blockstatements.add(end);
// name_pn.getTerminal() gives you the label
} else if (isNode(pn,"genreach")) {
String graphName = pn.getChild("graphName").getTerminal();
- blockstatements.add( new GenReachNode( graphName ) );
+ blockstatements.add(new GenReachNode(graphName) );
- } else if(isNode(pn,"labeledstatement")){
+ } else if(isNode(pn,"labeledstatement")) {
String label = pn.getChild("name").getTerminal();
BlockNode bn=parseSingleBlock(pn.getChild("statement").getFirstChild());
bn.setLabel(label);
- blockstatements.add(new SubBlockNode(bn));
+ blockstatements.add(new SubBlockNode(bn));
} else {
System.out.println("---------------");
System.out.println(pn.PPrint(3,true));
TypeDescriptor type=new TypeDescriptor(TypeDescriptor.TAG);
md.addTagParameter(type, paramname);
} else {
-
+
TypeDescriptor type=parseTypeDescriptor(paramn);
ParseNode tmp=paramn;
String paramname=tmp.getChild("single").getTerminal();
md.addParameter(type, paramname);
- if(isNode(paramn, "annotation_parameter")){
- ParseNode bodynode=paramn.getChild("annotation_body");
- parseParameterAnnotation(bodynode,type);
- }
-
+ if(isNode(paramn, "annotation_parameter")) {
+ ParseNode bodynode=paramn.getChild("annotation_body");
+ parseParameterAnnotation(bodynode,type);
+ }
+
}
}
}
if (modlist!=null) {
ParseNodeVector pnv=modlist.getChildren();
for(int i=0; i<pnv.size(); i++) {
- ParseNode modn=pnv.elementAt(i);
+ ParseNode modn=pnv.elementAt(i);
if (isNode(modn,"public"))
m.addModifier(Modifiers.PUBLIC);
else if (isNode(modn,"protected"))
m.addModifier(Modifiers.SYNCHRONIZED);
else if (isNode(modn,"atomic"))
m.addModifier(Modifiers.ATOMIC);
- else if (isNode(modn,"abstract"))
- m.addModifier(Modifiers.ABSTRACT);
- else if (isNode(modn,"volatile"))
- m.addModifier(Modifiers.VOLATILE);
- else if (isNode(modn,"transient"))
- m.addModifier(Modifiers.TRANSIENT);
- else if(isNode(modn,"annotation_list"))
- parseAnnotationList(modn,m);
- else{
- throw new Error("Unrecognized Modifier:"+modn.getLabel());}
+ else if (isNode(modn,"abstract"))
+ m.addModifier(Modifiers.ABSTRACT);
+ else if (isNode(modn,"volatile"))
+ m.addModifier(Modifiers.VOLATILE);
+ else if (isNode(modn,"transient"))
+ m.addModifier(Modifiers.TRANSIENT);
+ else if(isNode(modn,"annotation_list"))
+ parseAnnotationList(modn,m);
+ else {
+ throw new Error("Unrecognized Modifier:"+modn.getLabel());
+ }
}
}
return m;
}
-
+
private void parseAnnotationList(ParseNode pn, Modifiers m) {
ParseNodeVector pnv = pn.getChildren();
for (int i = 0; i < pnv.size(); i++) {
ParseNode body_list = pnv.elementAt(i);
if (isNode(body_list, "annotation_body")) {
- ParseNode body_node = body_list.getFirstChild();
- if (isNode(body_node, "marker_annotation")) {
- m.addAnnotation(new AnnotationDescriptor(body_node.getChild("name").getTerminal()));
- } else if (isNode(body_node, "single_annotation")) {
- m.addAnnotation(new AnnotationDescriptor(body_node.getChild("name").getTerminal(),
- body_node.getChild("element_value").getTerminal()));
- } else if (isNode(body_node, "normal_annotation")) {
- throw new Error("Annotation with multiple data members is not supported yet.");
- }
+ ParseNode body_node = body_list.getFirstChild();
+ if (isNode(body_node, "marker_annotation")) {
+ m.addAnnotation(new AnnotationDescriptor(body_node.getChild("name").getTerminal()));
+ } else if (isNode(body_node, "single_annotation")) {
+ m.addAnnotation(new AnnotationDescriptor(body_node.getChild("name").getTerminal(),
+ body_node.getChild("element_value").getTerminal()));
+ } else if (isNode(body_node, "normal_annotation")) {
+ throw new Error("Annotation with multiple data members is not supported yet.");
+ }
}
}
}
-
- private void parseParameterAnnotation(ParseNode body_list,TypeDescriptor type){
+
+ private void parseParameterAnnotation(ParseNode body_list,TypeDescriptor type) {
ParseNode body_node = body_list.getFirstChild();
if (isNode(body_node, "marker_annotation")) {
type.addAnnotationMarker(new AnnotationDescriptor(body_node.getChild("name").getTerminal()));
} else if (isNode(body_node, "single_annotation")) {
type.addAnnotationMarker(new AnnotationDescriptor(body_node.getChild("name").getTerminal(),
- body_node.getChild("element_value").getTerminal()));
+ body_node.getChild("element_value").getTerminal()));
} else if (isNode(body_node, "normal_annotation")) {
throw new Error("Annotation with multiple data members is not supported yet.");
}
}
-
+
private boolean isNode(ParseNode pn, String label) {
if (pn.getLabel().equals(label))
return true;