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

added type check for void types

parent 6e909d2c
No related branches found
No related tags found
No related merge requests found
...@@ -645,6 +645,10 @@ aspect CS_Class { ...@@ -645,6 +645,10 @@ aspect CS_Class {
" not declared"); " not declared");
} }
public boolean VoidType.CS_needInstance() {
return false;
}
public boolean PrimType.CS_needInstance() { public boolean PrimType.CS_needInstance() {
return false; return false;
} }
......
...@@ -371,8 +371,10 @@ aspect C_Declarations { ...@@ -371,8 +371,10 @@ aspect C_Declarations {
env.println("int labcomm"+env.verStr+"_encode_" + env.prefix + getName() + "("); env.println("int labcomm"+env.verStr+"_encode_" + env.prefix + getName() + "(");
env.indent(); env.indent();
env.println("struct labcomm"+env.verStr+"_encoder *e,"); env.println("struct labcomm"+env.verStr+"_encoder *e");
env.println(env.prefix + getName() + " *v"); if(!isVoid() ) {
env.println(", "+env.prefix + getName() + " *v");
}
env.unindent(); env.unindent();
env.println(");"); env.println(");");
...@@ -700,8 +702,10 @@ aspect C_Encoder { ...@@ -700,8 +702,10 @@ aspect C_Encoder {
env = env.nestStruct("(*v)"); env = env.nestStruct("(*v)");
env.println("static int encode_" + env.prefix + getName() + "("); env.println("static int encode_" + env.prefix + getName() + "(");
env.indent(); env.indent();
env.println("struct labcomm"+env.verStr+"_writer *w,"); env.println("struct labcomm"+env.verStr+"_writer *w");
env.println(env.prefix + getName() + " *v"); if(!isVoid() ) {
env.println(", "+env.prefix + getName() + " *v");
}
env.unindent(); env.unindent();
env.println(")"); env.println(")");
env.println("{"); env.println("{");
...@@ -714,16 +718,19 @@ aspect C_Encoder { ...@@ -714,16 +718,19 @@ aspect C_Encoder {
// Typesafe encode wrapper // Typesafe encode wrapper
env.println("int labcomm"+env.verStr+"_encode_" + env.prefix + getName() + "("); env.println("int labcomm"+env.verStr+"_encode_" + env.prefix + getName() + "(");
env.println("struct labcomm"+env.verStr+"_encoder *e,"); env.println("struct labcomm"+env.verStr+"_encoder *e");
env.println(env.prefix + getName() + " *v"); if(!isVoid() ) {
env.println(", "+env.prefix + getName() + " *v");
}
env.unindent(); env.unindent();
env.println(")"); env.println(")");
env.println("{"); env.println("{");
env.indent(); env.indent();
env.println("return labcomm"+env.verStr+"_internal_encode(e, &labcomm"+env.verStr+"_signature_" + env.println("return labcomm"+env.verStr+"_internal_encode(e, &labcomm"+env.verStr+"_signature_" +
env.prefix + getName() + env.prefix + getName() +
", (labcomm"+env.verStr+"_encoder_function)encode_" + env.prefix + getName() + ", (labcomm"+env.verStr+"_encoder_function)encode_" +
", v);"); env.prefix + getName() +
(!isVoid()?", v":", NULL")+");");
env.unindent(); env.unindent();
env.println("}"); env.println("}");
} }
...@@ -745,7 +752,7 @@ aspect C_Encoder { ...@@ -745,7 +752,7 @@ aspect C_Encoder {
} }
public void UserType.C_emitEncoder(C_env env) { public void UserType.C_emitEncoder(C_env env) {
lookupType(getName()).getType().C_emitEncoder(env); decl().getType().C_emitEncoder(env);
} }
public void StructType.C_emitEncoder(C_env env) { public void StructType.C_emitEncoder(C_env env) {
......
...@@ -20,6 +20,7 @@ aspect ErrorCheck { ...@@ -20,6 +20,7 @@ aspect ErrorCheck {
} }
public void ASTNode.errorCheck(Collection collection) { public void ASTNode.errorCheck(Collection collection) {
nameCheck(); nameCheck();
typeCheck();
if(hasErrors()) if(hasErrors())
collection.add(errors); collection.add(errors);
for(int i = 0; i < getNumChild(); i++) { for(int i = 0; i < getNumChild(); i++) {
......
...@@ -196,6 +196,7 @@ aspect Java_StructName { ...@@ -196,6 +196,7 @@ aspect Java_StructName {
aspect Java_Void { aspect Java_Void {
syn boolean Decl.isVoid() = getType().isVoid(); syn boolean Decl.isVoid() = getType().isVoid();
syn boolean UserType.isVoid() = decl().isVoid();
syn boolean Type.isVoid() = false; syn boolean Type.isVoid() = false;
syn boolean VoidType.isVoid() = true; syn boolean VoidType.isVoid() = true;
...@@ -746,6 +747,10 @@ aspect Java_Class { ...@@ -746,6 +747,10 @@ aspect Java_Class {
" not declared"); " not declared");
} }
public boolean VoidType.Java_needInstance() {
return false;
}
public boolean PrimType.Java_needInstance() { public boolean PrimType.Java_needInstance() {
return false; return false;
} }
......
...@@ -70,14 +70,13 @@ SampleDecl sample_decl = ...@@ -70,14 +70,13 @@ SampleDecl sample_decl =
{: return new SampleDecl(t, IDENTIFIER); :} {: return new SampleDecl(t, IDENTIFIER); :}
| SAMPLE type.t IDENTIFIER dim_list.d SEMICOLON | SAMPLE type.t IDENTIFIER dim_list.d SEMICOLON
{: return new SampleDecl(new ParseArrayType(t, d), IDENTIFIER); :} {: return new SampleDecl(new ParseArrayType(t, d), IDENTIFIER); :}
| SAMPLE VOID IDENTIFIER SEMICOLON
{: return new SampleDecl(new VoidType(), IDENTIFIER); :}
; ;
Type type = Type type =
prim_type.p {: return p; :} prim_type.p {: return p; :}
| user_type.u {: return u; :} | user_type.u {: return u; :}
| struct_type.s {: return s; :} | struct_type.s {: return s; :}
| void_type.v {: return v; :}
; ;
PrimType prim_type = PrimType prim_type =
...@@ -107,6 +106,10 @@ StructType struct_type = ...@@ -107,6 +106,10 @@ StructType struct_type =
STRUCT LBRACE var_decl_list.l RBRACE {: return new StructType(l); :} STRUCT LBRACE var_decl_list.l RBRACE {: return new StructType(l); :}
; ;
VoidType void_type =
VOID {: return new VoidType(); :}
;
List dim_list = List dim_list =
dim.d {: return new List().add(d); :} dim.d {: return new List().add(d); :}
| dim_list.l dim.d {: return l.add(d); :} | dim_list.l dim.d {: return l.add(d); :}
......
aspect TypeCheck {
public void ASTNode.typeCheck() {
for (int i = 0; i < getNumChild(); i++) {
getChild(i).typeCheck();
}
}
syn boolean Type.isNull();
eq Type.isNull() = false;
eq VoidType.isNull() = true;
public void Field.nullTypeCheck() {
if(getType().isNull()) {
error(getName() + ": fields cannot be of type void");
}
}
public void ParseArrayType.nullTypeCheck() {
if(getType().isNull()) {
error("array elements cannot be of type void");
}
}
public void ArrayType.nullTypeCheck() {
if(getType().isNull()) {
error("array elements cannot be of type void");
}
}
}
...@@ -5,7 +5,7 @@ import java.io.InputStream; ...@@ -5,7 +5,7 @@ import java.io.InputStream;
import se.lth.control.labcomm.LabCommDecoderChannel; import se.lth.control.labcomm.LabCommDecoderChannel;
public class Decoder public class Decoder
implements theTwoInts.Handler, anotherTwoInts.Handler, IntString.Handler, TwoArrays.Handler, TwoFixedArrays.Handler implements theTwoInts.Handler, anotherTwoInts.Handler, IntString.Handler, TwoArrays.Handler, TwoFixedArrays.Handler, doavoid.Handler
{ {
...@@ -20,6 +20,7 @@ public class Decoder ...@@ -20,6 +20,7 @@ public class Decoder
IntString.register(decoder, this); IntString.register(decoder, this);
TwoArrays.register(decoder, this); TwoArrays.register(decoder, this);
TwoFixedArrays.register(decoder, this); TwoFixedArrays.register(decoder, this);
doavoid.register(decoder, this);
try { try {
System.out.println("Running decoder."); System.out.println("Running decoder.");
...@@ -72,6 +73,10 @@ public class Decoder ...@@ -72,6 +73,10 @@ public class Decoder
} }
System.out.println(); System.out.println();
} }
public void handle_doavoid() throws java.io.IOException {
System.out.println("Got doavoid");
}
public static void main(String[] arg) throws Exception { public static void main(String[] arg) throws Exception {
......
...@@ -26,6 +26,6 @@ sample struct { ...@@ -26,6 +26,6 @@ sample struct {
int b[2,3]; int b[2,3];
} TwoFixedArrays; } TwoFixedArrays;
// typedef void avoid; typedef void avoid;
sample void doavoid; sample avoid doavoid;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment