From 32370bb322729f37aafadd93fb21ebc8a34ce04c Mon Sep 17 00:00:00 2001
From: Sven Gestegard Robertz <sven.robertz@cs.lth.se>
Date: Mon, 18 May 2015 17:26:54 +0200
Subject: [PATCH] preliminary refactoring of intention attributes

---
 compiler/2014/Annotations.jrag   |  6 +++---
 compiler/2014/FlatSignature.jrag |  4 ++--
 compiler/2014/LabComm.ast        |  1 +
 compiler/2014/Signature.jrag     | 26 +++++++++++++++++++++++---
 4 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/compiler/2014/Annotations.jrag b/compiler/2014/Annotations.jrag
index 2472bce..5141043 100644
--- a/compiler/2014/Annotations.jrag
+++ b/compiler/2014/Annotations.jrag
@@ -1,6 +1,6 @@
 aspect Annotations {
     syn boolean TypeInstance.hasAnnotations() = getNumAnnotation()>0;
-    syn boolean TypeInstance.hasIntentions() = ! intentions().isEmpty();
+    syn boolean TypeInstance.hasIntentions() = ! intentionSet().isEmpty();
 
     syn boolean Annotation.isIntention() = false;
     eq Intention.isIntention() = true;
@@ -9,9 +9,9 @@ aspect Annotations {
     eq TypeInstance.getAnnotation(int i).parentInstance() = this;
 
 
-    coll Set<Intention> TypeInstance.intentions() [new HashSet<Intention>()] with add;
+    coll Set<Intention> TypeInstance.intentionSet() [new HashSet<Intention>()] with add;
     Intention contributes this
-        to TypeInstance.intentions()
+        to TypeInstance.intentionSet()
         for parentInstance();
 
 }
diff --git a/compiler/2014/FlatSignature.jrag b/compiler/2014/FlatSignature.jrag
index 350b224..c3f92b3 100644
--- a/compiler/2014/FlatSignature.jrag
+++ b/compiler/2014/FlatSignature.jrag
@@ -35,7 +35,7 @@ aspect FlatSignature {
   public void TypeInstance.flatSignature(SignatureList list) {
     if(addIntentions()) {
       debugAnnotations(this.getName()+".TypeInstance.flatSignature");
-      list.addString(getIntentionString(), "intentions: "+getIntentionString());
+      list.addIntentions(intentions(), "intentions: "+getIntentionString());
     }
     getDataType().flatSignature(list);
   }
@@ -78,7 +78,7 @@ aspect FlatSignature {
 
   public void Field.flatSignature(SignatureList list) {
     debugAnnotations(this.getName()+".Field.flatSignature");
-    list.addString(getIntentionString(), "intentions: "+getIntentionString());
+    list.addIntentions(intentions(), "Field: "+getIntentionString());
     list.addString(getName(), signatureComment());
     getDataType().flatSignature(list);
   }
diff --git a/compiler/2014/LabComm.ast b/compiler/2014/LabComm.ast
index 361ca89..d76868c 100644
--- a/compiler/2014/LabComm.ast
+++ b/compiler/2014/LabComm.ast
@@ -22,6 +22,7 @@ abstract DataSignatureLine : SignatureLine;
 ByteArraySignatureLine     : DataSignatureLine ::= <Data:byte[]>;
 IntSignatureLine           : DataSignatureLine ::= <Data:int>;
 StringSignatureLine        : DataSignatureLine ::= <Data:String>;
+IntentionSignatureLine     : DataSignatureLine ::= <Data:java.util.Map> ;
 TypeRefSignatureLine       : SignatureLine     ::= Decl;
 
 Field : TypeInstance;
diff --git a/compiler/2014/Signature.jrag b/compiler/2014/Signature.jrag
index 30aad01..c996f9c 100644
--- a/compiler/2014/Signature.jrag
+++ b/compiler/2014/Signature.jrag
@@ -172,6 +172,10 @@ aspect Signature {
       return getIntBytes(getData(), version);
     }
 
+    public void SignatureList.addIntentions(Set<Intention> data, String comment) {
+        addString(TypeInstance.getIntentionString(data), comment);
+    }
+
     public void SignatureList.addString(String data, String comment) {
       addSignatureLine(new StringSignatureLine(indent, comment, data));
     }
@@ -229,10 +233,15 @@ aspect Signature {
                     " not declared");
   }
 
-  syn String ASTNode.getIntentionString() = "";
-  eq TypeInstance.getIntentionString() {
+  public String TypeInstance.getIntentionString() {
+      return getIntentionString(intentions());
+  }
+
+  public static String TypeInstance.getIntentionString(Set<Intention> intentions) {
+    if(intentions==null) return "";
+
     StringBuilder sb = new StringBuilder();
-    Iterator<Intention> it = intentions().iterator();
+    Iterator<Intention> it = intentions.iterator();
     while(it.hasNext()) {
         Intention i = it.next();
         sb.append(i.toString());
@@ -240,6 +249,17 @@ aspect Signature {
     return sb.toString();
   }
 
+
+  syn Set<Intention> Specification.emptyIntentions() = new HashSet<Intention>();
+
+  inh Set<Intention> ASTNode.noIntentions();
+  eq Specification.getChild(int i).noIntentions() = emptyIntentions();
+
+  syn Set<Intention> ASTNode.intentions();
+
+  eq ASTNode.intentions() = noIntentions();
+  eq TypeInstance.intentions() = intentionSet();
+
   public void TypeInstance.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
 //        debugAnnotations(this.getName());
 //        list.addString(inst.getIntentionString(), "intention string");
-- 
GitLab