Commit dadd6d29 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

Merge branch 'voidtest'

parents 9ca60152 e86fc9b2
......@@ -645,6 +645,10 @@ aspect CS_Class {
" not declared");
}
public boolean VoidType.CS_needInstance() {
return false;
}
public boolean PrimType.CS_needInstance() {
return false;
}
......@@ -772,13 +776,15 @@ aspect CS_Info {
public void TypeDecl.CS_info(CS_env env, String namespace) {
env.print(";C#;typedef;" + namespace + getName() + ";");
getType().CS_emitType(env);
getType().CS_emitType(env) ;
env.print(";not_applicable_for_C#");
env.println();
}
public void SampleDecl.CS_info(CS_env env, String namespace) {
env.print(";C#;sample;" + namespace + getName() + ";");
getType().CS_emitType(env);
env.print(";not_applicable_for_C#");
env.println();
}
......
......@@ -371,8 +371,10 @@ aspect C_Declarations {
env.println("int labcomm"+env.verStr+"_encode_" + env.prefix + getName() + "(");
env.indent();
env.println("struct labcomm"+env.verStr+"_encoder *e,");
env.println(env.prefix + getName() + " *v");
env.println("struct labcomm"+env.verStr+"_encoder *e");
if(!isVoid() ) {
env.println(", "+env.prefix + getName() + " *v");
}
env.unindent();
env.println(");");
......@@ -700,8 +702,10 @@ aspect C_Encoder {
env = env.nestStruct("(*v)");
env.println("static int encode_" + env.prefix + getName() + "(");
env.indent();
env.println("struct labcomm"+env.verStr+"_writer *w,");
env.println(env.prefix + getName() + " *v");
env.println("struct labcomm"+env.verStr+"_writer *w");
if(!isVoid() ) {
env.println(", "+env.prefix + getName() + " *v");
}
env.unindent();
env.println(")");
env.println("{");
......@@ -714,16 +718,19 @@ aspect C_Encoder {
// Typesafe encode wrapper
env.println("int labcomm"+env.verStr+"_encode_" + env.prefix + getName() + "(");
env.println("struct labcomm"+env.verStr+"_encoder *e,");
env.println(env.prefix + getName() + " *v");
env.println("struct labcomm"+env.verStr+"_encoder *e");
if(!isVoid() ) {
env.println(", "+env.prefix + getName() + " *v");
}
env.unindent();
env.println(")");
env.println("{");
env.indent();
env.println("return labcomm"+env.verStr+"_internal_encode(e, &labcomm"+env.verStr+"_signature_" +
env.prefix + getName() +
", (labcomm"+env.verStr+"_encoder_function)encode_" + env.prefix + getName() +
", v);");
", (labcomm"+env.verStr+"_encoder_function)encode_" +
env.prefix + getName() +
(!isVoid()?", v":", NULL")+");");
env.unindent();
env.println("}");
}
......@@ -745,7 +752,7 @@ aspect C_Encoder {
}
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) {
......@@ -1156,12 +1163,23 @@ aspect C_Info {
public void TypeDecl.C_info(C_env env) {
env.println(",C,typedef," + env.prefix + getName() + "," +
env.prefix + getName());
env.prefix + getName() + "," +
C_info_type_or_void(env.prefix));
}
public void SampleDecl.C_info(C_env env) {
env.println(",C,sample," + env.prefix + getName() + "," +
env.prefix + getName());
env.prefix + getName() + "," +
C_info_type_or_void(env.prefix));
}
// make void types explicitly as they require special treatment
// in encoder/decoder calls
protected String Decl.C_info_type_or_void(String prefix) {
if(isVoid() ) {
return "void";
} else {
return prefix + getName() ;
}
}
}
aspect DeclNames {
inh String Type.declName();
eq Decl.getType().declName() = getName();
inh String Field.declName();
eq StructType.getField(int i).declName() = declName();
}
......@@ -20,6 +20,7 @@ aspect ErrorCheck {
}
public void ASTNode.errorCheck(Collection collection) {
nameCheck();
typeCheck();
if(hasErrors())
collection.add(errors);
for(int i = 0; i < getNumChild(); i++) {
......
......@@ -196,6 +196,7 @@ aspect Java_StructName {
aspect Java_Void {
syn boolean Decl.isVoid() = getType().isVoid();
syn boolean UserType.isVoid() = decl().isVoid();
syn boolean Type.isVoid() = false;
syn boolean VoidType.isVoid() = true;
......@@ -746,6 +747,10 @@ aspect Java_Class {
" not declared");
}
public boolean VoidType.Java_needInstance() {
return false;
}
public boolean PrimType.Java_needInstance() {
return false;
}
......@@ -865,12 +870,14 @@ aspect Java_Info {
public void TypeDecl.Java_info(Java_env env) {
env.print(",Java,typedef," + getName() + ",");
getType().Java_emitType(env);
env.print(",not_applicable_for_Java");
env.println();
}
public void SampleDecl.Java_info(Java_env env) {
env.print(",Java,sample," + getName() + ",");
getType().Java_emitType(env);
env.print(",not_applicable_for_Java");
env.println();
}
......
......@@ -12,7 +12,7 @@ PrimType : Type ::= <Name:String> <Token:int>;
UserType : Type ::= <Name:String>;
StructType : Type ::= Field*;
ParseArrayType : Type ::= Type Dim*;
abstract ArrayType : Type ::= Type Exp*;
abstract ArrayType :Type ::= Type Exp*;
VariableArrayType : ArrayType;
FixedArrayType : ArrayType;
......
......@@ -249,6 +249,10 @@ public class LabComm {
if (prettyOnStdout) {
ast.pp(System.out);
}
} else {
// Catch-all for compilation errors
System.err.println("Error in specification");
System.exit(3);
}
}
}
......
......@@ -70,14 +70,13 @@ SampleDecl sample_decl =
{: return new SampleDecl(t, IDENTIFIER); :}
| SAMPLE type.t IDENTIFIER dim_list.d SEMICOLON
{: return new SampleDecl(new ParseArrayType(t, d), IDENTIFIER); :}
| SAMPLE VOID IDENTIFIER SEMICOLON
{: return new SampleDecl(new VoidType(), IDENTIFIER); :}
;
Type type =
prim_type.p {: return p; :}
| user_type.u {: return u; :}
| struct_type.s {: return s; :}
| void_type.v {: return v; :}
;
PrimType prim_type =
......@@ -107,6 +106,10 @@ StructType struct_type =
STRUCT LBRACE var_decl_list.l RBRACE {: return new StructType(l); :}
;
VoidType void_type =
VOID {: return new VoidType(); :}
;
List dim_list =
dim.d {: return new List().add(d); :}
| dim_list.l dim.d {: return l.add(d); :}
......
aspect TypeCheck {
public void ASTNode.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("field " + getName() + " of struct "+ declName()+ " may not be of type void");
}
}
public void ParseArrayType.nullTypeCheck() {
if(getType().isNull()) {
error("elements of array "+declName()+" may not be of type void");
}
}
public void ArrayType.nullTypeCheck() {
if(getType().isNull()) {
error("elements of array "+declName()+" may not be of type void");
}
}
}
......@@ -5,7 +5,7 @@ import java.io.InputStream;
import se.lth.control.labcomm.LabCommDecoderChannel;
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
IntString.register(decoder, this);
TwoArrays.register(decoder, this);
TwoFixedArrays.register(decoder, this);
doavoid.register(decoder, this);
try {
System.out.println("Running decoder.");
......@@ -72,6 +73,10 @@ public class Decoder
}
System.out.println();
}
public void handle_doavoid() throws java.io.IOException {
System.out.println("Got doavoid");
}
public static void main(String[] arg) throws Exception {
......
......@@ -20,9 +20,13 @@ int main(int argc, char *argv[]) {
labcomm_default_error_handler,
labcomm_default_memory,
labcomm_default_scheduler);
labcomm_encoder_register_simple_doavoid(encoder);
labcomm_encoder_register_simple_theTwoInts(encoder);
labcomm_encoder_register_simple_anotherTwoInts(encoder);
labcomm_encoder_register_simple_IntString(encoder);
labcomm_encode_simple_doavoid(encoder);
simple_IntString is;
is.x = 24;
is.s = "Hello, LabComm!";
......
......@@ -25,3 +25,18 @@ sample struct {
int a[2];
int b[2,3];
} TwoFixedArrays;
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[_];
......@@ -175,7 +175,7 @@ int main(int argc, char *argv[])
}
}
printf("\n");
labcomm_encode_types_Terminate(encoder, LABCOMM_VOID);
labcomm_encode_types_Terminate(encoder);
out:
return 0;
......
......@@ -179,7 +179,8 @@ void dump_encoder(struct labcomm_encoder *encoder)
int main(void)
{
generated_encoding_V V;
//no longer used
//generated_encoding_V V;
generated_encoding_B B = 1;
struct labcomm_encoder *encoder = labcomm_encoder_new(
......@@ -199,7 +200,8 @@ int main(void)
EXPECT({0x02, -1, 0x01, 'B', 0x21});
labcomm_encoder_ioctl(encoder, IOCTL_WRITER_RESET);
labcomm_encode_generated_encoding_V(encoder, &V);
// was: labcomm_encode_generated_encoding_V(encoder, &V);
labcomm_encode_generated_encoding_V(encoder);
EXPECT({-1});
labcomm_encoder_ioctl(encoder, IOCTL_WRITER_RESET);
......
......@@ -6,7 +6,7 @@ CFLAGS=-O3 -g -Wall -Werror
all:
test: $(TESTS:%=test_%)
test: $(TESTS:%=test_%) compiler_errors
# PYTHONPATH=../lib/python \
# ./test_encoder_decoder.py --labcomm="$(LABCOMM)" basic.lc
......@@ -27,6 +27,20 @@ test_%: gen/%/signatures.py \
--test mono gen/$*/cs_relay.exe /dev/stdin /dev/stdout \
--test java \\-cp gen/$*:../lib/java/labcomm.jar java_relay \
/dev/stdin /dev/stdout
# test cases for compiler error checking
.PHONY: compiler_errors testErrorsOK testErrorsNOK
compiler_errors: testErrorsOK testErrorsNOK
# tests that should succeed
testErrorsOK: $(wildcard errors/correct/*.lc)
./test_errors.py --labcomm="$(LABCOMM)" --testOK $^
# tests that should fail
testErrorsNOK: $(wildcard errors/incorrect/*.lc)
./test_errors.py --labcomm="$(LABCOMM)" --testNOK $^
.PRECIOUS: gen/%/.dir
gen/%/.dir:
mkdir -p gen/$*
......
typedef struct {
string topic;
} pubsub;
sample pubsub subscribe;
sample pubsub unsubscribe;
sample pubsub publish;
sample pubsub unpublish;
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[_];
typedef void avoid;
// examples of errors: void may not be used
// in structs or arrays
//
sample struct {
int a;
avoid error_1;
} foo;
sample void error_2[2] ;
sample avoid error_3[_];
......@@ -16,13 +16,14 @@ if __name__ == '__main__':
f = open(sys.argv[1])
sample = []
for l in map(lambda s: s.strip(), f):
lang,kind,func,arg = l[1:].split(l[0])
lang,kind,func,arg,stype = l[1:].split(l[0])
if lang == 'C' and kind == 'sample':
sample.append((func, arg))
sample.append((func, arg, stype))
pass
pass
result = []
result.extend(split_match('^[^|]*\|(.*)$', """
|// generated by relay_gen_c.py
|#include <sys/types.h>
|#include <sys/stat.h>
|#include <fcntl.h>
......@@ -34,13 +35,19 @@ if __name__ == '__main__':
|#include <labcomm_fd_writer.h>
|#include "c_code.h"
"""))
for func,arg in sample:
for func,arg,stype in sample:
result.extend(split_match('^[^|]*\|(.*)$', """
|void handle_%(func)s(%(arg)s *v, void *context)
|{
| struct labcomm_encoder *e = context;
| labcomm_encode_%(func)s(e, v);
|}""" % { 'func': func, 'arg': arg }))
| labcomm_encode_%(func)s(e%(valargstr)s);
|}""" % { 'func': func, 'arg': arg, 'valargstr': '' if stype == "void" else', v' }))
# result.extend(split_match('^[^|]*\|(.*)$', """
# |void handle_%(func)s(%(arg)s *v, void *context)
# |{
# | struct labcomm_encoder *e = context;
# | labcomm_encode_%(func)s(e, v);
# |}""" % { 'func': func, 'arg': arg }))
pass
result.extend(split_match('^[^|]*\|(.*)$', """
|int main(int argc, char *argv[]) {
......@@ -64,7 +71,7 @@ if __name__ == '__main__':
| labcomm_default_memory,
| labcomm_default_scheduler);
"""))
for func,arg in sample:
for func,arg,stype in sample:
result.extend(split_match('^[^|]*\|(.*)$', """
| labcomm_encoder_register_%(func)s(e);
| labcomm_decoder_register_%(func)s(d, handle_%(func)s, e);
......
......@@ -16,7 +16,7 @@ if __name__ == '__main__':
f = open(sys.argv[1])
sample = []
for l in map(lambda s: s.strip(), f):
lang,kind,func,arg = l[1:].split(l[0])
lang,kind,func,arg,dummy = l[1:].split(l[0])
if lang == 'C#' and kind == 'sample':
sample.append((func, arg))
pass
......
Supports Markdown
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