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

cherry-pick 332bab18d

parent dbae91b4
No related branches found
No related tags found
No related merge requests found
......@@ -337,6 +337,9 @@ aspect User_Types {
when parentDecl() != null && getType().isUserType()
to Decl.references()
for parentDecl();
syn boolean Decl.hasReferences();
eq Decl.hasReferences() = !references().isEmpty();
}
aspect Java_Class {
......@@ -358,7 +361,7 @@ aspect Java_Class {
}
public void Decl.Java_emitUserTypeDeps(Java_env env, String via, boolean outputCode) {
if( !references().isEmpty() ) {
if( hasReferences() ) {
Iterator<Decl> it = references().iterator();
while(it.hasNext()) {
Decl t = it.next();
......@@ -398,17 +401,26 @@ aspect Java_Class {
env.println("import se.lth.control.labcomm"+env.verStr+".SampleType;");
if (getType().Java_needInstance()) {
env.println("import java.io.IOException;");
env.println("import se.lth.control.labcomm"+env.verStr+".Encoder;");
env.println("import se.lth.control.labcomm"+env.verStr+".Decoder;");
}
if (getType().Java_needInstance() || hasReferences()) {
env.println("import se.lth.control.labcomm"+env.verStr+".Encoder;");
env.println();
}
//For types not needing an instance, currently just an empty class is generated
// For types without references and not needing an instance,
// currently just an empty class is generated
env.println("public class " + getName() + " implements SampleType {");
env.println();
if (getType().Java_needInstance()) {
env.indent();
if(hasReferences()) {
// XXX Java_emitRegisterEncoder(env);
// XXX Java_emitDispatcher(env, false);
}
if (getType().Java_needInstance()) {
getType().Java_emitInstance(env);
Java_emitEncoder(env);
Java_emitDecoder(env);
......@@ -461,7 +473,36 @@ aspect Java_Class {
env.println();
Java_emitRegisterEncoder(env);
Java_emitDispatcher(env, true);
Java_emitEncoder(env);
Java_emitDecoder(env);
env.println("private static byte[] signature = new byte[] {");
env.indent();
SignatureList signature = signature(env.version);
for (int i = 0 ; i < signature.size() ; i++) {
String comment = signature.getComment(i);
if (comment != null) {
env.println(signature.getIndent(i) + "// " + comment);
}
byte[] data = signature.getData(i);
if (data != null) {
env.print(signature.getIndent(i));
for (int j = 0 ; j < data.length ; j++) {
env.print(data[j] + ", ");
}
env.println();
}
}
env.unindent();
env.println("};");
env.unindent();
env.println();
env.println("}");
}
public void Decl.Java_emitDispatcher(Java_env env, boolean canDecodeAndHandle) {
env.println("private static class Dispatcher implements SampleDispatcher {");
env.indent();
env.println();
......@@ -483,15 +524,25 @@ aspect Java_Class {
env.unindent();
env.println("}");
env.println();
env.println("public boolean isSample() {");
env.indent();
env.println("return "+canDecodeAndHandle+";");
env.unindent();
env.println("}");
env.println();
env.println("public void decodeAndHandle(Decoder d,");
env.println(" SampleHandler h) throws Exception {");
env.indent();
if( canDecodeAndHandle) {
if (isVoid()) {
env.println(getName() + ".decode(d);");
env.println("((Handler)h).handle_" + getName() + "();");
} else {
env.println("((Handler)h).handle_" + getName() + "(" + getName() + ".decode(d));");
}
} else {
env.println("throw new Exception(\"A typedef has no handler, the corresponding method on the sample class should be called.\");");
}
env.unindent();
env.println("}");
env.println("");
......@@ -499,30 +550,6 @@ aspect Java_Class {
env.println("}");
env.println("");
Java_emitEncoder(env);
Java_emitDecoder(env);
env.println("private static byte[] signature = new byte[] {");
env.indent();
SignatureList signature = signature(env.version);
for (int i = 0 ; i < signature.size() ; i++) {
String comment = signature.getComment(i);
if (comment != null) {
env.println(signature.getIndent(i) + "// " + comment);
}
byte[] data = signature.getData(i);
if (data != null) {
env.print(signature.getIndent(i));
for (int j = 0 ; j < data.length ; j++) {
env.print(data[j] + ", ");
}
env.println();
}
}
env.unindent();
env.println("};");
env.unindent();
env.println();
env.println("}");
}
public void TypeDecl.Java_emitEncoder(Java_env env) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment