--- /dev/null
+package IR;
+
+import java.util.Set;
+
+public class AnnotationDescriptor extends Descriptor {
+
+ public static final int MARKER_ANNOTATION = 1;
+ public static final int SINGLE_ANNOTATION = 2;
+ public static final int FULL_ANNOTATION = 3;
+
+ private String marker;
+ private Set arrayedValues; // for single annotation
+ private int type;
+
+ public AnnotationDescriptor(String annotationName) {
+ // constructor for marker annotation
+ super(annotationName);
+ this.marker = annotationName;
+ this.type = MARKER_ANNOTATION;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public boolean isMarkerAnnotation() {
+ return type == MARKER_ANNOTATION;
+ }
+
+ public boolean isSingleAnnotation() {
+ return type == SINGLE_ANNOTATION;
+ }
+
+ public boolean isFullAnnotation() {
+ return type == FULL_ANNOTATION;
+ }
+
+ public String getMarker() {
+ return marker;
+ }
+
+ public boolean equals(Object o) {
+ if (o instanceof AnnotationDescriptor) {
+ AnnotationDescriptor a = (AnnotationDescriptor) o;
+ if (a.getType() != type)
+ return false;
+ if (!a.getMarker().equals(getMarker()))
+ return false;
+
+ return true;
+ }
+ return false;
+ }
+
+ public String toString() {
+ if (type == MARKER_ANNOTATION) {
+ return "@" + name;
+ } else {
+ return "@" + name + "()";
+ }
+ }
+
+}
+++ /dev/null
-package IR.Tree;
-
-public class AnnotationNode extends TreeNode {
- //currently it only supports marker annotation that have no variables.
- String name;
-
- public AnnotationNode(String name){
- //constructor for marker annotation
- this.name=name;
- }
-
-}
ParseNode tn=pn.getChild("type");
TypeDescriptor t=parseTypeDescriptor(tn);
+ assignAnnotationsToType(m,t);
ParseNode vn=pn.getChild("variables").getChild("variable_declarators_list");
ParseNodeVector pnv=vn.getChildren();
boolean isglobal=pn.getChild("global")!=null;
cn.addField(new FieldDescriptor(m, arrayt, identifier, en, isglobal));
}
}
+
+ 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);
+ }
+ }
private ExpressionNode parseExpression(ParseNode pn) {
if (isNode(pn,"assignment"))
blockstatements.add(new TagDeclarationNode(name, type));
} 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);
- // TODO: add annotations to corresponding descriptor
- }
- TypeDescriptor t=parseTypeDescriptor(pn);
+ assignAnnotationsToType(m, t);
+ }
ParseNode vn=pn.getChild("variable_declarators_list");
ParseNodeVector pnv=vn.getChildren();
for(int i=0; i<pnv.size(); i++) {
ParseNode tmp=vardecl;
TypeDescriptor arrayt=t;
+
while (tmp.getChild("single")==null) {
arrayt=arrayt.makeArray(state);
tmp=tmp.getChild("array");
if(isNode(body_list,"annotation_body")){
ParseNode body_node=body_list.getFirstChild();
if (isNode(body_node,"marker_annotation")){
- m.addAnnotation(new AnnotationNode(body_node.getChild("name").getTerminal()));
+ m.addAnnotation(new AnnotationDescriptor(body_node.getChild("name").getTerminal()));
}else if(isNode(body_node,"single_annotation")){
throw new Error("Annotation with single piece of data is not supported yet.");
} else if(isNode(body_node,"normal_annotation")){
import java.util.Vector;
+import IR.AnnotationDescriptor;
+
public class Modifiers {
public static final int PUBLIC=1;
public static final int PROTECTED=2;
// java annotation can be intermixed freely with modifiers
// so Modifiers maintains the list of annotations for later usage
- Vector<AnnotationNode> annotations;
+ Vector<AnnotationDescriptor> annotations;
private int value;
public Modifiers() {
value=0;
- annotations=new Vector<AnnotationNode>();
+ annotations=new Vector<AnnotationDescriptor>();
}
public Modifiers(int v) {
value=v;
}
- public void addAnnotation(AnnotationNode an){
+ public void addAnnotation(AnnotationDescriptor an){
annotations.add(an);
}
+
+ public Vector<AnnotationDescriptor> getAnnotations(){
+ return annotations;
+ }
public void addModifier(int mod) {
value|=mod;
package IR;
+import java.util.HashSet;
+import java.util.Set;
+
/**
* Descriptor
*
private int type;
ClassDescriptor class_desc;
boolean isClassNameRef = false;
+
+ private HashSet<AnnotationDescriptor> annotationSet;
public boolean equals(Object o) {
if (o instanceof TypeDescriptor) {
this.class_desc=null;
this.arraycount=0;
this.isClassNameRef =false;
+ this.annotationSet=new HashSet<AnnotationDescriptor>();
}
public TypeDescriptor(String st) {
this.class_desc=null;
this.arraycount=0;
this.isClassNameRef =false;
+ this.annotationSet=new HashSet<AnnotationDescriptor>();
}
public ClassDescriptor getClassDesc() {
this.class_desc=cd;
this.arraycount=0;
this.isClassNameRef =false;
+ this.annotationSet=new HashSet<AnnotationDescriptor>();
}
public TypeDescriptor(int t) {
this.type=t;
this.arraycount=0;
this.isClassNameRef =false;
+ this.annotationSet=new HashSet<AnnotationDescriptor>();
}
public String toString() {
return "offset";
else throw new Error();
}
+
+ public void addAnnotationMarker(AnnotationDescriptor an){
+ annotationSet.add(an);
+ }
+
+ public Set getAnnotationMarkerSet(){
+ return annotationSet;
+ }
+
}