From 121b7a79d94f880337562462f6e7bc1d203f856b Mon Sep 17 00:00:00 2001
From: Sven Gestegard Robertz <sven.robertz@cs.lth.se>
Date: Fri, 21 Mar 2014 18:39:52 +0100
Subject: [PATCH] some simple tests of void type check performed
---
compiler/TypeCheck.jrag | 19 +++++++++++++------
examples/simple/simple.lc | 11 +++++++++++
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/compiler/TypeCheck.jrag b/compiler/TypeCheck.jrag
index 1536ee8..747d830 100644
--- a/compiler/TypeCheck.jrag
+++ b/compiler/TypeCheck.jrag
@@ -1,29 +1,36 @@
aspect TypeCheck {
public void ASTNode.typeCheck() {
- for (int i = 0; i < getNumChild(); i++) {
- getChild(i).typeCheck();
- }
+ // calls to the different type checks to be performed
+ nullTypeCheck();
}
+
+// void is not allowed as a field in a struct or an array element
syn boolean Type.isNull();
eq Type.isNull() = false;
eq VoidType.isNull() = true;
+ eq UserType.isNull() = decl().isNull();
+
+ syn boolean TypeDecl.isNull();
+ eq TypeDecl.isNull() = getType().isNull();
+ public void ASTNode.nullTypeCheck() {}
+
public void Field.nullTypeCheck() {
if(getType().isNull()) {
- error(getName() + ": fields cannot be of type void");
+ error("field " + getName() + " may not be of type void");
}
}
public void ParseArrayType.nullTypeCheck() {
if(getType().isNull()) {
- error("array elements cannot be of type void");
+ error("array elements may not be of type void");
}
}
public void ArrayType.nullTypeCheck() {
if(getType().isNull()) {
- error("array elements cannot be of type void");
+ error("array elements may not be of type void");
}
}
}
diff --git a/examples/simple/simple.lc b/examples/simple/simple.lc
index c3725ac..f25295d 100644
--- a/examples/simple/simple.lc
+++ b/examples/simple/simple.lc
@@ -29,3 +29,14 @@ sample struct {
typedef void avoid;
sample avoid doavoid;
+
+// examples of errors: void may not be used
+// in structs or arrays
+//
+// sample struct {
+// int a;
+// avoid error;
+//} foo;
+//
+//sample void error2[2] ;
+//sample avoid error3[_];
--
GitLab