From 79c84f3bffb5dc9e14f9d72726164c9e2354eadb Mon Sep 17 00:00:00 2001 From: yeom Date: Wed, 27 Apr 2011 02:00:10 +0000 Subject: [PATCH] Extends the grammar to include the annotation type declaration. The current impl only supports marker and single annotation declaration. Annotation type is represented by class descriptor since annotation type declaration is a special kind of interface declaration. Later, we need to implement semantic checkings for annotations. --- Robust/src/IR/Tree/BuildIR.java | 48 ++++++++++++++++++ Robust/src/Parse/java14.cup | 89 ++++++++++++++++++++++++++------- 2 files changed, 120 insertions(+), 17 deletions(-) diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index 89d0a5c4..e31d6d14 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -165,6 +165,12 @@ public class BuildIR { 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()); } @@ -172,6 +178,8 @@ public class BuildIR { } } + + //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 @@ -265,6 +273,44 @@ public class BuildIR { cn.addEnumConstant(pn.getChild("name").getTerminal()); } + 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){ + cn.setModifiers(parseModifiersList(modifiers)); + } + parseAnnotationTypeBody(cn,pn.getChild("body")); + return cn; + } + + private void parseAnnotationTypeBody(ClassDescriptor cn, ParseNode pn){ + ParseNode list_node=pn.getChild("annotation_type_element_list"); + 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