From 9ef4fb930cc9230ddc47f9bd6d66d1f09a828a77 Mon Sep 17 00:00:00 2001 From: Sven Gestegard Robertz <sven.robertz@cs.lth.se> Date: Wed, 20 May 2015 11:28:46 +0200 Subject: [PATCH] Refactoring: Annotation* -> Annotations --- compiler/2014/Annotations.jrag | 14 +++++++++----- compiler/2014/LabComm.ast | 5 +++-- compiler/2014/LabCommParser.parser | 6 +++--- compiler/2014/Refactoring.jrag | 11 +++++++---- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/compiler/2014/Annotations.jrag b/compiler/2014/Annotations.jrag index 8616604..987dad9 100644 --- a/compiler/2014/Annotations.jrag +++ b/compiler/2014/Annotations.jrag @@ -1,13 +1,17 @@ aspect Annotations { - syn boolean TypeInstance.hasAnnotations() = getNumAnnotation()>0; + syn boolean TypeInstance.hasAnnotations() = getAnnotations().getNumAnnotation()>0; syn boolean TypeInstance.hasIntentions() = ! intentionSet().isEmpty(); +// syn String Annotations.getName() = new String(lookup("")); +// +// syn byte[] Annotation.lookup(String key) = (getKey().equals(key) ? getValue() : null); + syn boolean Annotation.isIntention() = false; eq Intention.isIntention() = true; inh ASTNode Annotation.parentInstance(); - eq TypeInstance.getAnnotation(int i).parentInstance() = this; - eq Decl.getAnnotation(int i).parentInstance() = this; + eq TypeInstance.getAnnotations().parentInstance() = this; + eq Decl.getAnnotations().parentInstance() = this; coll Set<Intention> TypeInstance.intentionSet() [new HashSet<Intention>()] with add; @@ -59,7 +63,7 @@ aspect SigAnnotations { syn int TypeInstance.fooHash() { - List<Annotation> ints = getAnnotationList(); + List<Annotation> ints = getAnnotations().getAnnotationList(); int result=0; for(Annotation i : ints) { if(i.isIntention()) { @@ -71,7 +75,7 @@ aspect SigAnnotations { syn String TypeInstance.getAnnotationString() { StringBuilder sb = new StringBuilder(); - List<Annotation> ints = getAnnotationList(); + List<Annotation> ints = getAnnotations().getAnnotationList(); for(Annotation i : ints) { sb.append(i.toString()); } diff --git a/compiler/2014/LabComm.ast b/compiler/2014/LabComm.ast index 311cac4..ad97733 100644 --- a/compiler/2014/LabComm.ast +++ b/compiler/2014/LabComm.ast @@ -1,9 +1,10 @@ Specification ::= Decl*; -abstract Decl ::= TypeInstance Annotation* /Signature/; +abstract Decl ::= TypeInstance Annotations /Signature/; -TypeInstance ::= DataType <Name:String> Annotation*; +TypeInstance ::= DataType <Name:String> Annotations; +Annotations ::= Annotation*; Annotation ::= <Key:String> <Value:byte[]>; Intention : Annotation; diff --git a/compiler/2014/LabCommParser.parser b/compiler/2014/LabCommParser.parser index 6624635..8daff77 100644 --- a/compiler/2014/LabCommParser.parser +++ b/compiler/2014/LabCommParser.parser @@ -54,9 +54,9 @@ List var_decl_list = | var_decl_list.l var_decl.v {: return l.add(v); :} ; -List annotations = - /* empty list */ {: return new List(); :} - | annotation_list.l {: return l; :} +Annotations annotations = + /* empty list */ {: return new Annotations(); :} + | annotation_list.l {: return new Annotations(l); :} ; List annotation_list = diff --git a/compiler/2014/Refactoring.jrag b/compiler/2014/Refactoring.jrag index 84f3484..43bddd2 100644 --- a/compiler/2014/Refactoring.jrag +++ b/compiler/2014/Refactoring.jrag @@ -4,19 +4,22 @@ aspect Refactoring { syn DataType Decl.getDataType() = getTypeInstance().getDataType(); public Field.Field(TypeInstance t) { - this(t.getDataType(), t.getName(), t.getAnnotationList()); + this(t.getDataType(), t.getName(), t.getAnnotations()); } public TypeInstance.TypeInstance(DataType t, String n) { - this(t, n, new List<Annotation>()); + this(t, n, new Annotations()); System.out.println("WARNING! TypeInstance(DataType, String) ignoring intention list"); } public TypeDecl.TypeDecl(TypeInstance t) { - this(t, new List<Annotation>()); + this(t, new Annotations()); System.out.println("WARNING! TypeDecl(TypeInstance) ignoring intention list"); } public SampleDecl.SampleDecl(TypeInstance t) { - this(t, new List<Annotation>()); + this(t, new Annotations()); System.out.println("WARNING! SampleDecl(TypeInstance) ignoring intention list"); } + + syn Annotation Decl.getAnnotation(int i) = getAnnotations().getAnnotation(i); + syn Annotation TypeInstance.getAnnotation(int i) = getAnnotations().getAnnotation(i); } -- GitLab