diff --git a/compiler/2014/Java_CodeGen.jrag b/compiler/2014/Java_CodeGen.jrag index e643aa4de53794f133c559f0b4fd40001e2d4695..62a59eff2b4d6db81c899e25dfbc817121f70aaa 100644 --- a/compiler/2014/Java_CodeGen.jrag +++ b/compiler/2014/Java_CodeGen.jrag @@ -465,7 +465,7 @@ aspect Java_Class { //the type_ids of dependent types. Therefore, flat sigs //are used for matching Java_emitFlatSignature(env); - if(isReferenced() || isSampleDecl()){ + if(isReferenced() || (isSampleDecl() && hasDependencies() )){ Signature signature = getSignature(); signature.Java_emitSignature(env, !isSampleDecl()); } @@ -545,11 +545,11 @@ aspect Java_Class { env.println("return "+isSample+";"); env.unindent(); env.println("}"); -// env.println("public boolean hasStaticSignature() {"); -// env.indent(); -// env.println("return "+!hasDependencies()+";"); -// env.unindent(); -// env.println("}"); + env.println("public boolean hasDependencies() {"); + env.indent(); + env.println("return "+hasDependencies()+";"); + env.unindent(); + env.println("}"); env.println(); env.println("/** return the flat signature. */"); env.println("public byte[] getSignature() {"); @@ -570,7 +570,11 @@ aspect Java_Class { // env.println(); env.println("public void encodeTypeDef(Encoder e, int index) throws IOException{"); env.indent(); - env.println("emitSignature(e);"); + if(!isSample || hasDependencies()) { + env.println("emitSignature(e);"); + } else { + env.println("// the type has no dependencies, do nothing"); + } env.unindent(); env.println("}"); env.println(); diff --git a/doc/tech_report.tex b/doc/tech_report.tex index 244cdd1709754b17bef8146644af900739e897f9..561d69a0ac4d9437c826735f71b919a3ca04464f 100644 --- a/doc/tech_report.tex +++ b/doc/tech_report.tex @@ -382,6 +382,11 @@ come from two independent number series. To identify which \verb+TYPE_DECL+ a particular \verb+SAMPLE_DECL+ corresponds to, the \verb+TYPE_BINDING+ packet is used. +For sample types that do not depend on any typedefs, no \verb+TYPE_DECL+ +is sent, and the \verb+TYPE_BINDING+ binds the sample id to the special +value zero to indicate that the type definition is identical to the +flattened signature. + \subsection{Example} The labcomm declaration diff --git a/examples/user_types/Decoder.java b/examples/user_types/Decoder.java index bdb17374517015db59e66c02c3144b9d9bf886bc..558131b741439ebf95c8157ecd61f83c56ce4f5c 100644 --- a/examples/user_types/Decoder.java +++ b/examples/user_types/Decoder.java @@ -5,7 +5,8 @@ import java.io.InputStream; import se.lth.control.labcomm.DecoderChannel; public class Decoder - implements twoLines.Handler + implements twoLines.Handler, + twoInts.Handler { @@ -15,6 +16,7 @@ public class Decoder throws Exception { decoder = new DecoderChannel(in); + twoInts.register(decoder, this); twoLines.register(decoder, this); try { @@ -33,6 +35,11 @@ public class Decoder return "Line from "+genPoint(l.start)+" to "+genPoint(l.end); } + public void handle_twoInts(twoInts d) throws java.io.IOException { + System.out.print("Got twoInts: "); + System.out.println(d.a +", "+d.b); + } + 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 aa2f80e9617aa3b47b468f4d46469573743a8bc9..acee88936e922a14fd902a2563a1c4a088f41d89 100644 --- a/examples/user_types/Encoder.java +++ b/examples/user_types/Encoder.java @@ -16,10 +16,18 @@ public class Encoder throws Exception { encoder = new EncoderChannel(out); + twoInts.register(encoder); twoLines.register(encoder); } public void doEncode() throws java.io.IOException { + twoInts ti = new twoInts(); + ti.a = 12; + ti.b = 21; + + System.out.println("Encoding twoInts"); + twoInts.encode(encoder, ti); + twoLines x = new twoLines(); line l1 = new line(); point p11 = new point(); diff --git a/examples/user_types/example_decoder.c b/examples/user_types/example_decoder.c index 1aebedc5cafe542d4b485e9388a5e3ef83733e37..ed3310020b1e6427018535a20f947f02ee335351 100644 --- a/examples/user_types/example_decoder.c +++ b/examples/user_types/example_decoder.c @@ -8,6 +8,10 @@ #include "gen/test.h" #include <stdio.h> +static void handle_test_twoInts(test_twoInts *v,void *context) { + printf("Got twoInts. (%d,%d) \n", v->a, v->b); +} + static void handle_test_twoLines(test_twoLines *v,void *context) { printf("Got twoLines. (%d,%d) -> (%d,%d), (%d,%d) -> (%d,%d)\n", v->l1.start.x.val, v->l1.start.y.val, v->l1.end.x.val, v->l1.end.y.val, @@ -33,6 +37,7 @@ int main(int argc, char *argv[]) { return 1; } + labcomm_decoder_register_test_twoInts(decoder, handle_test_twoInts, context); labcomm_decoder_register_test_twoLines(decoder, handle_test_twoLines, context); printf("Decoding:\n"); diff --git a/examples/user_types/test.lc b/examples/user_types/test.lc index d2225394b890937f471e6984a8122aff11b3d51b..9df2ebc98ec815fbd0db894e8f1a200de88392d3 100644 --- a/examples/user_types/test.lc +++ b/examples/user_types/test.lc @@ -23,3 +23,8 @@ sample struct { line l2; foo f; } twoLines; + +sample struct { + int a; + int b; +} twoInts; diff --git a/lib/java/se/lth/control/labcomm/Constant.java b/lib/java/se/lth/control/labcomm/Constant.java index fc52a2805a7089f3537bb379234e3dd680feb0fd..119817274bc1525dc31e87a265a92e0fa6a2f4a3 100644 --- a/lib/java/se/lth/control/labcomm/Constant.java +++ b/lib/java/se/lth/control/labcomm/Constant.java @@ -36,4 +36,10 @@ public class Constant { public static final int DOUBLE = 0x26; public static final int STRING = 0x27; + + /* + * Other predefined symbols + */ + + public static final int TYPE_BIND_SELF = 0x00; } diff --git a/lib/java/se/lth/control/labcomm/EncoderChannel.java b/lib/java/se/lth/control/labcomm/EncoderChannel.java index a76629308818a5b946d082d53e3c582ae7d86a2a..221259a37ef938214df481929cb8401e19735532 100644 --- a/lib/java/se/lth/control/labcomm/EncoderChannel.java +++ b/lib/java/se/lth/control/labcomm/EncoderChannel.java @@ -53,7 +53,12 @@ public class EncoderChannel implements Encoder { encodeByte(signature[i]); } end(null); - int tindex = registerTypeDef(dispatcher); + int tindex; + if(dispatcher.hasDependencies()){ + tindex = registerTypeDef(dispatcher); + } else { + tindex = Constant.TYPE_BIND_SELF; + } bindType(index, tindex); } diff --git a/lib/java/se/lth/control/labcomm/SampleDispatcher.java b/lib/java/se/lth/control/labcomm/SampleDispatcher.java index aeef84e1a3ac9f739dbe54fb4056a535ad6a68de..b2ed2fd98658f15461c6a8a60e8f4bb9df39418b 100644 --- a/lib/java/se/lth/control/labcomm/SampleDispatcher.java +++ b/lib/java/se/lth/control/labcomm/SampleDispatcher.java @@ -13,6 +13,10 @@ public interface SampleDispatcher <T extends SampleType>{ public void decodeAndHandle(Decoder decoder, SampleHandler handler) throws Exception; + /** @return true if the type depends on one or more typedefs + */ + public boolean hasDependencies(); + public void encodeTypeDef(Encoder e, int index) throws IOException; /** return the tag SAMPLE_DEF or TYPE_DEF, for use