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

added TYPE_BIND_SELF; don't send type_decl for samples without dependencies

parent c5978128
......@@ -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();
......
......@@ -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
......
......@@ -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));
......
......@@ -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();
......
......@@ -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");
......
......@@ -23,3 +23,8 @@ sample struct {
line l2;
foo f;
} twoLines;
sample struct {
int a;
int b;
} twoInts;
......@@ -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;
}
......@@ -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);
}
......
......@@ -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
......
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