From 6c90d315a142dfcb92e31e743e54568936c5e682 Mon Sep 17 00:00:00 2001 From: Sven Gestegard Robertz <sven.robertz@cs.lth.se> Date: Wed, 11 Feb 2015 16:37:05 +0100 Subject: [PATCH] commented out unused SampleRefType in compiler, and added ref tests in examples/user_types --- compiler/2014/FlatSignature.jrag | 12 ++++----- compiler/2014/LabComm.ast | 2 +- compiler/2014/PrettyPrint.jrag | 6 ++--- compiler/2014/Signature.jrag | 6 ++--- examples/user_types/Decoder.java | 9 ++++++- examples/user_types/Encoder.java | 15 ++++++++--- examples/user_types/ExampleDecoder.cs | 10 +++++++- examples/user_types/TDDecoder.java | 11 ++++++-- examples/user_types/example_decoder.c | 7 ++++++ examples/user_types/test.lc | 5 ++++ .../se/lth/control/labcomm/TypeDefParser.java | 25 +++++++++++-------- .../lth/control/labcomm/TypeDefVisitor.java | 8 +++--- 12 files changed, 81 insertions(+), 35 deletions(-) diff --git a/compiler/2014/FlatSignature.jrag b/compiler/2014/FlatSignature.jrag index 2a9ca4d..b96c119 100644 --- a/compiler/2014/FlatSignature.jrag +++ b/compiler/2014/FlatSignature.jrag @@ -21,9 +21,9 @@ aspect FlatSignature { getType().flatSignature(list); } - public void SampleRefType.flatSignature(SignatureList list) { - list.addInt(LABCOMM_SAMPLE_REF, "sample"); - } +// public void SampleRefType.flatSignature(SignatureList list) { +// list.addInt(LABCOMM_SAMPLE_REF, "sample"); +// } public void VoidType.flatSignature(SignatureList list) { list.addInt(LABCOMM_STRUCT, "void"); @@ -96,9 +96,9 @@ aspect FlatSignature { return getType().signatureComment() + " '" + getName() +"'"; } - public String SampleRefType.signatureComment() { - return "sample"; - } +// public String SampleRefType.signatureComment() { +// return "sample"; +// } public String PrimType.signatureComment() { return getName(); diff --git a/compiler/2014/LabComm.ast b/compiler/2014/LabComm.ast index bbadfad..d3d5e59 100644 --- a/compiler/2014/LabComm.ast +++ b/compiler/2014/LabComm.ast @@ -21,7 +21,7 @@ Field ::= Type <Name:String>; abstract Type; VoidType : Type; -SampleRefType : Type; +//SampleRefType : Type; PrimType : Type ::= <Name:String> <Token:int>; UserType : Type ::= <Name:String>; StructType : Type ::= Field*; diff --git a/compiler/2014/PrettyPrint.jrag b/compiler/2014/PrettyPrint.jrag index a7fa877..3808c95 100644 --- a/compiler/2014/PrettyPrint.jrag +++ b/compiler/2014/PrettyPrint.jrag @@ -68,9 +68,9 @@ aspect PrettyPrint { out.print("void"); } - public void SampleRefType.ppPrefix(PrintStream out) { - out.print("sample"); - } +// public void SampleRefType.ppPrefix(PrintStream out) { +// out.print("sample"); +// } public void PrimType.ppPrefix(PrintStream out) { out.print(getName()); diff --git a/compiler/2014/Signature.jrag b/compiler/2014/Signature.jrag index fb232b9..b32e535 100644 --- a/compiler/2014/Signature.jrag +++ b/compiler/2014/Signature.jrag @@ -174,9 +174,9 @@ aspect Signature { list.addInt(0, null); } - public void SampleRefType.genSigLineForDecl(SignatureList list, boolean decl) { - list.addInt(LABCOMM_SAMPLE_REF, "sample"); - } +// public void SampleRefType.genSigLineForDecl(SignatureList list, boolean decl) { +// list.addInt(LABCOMM_SAMPLE_REF, "sample"); +// } public void PrimType.genSigLineForDecl(SignatureList list, boolean decl) { list.addInt(getToken(), null); } diff --git a/examples/user_types/Decoder.java b/examples/user_types/Decoder.java index 9d15143..29069b1 100644 --- a/examples/user_types/Decoder.java +++ b/examples/user_types/Decoder.java @@ -16,7 +16,8 @@ public class Decoder twoInts.Handler, theFirstInt.Handler, theSecondInt.Handler, - doavoid.Handler + doavoid.Handler, + intAndRef.Handler { private DecoderChannel decoder; @@ -31,6 +32,8 @@ public class Decoder twoLines.register(decoder, this); theFirstInt.register(decoder, this); theSecondInt.register(decoder, this); + intAndRef.register(decoder, this); + doavoid.registerSampleRef(decoder); this.tdp = TypeDefParser.registerTypeDefParser(decoder); // TypeDef.register(decoder, this); // TypeBinding.register(decoder, this); @@ -92,6 +95,10 @@ public class Decoder System.out.println("Got theSecondInt: "+d); } + public void handle_intAndRef(intAndRef d) throws java.io.IOException { + System.out.println("Got intAndRef: "+d.x+", "+d.reference); + } + public void handle_twoLines(twoLines d) throws java.io.IOException { System.out.print("Got twoLines: "); System.out.println("Line l1: "+genLine(d.l1)); diff --git a/examples/user_types/Encoder.java b/examples/user_types/Encoder.java index ac8add6..d5687a2 100644 --- a/examples/user_types/Encoder.java +++ b/examples/user_types/Encoder.java @@ -21,16 +21,25 @@ public class Encoder twoLines.register(encoder); theFirstInt.register(encoder); theSecondInt.register(encoder); + intAndRef.register(encoder); + doavoid.registerSampleRef(encoder); } public void doEncode() throws java.io.IOException { + System.out.println("Encoding doavoid"); + doavoid.encode(encoder); + + intAndRef iar = new intAndRef(); + iar.x = 17; + iar.reference = doavoid.class; + + System.out.println("Encoding intAndRef"); + intAndRef.encode(encoder, iar); + twoInts ti = new twoInts(); ti.a = 12; ti.b = 21; - System.out.println("Encoding doavoid"); - doavoid.encode(encoder); - System.out.println("Encoding twoInts"); twoInts.encode(encoder, ti); diff --git a/examples/user_types/ExampleDecoder.cs b/examples/user_types/ExampleDecoder.cs index ec0f096..95b1fca 100644 --- a/examples/user_types/ExampleDecoder.cs +++ b/examples/user_types/ExampleDecoder.cs @@ -11,7 +11,8 @@ namespace user_types twoInts.Handler, theFirstInt.Handler, theSecondInt.Handler, - doavoid.Handler + doavoid.Handler, + intAndRef.Handler { DecoderChannel dec; @@ -23,6 +24,8 @@ namespace user_types theFirstInt.register(dec, this); theSecondInt.register(dec, this); doavoid.register(dec, this); + intAndRef.register(dec, this); + doavoid.registerSampleRef(dec); try { Console.WriteLine("Running decoder."); @@ -71,6 +74,11 @@ namespace user_types Console.WriteLine("Got a void."); } + void intAndRef.Handler.handle(intAndRef d) + { + Console.WriteLine("Got intAndRef: "+d.x+" : "+d.reference); + } + static void Main(string[] args) { new Decoder(new FileStream(args[0], FileMode.Open)); diff --git a/examples/user_types/TDDecoder.java b/examples/user_types/TDDecoder.java index a689842..be6e7eb 100644 --- a/examples/user_types/TDDecoder.java +++ b/examples/user_types/TDDecoder.java @@ -26,7 +26,8 @@ public class TDDecoder twoInts.Handler, theFirstInt.Handler, theSecondInt.Handler, - doavoid.Handler + doavoid.Handler, + intAndRef.Handler { private DecoderChannel decoder; @@ -41,6 +42,8 @@ public class TDDecoder theFirstInt.register(decoder, this); theSecondInt.register(decoder, this); doavoid.register(decoder, this); + intAndRef.register(decoder, this); + doavoid.registerSampleRef(decoder); this.tdp = TypeDefParser.registerTypeDefParser(decoder); // TypeDef.register(decoder, this); // TypeBinding.register(decoder, this); @@ -84,7 +87,7 @@ public class TDDecoder //FileOutputStream f = new FileOutputStream("/tmp/foopp"+d.getName()+".txt"); //PrintStream out = new PrintStream(f); p.pp(System.out); - p.C_genC(System.out, new Vector(), "lcname", "prefix", 2014); + //p.C_genC(System.out, new Vector(), "lcname", "prefix", 2014); //p.J_gen(out, "testpackage", 2014); //out.close(); } catch (Throwable e) { @@ -125,6 +128,10 @@ public class TDDecoder System.out.println("Got a void."); } + public void handle_intAndRef(intAndRef d) throws java.io.IOException { + System.out.println("Got intAndRef: "+d.x+", "+d.reference); + } + public void handle_twoLines(twoLines d) throws java.io.IOException { System.out.print("Got twoLines: "); System.out.println("Line l1: "+genLine(d.l1)); diff --git a/examples/user_types/example_decoder.c b/examples/user_types/example_decoder.c index 2728158..b727f8a 100644 --- a/examples/user_types/example_decoder.c +++ b/examples/user_types/example_decoder.c @@ -12,6 +12,10 @@ static void handle_test_doavoid(test_doavoid *v,void *context) { printf("Got a void.\n"); } +static void handle_test_intAndRef(test_intAndRef *v,void *context) { + printf("Got intAndRef. (%d : %s) \n", v->x, v->reference->name); +} + static void handle_test_twoInts(test_twoInts *v,void *context) { printf("Got twoInts. (%d,%d) \n", v->a, v->b); } @@ -58,6 +62,9 @@ int main(int argc, char *argv[]) { } labcomm_decoder_register_test_doavoid(decoder, handle_test_doavoid, context); + labcomm_decoder_register_test_intAndRef(decoder, handle_test_intAndRef, context); + labcomm_decoder_sample_ref_register(decoder,labcomm_signature_test_doavoid ); + labcomm_decoder_register_test_twoInts(decoder, handle_test_twoInts, context); labcomm_decoder_register_test_theFirstInt(decoder, handle_test_theFirstInt, context); labcomm_decoder_register_test_theSecondInt(decoder, handle_test_theSecondInt, context); diff --git a/examples/user_types/test.lc b/examples/user_types/test.lc index f882abb..75497b4 100644 --- a/examples/user_types/test.lc +++ b/examples/user_types/test.lc @@ -7,6 +7,11 @@ typedef int anInt; typedef void avoid; sample avoid doavoid; +sample struct { + int x; + sample reference; +} intAndRef; + typedef struct { coord x; coord y; diff --git a/lib/java/se/lth/control/labcomm/TypeDefParser.java b/lib/java/se/lth/control/labcomm/TypeDefParser.java index 90c7f1d..5a12cf3 100644 --- a/lib/java/se/lth/control/labcomm/TypeDefParser.java +++ b/lib/java/se/lth/control/labcomm/TypeDefParser.java @@ -181,7 +181,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler { void visit(SampleSymbol s); void visit(NameSymbol s); void visit(PrimitiveType t); - void visit(SampleRefType t); + //void visit(SampleRefType t); void visit(ParsedStructType t); void visit(ParsedField t); void visit(ArrayType t); @@ -227,14 +227,14 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler { public abstract class ParsedType extends ParsedSymbol{ } - public class SampleRefType extends ParsedType { - public void accept(ParsedSymbolVisitor v) { - v.visit(this); - } - - public String toString() { - return "sample";} - } +// public class SampleRefType extends ParsedType { +// public void accept(ParsedSymbolVisitor v) { +// v.visit(this); +// } +// +// public String toString() { +// return "sample";} +// } public class PrimitiveType extends ParsedType { private final String name; @@ -274,6 +274,9 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler { case Constant.STRING: this.name = "string"; break; + case Constant.SAMPLE: + this.name = "sample"; + break; default: this.name = "??? unknown tag 0x"+Integer.toHexString(tag); } @@ -643,8 +646,8 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler { TypeDef td = typeDefs.get(tag); result = new ParsedUserType(td.getName()); in.pushType(tag); - } else if(tag == Constant.SAMPLE) { - result = new SampleRefType(); +// } else if(tag == Constant.SAMPLE) { +// result = new SampleRefType(); } else { result = new PrimitiveType(tag); } diff --git a/lib/java/se/lth/control/labcomm/TypeDefVisitor.java b/lib/java/se/lth/control/labcomm/TypeDefVisitor.java index 63733e8..96a0991 100644 --- a/lib/java/se/lth/control/labcomm/TypeDefVisitor.java +++ b/lib/java/se/lth/control/labcomm/TypeDefVisitor.java @@ -23,7 +23,7 @@ import se.lth.control.labcomm2014.compiler.TypeDecl; import se.lth.control.labcomm2014.compiler.SampleDecl; import se.lth.control.labcomm2014.compiler.Type; import se.lth.control.labcomm2014.compiler.VoidType; -import se.lth.control.labcomm2014.compiler.SampleRefType; +//import se.lth.control.labcomm2014.compiler.SampleRefType; import se.lth.control.labcomm2014.compiler.PrimType; import se.lth.control.labcomm2014.compiler.UserType; import se.lth.control.labcomm2014.compiler.StructType; @@ -69,9 +69,9 @@ public class TypeDefVisitor implements TypeDefParser.ParsedSymbolVisitor { typeStack.push(new PrimType(t.getName(), t.getTag())); } - public void visit(TypeDefParser.SampleRefType t){ - typeStack.push(new SampleRefType()); - } +// public void visit(TypeDefParser.SampleRefType t){ +// typeStack.push(new SampleRefType()); +// } public void visit(TypeDefParser.ParsedStructType t){ if(t.isVoid()) { -- GitLab