From 94be58ca58935953f8f7e5d0e325a14f727991c4 Mon Sep 17 00:00:00 2001
From: Sven Gestegard Robertz <sven.robertz@cs.lth.se>
Date: Wed, 13 May 2015 16:26:47 +0200
Subject: [PATCH] Added checking that TypeDefs do not have intentions to
 compiler

---
 compiler/2014/ErrorCheck.jrag | 45 +++++++++++++++++------------------
 compiler/2014/TypeCheck.jrag  | 23 ++++++++++++++----
 2 files changed, 41 insertions(+), 27 deletions(-)

diff --git a/compiler/2014/ErrorCheck.jrag b/compiler/2014/ErrorCheck.jrag
index caa8081..6953c7c 100644
--- a/compiler/2014/ErrorCheck.jrag
+++ b/compiler/2014/ErrorCheck.jrag
@@ -2,30 +2,29 @@ import java.util.Collection;
 
 aspect ErrorCheck {
 
-	syn int ASTNode.lineNumber() = getLine(getStart());
+    syn int ASTNode.lineNumber() = getLine(getStart());
 
-	protected String ASTNode.errors = null;
-	
-	protected void ASTNode.error(String s) {
-	    s = "Error at " + lineNumber() + ": " + s;
-	    if(errors == null) {
-	      errors = s;
-	    } else {
-	      errors = errors + "\n" + s;
-	    }
-	}
+    protected String ASTNode.errors = null;
 
-	protected boolean ASTNode.hasErrors() {
-		return errors != null;
-	}
-	public void ASTNode.errorCheck(Collection collection) {
-	    nameCheck();
-            typeCheck();
-	    if(hasErrors())
-		collection.add(errors);
-	    for(int i = 0; i < getNumChild(); i++) {
-		getChild(i).errorCheck(collection);
-	    }
-	}
+    protected void ASTNode.error(String s) {
+        s = "Error at " + lineNumber() + ": " + s;
+        if(errors == null) {
+          errors = s;
+        } else {
+          errors = errors + "\n" + s;
+        }
+    }
 
+    protected boolean ASTNode.hasErrors() {
+        return errors != null;
+    }
+    public void ASTNode.errorCheck(Collection collection) {
+        nameCheck();
+        typeCheck();
+        if(hasErrors())
+        collection.add(errors);
+        for(int i = 0; i < getNumChild(); i++) {
+        getChild(i).errorCheck(collection);
+        }
+    }
 }
diff --git a/compiler/2014/TypeCheck.jrag b/compiler/2014/TypeCheck.jrag
index 4d8c40a..3e6dd9c 100644
--- a/compiler/2014/TypeCheck.jrag
+++ b/compiler/2014/TypeCheck.jrag
@@ -5,7 +5,7 @@ aspect TypeCheck {
   }
 
 // void is not allowed as a field in a struct or an array element
-  
+
   syn boolean DataType.isNull();
   eq DataType.isNull() = false;
   eq VoidType.isNull() = true;
@@ -13,9 +13,9 @@ aspect TypeCheck {
 
   syn boolean TypeDecl.isNull();
   eq TypeDecl.isNull() = getDataType().isNull();
-  
+
   public void ASTNode.nullTypeCheck() {}
- 
+
   public void Field.nullTypeCheck() {
     if(getDataType().isNull()) {
       error("field " + getName() + " of struct "+ declName()+ " may not be of type void");
@@ -33,4 +33,19 @@ aspect TypeCheck {
       error("elements of array "+declName()+" may not be of type void");
     }
   }
-} 
+}
+
+aspect AnnotationCheck {
+
+  refine TypeCheck void ASTNode.typeCheck() {
+    refined(); // similar to call to super
+    annotationCheck();
+  }
+  public void ASTNode.annotationCheck() {}
+
+  public void TypeDecl.annotationCheck() {
+    if(getTypeInstance().hasIntentions()) {
+      error("TypeDecl " + getName() + " has intentions. (Not allowed for typedefs)");
+    }
+  }
+}
-- 
GitLab