From a1a16851c2d88f1a4831b163d3504a269c6bb930 Mon Sep 17 00:00:00 2001
From: Sven Gestegard Robertz <sven.robertz@cs.lth.se>
Date: Sun, 3 May 2015 00:42:22 +0200
Subject: [PATCH] WiP: generating intentions in signatures.

---
 compiler/2014/Annotations.jrag   | 18 ++++++++++++++++++
 compiler/2014/FlatSignature.jrag | 11 +++++++++--
 compiler/2014/Signature.jrag     | 14 +++++++++++++-
 3 files changed, 40 insertions(+), 3 deletions(-)
 create mode 100644 compiler/2014/Annotations.jrag

diff --git a/compiler/2014/Annotations.jrag b/compiler/2014/Annotations.jrag
new file mode 100644
index 0000000..2472bce
--- /dev/null
+++ b/compiler/2014/Annotations.jrag
@@ -0,0 +1,18 @@
+aspect Annotations {
+    syn boolean TypeInstance.hasAnnotations() = getNumAnnotation()>0;
+    syn boolean TypeInstance.hasIntentions() = ! intentions().isEmpty();
+
+    syn boolean Annotation.isIntention() = false;
+    eq Intention.isIntention() = true;
+
+    inh TypeInstance Annotation.parentInstance();
+    eq TypeInstance.getAnnotation(int i).parentInstance() = this;
+
+
+    coll Set<Intention> TypeInstance.intentions() [new HashSet<Intention>()] with add;
+    Intention contributes this
+        to TypeInstance.intentions()
+        for parentInstance();
+
+}
+
diff --git a/compiler/2014/FlatSignature.jrag b/compiler/2014/FlatSignature.jrag
index 688d84c..363e322 100644
--- a/compiler/2014/FlatSignature.jrag
+++ b/compiler/2014/FlatSignature.jrag
@@ -14,17 +14,23 @@ aspect FlatSignature {
   }
 
   public void TypeDecl.flatSignature(SignatureList list) {
-    getDataType().flatSignature(list);
+    getTypeInstance().flatSignature(list);
   }
 
   public void SampleDecl.flatSignature(SignatureList list) {
-    getDataType().flatSignature(list);
+    getTypeInstance().flatSignature(list);
   }
 
 //  public void SampleRefType.flatSignature(SignatureList list) {
 //    list.addInt(LABCOMM_SAMPLE_REF, "sample");
 //  }
 
+  public void TypeInstance.flatSignature(SignatureList list) {
+        debugAnnotations(this.getName());
+        list.addString(getIntentionString(), "intentions: "+getIntentionString());
+        getDataType().flatSignature(list);
+  }
+
   public void VoidType.flatSignature(SignatureList list) {
     list.addInt(LABCOMM_STRUCT, "void");
     list.addInt(0, null);
@@ -62,6 +68,7 @@ aspect FlatSignature {
   }
 
   public void Field.flatSignature(SignatureList list) {
+    list.addString(getIntentionString(), "intentions: "+getIntentionString());
     list.addString(getName(), signatureComment());
     getDataType().flatSignature(list);
   }
diff --git a/compiler/2014/Signature.jrag b/compiler/2014/Signature.jrag
index 8c50f91..30aad01 100644
--- a/compiler/2014/Signature.jrag
+++ b/compiler/2014/Signature.jrag
@@ -229,8 +229,20 @@ aspect Signature {
                     " not declared");
   }
 
+  syn String ASTNode.getIntentionString() = "";
+  eq TypeInstance.getIntentionString() {
+    StringBuilder sb = new StringBuilder();
+    Iterator<Intention> it = intentions().iterator();
+    while(it.hasNext()) {
+        Intention i = it.next();
+        sb.append(i.toString());
+    }
+    return sb.toString();
+  }
+
   public void TypeInstance.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
-        debugAnnotations(this.getName());
+//        debugAnnotations(this.getName());
+//        list.addString(inst.getIntentionString(), "intention string");
         getDataType().genSigLineForDecl(list, decl, this);
   }
 
-- 
GitLab