Commit 046d7a95 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

cherry-pick 7f014efd9

parent 415a7153
...@@ -320,27 +320,6 @@ aspect Java_Register { ...@@ -320,27 +320,6 @@ aspect Java_Register {
} }
} }
aspect User_Types {
syn String Type.getTypeName();
eq Type.getTypeName() = getClass().getName();
eq PrimType.getTypeName() = getName();
eq UserType.getTypeName() = getName();
syn boolean Type.isUserType();
eq Type.isUserType() = false;
eq UserType.isUserType() = true;
coll Set<Decl> Decl.references() [new HashSet<Decl>()] with add;
Field contributes ((UserType)getType()).decl()
when parentDecl() != null && getType().isUserType()
to Decl.references()
for parentDecl();
syn boolean Decl.hasReferences();
eq Decl.hasReferences() = !references().isEmpty();
}
aspect Java_Class { aspect Java_Class {
...@@ -356,13 +335,14 @@ aspect Java_Class { ...@@ -356,13 +335,14 @@ aspect Java_Class {
pp(env.getPrintStream()); pp(env.getPrintStream());
Java_emitUserTypeDeps(env, null, false); Java_emitUserTypeDeps(env, null, false);
Java_emitUserTypeRefs(env, null, false);
env.println("*/"); env.println("*/");
} }
public void Decl.Java_emitUserTypeDeps(Java_env env, String via, boolean outputCode) { public void Decl.Java_emitUserTypeDeps(Java_env env, String via, boolean outputCode) {
if( hasReferences() ) { if( hasDependencies() ) {
Iterator<Decl> it = references().iterator(); Iterator<Decl> it = type_dependencies().iterator();
while(it.hasNext()) { while(it.hasNext()) {
Decl t = it.next(); Decl t = it.next();
...@@ -376,10 +356,24 @@ aspect Java_Class { ...@@ -376,10 +356,24 @@ aspect Java_Class {
} }
} }
} }
// else {
// env.println(" //no more deps ");
// }
} }
public void Decl.Java_emitUserTypeRefs(Java_env env, String via, boolean outputCode) {
if( isReferenced() ) {
Iterator<Decl> it = type_references().iterator();
while(it.hasNext()) {
Decl t = it.next();
t.Java_emitUserTypeRefs(env, t.getName(), outputCode);
if(outputCode) {
env.println(t.getName()+".register(e);");
} else { // Just output a comment
String refpath = (via == null) ? "directly" : "indirectly via "+via;
env.println(" //Is referenced by ("+refpath+") on "+t.getName() );
}
}
}
}
public void Decl.Java_emitRegisterEncoder(Java_env env) { public void Decl.Java_emitRegisterEncoder(Java_env env) {
env.println("public static void register(Encoder e) throws IOException {"); env.println("public static void register(Encoder e) throws IOException {");
...@@ -403,19 +397,19 @@ aspect Java_Class { ...@@ -403,19 +397,19 @@ aspect Java_Class {
env.println("import java.io.IOException;"); env.println("import java.io.IOException;");
env.println("import se.lth.control.labcomm"+env.verStr+".Decoder;"); env.println("import se.lth.control.labcomm"+env.verStr+".Decoder;");
} }
if (getType().Java_needInstance() || hasReferences()) { if (getType().Java_needInstance() || hasDependencies()) {
env.println("import se.lth.control.labcomm"+env.verStr+".Encoder;"); env.println("import se.lth.control.labcomm"+env.verStr+".Encoder;");
env.println(); env.println();
} }
// For types without references and not needing an instance, // For types without type_dependencies and not needing an instance,
// currently just an empty class is generated // currently just an empty class is generated
env.println("public class " + getName() + " implements SampleType {"); env.println("public class " + getName() + " implements SampleType {");
env.println(); env.println();
env.indent(); env.indent();
if(hasReferences()) { if(hasDependencies() || isReferenced()) {
// XXX Java_emitRegisterEncoder(env); // XXX Java_emitRegisterEncoder(env);
// XXX Java_emitDispatcher(env, false); // XXX Java_emitDispatcher(env, false);
} }
......
aspect User_Types {
syn String Type.getTypeName();
eq Type.getTypeName() = getClass().getName();
eq PrimType.getTypeName() = getName();
eq UserType.getTypeName() = getName();
syn boolean Type.isUserType();
eq Type.isUserType() = false;
eq UserType.isUserType() = true;
}
aspect Type_References {
// The dependencies on other type declarations for a Decl.
coll Set<Decl> Decl.type_dependencies() [new HashSet<Decl>()] with add;
Field contributes ((UserType)getType()).decl()
when parentDecl() != null && getType().isUserType()
to Decl.type_dependencies()
for parentDecl();
// The references from other type declarations to a Decl.
coll Set<Decl> Decl.type_references() [new HashSet<Decl>()] with add;
Decl contributes this
to Decl.type_references()
for each type_dependencies();
syn boolean Decl.hasDependencies();
eq Decl.hasDependencies() = !type_dependencies().isEmpty();
syn boolean Decl.isReferenced();
eq Decl.isReferenced() = !type_references().isEmpty();
}
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