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
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<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) {
}
}
+
+
private void parseInterfaceConstant(ClassDescriptor cn, ParseNode pn) {
if (pn!=null) {
parseFieldDecl(cn,pn.getChild("field_declaration"));
non terminal ParseNode location_order_declaration, location_order_list, location_order;
// 19.9.1) Interface Declarations
non terminal ParseNode interface_declaration;
-non terminal normal_interface_declaration, annotation_type_declaration;
+non terminal ParseNode normal_interface_declaration, annotation_type_declaration;
non terminal ParseNode extends_interfaces_opt, extends_interfaces;
non terminal ParseNode interface_body;
non terminal ParseNode interface_member_declarations_opt, interface_member_declarations;
pn.addChild("interfacebody").addChild(body);
RESULT=pn;
:}
- | annotation_type_declaration
+ | annotation_type_declaration:atd{:
+ RESULT=atd;
+ :}
;
extends_interfaces_opt ::=
{: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
RESULT=pn;
:}
;
-/*
+
annotation_type_declaration ::=
- AT INTERFACE IDENTIFIER annotation_type_body
- | modifiers_at INTERFACE IDENTIFIER annotation_type_body
+ AT INTERFACE IDENTIFIER:id annotation_type_body:atb{:
+ ParseNode pn=new ParseNode("annotation_type_declaration",parser.lexer.line_num);
+ pn.addChild("name").addChild(id);
+ pn.addChild("body").addChild(atb);
+ RESULT=pn;
+
+ :}
+ | modifiers_at:ma INTERFACE IDENTIFIER:id annotation_type_body:atb{:
+ ParseNode pn=new ParseNode("annotation_type_declaration",parser.lexer.line_num);
+ pn.addChild("name").addChild(id);
+ pn.addChild("modifiers").addChild(ma);
+ pn.addChild("body").addChild(atb);
+ RESULT=pn;
+ :}
;
annotation_type_body ::=
- LBRACE annotation_type_element_declarations_opt RBRACE
+ LBRACE annotation_type_element_declarations_opt:atedo RBRACE{:
+ RESULT=atedo;
+ :}
;
-annotation_type_element_declarations_opt ::=
- | annotation_type_element_declarations
+annotation_type_element_declarations_opt ::={:
+ RESULT=new ParseNode("empty",parser.lexer.line_num);
+ :}
+ | annotation_type_element_declarations:ated{:
+ RESULT=ated;
+ :}
;
annotation_type_element_declarations ::=
- annotation_type_element_declaration
- | annotation_type_element_declarations annotation_type_element_declaration
+ annotation_type_element_declaration:ated{:
+ ParseNode pn=new ParseNode("annotation_type_element_list",parser.lexer.line_num);
+ pn.addChild(ated);
+ RESULT=pn;
+ :}
+ | annotation_type_element_declarations:ateds annotation_type_element_declaration:ated{:
+ ateds.addChild(ated);
+ RESULT=ateds;
+ :}
;
annotation_type_element_declaration ::=
- constant_declaration
- | modifiers_opt type IDENTIFIER LPAREN RPAREN default_value_opt SEMICOLON
- | class_declaration
- | enum_declaration
- | interface_declaration
- | SEMICOLON
+ constant_declaration:cd {:
+ RESULT=cd;
+ :}
+ | modifiers_opt:mo type:type IDENTIFIER:id LPAREN RPAREN default_value_opt:dvo SEMICOLON {:
+ ParseNode pn=new ParseNode("annotation_type_element_declaration",parser.lexer.line_num);
+ pn.addChild("modifier").addChild(mo);
+ pn.addChild("type").addChild(type);
+ pn.addChild("name").addChild(id);
+ pn.addChild("defaultvalue").addChild(dvo);
+ RESULT=pn;
+ :}
+ | class_declaration:cd{:
+ RESULT=cd;
+ :}
+ | enum_declaration:ed{:
+ RESULT=ed;
+ :}
+ | interface_declaration:id{:
+ RESULT=id;
+ :}
+ | SEMICOLON{:
+ RESULT=new ParseNode("empty",parser.lexer.line_num);
+ :}
;
-*/
+default_value_opt ::= {:
+ RESULT=new ParseNode("empty",parser.lexer.line_num);
+ :}
+ | default_value:dv{:
+ RESULT=dv;
+ :}
+ ;
+default_value ::= DEFAULT element_value:ev {:
+ RESULT=ev;
+ :}
+ ;
+
// 19.10) Arrays
array_initializer ::=
LBRACE variable_initializers:var_init_list COMMA RBRACE {: