From: yeom Date: Mon, 18 Apr 2011 19:10:48 +0000 (+0000) Subject: extend grammar for parameter annotation. forgot to handle this case in the past X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f1136ecd8d324adcf8aa8dcf83f2b38c39eb8fd6;p=IRC.git extend grammar for parameter annotation. forgot to handle this case in the past --- diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index 8acca7b2..663f2395 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -1436,7 +1436,8 @@ public class BuildIR { String paramname=paramn.getChild("single").getTerminal(); TypeDescriptor type=new TypeDescriptor(TypeDescriptor.TAG); md.addTagParameter(type, paramname); - } else { + } else { + TypeDescriptor type=parseTypeDescriptor(paramn); ParseNode tmp=paramn; @@ -1447,6 +1448,11 @@ public class BuildIR { String paramname=tmp.getChild("single").getTerminal(); md.addParameter(type, paramname); + if(isNode(paramn, "annotation_parameter")){ + ParseNode bodynode=paramn.getChild("annotation_body"); + parseParameterAnnotation(bodynode,type); + } + } } } @@ -1506,7 +1512,19 @@ public class BuildIR { } } } - + + 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())); + } 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; diff --git a/Robust/src/Parse/java14.cup b/Robust/src/Parse/java14.cup index f2de1ea0..9644ac5b 100644 --- a/Robust/src/Parse/java14.cup +++ b/Robust/src/Parse/java14.cup @@ -1184,6 +1184,13 @@ formal_parameter ::= pn.addChild(name); RESULT=pn; :} + | annotation:an type:type variable_declarator_id:name {: + ParseNode pn=new ParseNode("annotation_parameter",parser.lexer.line_num); + pn.addChild(type); + pn.addChild(name); + pn.addChild(an); + RESULT=pn; + :} ; throws_opt ::= {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}