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
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");
}
}
}
......@@ -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[_];
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment