Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • anders_blomdell/labcomm
  • klaren/labcomm
  • tommyo/labcomm
  • erikj/labcomm
  • sven/labcomm
5 results
Select Git revision
Loading items
Show changes
Commits on Source (108)
Showing
with 1200 additions and 950 deletions
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
*.class *.class
*.o *.o
*.pyc *.pyc
examples/dynamic/gen
SUBDIRS=compiler lib test examples packaging SUBDIRS=compiler lib test examples packaging
export LABCOMM_JAR=$(shell pwd)/compiler/labcomm2014_compiler.jar export LABCOMM_JAR=$(shell pwd)/compiler/labcomm2014_compiler.jar
export LABCOMM=java -jar $(LABCOMM_JAR) export LABCOMM=java -jar $(LABCOMM_JAR)
export VALGRIND=valgrind --leak-check=full --error-exitcode=1
UNAME_S=$(shell uname -s)
.PHONY: all .PHONY: all
all: $(SUBDIRS:%=all-%) all: $(SUBDIRS:%=all-%)
.PHONY: all-% .PHONY: all-%
all-%: all-%:
ifeq ($(UNAME_S),Darwin)
DYLD_LIBRARY_PATH=`pwd`/lib/c $(MAKE) -C $*
else
LD_LIBRARY_PATH=`pwd`/lib/c $(MAKE) -C $* LD_LIBRARY_PATH=`pwd`/lib/c $(MAKE) -C $*
endif
.PHONY: test .PHONY: test
test: $(SUBDIRS:%=test-%) test: $(SUBDIRS:%=test-%)
.PHONY: test-% .PHONY: test-%
test-%: test-%:
ifeq ($(UNAME_S),Darwin)
DYLD_LIBRARY_PATH=`pwd`/lib/c $(MAKE) -C $* test
else
LD_LIBRARY_PATH=`pwd`/lib/c $(MAKE) -C $* test LD_LIBRARY_PATH=`pwd`/lib/c $(MAKE) -C $* test
endif
.PHONY: clean .PHONY: clean
clean: $(SUBDIRS:%=clean-%) clean: $(SUBDIRS:%=clean-%)
......
aspect Annotations {
syn boolean TypeInstance.hasAnnotations() = getAnnotations().getNumAnnotation()>0;
syn boolean TypeInstance.hasIntentions() = ! intentionSet().isEmpty();
syn String Annotations.getName() = new String(lookup(""));
syn byte[] Annotations.lookup(String key) {
for(Annotation a: getAnnotations()) {
byte[] res = a.lookup(key);
if(res != null) return res;
}
return null;
}
syn byte[] Annotation.lookup(String key) = (getKey().equals(key) ? getValue() : null);
syn boolean Annotation.isIntention() = false;
eq Intention.isIntention() = true;
inh TypeInstance Annotation.parentInstance();
eq TypeInstance.getAnnotations().parentInstance() = this;
coll Set<Intention> TypeInstance.intentionSet() [new HashSet<Intention>()] with add;
Intention contributes this
to TypeInstance.intentionSet()
for parentInstance();
}
aspect SigAnnotations {
inh Decl TypeInstance.parentDecl();
coll Set Decl.allAnnotations() [new HashSet()] with add;
TypeInstance contributes getAnnotationString()
to Decl.allAnnotations()
for parentDecl();
// Helper attribute to get the "outermost" intentions for Decls
syn byte[] TypeInstance.intentionBytes() = getIntentionBytes(sortedIntentions());
syn byte[] Decl.getIntentionBytes() = getTypeInstance().intentionBytes();
static Comparator TypeInstance.intentionComp =
new Comparator<Intention>() {
public int compare(Intention i1, Intention i2) {
return i1.getKey().compareTo(i2.getKey());
}
};
syn int Decl.getNumIntentions() = getTypeInstance().sortedIntentions().getNumChild();
syn List<Intention> TypeInstance.sortedIntentions() {
List<Intention> res = new List<Intention>();
//TODO: refactor out creation of sorted list of intentions
java.util.ArrayList<Intention> sorted = new ArrayList(intentionSet());
java.util.Collections.sort(sorted, intentionComp);
for(Intention i : sorted) {
res.add(i);
}
return res;
}
public DocString.DocString(byte[] bs) {
super("DOCSTRING", bs);
}
public DocString.DocString(String s) {
super("DOCSTRING", s.getBytes());
}
public String Intention.toString() {
return "("+getKey() + ":"+new String(getValue())+")";
}
public String DocString.toString() {
return "\""+new String(getValue())+"\"";
}
/// TESTING
syn String Decl.getAnnotationString() {
StringBuilder sb = new StringBuilder();
Iterator<String> iti = allAnnotations().iterator();
while(iti.hasNext()) {
//Annotation i = iti.next();
//sb.append("("+i.getKey()+" : "+i.getValue()+") ");
String i = iti.next();
sb.append(i);
}
return sb.toString();
}
syn int TypeInstance.fooHash() {
List<Annotation> ints = getAnnotations().getAnnotationList();
int result=0;
for(Annotation i : ints) {
if(i.isIntention()) {
result += i.toString().hashCode();
}
}
return result;
}
syn String TypeInstance.getAnnotationString() {
StringBuilder sb = new StringBuilder();
List<Annotation> ints = getAnnotations().getAnnotationList();
for(Annotation i : ints) {
sb.append(i.toString());
}
return sb.toString();
}
public void Decl.debugAnnotations() {
getTypeInstance().debugAnnotations(getName());
}
public void TypeInstance.debugAnnotations(String context) {
if(hasAnnotations()){
System.out.println(context+".annotations: " + fooHash() + " : " + getAnnotationString());
} else {
//System.out.println(context + " : " + fooHash() + " : " + ": NO ANNOTATIONS ");
}
}
// TESTING END
}
...@@ -13,29 +13,29 @@ aspect ArrayRewrite { ...@@ -13,29 +13,29 @@ aspect ArrayRewrite {
when (! getDim(0).isVariable()) when (! getDim(0).isVariable())
to FixedArrayType { to FixedArrayType {
if (getNumDim() == 1) { if (getNumDim() == 1) {
return new FixedArrayType(getType(), return new FixedArrayType(getDataType(),
getDim(0).getExpList()); getDim(0));
} else { } else {
List l = new List(); List l = new List();
for (int i = 1 ; i < getNumDim() ; i++) { for (int i = 1 ; i < getNumDim() ; i++) {
l.add(getDim(i)); l.add(getDim(i));
} }
return new FixedArrayType(new ParseArrayType(getType(), l), return new FixedArrayType(new ParseArrayType(getDataType(), l),
getDim(0).getExpList()); getDim(0));
} }
} }
when (getDim(0).isVariable()) when (getDim(0).isVariable())
to VariableArrayType { to VariableArrayType {
if (getNumDim() == 1) { if (getNumDim() == 1) {
return new VariableArrayType(getType(), return new VariableArrayType(getDataType(),
getDim(0).getExpList()); getDim(0));
} else { } else {
List l = new List(); List l = new List();
for (int i = 1 ; i < getNumDim() ; i++) { for (int i = 1 ; i < getNumDim() ; i++) {
l.add(getDim(i)); l.add(getDim(i));
} }
return new VariableArrayType(new ParseArrayType(getType(), l), return new VariableArrayType(new ParseArrayType(getDataType(), l),
getDim(0).getExpList()); getDim(0));
} }
} }
} }
......
...@@ -6,145 +6,42 @@ aspect CS_CodeGenEnv { ...@@ -6,145 +6,42 @@ aspect CS_CodeGenEnv {
// Environment wrapper for CS-code generation // Environment wrapper for CS-code generation
// handles indentation, file writing, // handles indentation, file writing,
public class CS_env { public class CS_env extends PrintEnv {
public final int version;
public final String verStr;
private int indent;
private int depth;
private CS_printer printer; private CS_printer printer;
private HashMap unique = new HashMap();
final private static class CS_printer {
private boolean newline = true;
private File file;
private PrintStream out;
private IOException exception;
final private static class CS_printer extends PrintEnv.FilePrinter {
public CS_printer(File f) { public CS_printer(File f) {
file = f; super(f);
File parentFile = f.getParentFile();
if(parentFile != null) {
parentFile.mkdirs();
}
} }
public CS_printer(PrintStream out) { public CS_printer(PrintStream out) {
this.out = out; super(out);
} }
public void close() throws IOException {
if (out != null) {
out.close();
}
if (exception != null) {
throw exception;
}
}
public PrintStream getPrintStream() {
return(out);
}
public void checkOpen() {
if (out == null && exception == null) {
try {
out = new PrintStream(new FileOutputStream(file));
} catch (IOException e) {
exception = e;
}
}
}
public void print(CS_env env, String s) {
checkOpen();
if (newline) {
newline = false;
for (int i = 0 ; i < env.indent ; i++) {
out.print(" ");
}
}
out.print(s);
}
public void println(CS_env env, String s) {
checkOpen();
print(env, s);
out.println();
newline = true;
}
}
private CS_env(int indent, CS_printer printer, int version) {
this.version = version;
this.indent = indent;
this.printer = printer;
this.verStr = LabCommVersion.versionString(version);
} }
public CS_env(File f, int version) { public CS_env(File f, int version) {
this(0, new CS_printer(f), version); super(0, new CS_printer(f), version);
} }
public CS_env(PrintStream out, int version) { public CS_env(PrintStream out, int version) {
this(0, new CS_printer(out), version); super(0, new CS_printer(out), version);
}
public void close() throws IOException {
printer.close();
}
public PrintStream getPrintStream() {
return printer.getPrintStream();
}
public void indent(int amount) {
indent += amount;
} }
public void indent() {
indent(1);
}
public void unindent(int amount) {
indent -= amount;
if (indent < 0) {
throw new Error("Negative indent level");
}
}
public void unindent() {
unindent(1);
}
public void print(String s) {
printer.print(this, s);
}
public void println(String s) {
printer.println(this, s);
}
public void println() {
printer.println(this, "");
}
public int getDepth() {
return depth;
}
public String print_for_begin(String limit) { public String print_for_begin(String limit) {
int depth = getDepth();
print("for (int i_" + depth + " = 0 ; "); print("for (int i_" + depth + " = 0 ; ");
print("i_" + depth + " < " + limit + " ; "); print("i_" + depth + " < " + limit + " ; ");
println("i_" + depth + "++) {"); println("i_" + depth + "++) {");
indent(); indent();
depth++; incDepth();
return "i_" + (depth - 1); return "i_" + (depth);
} }
public void print_for_end() { public void print_for_end() {
depth--; decDepth();
unindent(); unindent();
println("}"); println("}");
} }
...@@ -159,15 +56,6 @@ aspect CS_CodeGenEnv { ...@@ -159,15 +56,6 @@ aspect CS_CodeGenEnv {
println("}"); println("}");
} }
public String getUnique(Object o) {
String result = (String)unique.get(o);
if (result == null) {
result = "_" + (unique.size() + 1) + "_";
}
unique.put(o, result);
return result;
}
} }
} }
...@@ -175,12 +63,12 @@ aspect CS_CodeGenEnv { ...@@ -175,12 +63,12 @@ aspect CS_CodeGenEnv {
aspect CS_StructName { aspect CS_StructName {
inh int Decl.CS_Depth(); inh int Decl.CS_Depth();
inh int Type.CS_Depth(); inh int DataType.CS_Depth();
eq Program.getDecl(int i).CS_Depth() = 0; eq Specification.getDecl(int i).CS_Depth() = 0;
eq StructType.getField(int i).CS_Depth() = CS_Depth() + 1; eq StructType.getField(int i).CS_Depth() = CS_Depth() + 1;
inh String Type.CS_structName(); inh String DataType.CS_structName();
eq Program.getDecl(int i).CS_structName() = getDecl(i).getName(); eq Specification.getDecl(int i).CS_structName() = getDecl(i).getName();
eq StructType.getField(int i).CS_structName() { eq StructType.getField(int i).CS_structName() {
if (CS_Depth() == 0) { if (CS_Depth() == 0) {
return "struct_" + getField(i).getName(); return "struct_" + getField(i).getName();
...@@ -192,16 +80,16 @@ aspect CS_StructName { ...@@ -192,16 +80,16 @@ aspect CS_StructName {
aspect CS_Void { aspect CS_Void {
syn boolean Decl.CS_isVoid() = getType().CS_isVoid(); syn boolean Decl.CS_isVoid() = getDataType().CS_isVoid();
syn boolean UserType.CS_isVoid() = decl().CS_isVoid(); syn boolean UserType.CS_isVoid() = decl().CS_isVoid();
syn boolean Type.CS_isVoid() = false; syn boolean DataType.CS_isVoid() = false;
syn boolean VoidType.CS_isVoid() = true; syn boolean VoidType.CS_isVoid() = true;
} }
aspect CS_CodeGen { aspect CS_CodeGen {
public void Program.CS_gen(String file, public void Specification.CS_gen(String file,
String namespace, int version) throws IOException { String namespace, int version) throws IOException {
// Registration class // Registration class
CS_env env = new CS_env(new File(file), version); CS_env env = new CS_env(new File(file), version);
...@@ -230,7 +118,7 @@ aspect CS_CodeGen { ...@@ -230,7 +118,7 @@ aspect CS_CodeGen {
aspect CS_Register { aspect CS_Register {
public void Program.CS_emitTypeRegister(CS_env env) { public void Specification.CS_emitTypeRegister(CS_env env) {
} }
public void Decl.CS_emitTypeRegister(CS_env env) { public void Decl.CS_emitTypeRegister(CS_env env) {
...@@ -273,7 +161,7 @@ aspect CS_Class { ...@@ -273,7 +161,7 @@ aspect CS_Class {
Decl t = it.next(); Decl t = it.next();
t.CS_emitUserTypeDeps(env, t.getName(), outputCode); t.CS_emitUserTypeDeps(env, t.getName(), outputCode);
if( outputCode && t.getType().isUserType() ) { if( outputCode && t.getDataType().isUserType() ) {
env.println(t.getName()+".register(e);"); env.println(t.getName()+".register(e);");
} else { // Just output a comment } else { // Just output a comment
String refpath = (via == null) ? "directly" : "indirectly via "+via; String refpath = (via == null) ? "directly" : "indirectly via "+via;
...@@ -329,7 +217,7 @@ aspect CS_Class { ...@@ -329,7 +217,7 @@ aspect CS_Class {
} }
public void TypeDecl.CS_emitClass(CS_env env) { public void TypeDecl.CS_emitClass(CS_env env) {
if (getType().CS_needInstance()) { if (getDataType().CS_needInstance()) {
// Hackish prettyprint preamble // Hackish prettyprint preamble
env.println("/* "); env.println("/* ");
pp(env.getPrintStream()); pp(env.getPrintStream());
...@@ -338,7 +226,7 @@ aspect CS_Class { ...@@ -338,7 +226,7 @@ aspect CS_Class {
env.println("public class " + getName() + " : SampleType {"); env.println("public class " + getName() + " : SampleType {");
env.println(); env.println();
env.indent(); env.indent();
getType().CS_emitInstance(env); getDataType().CS_emitInstance(env);
if( isReferenced()) { if( isReferenced()) {
CS_emitRegisterEncoder(env); CS_emitRegisterEncoder(env);
CS_emitDispatcher(env,false); CS_emitDispatcher(env,false);
...@@ -359,11 +247,11 @@ aspect CS_Class { ...@@ -359,11 +247,11 @@ aspect CS_Class {
env.println("public class " + getName() + " : Sample {"); env.println("public class " + getName() + " : Sample {");
env.println(); env.println();
env.indent(); env.indent();
getType().CS_emitInstance(env); getDataType().CS_emitInstance(env);
env.println("public interface Handler : SampleHandler {"); env.println("public interface Handler : SampleHandler {");
env.print(" void handle("); env.print(" void handle(");
if (!isVoid()) { if (!isVoid()) {
getType().CS_emitType(env); getDataType().CS_emitType(env);
env.print(" value"); env.print(" value");
} }
env.println(");"); env.println(");");
...@@ -377,6 +265,7 @@ aspect CS_Class { ...@@ -377,6 +265,7 @@ aspect CS_Class {
CS_emitSignature(env); CS_emitSignature(env);
env.println("}"); env.println("}");
env.unindent();
} }
public void Decl.CS_emitSignature(CS_env env) { public void Decl.CS_emitSignature(CS_env env) {
...@@ -425,12 +314,6 @@ aspect CS_Class { ...@@ -425,12 +314,6 @@ aspect CS_Class {
env.println("private class Dispatcher : SampleDispatcher {"); env.println("private class Dispatcher : SampleDispatcher {");
env.indent(); env.indent();
env.println(); env.println();
env.println("public Type getSampleClass() {");
env.indent();
env.println("return typeof(" + getName() + ");");
env.unindent();
env.println("}");
env.println();
env.println("public String getName() {"); env.println("public String getName() {");
env.indent(); env.indent();
env.println("return \"" + getName() + "\";"); env.println("return \"" + getName() + "\";");
...@@ -459,21 +342,6 @@ aspect CS_Class { ...@@ -459,21 +342,6 @@ aspect CS_Class {
env.unindent(); env.unindent();
env.println("}"); env.println("}");
env.println(); env.println();
// env.println("public void encodeSignature(Encoder e) throws IOException{");
// env.indent();
// env.println("emitSignature(e);");
// env.unindent();
// env.println("}");
// env.println();
// env.println("public void encodeSignatureMetadata(Encoder e, int index){");
// env.indent();
// env.println("e.encodePacked32(Constant.TYPE_DEF);");
// env.println("e.encodePacked32(index);");
// env.println("e.encodeString(getName());");
// env.println("emitSignature(e);");
// env.unindent();
// env.println("}");
// env.println();
env.println("public bool canDecodeAndHandle() {"); env.println("public bool canDecodeAndHandle() {");
env.indent(); env.indent();
env.println("return "+isSample+";"); env.println("return "+isSample+";");
...@@ -499,19 +367,18 @@ aspect CS_Class { ...@@ -499,19 +367,18 @@ aspect CS_Class {
env.unindent(); env.unindent();
env.println("}"); env.println("}");
env.println(""); env.println("");
} //TODO, fix above method } //TODO, fix above method
public void TypeDecl.CS_emitEncoder(CS_env env) { public void TypeDecl.CS_emitEncoder(CS_env env) {
env.print("public static void encode(Encoder e"); env.print("public static void encode(Encoder e");
if (!isVoid()) { if (!isVoid()) {
env.print(", "); env.print(", ");
getType().CS_emitType(env); getDataType().CS_emitType(env);
env.print(" value"); env.print(" value");
} }
env.println(") {"); env.println(") {");
env.indent(); env.indent();
getType().CS_emitEncoder(env, "value"); getDataType().CS_emitEncoder(env, "value");
env.unindent(); env.unindent();
env.println("}"); env.println("}");
env.println(); env.println();
...@@ -521,20 +388,20 @@ aspect CS_Class { ...@@ -521,20 +388,20 @@ aspect CS_Class {
env.print("public static void encode(Encoder e"); env.print("public static void encode(Encoder e");
if (!isVoid()) { if (!isVoid()) {
env.print(", "); env.print(", ");
getType().CS_emitType(env); getDataType().CS_emitType(env);
env.print(" value"); env.print(" value");
} }
env.println(") {"); env.println(") {");
env.indent(); env.indent();
env.println("e.begin(typeof(" + getName() + "));"); env.println("e.begin(dispatcher);");
getType().CS_emitEncoder(env, "value"); getDataType().CS_emitEncoder(env, "value");
env.println("e.end(typeof(" + getName() + "));"); env.println("e.end(dispatcher);");
env.unindent(); env.unindent();
env.println("}"); env.println("}");
env.println(); env.println();
} }
public void Type.CS_emitEncoder(CS_env env, String name) { public void DataType.CS_emitEncoder(CS_env env, String name) {
throw new Error(this.getClass().getName() + throw new Error(this.getClass().getName() +
".CS_emitEncoder(CS_env env, String name)" + ".CS_emitEncoder(CS_env env, String name)" +
" not declared"); " not declared");
...@@ -575,7 +442,7 @@ aspect CS_Class { ...@@ -575,7 +442,7 @@ aspect CS_Class {
index = index + ", " + env.print_for_begin(limit); index = index + ", " + env.print_for_begin(limit);
} }
} }
getType().CS_emitEncoder(env, name + "[" + index + "]"); getDataType().CS_emitEncoder(env, name + "[" + index + "]");
for (int i = 0 ; i < getNumExp() ; i++) { for (int i = 0 ; i < getNumExp() ; i++) {
env.print_for_end(); env.print_for_end();
} }
...@@ -600,7 +467,7 @@ aspect CS_Class { ...@@ -600,7 +467,7 @@ aspect CS_Class {
public void StructType.CS_emitEncoder(CS_env env, String name) { public void StructType.CS_emitEncoder(CS_env env, String name) {
for (int i = 0 ; i < getNumField() ; i++) { for (int i = 0 ; i < getNumField() ; i++) {
Field f = getField(i); Field f = getField(i);
f.getType().CS_emitEncoder(env, name + "." + f.getName()); f.getDataType().CS_emitEncoder(env, name + "." + f.getName());
} }
} }
...@@ -608,19 +475,19 @@ aspect CS_Class { ...@@ -608,19 +475,19 @@ aspect CS_Class {
if (CS_needInstance()) { if (CS_needInstance()) {
env.println(getName() + ".encode(e, " + name + ");"); env.println(getName() + ".encode(e, " + name + ");");
} else { } else {
decl().getType().CS_emitEncoder(env, name); decl().getDataType().CS_emitEncoder(env, name);
} }
} }
public void Decl.CS_emitDecoder(CS_env env) { public void Decl.CS_emitDecoder(CS_env env) {
env.print("public static "); env.print("public static ");
getType().CS_emitType(env); getDataType().CS_emitType(env);
env.println(" decode(Decoder d) {"); env.println(" decode(Decoder d) {");
env.indent(); env.indent();
if (!isVoid()) { if (!isVoid()) {
getType().CS_emitType(env); getDataType().CS_emitType(env);
env.println(" result;"); env.println(" result;");
getType().CS_emitDecoder(env, "result"); getDataType().CS_emitDecoder(env, "result");
env.println("return result;"); env.println("return result;");
} }
env.unindent(); env.unindent();
...@@ -628,7 +495,7 @@ aspect CS_Class { ...@@ -628,7 +495,7 @@ aspect CS_Class {
env.println(); env.println();
} }
public void Type.CS_emitDecoder(CS_env env, String name) { public void DataType.CS_emitDecoder(CS_env env, String name) {
throw new Error(this.getClass().getName() + throw new Error(this.getClass().getName() +
".CS_emitDecoder(CS_env env, String name)" + ".CS_emitDecoder(CS_env env, String name)" +
" not declared"); " not declared");
...@@ -666,7 +533,7 @@ aspect CS_Class { ...@@ -666,7 +533,7 @@ aspect CS_Class {
env.println(";"); env.println(";");
} }
env.print(name + " = new "); env.print(name + " = new ");
getType().CS_emitTypePrefix(env); getDataType().CS_emitTypePrefix(env);
env.print("["); env.print("[");
for (int i = 0 ; i < getNumExp() ; i++) { for (int i = 0 ; i < getNumExp() ; i++) {
if (i > 0) { if (i > 0) {
...@@ -675,7 +542,7 @@ aspect CS_Class { ...@@ -675,7 +542,7 @@ aspect CS_Class {
env.print("i_" + (baseDepth + i) + "_max"); env.print("i_" + (baseDepth + i) + "_max");
} }
env.print("]"); env.print("]");
getType().CS_emitTypeSuffix(env); getDataType().CS_emitTypeSuffix(env);
env.println(";"); env.println(";");
String index = null; String index = null;
...@@ -687,7 +554,7 @@ aspect CS_Class { ...@@ -687,7 +554,7 @@ aspect CS_Class {
index = index + ", " + env.print_for_begin(limit); index = index + ", " + env.print_for_begin(limit);
} }
} }
getType().CS_emitDecoder(env, name + "[" + index + "]"); getDataType().CS_emitDecoder(env, name + "[" + index + "]");
for (int i = 0 ; i < getNumExp() ; i++) { for (int i = 0 ; i < getNumExp() ; i++) {
env.print_for_end(); env.print_for_end();
} }
...@@ -715,7 +582,7 @@ aspect CS_Class { ...@@ -715,7 +582,7 @@ aspect CS_Class {
env.println("();"); env.println("();");
for (int i = 0 ; i < getNumField() ; i++) { for (int i = 0 ; i < getNumField() ; i++) {
Field f = getField(i); Field f = getField(i);
f.getType().CS_emitDecoder(env, name + "." + f.getName()); f.getDataType().CS_emitDecoder(env, name + "." + f.getName());
} }
} }
...@@ -723,11 +590,11 @@ aspect CS_Class { ...@@ -723,11 +590,11 @@ aspect CS_Class {
if (CS_needInstance()) { if (CS_needInstance()) {
env.println(name + " = " + getName() + ".decode(d);"); env.println(name + " = " + getName() + ".decode(d);");
} else { } else {
decl().getType().CS_emitDecoder(env, name); decl().getDataType().CS_emitDecoder(env, name);
} }
} }
public void Type.CS_emitTypePrefix(CS_env env) { public void DataType.CS_emitTypePrefix(CS_env env) {
throw new Error(this.getClass().getName() + throw new Error(this.getClass().getName() +
".CS_emitTypePrefix(CS_env env)" + ".CS_emitTypePrefix(CS_env env)" +
" not declared"); " not declared");
...@@ -736,7 +603,7 @@ aspect CS_Class { ...@@ -736,7 +603,7 @@ aspect CS_Class {
public void PrimType.CS_emitTypePrefix(CS_env env) { public void PrimType.CS_emitTypePrefix(CS_env env) {
switch (getToken()) { switch (getToken()) {
case LABCOMM_STRING: { env.print("String"); } break; case LABCOMM_STRING: { env.print("String"); } break;
case LABCOMM_SAMPLE: { env.print("Type"); } break; case LABCOMM_SAMPLE: { env.print("SampleDispatcher"); } break;
default: { env.print(getName()); } break; default: { env.print(getName()); } break;
} }
} }
...@@ -745,24 +612,24 @@ aspect CS_Class { ...@@ -745,24 +612,24 @@ aspect CS_Class {
if (CS_needInstance()) { if (CS_needInstance()) {
env.print(getName()); env.print(getName());
} else { } else {
decl().getType().CS_emitTypePrefix(env); decl().getDataType().CS_emitTypePrefix(env);
} }
} }
public void ArrayType.CS_emitTypePrefix(CS_env env){ public void ArrayType.CS_emitTypePrefix(CS_env env){
getType().CS_emitTypePrefix(env); getDataType().CS_emitTypePrefix(env);
} }
public void StructType.CS_emitTypePrefix(CS_env env){ public void StructType.CS_emitTypePrefix(CS_env env){
env.print(CS_structName()); env.print(CS_structName());
} }
public void Type.CS_emitTypeSuffix(CS_env env) { public void DataType.CS_emitTypeSuffix(CS_env env) {
} }
public void UserType.CS_emitTypeSuffix(CS_env env) { public void UserType.CS_emitTypeSuffix(CS_env env) {
if (! CS_needInstance()) { if (! CS_needInstance()) {
decl().getType().CS_emitTypeSuffix(env); decl().getDataType().CS_emitTypeSuffix(env);
} }
} }
...@@ -772,10 +639,10 @@ aspect CS_Class { ...@@ -772,10 +639,10 @@ aspect CS_Class {
env.print(","); env.print(",");
} }
env.print("]"); env.print("]");
getType().CS_emitTypeSuffix(env); getDataType().CS_emitTypeSuffix(env);
} }
public boolean Type.CS_needInstance() { public boolean DataType.CS_needInstance() {
throw new Error(this.getClass().getName() + throw new Error(this.getClass().getName() +
".CS_needInstance()" + ".CS_needInstance()" +
" not declared"); " not declared");
...@@ -790,7 +657,7 @@ aspect CS_Class { ...@@ -790,7 +657,7 @@ aspect CS_Class {
} }
public boolean UserType.CS_needInstance() { public boolean UserType.CS_needInstance() {
return decl().getType().CS_needInstance(); return decl().getDataType().CS_needInstance();
} }
public boolean StructType.CS_needInstance() { public boolean StructType.CS_needInstance() {
...@@ -798,10 +665,10 @@ aspect CS_Class { ...@@ -798,10 +665,10 @@ aspect CS_Class {
} }
public boolean ArrayType.CS_needInstance() { public boolean ArrayType.CS_needInstance() {
return getType().CS_needInstance(); return getDataType().CS_needInstance();
} }
public boolean Type.CS_isPrimitive() { public boolean DataType.CS_isPrimitive() {
return false; return false;
} }
...@@ -809,7 +676,7 @@ aspect CS_Class { ...@@ -809,7 +676,7 @@ aspect CS_Class {
return true; return true;
} }
public void Type.CS_emitInstance(CS_env env) { public void DataType.CS_emitInstance(CS_env env) {
throw new Error(this.getClass().getName() + throw new Error(this.getClass().getName() +
".CS_emitInstance(CS_env env)" + ".CS_emitInstance(CS_env env)" +
" not declared"); " not declared");
...@@ -822,7 +689,7 @@ aspect CS_Class { ...@@ -822,7 +689,7 @@ aspect CS_Class {
} }
public void ArrayType.CS_emitInstance(CS_env env) { public void ArrayType.CS_emitInstance(CS_env env) {
getType().CS_emitInstance(env); getDataType().CS_emitInstance(env);
} }
public void StructType.CS_emitInstance(CS_env env) { public void StructType.CS_emitInstance(CS_env env) {
...@@ -831,7 +698,7 @@ aspect CS_Class { ...@@ -831,7 +698,7 @@ aspect CS_Class {
env.indent(); env.indent();
} }
for (int i = 0 ; i < getNumField() ; i++) { for (int i = 0 ; i < getNumField() ; i++) {
getField(i).getType().CS_emitInstance(env); getField(i).getDataType().CS_emitInstance(env);
} }
for (int i = 0 ; i < getNumField() ; i++) { for (int i = 0 ; i < getNumField() ; i++) {
getField(i).CS_emitField(env); getField(i).CS_emitField(env);
...@@ -848,11 +715,11 @@ aspect CS_Class { ...@@ -848,11 +715,11 @@ aspect CS_Class {
public void Field.CS_emitField(CS_env env) { public void Field.CS_emitField(CS_env env) {
env.print("public "); env.print("public ");
getType().CS_emitType(env); getDataType().CS_emitType(env);
env.println(" " + getName() + ";"); env.println(" " + getName() + ";");
} }
public void Type.CS_emitType(CS_env env) { public void DataType.CS_emitType(CS_env env) {
throw new Error(this.getClass().getName() + throw new Error(this.getClass().getName() +
".CS_emitType(CS_env env)" + ".CS_emitType(CS_env env)" +
" not declared"); " not declared");
...@@ -866,23 +733,23 @@ aspect CS_Class { ...@@ -866,23 +733,23 @@ aspect CS_Class {
switch (getToken()) { switch (getToken()) {
case LABCOMM_STRING: { env.print("String"); } break; case LABCOMM_STRING: { env.print("String"); } break;
case LABCOMM_BOOLEAN: { env.print("bool"); } break; case LABCOMM_BOOLEAN: { env.print("bool"); } break;
case LABCOMM_SAMPLE: { env.print("Type"); } break; case LABCOMM_SAMPLE: { env.print("SampleDispatcher"); } break;
default: { env.print(getName()); } break; default: { env.print(getName()); } break;
} }
} }
public void UserType.CS_emitType(CS_env env) { public void UserType.CS_emitType(CS_env env) {
decl().getType().CS_emitType(env); decl().getDataType().CS_emitType(env);
} }
public void ArrayType.CS_emitType(CS_env env){ public void ArrayType.CS_emitType(CS_env env){
getType().CS_emitTypePrefix(env); getDataType().CS_emitTypePrefix(env);
env.print("["); env.print("[");
for (int i = 1 ; i < getNumExp() ; i++) { for (int i = 1 ; i < getNumExp() ; i++) {
env.print(","); env.print(",");
} }
env.print("]"); env.print("]");
getType().CS_emitTypeSuffix(env); getDataType().CS_emitTypeSuffix(env);
} }
public void StructType.CS_emitType(CS_env env){ public void StructType.CS_emitType(CS_env env){
...@@ -902,7 +769,7 @@ aspect CS_Signature { ...@@ -902,7 +769,7 @@ aspect CS_Signature {
public void TypeRefSignatureLine.CS_emitSignature(CS_env env, boolean isDecl){ public void TypeRefSignatureLine.CS_emitSignature(CS_env env, boolean isDecl){
env.print(getIndentString()); env.print(getIndentString());
env.println("e.encodePacked32(e.getTypeId( typeof("+decl.getName()+")));"); env.println("e.encodePacked32(e.getDataTypeId( typeof("+decl.getName()+")));");
} }
public void DataSignatureLine.CS_emitSignature(CS_env env, boolean decl){ public void DataSignatureLine.CS_emitSignature(CS_env env, boolean decl){
...@@ -935,7 +802,7 @@ aspect CS_Signature { ...@@ -935,7 +802,7 @@ aspect CS_Signature {
aspect CS_Info { aspect CS_Info {
public void Program.CS_info(PrintStream out, String namespace, int version) { public void Specification.CS_info(PrintStream out, String namespace, int version) {
CS_env env = new CS_env(out, version); CS_env env = new CS_env(out, version);
if (namespace == null) { if (namespace == null) {
namespace = ""; namespace = "";
...@@ -955,14 +822,14 @@ aspect CS_Info { ...@@ -955,14 +822,14 @@ aspect CS_Info {
public void TypeDecl.CS_info(CS_env env, String namespace) { public void TypeDecl.CS_info(CS_env env, String namespace) {
env.print(";C#;typedef;" + namespace + getName() + ";"); env.print(";C#;typedef;" + namespace + getName() + ";");
getType().CS_emitType(env) ; getDataType().CS_emitType(env) ;
env.print(";not_applicable_for_C#"); env.print(";not_applicable_for_C#");
env.println(); env.println();
} }
public void SampleDecl.CS_info(CS_env env, String namespace) { public void SampleDecl.CS_info(CS_env env, String namespace) {
env.print(";C#;sample;" + namespace + getName() + ";"); env.print(";C#;sample;" + namespace + getName() + ";");
getType().CS_emitType(env); getDataType().CS_emitType(env);
env.print(";not_applicable_for_C#"); env.print(";not_applicable_for_C#");
env.println(); env.println();
} }
......
This diff is collapsed.
aspect DeclNames { aspect DeclNames {
inh String Type.declName(); inh String DataType.declName();
eq Decl.getType().declName() = getName(); eq Decl.getTypeInstance().declName() = getName();
inh String Field.declName(); inh String Field.declName();
eq StructType.getField(int i).declName() = declName(); eq StructType.getField(int i).declName() = declName();
//TODO: aspect should be renamed to parent-something //TODO: aspect should be renamed to parent-something
inh Decl Type.parentDecl(); inh Decl DataType.parentDecl();
inh Decl Field.parentDecl(); inh Decl Field.parentDecl();
eq Decl.getType().parentDecl() = this; eq Decl.getTypeInstance().parentDecl() = this;
eq StructType.getField(int i).parentDecl() = parentDecl(); eq StructType.getField(int i).parentDecl() = parentDecl();
} }
...@@ -27,5 +27,4 @@ aspect ErrorCheck { ...@@ -27,5 +27,4 @@ aspect ErrorCheck {
getChild(i).errorCheck(collection); getChild(i).errorCheck(collection);
} }
} }
} }
import java.util.*; import java.util.*;
aspect NoIntentionForTypeOrSampledefs {
inh boolean TypeInstance.addIntentions();
eq Decl.getTypeInstance().addIntentions() = false;
eq StructType.getField(int i).addIntentions() = true;
}
aspect FlatSignature { aspect FlatSignature {
public SignatureList Decl.flatSignature(int version) { public SignatureList Decl.flatSignature(int version) {
...@@ -14,17 +20,25 @@ aspect FlatSignature { ...@@ -14,17 +20,25 @@ aspect FlatSignature {
} }
public void TypeDecl.flatSignature(SignatureList list) { public void TypeDecl.flatSignature(SignatureList list) {
getType().flatSignature(list); getTypeInstance().flatSignature(list);
} }
public void SampleDecl.flatSignature(SignatureList list) { public void SampleDecl.flatSignature(SignatureList list) {
getType().flatSignature(list); getTypeInstance().flatSignature(list);
} }
// public void SampleRefType.flatSignature(SignatureList list) { // public void SampleRefType.flatSignature(SignatureList list) {
// list.addInt(LABCOMM_SAMPLE_REF, "sample"); // list.addInt(LABCOMM_SAMPLE_REF, "sample");
// } // }
public void TypeInstance.flatSignature(SignatureList list) {
if(addIntentions()) {
debugAnnotations(this.getName()+".TypeInstance.flatSignature");
list.addIntentions(intentions(), "intentions: "+getIntentionString());
}
getDataType().flatSignature(list);
}
public void VoidType.flatSignature(SignatureList list) { public void VoidType.flatSignature(SignatureList list) {
list.addInt(LABCOMM_STRUCT, "void"); list.addInt(LABCOMM_STRUCT, "void");
list.addInt(0, null); list.addInt(0, null);
...@@ -45,7 +59,7 @@ aspect FlatSignature { ...@@ -45,7 +59,7 @@ aspect FlatSignature {
for (int i = 0 ; i < getNumExp() ; i++) { for (int i = 0 ; i < getNumExp() ; i++) {
getExp(i).flatSignature(list); getExp(i).flatSignature(list);
} }
getType().flatSignature(list); getDataType().flatSignature(list);
list.unindent(); list.unindent();
list.add(null, "}"); list.add(null, "}");
} }
...@@ -62,8 +76,10 @@ aspect FlatSignature { ...@@ -62,8 +76,10 @@ aspect FlatSignature {
} }
public void Field.flatSignature(SignatureList list) { public void Field.flatSignature(SignatureList list) {
list.addString(getName(), signatureComment()); debugAnnotations(this.getName()+".Field.flatSignature");
getType().flatSignature(list); list.addIntentions(intentions(), "Field: "+getIntentionString());
// list.addString(getName(), signatureComment());
getDataType().flatSignature(list);
} }
public void IntegerLiteral.flatSignature(SignatureList list) { public void IntegerLiteral.flatSignature(SignatureList list) {
...@@ -93,7 +109,7 @@ aspect FlatSignature { ...@@ -93,7 +109,7 @@ aspect FlatSignature {
} }
public String Field.signatureComment() { public String Field.signatureComment() {
return getType().signatureComment() + " '" + getName() +"'"; return getDataType().signatureComment() + " '" + getName() +"'";
} }
// public String SampleRefType.signatureComment() { // public String SampleRefType.signatureComment() {
......
aspect TypeDefGen {
public void Specification.generateTypedefs(PrintStream out, int ver) {
for(Decl d : getDecls()) {
d.generateTypedefs(out);
}
}
public void Decl.generateTypedefs(PrintStream out) {
}
public void Decl.generateDepTypedefs(PrintStream out){
Iterator<Decl> it = type_dependencies().iterator();
while(it.hasNext()) {
Decl d = it.next();
d.generateDepTypedefs(out);
}
pp(out);
}
public void SampleDecl.generateTypedefs(PrintStream out){
if(hasDependencies()) {
out.println("sample "+getName()+"_def {");
out.println(" sample sample;");
out.println(" string typedef = <<EOL");
for(Decl d : type_dependencies()) {
d.generateDepTypedefs(out);
}
pp(out);
out.println("EOL;");
}
}
}
This diff is collapsed.
Program ::= Decl*; Specification ::= Decl*;
abstract Decl ::= Type <Name:String> /Signature/; abstract Decl ::= TypeInstance /Signature/;
TypeInstance ::= DataType Annotations;
Annotations ::= Annotation*;
Annotation ::= <Key:String> <Value:byte[]>;
Intention : Annotation;
DocString : Annotation;
TypeDecl : Decl; TypeDecl : Decl;
SampleDecl : Decl; SampleDecl : Decl;
...@@ -15,18 +23,19 @@ abstract DataSignatureLine : SignatureLine; ...@@ -15,18 +23,19 @@ abstract DataSignatureLine : SignatureLine;
ByteArraySignatureLine : DataSignatureLine ::= <Data:byte[]>; ByteArraySignatureLine : DataSignatureLine ::= <Data:byte[]>;
IntSignatureLine : DataSignatureLine ::= <Data:int>; IntSignatureLine : DataSignatureLine ::= <Data:int>;
StringSignatureLine : DataSignatureLine ::= <Data:String>; StringSignatureLine : DataSignatureLine ::= <Data:String>;
IntentionSignatureLine : DataSignatureLine ::= Intention* ;
TypeRefSignatureLine : SignatureLine ::= Decl; TypeRefSignatureLine : SignatureLine ::= Decl;
Field ::= Type <Name:String>; Field : TypeInstance;
abstract Type; abstract DataType;
VoidType : Type; VoidType : DataType;
//SampleRefType : Type; //SampleRefType : DataType;
PrimType : Type ::= <Name:String> <Token:int>; PrimType : DataType ::= <Name:String> <Token:int>;
UserType : Type ::= <Name:String>; UserType : DataType ::= <Name:String>;
StructType : Type ::= Field*; StructType : DataType ::= Field*;
ParseArrayType : Type ::= Type Dim*; ParseArrayType : DataType ::= DataType Dim*;
abstract ArrayType : Type ::= Type Exp*; abstract ArrayType : DataType ::= DataType Dim;
VariableArrayType : ArrayType; VariableArrayType : ArrayType;
FixedArrayType : ArrayType; FixedArrayType : ArrayType;
......
...@@ -36,6 +36,7 @@ public class LabComm { ...@@ -36,6 +36,7 @@ public class LabComm {
println("[ Misc options ]"); println("[ Misc options ]");
println(" --pretty=PFILE Pretty prints to PFILE"); println(" --pretty=PFILE Pretty prints to PFILE");
println(" --typeinfo=TIFILE Generates typeinfo in TIFILE"); println(" --typeinfo=TIFILE Generates typeinfo in TIFILE");
println(" --typedefs=TIFILE Generates typedefs in TIFILE");
} }
/** To be cleaned up. /** To be cleaned up.
...@@ -48,7 +49,7 @@ public class LabComm { ...@@ -48,7 +49,7 @@ public class LabComm {
} }
} }
private static void genH(Program p, String hName, private static void genH(Specification p, String hName,
Vector cIncludes, String coreName, String prefix, int ver) { Vector cIncludes, String coreName, String prefix, int ver) {
try { try {
FileOutputStream f; FileOutputStream f;
...@@ -63,7 +64,7 @@ public class LabComm { ...@@ -63,7 +64,7 @@ public class LabComm {
} }
} }
private static void genC(Program p, String cName, private static void genC(Specification p, String cName,
Vector cIncludes, String coreName, String prefix, int ver) { Vector cIncludes, String coreName, String prefix, int ver) {
try { try {
FileOutputStream f; FileOutputStream f;
...@@ -78,7 +79,7 @@ public class LabComm { ...@@ -78,7 +79,7 @@ public class LabComm {
} }
} }
private static void genCS(Program p, String csName, String csNamespace, int ver) { private static void genCS(Specification p, String csName, String csNamespace, int ver) {
// throw new Error("C# generation currently disabled"); // throw new Error("C# generation currently disabled");
try { try {
p.CS_gen(csName, csNamespace, ver); p.CS_gen(csName, csNamespace, ver);
...@@ -88,7 +89,7 @@ public class LabComm { ...@@ -88,7 +89,7 @@ public class LabComm {
} }
} }
private static void genJava(Program p, String dirName, String packageName, int ver) { private static void genJava(Specification p, String dirName, String packageName, int ver) {
try { try {
p.J_gen(dirName, packageName, ver); p.J_gen(dirName, packageName, ver);
} catch (IOException e) { } catch (IOException e) {
...@@ -97,7 +98,7 @@ public class LabComm { ...@@ -97,7 +98,7 @@ public class LabComm {
} }
} }
private static void genPython(Program p, String filename, String prefix, int ver) { private static void genPython(Specification p, String filename, String prefix, int ver) {
try { try {
FileOutputStream f; FileOutputStream f;
PrintStream out; PrintStream out;
...@@ -111,7 +112,7 @@ public class LabComm { ...@@ -111,7 +112,7 @@ public class LabComm {
} }
} }
private static void genRAPID(Program p, String filename, String prefix, int ver) { private static void genRAPID(Specification p, String filename, String prefix, int ver) {
try { try {
p.RAPID_gen(filename, prefix, ver); p.RAPID_gen(filename, prefix, ver);
} catch (IOException e) { } catch (IOException e) {
...@@ -139,6 +140,7 @@ public class LabComm { ...@@ -139,6 +140,7 @@ public class LabComm {
String pythonFile = null; String pythonFile = null;
String prettyFile = null; String prettyFile = null;
String typeinfoFile = null; String typeinfoFile = null;
String typedefsFile = null;
String rapidFile = null; String rapidFile = null;
String fileName = null; String fileName = null;
...@@ -223,6 +225,8 @@ public class LabComm { ...@@ -223,6 +225,8 @@ public class LabComm {
prettyFile = args[i].substring(9); prettyFile = args[i].substring(9);
} else if (args[i].startsWith("--typeinfo=")) { } else if (args[i].startsWith("--typeinfo=")) {
typeinfoFile = args[i].substring(11); typeinfoFile = args[i].substring(11);
} else if (args[i].startsWith("--typedefs=")) {
typedefsFile = args[i].substring(11);
} else if (args[i].equals("--rapid")) { } else if (args[i].equals("--rapid")) {
rapidFile = coreName + ".sys"; rapidFile = coreName + ".sys";
} else if (i == args.length - 1) { } else if (i == args.length - 1) {
...@@ -239,14 +243,14 @@ public class LabComm { ...@@ -239,14 +243,14 @@ public class LabComm {
} }
} }
Program parseFile(){ Specification parseFile(){
Program ast = null; Specification ast = null;
try { try {
// Check for errors // Check for errors
LabCommScanner scanner = new LabCommScanner( LabCommScanner scanner = new LabCommScanner(
new FileReader(fileName)); new FileReader(fileName));
LabCommParser parser = new LabCommParser(); LabCommParser parser = new LabCommParser();
Program p = (Program)parser.parse(scanner); Specification p = (Specification)parser.parse(scanner);
Collection errors = new LinkedList(); Collection errors = new LinkedList();
p.errorCheck(errors); p.errorCheck(errors);
...@@ -268,7 +272,7 @@ public class LabComm { ...@@ -268,7 +272,7 @@ public class LabComm {
return ast; return ast;
} }
boolean generateC(Program ast) { boolean generateC(Specification ast) {
boolean wroteFile = false; boolean wroteFile = false;
Vector hIncludes = new Vector(cIncludes); Vector hIncludes = new Vector(cIncludes);
if (hFile != null) { if (hFile != null) {
...@@ -287,7 +291,7 @@ public class LabComm { ...@@ -287,7 +291,7 @@ public class LabComm {
return wroteFile; return wroteFile;
} }
boolean generateCS(Program ast) { boolean generateCS(Specification ast) {
boolean wroteFile = false; boolean wroteFile = false;
if (csFile != null) { if (csFile != null) {
printStatus("C#: " , csFile); printStatus("C#: " , csFile);
...@@ -297,7 +301,7 @@ public class LabComm { ...@@ -297,7 +301,7 @@ public class LabComm {
return wroteFile; return wroteFile;
} }
boolean generateJava(Program ast) { boolean generateJava(Specification ast) {
boolean wroteFile = false; boolean wroteFile = false;
if (javaDir != null) { if (javaDir != null) {
printStatus("Java: " , javaDir); printStatus("Java: " , javaDir);
...@@ -307,7 +311,7 @@ public class LabComm { ...@@ -307,7 +311,7 @@ public class LabComm {
return wroteFile; return wroteFile;
} }
boolean generatePython(Program ast) { boolean generatePython(Specification ast) {
boolean wroteFile = false; boolean wroteFile = false;
if (pythonFile != null) { if (pythonFile != null) {
printStatus("Python: " , pythonFile); printStatus("Python: " , pythonFile);
...@@ -317,7 +321,7 @@ public class LabComm { ...@@ -317,7 +321,7 @@ public class LabComm {
return wroteFile; return wroteFile;
} }
boolean generateRAPID(Program ast) { boolean generateRAPID(Specification ast) {
boolean wroteFile = false; boolean wroteFile = false;
if (rapidFile != null) { if (rapidFile != null) {
printStatus("RAPID: " , rapidFile); printStatus("RAPID: " , rapidFile);
...@@ -326,7 +330,7 @@ public class LabComm { ...@@ -326,7 +330,7 @@ public class LabComm {
} }
return wroteFile; return wroteFile;
} }
boolean generatePrettyPrint(Program ast) { boolean generatePrettyPrint(Specification ast) {
boolean wroteFile = false; boolean wroteFile = false;
if (prettyFile != null) { if (prettyFile != null) {
printStatus("Pretty: " , prettyFile); printStatus("Pretty: " , prettyFile);
...@@ -343,7 +347,7 @@ public class LabComm { ...@@ -343,7 +347,7 @@ public class LabComm {
return wroteFile; return wroteFile;
} }
boolean generateTypeinfo(Program ast) { boolean generateTypeinfo(Specification ast) {
boolean wroteFile = false; boolean wroteFile = false;
if (typeinfoFile != null) { if (typeinfoFile != null) {
printStatus("TypeInfo: " , typeinfoFile); printStatus("TypeInfo: " , typeinfoFile);
...@@ -361,6 +365,22 @@ public class LabComm { ...@@ -361,6 +365,22 @@ public class LabComm {
return wroteFile; return wroteFile;
} }
boolean generateTypedefs(Specification ast) {
boolean wroteFile = false;
if (typedefsFile != null) {
printStatus("Typedefs: " , typedefsFile);
try {
FileOutputStream f = new FileOutputStream(typedefsFile);
PrintStream out = new PrintStream(f);
ast.generateTypedefs(out, ver);
wroteFile = true;
} catch (IOException e) {
System.err.println("IOException: " + typedefsFile + " " + e);
}
}
return wroteFile;
}
private void printStatus(String kind, String filename){ private void printStatus(String kind, String filename){
if (verbose) { if (verbose) {
System.err.println("Generating "+kind+": " + filename); System.err.println("Generating "+kind+": " + filename);
...@@ -376,7 +396,7 @@ public class LabComm { ...@@ -376,7 +396,7 @@ public class LabComm {
System.exit(1); System.exit(1);
} else { } else {
opts.processArgs(); opts.processArgs();
Program ast = opts.parseFile(); Specification ast = opts.parseFile();
if (ast != null) { if (ast != null) {
...@@ -389,6 +409,7 @@ public class LabComm { ...@@ -389,6 +409,7 @@ public class LabComm {
fileWritten |= opts.generateRAPID(ast); fileWritten |= opts.generateRAPID(ast);
fileWritten |= opts.generatePrettyPrint(ast); fileWritten |= opts.generatePrettyPrint(ast);
fileWritten |= opts.generateTypeinfo(ast); fileWritten |= opts.generateTypeinfo(ast);
fileWritten |= opts.generateTypedefs(ast);
// if no output to files, prettyprint on stdout // if no output to files, prettyprint on stdout
if (!fileWritten) { if (!fileWritten) {
......
...@@ -34,9 +34,9 @@ ...@@ -34,9 +34,9 @@
} }
:}; :};
Program goal = Specification goal =
/* Empty program */ {: return new Program(); :} /* Empty program */ {: return new Specification(); :}
| decl_list.l {: return new Program(l); :} | decl_list.l {: return new Specification(l); :}
; ;
List decl_list = List decl_list =
...@@ -54,26 +54,40 @@ List var_decl_list = ...@@ -54,26 +54,40 @@ List var_decl_list =
| var_decl_list.l var_decl.v {: return l.add(v); :} | var_decl_list.l var_decl.v {: return l.add(v); :}
; ;
Annotations annotations =
/* empty list */ {: return new Annotations(); :}
| annotation_list.l {: return new Annotations(l); :}
;
List annotation_list =
annotation.i {: return new List().add(i); :}
| annotation_list.l annotation.i {: return l.add(i); :}
;
String key = IDENTIFIER;
String stringliteral = IDENTIFIER | QUOTEDSTRING;
Annotation annotation = intention.i | docstring.d;
Annotation intention = LPAREN key.k COLON stringliteral.v RPAREN {: return new Intention(k,v.getBytes()); :};
Annotation docstring = QUOTEDSTRING.s {: return new DocString(s.substring(1,s.length()-1).getBytes()); :};
TypeInstance type_instance =
annotations.a type.t IDENTIFIER {: return new TypeInstance(t, IDENTIFIER, a); :}
| annotations.a type.t IDENTIFIER dim_list.d
{: return new TypeInstance(new ParseArrayType(t, d), IDENTIFIER, a); :}
;
Field var_decl = Field var_decl =
type.t IDENTIFIER SEMICOLON {: return new Field(t, IDENTIFIER); :} type_instance.t SEMICOLON {: return new Field(t); :}
| type.t IDENTIFIER dim_list.d SEMICOLON
{: return new Field(new ParseArrayType(t, d), IDENTIFIER); :}
; ;
TypeDecl type_decl = TypeDecl type_decl =
TYPEDEF type.t IDENTIFIER SEMICOLON {: return new TypeDecl(t, IDENTIFIER); :} TYPEDEF type_instance.t SEMICOLON {: return new TypeDecl(t); :} ;
| TYPEDEF type.t IDENTIFIER dim_list.d SEMICOLON
{: return new TypeDecl(new ParseArrayType(t, d), IDENTIFIER); :}
;
SampleDecl sample_decl = SampleDecl sample_decl =
SAMPLE type.t IDENTIFIER SEMICOLON SAMPLE type_instance.t SEMICOLON {: return new SampleDecl(t); :} ;
{: return new SampleDecl(t, IDENTIFIER); :}
| SAMPLE type.t IDENTIFIER dim_list.d SEMICOLON
{: return new SampleDecl(new ParseArrayType(t, d), IDENTIFIER); :}
;
Type type = DataType type =
prim_type.p {: return p; :} prim_type.p {: return p; :}
| user_type.u {: return u; :} | user_type.u {: return u; :}
| struct_type.s {: return s; :} | struct_type.s {: return s; :}
......
...@@ -44,13 +44,16 @@ Comment = {TraditionalComment} ...@@ -44,13 +44,16 @@ Comment = {TraditionalComment}
TraditionalComment = "/*" [^*] ~"*/" | "/*" "*"+ "/" | "/*" "*"+ [^/*] ~"*/" TraditionalComment = "/*" [^*] ~"*/" | "/*" "*"+ "/" | "/*" "*"+ [^/*] ~"*/"
EndOfLineComment = "//" {InputCharacter}* {LineTerminator}? EndOfLineComment = "//" {InputCharacter}* {LineTerminator}?
Identifier = [:jletter:][:jletterdigit:]* Identifier = [[:letter:]_]([[:letter:]_[:digit:]])*
StringLiteral = [:jletterdigit:]*
DecimalNumeral = 0 | {NonZeroDigit} {Digits}? DecimalNumeral = 0 | {NonZeroDigit} {Digits}?
Digits = {Digit}+ Digits = {Digit}+
Digit = 0 | {NonZeroDigit} Digit = 0 | {NonZeroDigit}
NonZeroDigit = [1-9] NonZeroDigit = [1-9]
QuotedString = "\""~"\""
%% %%
<YYINITIAL> { <YYINITIAL> {
...@@ -76,10 +79,14 @@ NonZeroDigit = [1-9] ...@@ -76,10 +79,14 @@ NonZeroDigit = [1-9]
"}" { return sym(Terminals.RBRACE); } "}" { return sym(Terminals.RBRACE); }
"[" { return sym(Terminals.LBRACK); } "[" { return sym(Terminals.LBRACK); }
"]" { return sym(Terminals.RBRACK); } "]" { return sym(Terminals.RBRACK); }
"(" { return sym(Terminals.LPAREN); }
")" { return sym(Terminals.RPAREN); }
";" { return sym(Terminals.SEMICOLON); } ";" { return sym(Terminals.SEMICOLON); }
":" { return sym(Terminals.COLON); }
"," { return sym(Terminals.COMMA); } "," { return sym(Terminals.COMMA); }
{Identifier} { return sym(Terminals.IDENTIFIER); } {Identifier} { return sym(Terminals.IDENTIFIER); }
{QuotedString} { return sym(Terminals.QUOTEDSTRING); }
} }
// fall through errors // fall through errors
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
aspect NameAnalysis { aspect NameAnalysis {
inh String Decl.lookupName(String name); inh String Decl.lookupName(String name);
eq Program.getDecl(int index).lookupName(String name) { eq Specification.getDecl(int index).lookupName(String name) {
for (int i = 0; i < index; i++) { for (int i = 0; i < index; i++) {
String s = getDecl(i).getName(); String s = getDecl(i).getName();
if (s.equals(name)) { if (s.equals(name)) {
...@@ -24,7 +24,7 @@ aspect NameAnalysis { ...@@ -24,7 +24,7 @@ aspect NameAnalysis {
inh TypeDecl Decl.lookupType(String name); inh TypeDecl Decl.lookupType(String name);
inh TypeDecl UserType.lookupType(String name); inh TypeDecl UserType.lookupType(String name);
eq Program.getDecl(int index).lookupType(String name) { eq Specification.getDecl(int index).lookupType(String name) {
for(int i = 0; i < index; i++) { for(int i = 0; i < index; i++) {
Decl d = getDecl(i); Decl d = getDecl(i);
if(d instanceof TypeDecl && d.getName().equals(name)) { if(d instanceof TypeDecl && d.getName().equals(name)) {
...@@ -34,8 +34,8 @@ aspect NameAnalysis { ...@@ -34,8 +34,8 @@ aspect NameAnalysis {
return null; return null;
} }
syn TypeDecl Type.decl(); syn TypeDecl DataType.decl();
eq Type.decl() = null; eq DataType.decl() = null;
eq UserType.decl() = lookupType(getName()); eq UserType.decl() = lookupType(getName());
eq PrimType.decl() = null; //HERE BE DRAGONS XXX eq PrimType.decl() = null; //HERE BE DRAGONS XXX
......
...@@ -6,7 +6,7 @@ aspect PPIndentation { ...@@ -6,7 +6,7 @@ aspect PPIndentation {
inh String Field.pp_indent(); inh String Field.pp_indent();
inh String StructType.pp_indent(); inh String StructType.pp_indent();
eq StructType.getField(int index).pp_indent() = pp_indent() + " "; eq StructType.getField(int index).pp_indent() = pp_indent() + " ";
eq Program.getDecl(int index).pp_indent() = ""; eq Specification.getDecl(int index).pp_indent() = "";
} }
...@@ -18,7 +18,7 @@ aspect PrettyPrint { ...@@ -18,7 +18,7 @@ aspect PrettyPrint {
" not declared"); " not declared");
} }
public void Program.pp(PrintStream out) { public void Specification.pp(PrintStream out) {
for(int i = 0; i < getNumDecl(); i++) { for(int i = 0; i < getNumDecl(); i++) {
getDecl(i).pp(out); getDecl(i).pp(out);
} }
...@@ -27,24 +27,24 @@ aspect PrettyPrint { ...@@ -27,24 +27,24 @@ aspect PrettyPrint {
// Pretty print declarations // Pretty print declarations
public void TypeDecl.pp(PrintStream out) { public void TypeDecl.pp(PrintStream out) {
out.print("typedef "); out.print("typedef ");
getType().ppIdentifier(out, getName()); getDataType().ppIdentifier(out, getName());
out.println(";"); out.println(";");
} }
public void SampleDecl.pp(PrintStream out) { public void SampleDecl.pp(PrintStream out) {
out.print("sample "); out.print("sample ");
getType().ppIdentifier(out, getName()); getDataType().ppIdentifier(out, getName());
out.println(";"); out.println(";");
} }
public void Field.pp(PrintStream out) { public void Field.pp(PrintStream out) {
out.print(pp_indent()); out.print(pp_indent());
getType().ppIdentifier(out, getName()); getDataType().ppIdentifier(out, getName());
out.println(";"); out.println(";");
} }
// Pretty print variable of a given type // Pretty print variable of a given type
public void Type.ppIdentifier(PrintStream out, String id) { public void DataType.ppIdentifier(PrintStream out, String id) {
ppPrefix(out); ppPrefix(out);
out.print(" "); out.print(" ");
out.print(id); out.print(id);
...@@ -58,7 +58,7 @@ aspect PrettyPrint { ...@@ -58,7 +58,7 @@ aspect PrettyPrint {
} }
// PrettyPrint prefix type info // PrettyPrint prefix type info
public void Type.ppPrefix(PrintStream out) { public void DataType.ppPrefix(PrintStream out) {
throw new Error(this.getClass().getName() + throw new Error(this.getClass().getName() +
".ppPrefix(PrintStream out)" + ".ppPrefix(PrintStream out)" +
" not declared"); " not declared");
...@@ -81,7 +81,7 @@ aspect PrettyPrint { ...@@ -81,7 +81,7 @@ aspect PrettyPrint {
} }
public void ArrayType.ppPrefix(PrintStream out) { public void ArrayType.ppPrefix(PrintStream out) {
getType().ppPrefix(out); getDataType().ppPrefix(out);
} }
public void StructType.ppPrefix(PrintStream out) { public void StructType.ppPrefix(PrintStream out) {
...@@ -94,7 +94,7 @@ aspect PrettyPrint { ...@@ -94,7 +94,7 @@ aspect PrettyPrint {
} }
// PrettyPrint suffix type info (array dimensions) // PrettyPrint suffix type info (array dimensions)
public void Type.ppSuffix(PrintStream out) { } public void DataType.ppSuffix(PrintStream out) { }
public void ArrayType.ppSuffix(PrintStream out) { public void ArrayType.ppSuffix(PrintStream out) {
out.print("["); out.print("[");
...@@ -103,7 +103,7 @@ aspect PrettyPrint { ...@@ -103,7 +103,7 @@ aspect PrettyPrint {
getExp(i).pp(out); getExp(i).pp(out);
} }
out.print("]"); out.print("]");
getType().ppSuffix(out); getDataType().ppSuffix(out);
} }
public void IntegerLiteral.pp(PrintStream out) { public void IntegerLiteral.pp(PrintStream out) {
......
...@@ -4,78 +4,23 @@ aspect Python_CodeGenEnv { ...@@ -4,78 +4,23 @@ aspect Python_CodeGenEnv {
// handles qualid nesting, indentation, file writing and // handles qualid nesting, indentation, file writing and
// prefix propagation // prefix propagation
public class Python_env { public class Python_env extends PrintEnv {
final private class Python_printer { final private class Python_printer extends PrintEnv.Printer {
// public C_printer(PrintStream out) {
private boolean newline = true; // super(out, " ");
private PrintStream out; // }
public Python_printer(PrintStream out) {
this.out = out;
}
public void print(Python_env env, String s) {
if (newline) {
newline = false;
for (int i = 0 ; i < env.indent ; i++) {
out.print(" ");
}
}
out.print(s);
}
public void println(Python_env env, String s) {
print(env, s);
out.println();
newline = true;
}
public void println(Python_env env) {
out.println();
newline = true;
} }
}
private int indent;
private Python_printer printer;
public Python_env(PrintStream out) { public Python_env(PrintStream out) {
this.indent = 0; super(out);
this.printer = new Python_printer(out);
}
public void indent() {
indent++;
}
public void unindent() {
indent--;
}
public void print(String s) {
printer.print(this, s);
}
public void println(String s) {
printer.println(this, s);
} }
public void println() {
printer.println(this);
} }
}
} }
aspect Python_CodeGen { aspect Python_CodeGen {
public void Program.Python_gen(PrintStream out, String baseName, int version) { public void Specification.Python_gen(PrintStream out, String baseName, int version) {
// Remove when Blomdell has verified that it is OK to ignore version
// when generating python code.
System.err.println("*** Warning! Python_gen ignores version: "+version);
Python_env env = new Python_env(out); Python_env env = new Python_env(out);
env.println("#!/usr/bin/python"); env.println("#!/usr/bin/python");
env.println("# Auto generated " + baseName); env.println("# Auto generated " + baseName);
...@@ -103,48 +48,78 @@ aspect Python_CodeGen { ...@@ -103,48 +48,78 @@ aspect Python_CodeGen {
aspect PythonTypes { aspect PythonTypes {
public void Program.Python_genTypes(Python_env env) { public void Specification.Python_genTypes(Python_env env) {
for (int i = 0 ; i < getNumDecl() ; i++) { for (int i = 0 ; i < getNumDecl() ; i++) {
getDecl(i).Python_genSignature(env); getDecl(i).Python_genSignatureAndTypedef(env);
} }
} }
public void Decl.Python_genSignature(Python_env env) { public void Decl.Python_genSignatureAndTypedef(Python_env env) {
throw new Error(this.getClass().getName() + throw new Error(this.getClass().getName() +
".Python_genSignature(Python_env env)" + ".Python_genSignatureAndTypedef(Python_env env)" +
" not declared"); " not declared");
} }
public void TypeDecl.Python_genSignature(Python_env env) { public void TypeDecl.Python_genSignatureAndTypedef(Python_env env) {
env.println("class " + getName() + "(object):"); env.println("class " + getName() + "(object):");
env.indent(); env.indent();
env.println("signature = labcomm2014.typedef('" + getName() + "',"); env.print("typedef = labcomm2014.typedef(");
Python_genIntentions(env);
env.println(",");
env.indent(); env.indent();
getType().Python_genSignature(env); getTypeInstance().Python_genTypedef(env);
env.unindent(); env.unindent();
env.println(")"); env.println(")");
env.unindent(); env.unindent();
env.println(); env.println();
} }
public void SampleDecl.Python_genSignature(Python_env env) { public void SampleDecl.Python_genSignatureAndTypedef(Python_env env) {
env.println("class " + getName() + "(object):"); env.println("class " + getName() + "(object):");
env.indent(); env.indent();
env.println("signature = labcomm2014.sample('" + getName() + "', "); env.print("signature = labcomm2014.sample(");
Python_genIntentions(env);
env.println(",");
env.indent(); env.indent();
getType().Python_genSignature(env); getDataType().Python_genSignature(env);
env.unindent();
env.println(")");
env.print("typedef = labcomm2014.sample(");
Python_genIntentions(env);
env.println(",");
env.indent();
getTypeInstance().Python_genTypedef(env);
env.unindent(); env.unindent();
env.println(")"); env.println(")");
env.unindent(); env.unindent();
env.println(); env.println();
} }
public void Decl.Python_genIntentions(Python_env env) {
getTypeInstance().Python_genIntentions(env);
}
public void TypeInstance.Python_genIntentions(Python_env env) {
// env.print("{");
// for(Intention i : sortedIntentions()) {
// env.print("'"+i.getKey()+"':'"+new String(i.getValue())+"', ");
// }
// env.print("}");
env.print("tuple((");
for(Intention i : sortedIntentions()) {
env.print("('"+i.getKey()+"','"+new String(i.getValue())+"'), ");
}
env.print("))");
}
public void TypeInstance.Python_genTypedef(Python_env env) {
getDataType().Python_genTypedef(env);
}
public void UserType.Python_genSignature(Python_env env) { public void UserType.Python_genSignature(Python_env env) {
env.println(getName() + ".signature"); lookupType(getName()).getDataType().Python_genSignature(env);
// lookupType(getName()).getType().Python_genSignature(env);
} }
public void Type.Python_genSignature(Python_env env) { public void DataType.Python_genSignature(Python_env env) {
throw new Error(this.getClass().getName() + throw new Error(this.getClass().getName() +
".Python_genSignature(Python_env env)" + ".Python_genSignature(Python_env env)" +
" not declared"); " not declared");
...@@ -172,7 +147,7 @@ aspect PythonTypes { ...@@ -172,7 +147,7 @@ aspect PythonTypes {
} }
env.println("],"); env.println("],");
env.indent(); env.indent();
getType().Python_genSignature(env); getDataType().Python_genSignature(env);
env.print(")"); env.print(")");
env.unindent(); env.unindent();
} }
...@@ -193,8 +168,70 @@ aspect PythonTypes { ...@@ -193,8 +168,70 @@ aspect PythonTypes {
} }
public void Field.Python_genSignature(Python_env env) { public void Field.Python_genSignature(Python_env env) {
env.print("('" + getName() + "', "); env.print("(");
getType().Python_genSignature(env); Python_genIntentions(env);
env.print(", ");
getDataType().Python_genSignature(env);
env.print(")");
}
public void UserType.Python_genTypedef(Python_env env) {
env.println(getName() + ".typedef");
}
public void DataType.Python_genTypedef(Python_env env) {
throw new Error(this.getClass().getName() +
".Python_genTypedef(Python_env env)" +
" not declared");
}
public void PrimType.Python_genTypedef(Python_env env) {
switch (getToken()) {
case LABCOMM_BOOLEAN: { env.print("labcomm2014.BOOLEAN()"); } break;
case LABCOMM_BYTE: { env.print("labcomm2014.BYTE()"); } break;
case LABCOMM_SHORT: { env.print("labcomm2014.SHORT()"); } break;
case LABCOMM_INT: { env.print("labcomm2014.INTEGER()"); } break;
case LABCOMM_LONG: { env.print("labcomm2014.LONG()"); } break;
case LABCOMM_FLOAT: { env.print("labcomm2014.FLOAT()"); } break;
case LABCOMM_DOUBLE: { env.print("labcomm2014.DOUBLE()"); } break;
case LABCOMM_STRING: { env.print("labcomm2014.STRING()"); } break;
case LABCOMM_SAMPLE: { env.print("labcomm2014.SAMPLE()"); } break;
}
}
public void ArrayType.Python_genTypedef(Python_env env) {
env.print("labcomm2014.array([");
for (int i = 0 ; i < getNumExp() ; i++) {
if (i > 0) { env.print(", "); }
env.print(getExp(i).Python_getValue());
}
env.println("],");
env.indent();
getDataType().Python_genTypedef(env);
env.print(")");
env.unindent();
}
public void StructType.Python_genTypedef(Python_env env) {
env.println("labcomm2014.struct([");
env.indent();
for (int i = 0 ; i < getNumField() ; i++) {
if (i > 0) { env.println(","); }
getField(i).Python_genTypedef(env);
}
env.print("])");
env.unindent();
}
public void VoidType.Python_genTypedef(Python_env env) {
env.println("labcomm2014.struct([])");
}
public void Field.Python_genTypedef(Python_env env) {
env.print("(");
Python_genIntentions(env);
env.print(", ");
getDataType().Python_genTypedef(env);
env.print(")"); env.print(")");
} }
......
...@@ -77,7 +77,7 @@ aspect RAPID_CodeGen { ...@@ -77,7 +77,7 @@ aspect RAPID_CodeGen {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public void Program.RAPID_gen(String file, String prefix, int version) public void Specification.RAPID_gen(String file, String prefix, int version)
throws IOException throws IOException
{ {
PrintStream ps = new PrintStream(new FileOutputStream(new File(file))); PrintStream ps = new PrintStream(new FileOutputStream(new File(file)));
...@@ -85,7 +85,7 @@ aspect RAPID_CodeGen { ...@@ -85,7 +85,7 @@ aspect RAPID_CodeGen {
RAPID_gen(env); RAPID_gen(env);
} }
public void Program.RAPID_gen(RAPID_env env) public void Specification.RAPID_gen(RAPID_env env)
{ {
for (int i = 0; i < getNumDecl(); i++) { for (int i = 0; i < getNumDecl(); i++) {
getDecl(i).RAPID_gen(env); getDecl(i).RAPID_gen(env);
...@@ -126,7 +126,7 @@ aspect RAPID_CodeGen { ...@@ -126,7 +126,7 @@ aspect RAPID_CodeGen {
public void SampleDecl.RAPID_gen(RAPID_env env) { public void SampleDecl.RAPID_gen(RAPID_env env) {
// Add type declarations // Add type declarations
String fullName = getType().RAPID_AddType(env, getName()); String fullName = getDataType().RAPID_AddType(env, getName());
// Add signature constants // Add signature constants
String sig_len_name = "signature_len_" + getName(); String sig_len_name = "signature_len_" + getName();
String sig_name = "signature_" + getName(); String sig_name = "signature_" + getName();
...@@ -167,7 +167,7 @@ aspect RAPID_CodeGen { ...@@ -167,7 +167,7 @@ aspect RAPID_CodeGen {
params.add("VAR LabComm_Stream st"); params.add("VAR LabComm_Stream st");
params.add("VAR LabComm_Decoder_Sample s"); params.add("VAR LabComm_Decoder_Sample s");
stmts.add("VAR " + fullName + " tmp;"); stmts.add("VAR " + fullName + " tmp;");
getType().RAPID_AddDecodeInstr(env, stmts, "tmp", "st"); getDataType().RAPID_AddDecodeInstr(env, stmts, "tmp", "st");
stmts.add("% s.handler % tmp;"); stmts.add("% s.handler % tmp;");
env.addProc("Decode_And_Handle_" + getName(), params, stmts); env.addProc("Decode_And_Handle_" + getName(), params, stmts);
...@@ -201,11 +201,11 @@ aspect RAPID_CodeGen { ...@@ -201,11 +201,11 @@ aspect RAPID_CodeGen {
params.add("VAR LabComm_Encoder_Sample s"); params.add("VAR LabComm_Encoder_Sample s");
params.add("VAR " + fullName + " val"); params.add("VAR " + fullName + " val");
stmts.add("Encode_Packed st, s.user_id;"); stmts.add("Encode_Packed st, s.user_id;");
getType().RAPID_AddEncodeInstr(env, stmts, "val", "st"); getDataType().RAPID_AddEncodeInstr(env, stmts, "val", "st");
env.addProc("Encode_" + getName(), params, stmts); env.addProc("Encode_" + getName(), params, stmts);
} }
public String Type.RAPID_AddType(RAPID_env env, String name) { public String DataType.RAPID_AddType(RAPID_env env, String name) {
throw new UnsupportedOperationException("RAPID code generation does (currently) not support "+getClass().getSimpleName()); throw new UnsupportedOperationException("RAPID code generation does (currently) not support "+getClass().getSimpleName());
} }
...@@ -214,7 +214,7 @@ aspect RAPID_CodeGen { ...@@ -214,7 +214,7 @@ aspect RAPID_CodeGen {
for (int i = 0; i < getNumField(); i++) { for (int i = 0; i < getNumField(); i++) {
Field f = getField(i); Field f = getField(i);
components.add( components.add(
f.getType().RAPID_AddType(env, name + "_" + f.getName()) + f.getDataType().RAPID_AddType(env, name + "_" + f.getName()) +
" " + f.getName() + ";"); " " + f.getName() + ";");
} }
String typeName = env.addRecord(name, components); String typeName = env.addRecord(name, components);
...@@ -222,7 +222,7 @@ aspect RAPID_CodeGen { ...@@ -222,7 +222,7 @@ aspect RAPID_CodeGen {
} }
public String FixedArrayType.RAPID_AddType(RAPID_env env, String name) { public String FixedArrayType.RAPID_AddType(RAPID_env env, String name) {
String typeName = getType().RAPID_AddType(env, name + "_e"); String typeName = getDataType().RAPID_AddType(env, name + "_e");
if (getNumExp() > 1) { if (getNumExp() > 1) {
throw new UnsupportedOperationException("RAPID generation only (currently) supports one-dimensional arrays"); throw new UnsupportedOperationException("RAPID generation only (currently) supports one-dimensional arrays");
} }
...@@ -251,7 +251,7 @@ aspect RAPID_CodeGen { ...@@ -251,7 +251,7 @@ aspect RAPID_CodeGen {
throw new UnsupportedOperationException("RAPID code generation does not (currently) support "+getName()); throw new UnsupportedOperationException("RAPID code generation does not (currently) support "+getName());
} }
public void Type.RAPID_AddDecodeInstr(RAPID_env env, public void DataType.RAPID_AddDecodeInstr(RAPID_env env,
java.util.List<String> instrs, java.util.List<String> instrs,
String var_name, String stream_name) { String var_name, String stream_name) {
throw new UnsupportedOperationException("RAPID code generation does not (currently) support "+getClass().getSimpleName()); throw new UnsupportedOperationException("RAPID code generation does not (currently) support "+getClass().getSimpleName());
...@@ -261,7 +261,7 @@ aspect RAPID_CodeGen { ...@@ -261,7 +261,7 @@ aspect RAPID_CodeGen {
java.util.List<String> instrs, java.util.List<String> instrs,
String var_name, String stream_name) { String var_name, String stream_name) {
for (int i = 0; i < getNumField(); i++) { for (int i = 0; i < getNumField(); i++) {
getField(i).getType().RAPID_AddDecodeInstr(env, instrs, getField(i).getDataType().RAPID_AddDecodeInstr(env, instrs,
var_name + "." + getField(i).getName(), stream_name); var_name + "." + getField(i).getName(), stream_name);
} }
} }
...@@ -270,7 +270,7 @@ aspect RAPID_CodeGen { ...@@ -270,7 +270,7 @@ aspect RAPID_CodeGen {
java.util.List<String> instrs, java.util.List<String> instrs,
String var_name, String stream_name) { String var_name, String stream_name) {
for (int i = 1; i <= getExp(0).RAPID_getValue(); i++) { for (int i = 1; i <= getExp(0).RAPID_getValue(); i++) {
getType().RAPID_AddDecodeInstr(env, instrs, getDataType().RAPID_AddDecodeInstr(env, instrs,
var_name + ".e" + i, stream_name); var_name + ".e" + i, stream_name);
} }
} }
...@@ -305,7 +305,7 @@ aspect RAPID_CodeGen { ...@@ -305,7 +305,7 @@ aspect RAPID_CodeGen {
} }
} }
public void Type.RAPID_AddEncodeInstr(RAPID_env env, public void DataType.RAPID_AddEncodeInstr(RAPID_env env,
java.util.List<String> instrs, java.util.List<String> instrs,
String var_name, String stream_name) { String var_name, String stream_name) {
throw new UnsupportedOperationException("RAPID code generation does not (currently) support "+getClass().getSimpleName()); throw new UnsupportedOperationException("RAPID code generation does not (currently) support "+getClass().getSimpleName());
...@@ -315,7 +315,7 @@ aspect RAPID_CodeGen { ...@@ -315,7 +315,7 @@ aspect RAPID_CodeGen {
java.util.List<String> instrs, java.util.List<String> instrs,
String var_name, String stream_name) { String var_name, String stream_name) {
for (int i = 0; i < getNumField(); i++) { for (int i = 0; i < getNumField(); i++) {
getField(i).getType().RAPID_AddEncodeInstr(env, instrs, getField(i).getDataType().RAPID_AddEncodeInstr(env, instrs,
var_name + "." + getField(i).getName(), stream_name); var_name + "." + getField(i).getName(), stream_name);
} }
} }
...@@ -324,7 +324,7 @@ aspect RAPID_CodeGen { ...@@ -324,7 +324,7 @@ aspect RAPID_CodeGen {
java.util.List<String> instrs, java.util.List<String> instrs,
String var_name, String stream_name) { String var_name, String stream_name) {
for (int i = 1; i <= getExp(0).RAPID_getValue(); i++) { for (int i = 1; i <= getExp(0).RAPID_getValue(); i++) {
getType().RAPID_AddEncodeInstr(env, instrs, getDataType().RAPID_AddEncodeInstr(env, instrs,
var_name + ".e" + i, stream_name); var_name + ".e" + i, stream_name);
} }
} }
......
/* Temporary aspect with forwarding methods */
aspect Refactoring {
syn int ArrayType.getNumExp() = getDim().getNumExp();
syn Exp ArrayType.getExp(int i) = getDim().getExp(i);
syn String Decl.getName() = getTypeInstance().getName();
syn DataType Decl.getDataType() = getTypeInstance().getDataType();
syn String TypeInstance.getName() = getAnnotations().getName();
public Annotations Annotations.addName(String n) {
//XXX TODO: check if name already exists
addAnnotation(new Intention("",n.getBytes()));
return this;
}
public Field.Field(TypeInstance t) {
this(t.getDataType(), t.getAnnotations());
}
public TypeInstance.TypeInstance(DataType t, String n, Annotations a) {
this(t, a.addName(n));
}
public TypeInstance.TypeInstance(DataType t, String n) {
this(t, new Annotations().addName(n));
System.out.println("WARNING! TypeInstance(DataType, String) ignoring intention list");
}
syn Annotation TypeInstance.getAnnotation(int i) = getAnnotations().getAnnotation(i);
}