Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sven Gestegård Robertz
LabComm
Commits
121b7a79
Commit
121b7a79
authored
Mar 21, 2014
by
Sven Gestegård Robertz
Browse files
some simple tests of void type check performed
parent
b25d312c
Changes
2
Hide whitespace changes
Inline
Side-by-side
compiler/TypeCheck.jrag
View file @
121b7a79
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 can
not 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
can
not 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
can
not be of type void");
error("array elements
may
not be of type void");
}
}
}
}
}
}
examples/simple/simple.lc
View file @
121b7a79
...
@@ -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[_];
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment