Skip to content
Snippets Groups Projects
Commit 121b7a79 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

some simple tests of void type check performed

parent b25d312c
Branches
Tags
No related merge requests found
aspect TypeCheck { aspect TypeCheck {
public void ASTNode.typeCheck() { public void ASTNode.typeCheck() {
for (int i = 0; i < getNumChild(); i++) { // calls to the different type checks to be performed
getChild(i).typeCheck(); nullTypeCheck();
}
} }
// void is not allowed as a field in a struct or an array element
syn boolean Type.isNull(); syn boolean Type.isNull();
eq Type.isNull() = false; eq Type.isNull() = false;
eq VoidType.isNull() = true; 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() { public void Field.nullTypeCheck() {
if(getType().isNull()) { if(getType().isNull()) {
error(getName() + ": fields cannot be of type void"); error("field " + getName() + " may not be of type void");
} }
} }
public void ParseArrayType.nullTypeCheck() { public void ParseArrayType.nullTypeCheck() {
if(getType().isNull()) { if(getType().isNull()) {
error("array elements cannot be of type void"); error("array elements may not be of type void");
} }
} }
public void ArrayType.nullTypeCheck() { public void ArrayType.nullTypeCheck() {
if(getType().isNull()) { if(getType().isNull()) {
error("array elements cannot be of type void"); error("array elements may not be of type void");
} }
} }
} }
...@@ -29,3 +29,14 @@ sample struct { ...@@ -29,3 +29,14 @@ sample struct {
typedef void avoid; typedef void avoid;
sample avoid doavoid; 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[_];
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment