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

cherry-pick 332bab18d

parent dbae91b4
......@@ -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();
......@@ -392,27 +395,36 @@ aspect Java_Class {
public void TypeDecl.Java_emitClass(Java_env env, String pack) {
Java_emitDeclPP(env);
if (pack != null && pack.length() > 0) {
env.println("package " + pack + ";");
env.println("package " + pack + ";");
}
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;");
env.println();
}
//For types not needing an instance, currently just an empty class is generated
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+".Decoder;");
}
if (getType().Java_needInstance() || hasReferences()) {
env.println("import se.lth.control.labcomm"+env.verStr+".Encoder;");
env.println();
}
// 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();
getType().Java_emitInstance(env);
Java_emitEncoder(env);
Java_emitDecoder(env);
}
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);
}
env.unindent();
env.println("}");
}
......@@ -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,14 +524,24 @@ 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 (isVoid()) {
env.println(getName() + ".decode(d);");
env.println("((Handler)h).handle_" + getName() + "();");
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("((Handler)h).handle_" + getName() + "(" + getName() + ".decode(d));");
env.println("throw new Exception(\"A typedef has no handler, the corresponding method on the sample class should be called.\");");
}
env.unindent();
env.println("}");
......@@ -499,31 +550,7 @@ 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) {
env.print("public static void encode(Encoder e");
......
Markdown is supported
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