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
  • anders.blomdell
  • compiler-refactoring
  • labcomm2006
  • labcomm2013
  • labcomm2014
  • master
  • pragma
  • python_sig_hash
  • typedefs
  • typeref
  • v2006.0
  • v2013.0
  • v2014.0
  • v2014.1
  • v2014.2
  • v2014.3
  • v2014.4
  • v2014.5
  • v2014.6
  • v2015.0
20 results

Target

Select target project
  • anders_blomdell/labcomm
  • klaren/labcomm
  • tommyo/labcomm
  • erikj/labcomm
  • sven/labcomm
5 results
Select Git revision
  • anders.blomdell
  • compiler-refactoring
  • labcomm2006
  • labcomm2013
  • master
  • pragma
  • typedefs
  • typeref
  • v2006.0
  • v2013.0
  • v2014.0
  • v2014.1
  • v2014.2
  • v2014.3
  • v2014.4
15 results
Show changes
Commits on Source (90)
Showing
with 1131 additions and 950 deletions
......@@ -2,3 +2,4 @@
*.class
*.o
*.pyc
examples/dynamic/gen
SUBDIRS=compiler lib test examples packaging
export LABCOMM_JAR=$(shell pwd)/compiler/labcomm2014_compiler.jar
export LABCOMM=java -jar $(LABCOMM_JAR)
export VALGRIND=valgrind --leak-check=full --error-exitcode=1
UNAME_S=$(shell uname -s)
......
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 {
when (! getDim(0).isVariable())
to FixedArrayType {
if (getNumDim() == 1) {
return new FixedArrayType(getType(),
getDim(0).getExpList());
return new FixedArrayType(getDataType(),
getDim(0));
} else {
List l = new List();
for (int i = 1 ; i < getNumDim() ; i++) {
l.add(getDim(i));
}
return new FixedArrayType(new ParseArrayType(getType(), l),
getDim(0).getExpList());
return new FixedArrayType(new ParseArrayType(getDataType(), l),
getDim(0));
}
}
when (getDim(0).isVariable())
to VariableArrayType {
if (getNumDim() == 1) {
return new VariableArrayType(getType(),
getDim(0).getExpList());
return new VariableArrayType(getDataType(),
getDim(0));
} else {
List l = new List();
for (int i = 1 ; i < getNumDim() ; i++) {
l.add(getDim(i));
}
return new VariableArrayType(new ParseArrayType(getType(), l),
getDim(0).getExpList());
return new VariableArrayType(new ParseArrayType(getDataType(), l),
getDim(0));
}
}
}
......
......@@ -6,145 +6,42 @@ aspect CS_CodeGenEnv {
// Environment wrapper for CS-code generation
// 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 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) {
file = f;
File parentFile = f.getParentFile();
if(parentFile != null) {
parentFile.mkdirs();
}
super(f);
}
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) {
this(0, new CS_printer(f), version);
super(0, new CS_printer(f), version);
}
public CS_env(PrintStream out, int version) {
this(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;
super(0, new CS_printer(out), version);
}
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) {
int depth = getDepth();
print("for (int i_" + depth + " = 0 ; ");
print("i_" + depth + " < " + limit + " ; ");
println("i_" + depth + "++) {");
indent();
depth++;
return "i_" + (depth - 1);
incDepth();
return "i_" + (depth);
}
public void print_for_end() {
depth--;
decDepth();
unindent();
println("}");
}
......@@ -159,15 +56,6 @@ aspect CS_CodeGenEnv {
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 {
aspect CS_StructName {
inh int Decl.CS_Depth();
inh int Type.CS_Depth();
eq Program.getDecl(int i).CS_Depth() = 0;
inh int DataType.CS_Depth();
eq Specification.getDecl(int i).CS_Depth() = 0;
eq StructType.getField(int i).CS_Depth() = CS_Depth() + 1;
inh String Type.CS_structName();
eq Program.getDecl(int i).CS_structName() = getDecl(i).getName();
inh String DataType.CS_structName();
eq Specification.getDecl(int i).CS_structName() = getDecl(i).getName();
eq StructType.getField(int i).CS_structName() {
if (CS_Depth() == 0) {
return "struct_" + getField(i).getName();
......@@ -192,16 +80,16 @@ aspect CS_StructName {
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 Type.CS_isVoid() = false;
syn boolean DataType.CS_isVoid() = false;
syn boolean VoidType.CS_isVoid() = true;
}
aspect CS_CodeGen {
public void Program.CS_gen(String file,
public void Specification.CS_gen(String file,
String namespace, int version) throws IOException {
// Registration class
CS_env env = new CS_env(new File(file), version);
......@@ -230,7 +118,7 @@ aspect CS_CodeGen {
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) {
......@@ -273,7 +161,7 @@ aspect CS_Class {
Decl t = it.next();
t.CS_emitUserTypeDeps(env, t.getName(), outputCode);
if( outputCode && t.getType().isUserType() ) {
if( outputCode && t.getDataType().isUserType() ) {
env.println(t.getName()+".register(e);");
} else { // Just output a comment
String refpath = (via == null) ? "directly" : "indirectly via "+via;
......@@ -329,7 +217,7 @@ aspect CS_Class {
}
public void TypeDecl.CS_emitClass(CS_env env) {
if (getType().CS_needInstance()) {
if (getDataType().CS_needInstance()) {
// Hackish prettyprint preamble
env.println("/* ");
pp(env.getPrintStream());
......@@ -338,7 +226,7 @@ aspect CS_Class {
env.println("public class " + getName() + " : SampleType {");
env.println();
env.indent();
getType().CS_emitInstance(env);
getDataType().CS_emitInstance(env);
if( isReferenced()) {
CS_emitRegisterEncoder(env);
CS_emitDispatcher(env,false);
......@@ -359,11 +247,11 @@ aspect CS_Class {
env.println("public class " + getName() + " : Sample {");
env.println();
env.indent();
getType().CS_emitInstance(env);
getDataType().CS_emitInstance(env);
env.println("public interface Handler : SampleHandler {");
env.print(" void handle(");
if (!isVoid()) {
getType().CS_emitType(env);
getDataType().CS_emitType(env);
env.print(" value");
}
env.println(");");
......@@ -377,6 +265,7 @@ aspect CS_Class {
CS_emitSignature(env);
env.println("}");
env.unindent();
}
public void Decl.CS_emitSignature(CS_env env) {
......@@ -425,12 +314,6 @@ aspect CS_Class {
env.println("private class Dispatcher : SampleDispatcher {");
env.indent();
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.indent();
env.println("return \"" + getName() + "\";");
......@@ -459,21 +342,6 @@ aspect CS_Class {
env.unindent();
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.indent();
env.println("return "+isSample+";");
......@@ -499,19 +367,18 @@ aspect CS_Class {
env.unindent();
env.println("}");
env.println("");
} //TODO, fix above method
public void TypeDecl.CS_emitEncoder(CS_env env) {
env.print("public static void encode(Encoder e");
if (!isVoid()) {
env.print(", ");
getType().CS_emitType(env);
getDataType().CS_emitType(env);
env.print(" value");
}
env.println(") {");
env.indent();
getType().CS_emitEncoder(env, "value");
getDataType().CS_emitEncoder(env, "value");
env.unindent();
env.println("}");
env.println();
......@@ -521,20 +388,20 @@ aspect CS_Class {
env.print("public static void encode(Encoder e");
if (!isVoid()) {
env.print(", ");
getType().CS_emitType(env);
getDataType().CS_emitType(env);
env.print(" value");
}
env.println(") {");
env.indent();
env.println("e.begin(typeof(" + getName() + "));");
getType().CS_emitEncoder(env, "value");
env.println("e.end(typeof(" + getName() + "));");
env.println("e.begin(dispatcher);");
getDataType().CS_emitEncoder(env, "value");
env.println("e.end(dispatcher);");
env.unindent();
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() +
".CS_emitEncoder(CS_env env, String name)" +
" not declared");
......@@ -575,7 +442,7 @@ aspect CS_Class {
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++) {
env.print_for_end();
}
......@@ -600,7 +467,7 @@ aspect CS_Class {
public void StructType.CS_emitEncoder(CS_env env, String name) {
for (int i = 0 ; i < getNumField() ; 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 {
if (CS_needInstance()) {
env.println(getName() + ".encode(e, " + name + ");");
} else {
decl().getType().CS_emitEncoder(env, name);
decl().getDataType().CS_emitEncoder(env, name);
}
}
public void Decl.CS_emitDecoder(CS_env env) {
env.print("public static ");
getType().CS_emitType(env);
getDataType().CS_emitType(env);
env.println(" decode(Decoder d) {");
env.indent();
if (!isVoid()) {
getType().CS_emitType(env);
getDataType().CS_emitType(env);
env.println(" result;");
getType().CS_emitDecoder(env, "result");
getDataType().CS_emitDecoder(env, "result");
env.println("return result;");
}
env.unindent();
......@@ -628,7 +495,7 @@ aspect CS_Class {
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() +
".CS_emitDecoder(CS_env env, String name)" +
" not declared");
......@@ -666,7 +533,7 @@ aspect CS_Class {
env.println(";");
}
env.print(name + " = new ");
getType().CS_emitTypePrefix(env);
getDataType().CS_emitTypePrefix(env);
env.print("[");
for (int i = 0 ; i < getNumExp() ; i++) {
if (i > 0) {
......@@ -675,7 +542,7 @@ aspect CS_Class {
env.print("i_" + (baseDepth + i) + "_max");
}
env.print("]");
getType().CS_emitTypeSuffix(env);
getDataType().CS_emitTypeSuffix(env);
env.println(";");
String index = null;
......@@ -687,7 +554,7 @@ aspect CS_Class {
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++) {
env.print_for_end();
}
......@@ -715,7 +582,7 @@ aspect CS_Class {
env.println("();");
for (int i = 0 ; i < getNumField() ; 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 {
if (CS_needInstance()) {
env.println(name + " = " + getName() + ".decode(d);");
} 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() +
".CS_emitTypePrefix(CS_env env)" +
" not declared");
......@@ -736,7 +603,7 @@ aspect CS_Class {
public void PrimType.CS_emitTypePrefix(CS_env env) {
switch (getToken()) {
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;
}
}
......@@ -745,24 +612,24 @@ aspect CS_Class {
if (CS_needInstance()) {
env.print(getName());
} else {
decl().getType().CS_emitTypePrefix(env);
decl().getDataType().CS_emitTypePrefix(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){
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) {
if (! CS_needInstance()) {
decl().getType().CS_emitTypeSuffix(env);
decl().getDataType().CS_emitTypeSuffix(env);
}
}
......@@ -772,10 +639,10 @@ aspect CS_Class {
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() +
".CS_needInstance()" +
" not declared");
......@@ -790,7 +657,7 @@ aspect CS_Class {
}
public boolean UserType.CS_needInstance() {
return decl().getType().CS_needInstance();
return decl().getDataType().CS_needInstance();
}
public boolean StructType.CS_needInstance() {
......@@ -798,10 +665,10 @@ aspect CS_Class {
}
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;
}
......@@ -809,7 +676,7 @@ aspect CS_Class {
return true;
}
public void Type.CS_emitInstance(CS_env env) {
public void DataType.CS_emitInstance(CS_env env) {
throw new Error(this.getClass().getName() +
".CS_emitInstance(CS_env env)" +
" not declared");
......@@ -822,7 +689,7 @@ aspect CS_Class {
}
public void ArrayType.CS_emitInstance(CS_env env) {
getType().CS_emitInstance(env);
getDataType().CS_emitInstance(env);
}
public void StructType.CS_emitInstance(CS_env env) {
......@@ -831,7 +698,7 @@ aspect CS_Class {
env.indent();
}
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++) {
getField(i).CS_emitField(env);
......@@ -848,11 +715,11 @@ aspect CS_Class {
public void Field.CS_emitField(CS_env env) {
env.print("public ");
getType().CS_emitType(env);
getDataType().CS_emitType(env);
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() +
".CS_emitType(CS_env env)" +
" not declared");
......@@ -866,23 +733,23 @@ aspect CS_Class {
switch (getToken()) {
case LABCOMM_STRING: { env.print("String"); } 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;
}
}
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){
getType().CS_emitTypePrefix(env);
getDataType().CS_emitTypePrefix(env);
env.print("[");
for (int i = 1 ; i < getNumExp() ; i++) {
env.print(",");
}
env.print("]");
getType().CS_emitTypeSuffix(env);
getDataType().CS_emitTypeSuffix(env);
}
public void StructType.CS_emitType(CS_env env){
......@@ -902,7 +769,7 @@ aspect CS_Signature {
public void TypeRefSignatureLine.CS_emitSignature(CS_env env, boolean isDecl){
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){
......@@ -935,7 +802,7 @@ aspect CS_Signature {
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);
if (namespace == null) {
namespace = "";
......@@ -955,14 +822,14 @@ aspect CS_Info {
public void TypeDecl.CS_info(CS_env env, String namespace) {
env.print(";C#;typedef;" + namespace + getName() + ";");
getType().CS_emitType(env) ;
getDataType().CS_emitType(env) ;
env.print(";not_applicable_for_C#");
env.println();
}
public void SampleDecl.CS_info(CS_env env, String namespace) {
env.print(";C#;sample;" + namespace + getName() + ";");
getType().CS_emitType(env);
getDataType().CS_emitType(env);
env.print(";not_applicable_for_C#");
env.println();
}
......
This diff is collapsed.
aspect DeclNames {
inh String Type.declName();
eq Decl.getType().declName() = getName();
inh String DataType.declName();
eq Decl.getTypeInstance().declName() = getName();
inh String Field.declName();
eq StructType.getField(int i).declName() = declName();
//TODO: aspect should be renamed to parent-something
inh Decl Type.parentDecl();
inh Decl DataType.parentDecl();
inh Decl Field.parentDecl();
eq Decl.getType().parentDecl() = this;
eq Decl.getTypeInstance().parentDecl() = this;
eq StructType.getField(int i).parentDecl() = parentDecl();
}
......@@ -27,5 +27,4 @@ aspect ErrorCheck {
getChild(i).errorCheck(collection);
}
}
}
import java.util.*;
aspect NoIntentionForTypeOrSampledefs {
inh boolean TypeInstance.addIntentions();
eq Decl.getTypeInstance().addIntentions() = false;
eq StructType.getField(int i).addIntentions() = true;
}
aspect FlatSignature {
public SignatureList Decl.flatSignature(int version) {
......@@ -14,17 +20,25 @@ aspect FlatSignature {
}
public void TypeDecl.flatSignature(SignatureList list) {
getType().flatSignature(list);
getTypeInstance().flatSignature(list);
}
public void SampleDecl.flatSignature(SignatureList list) {
getType().flatSignature(list);
getTypeInstance().flatSignature(list);
}
// public void SampleRefType.flatSignature(SignatureList list) {
// 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) {
list.addInt(LABCOMM_STRUCT, "void");
list.addInt(0, null);
......@@ -45,7 +59,7 @@ aspect FlatSignature {
for (int i = 0 ; i < getNumExp() ; i++) {
getExp(i).flatSignature(list);
}
getType().flatSignature(list);
getDataType().flatSignature(list);
list.unindent();
list.add(null, "}");
}
......@@ -62,8 +76,10 @@ aspect FlatSignature {
}
public void Field.flatSignature(SignatureList list) {
list.addString(getName(), signatureComment());
getType().flatSignature(list);
debugAnnotations(this.getName()+".Field.flatSignature");
list.addIntentions(intentions(), "Field: "+getIntentionString());
// list.addString(getName(), signatureComment());
getDataType().flatSignature(list);
}
public void IntegerLiteral.flatSignature(SignatureList list) {
......@@ -93,7 +109,7 @@ aspect FlatSignature {
}
public String Field.signatureComment() {
return getType().signatureComment() + " '" + getName() +"'";
return getDataType().signatureComment() + " '" + getName() +"'";
}
// 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;
SampleDecl : Decl;
......@@ -15,18 +23,19 @@ abstract DataSignatureLine : SignatureLine;
ByteArraySignatureLine : DataSignatureLine ::= <Data:byte[]>;
IntSignatureLine : DataSignatureLine ::= <Data:int>;
StringSignatureLine : DataSignatureLine ::= <Data:String>;
IntentionSignatureLine : DataSignatureLine ::= Intention* ;
TypeRefSignatureLine : SignatureLine ::= Decl;
Field ::= Type <Name:String>;
Field : TypeInstance;
abstract Type;
VoidType : Type;
//SampleRefType : Type;
PrimType : Type ::= <Name:String> <Token:int>;
UserType : Type ::= <Name:String>;
StructType : Type ::= Field*;
ParseArrayType : Type ::= Type Dim*;
abstract ArrayType : Type ::= Type Exp*;
abstract DataType;
VoidType : DataType;
//SampleRefType : DataType;
PrimType : DataType ::= <Name:String> <Token:int>;
UserType : DataType ::= <Name:String>;
StructType : DataType ::= Field*;
ParseArrayType : DataType ::= DataType Dim*;
abstract ArrayType : DataType ::= DataType Dim;
VariableArrayType : ArrayType;
FixedArrayType : ArrayType;
......
......@@ -36,6 +36,7 @@ public class LabComm {
println("[ Misc options ]");
println(" --pretty=PFILE Pretty prints to PFILE");
println(" --typeinfo=TIFILE Generates typeinfo in TIFILE");
println(" --typedefs=TIFILE Generates typedefs in TIFILE");
}
/** To be cleaned up.
......@@ -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) {
try {
FileOutputStream f;
......@@ -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) {
try {
FileOutputStream f;
......@@ -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");
try {
p.CS_gen(csName, csNamespace, ver);
......@@ -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 {
p.J_gen(dirName, packageName, ver);
} catch (IOException e) {
......@@ -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 {
FileOutputStream f;
PrintStream out;
......@@ -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 {
p.RAPID_gen(filename, prefix, ver);
} catch (IOException e) {
......@@ -139,6 +140,7 @@ public class LabComm {
String pythonFile = null;
String prettyFile = null;
String typeinfoFile = null;
String typedefsFile = null;
String rapidFile = null;
String fileName = null;
......@@ -223,6 +225,8 @@ public class LabComm {
prettyFile = args[i].substring(9);
} else if (args[i].startsWith("--typeinfo=")) {
typeinfoFile = args[i].substring(11);
} else if (args[i].startsWith("--typedefs=")) {
typedefsFile = args[i].substring(11);
} else if (args[i].equals("--rapid")) {
rapidFile = coreName + ".sys";
} else if (i == args.length - 1) {
......@@ -239,14 +243,14 @@ public class LabComm {
}
}
Program parseFile(){
Program ast = null;
Specification parseFile(){
Specification ast = null;
try {
// Check for errors
LabCommScanner scanner = new LabCommScanner(
new FileReader(fileName));
LabCommParser parser = new LabCommParser();
Program p = (Program)parser.parse(scanner);
Specification p = (Specification)parser.parse(scanner);
Collection errors = new LinkedList();
p.errorCheck(errors);
......@@ -268,7 +272,7 @@ public class LabComm {
return ast;
}
boolean generateC(Program ast) {
boolean generateC(Specification ast) {
boolean wroteFile = false;
Vector hIncludes = new Vector(cIncludes);
if (hFile != null) {
......@@ -287,7 +291,7 @@ public class LabComm {
return wroteFile;
}
boolean generateCS(Program ast) {
boolean generateCS(Specification ast) {
boolean wroteFile = false;
if (csFile != null) {
printStatus("C#: " , csFile);
......@@ -297,7 +301,7 @@ public class LabComm {
return wroteFile;
}
boolean generateJava(Program ast) {
boolean generateJava(Specification ast) {
boolean wroteFile = false;
if (javaDir != null) {
printStatus("Java: " , javaDir);
......@@ -307,7 +311,7 @@ public class LabComm {
return wroteFile;
}
boolean generatePython(Program ast) {
boolean generatePython(Specification ast) {
boolean wroteFile = false;
if (pythonFile != null) {
printStatus("Python: " , pythonFile);
......@@ -317,7 +321,7 @@ public class LabComm {
return wroteFile;
}
boolean generateRAPID(Program ast) {
boolean generateRAPID(Specification ast) {
boolean wroteFile = false;
if (rapidFile != null) {
printStatus("RAPID: " , rapidFile);
......@@ -326,7 +330,7 @@ public class LabComm {
}
return wroteFile;
}
boolean generatePrettyPrint(Program ast) {
boolean generatePrettyPrint(Specification ast) {
boolean wroteFile = false;
if (prettyFile != null) {
printStatus("Pretty: " , prettyFile);
......@@ -343,7 +347,7 @@ public class LabComm {
return wroteFile;
}
boolean generateTypeinfo(Program ast) {
boolean generateTypeinfo(Specification ast) {
boolean wroteFile = false;
if (typeinfoFile != null) {
printStatus("TypeInfo: " , typeinfoFile);
......@@ -361,6 +365,22 @@ public class LabComm {
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){
if (verbose) {
System.err.println("Generating "+kind+": " + filename);
......@@ -376,7 +396,7 @@ public class LabComm {
System.exit(1);
} else {
opts.processArgs();
Program ast = opts.parseFile();
Specification ast = opts.parseFile();
if (ast != null) {
......@@ -389,6 +409,7 @@ public class LabComm {
fileWritten |= opts.generateRAPID(ast);
fileWritten |= opts.generatePrettyPrint(ast);
fileWritten |= opts.generateTypeinfo(ast);
fileWritten |= opts.generateTypedefs(ast);
// if no output to files, prettyprint on stdout
if (!fileWritten) {
......
......@@ -34,9 +34,9 @@
}
:};
Program goal =
/* Empty program */ {: return new Program(); :}
| decl_list.l {: return new Program(l); :}
Specification goal =
/* Empty program */ {: return new Specification(); :}
| decl_list.l {: return new Specification(l); :}
;
List decl_list =
......@@ -54,26 +54,40 @@ List var_decl_list =
| 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 =
type.t IDENTIFIER SEMICOLON {: return new Field(t, IDENTIFIER); :}
| type.t IDENTIFIER dim_list.d SEMICOLON
{: return new Field(new ParseArrayType(t, d), IDENTIFIER); :}
type_instance.t SEMICOLON {: return new Field(t); :}
;
TypeDecl type_decl =
TYPEDEF type.t IDENTIFIER SEMICOLON {: return new TypeDecl(t, IDENTIFIER); :}
| TYPEDEF type.t IDENTIFIER dim_list.d SEMICOLON
{: return new TypeDecl(new ParseArrayType(t, d), IDENTIFIER); :}
;
TYPEDEF type_instance.t SEMICOLON {: return new TypeDecl(t); :} ;
SampleDecl sample_decl =
SAMPLE type.t IDENTIFIER SEMICOLON
{: return new SampleDecl(t, IDENTIFIER); :}
| SAMPLE type.t IDENTIFIER dim_list.d SEMICOLON
{: return new SampleDecl(new ParseArrayType(t, d), IDENTIFIER); :}
;
SAMPLE type_instance.t SEMICOLON {: return new SampleDecl(t); :} ;
Type type =
DataType type =
prim_type.p {: return p; :}
| user_type.u {: return u; :}
| struct_type.s {: return s; :}
......
......@@ -44,13 +44,16 @@ Comment = {TraditionalComment}
TraditionalComment = "/*" [^*] ~"*/" | "/*" "*"+ "/" | "/*" "*"+ [^/*] ~"*/"
EndOfLineComment = "//" {InputCharacter}* {LineTerminator}?
Identifier = [:jletter:][:jletterdigit:]*
Identifier = [[:letter:]_]([[:letter:]_[:digit:]])*
StringLiteral = [:jletterdigit:]*
DecimalNumeral = 0 | {NonZeroDigit} {Digits}?
Digits = {Digit}+
Digit = 0 | {NonZeroDigit}
NonZeroDigit = [1-9]
QuotedString = "\""~"\""
%%
<YYINITIAL> {
......@@ -76,10 +79,14 @@ NonZeroDigit = [1-9]
"}" { return sym(Terminals.RBRACE); }
"[" { return sym(Terminals.LBRACK); }
"]" { return sym(Terminals.RBRACK); }
"(" { return sym(Terminals.LPAREN); }
")" { return sym(Terminals.RPAREN); }
";" { return sym(Terminals.SEMICOLON); }
":" { return sym(Terminals.COLON); }
"," { return sym(Terminals.COMMA); }
{Identifier} { return sym(Terminals.IDENTIFIER); }
{QuotedString} { return sym(Terminals.QUOTEDSTRING); }
}
// fall through errors
......
......@@ -2,7 +2,7 @@
aspect NameAnalysis {
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++) {
String s = getDecl(i).getName();
if (s.equals(name)) {
......@@ -24,7 +24,7 @@ aspect NameAnalysis {
inh TypeDecl Decl.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++) {
Decl d = getDecl(i);
if(d instanceof TypeDecl && d.getName().equals(name)) {
......@@ -34,8 +34,8 @@ aspect NameAnalysis {
return null;
}
syn TypeDecl Type.decl();
eq Type.decl() = null;
syn TypeDecl DataType.decl();
eq DataType.decl() = null;
eq UserType.decl() = lookupType(getName());
eq PrimType.decl() = null; //HERE BE DRAGONS XXX
......
......@@ -6,7 +6,7 @@ aspect PPIndentation {
inh String Field.pp_indent();
inh String StructType.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 {
" not declared");
}
public void Program.pp(PrintStream out) {
public void Specification.pp(PrintStream out) {
for(int i = 0; i < getNumDecl(); i++) {
getDecl(i).pp(out);
}
......@@ -27,24 +27,24 @@ aspect PrettyPrint {
// Pretty print declarations
public void TypeDecl.pp(PrintStream out) {
out.print("typedef ");
getType().ppIdentifier(out, getName());
getDataType().ppIdentifier(out, getName());
out.println(";");
}
public void SampleDecl.pp(PrintStream out) {
out.print("sample ");
getType().ppIdentifier(out, getName());
getDataType().ppIdentifier(out, getName());
out.println(";");
}
public void Field.pp(PrintStream out) {
out.print(pp_indent());
getType().ppIdentifier(out, getName());
getDataType().ppIdentifier(out, getName());
out.println(";");
}
// 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);
out.print(" ");
out.print(id);
......@@ -58,7 +58,7 @@ aspect PrettyPrint {
}
// PrettyPrint prefix type info
public void Type.ppPrefix(PrintStream out) {
public void DataType.ppPrefix(PrintStream out) {
throw new Error(this.getClass().getName() +
".ppPrefix(PrintStream out)" +
" not declared");
......@@ -81,7 +81,7 @@ aspect PrettyPrint {
}
public void ArrayType.ppPrefix(PrintStream out) {
getType().ppPrefix(out);
getDataType().ppPrefix(out);
}
public void StructType.ppPrefix(PrintStream out) {
......@@ -94,7 +94,7 @@ aspect PrettyPrint {
}
// PrettyPrint suffix type info (array dimensions)
public void Type.ppSuffix(PrintStream out) { }
public void DataType.ppSuffix(PrintStream out) { }
public void ArrayType.ppSuffix(PrintStream out) {
out.print("[");
......@@ -103,7 +103,7 @@ aspect PrettyPrint {
getExp(i).pp(out);
}
out.print("]");
getType().ppSuffix(out);
getDataType().ppSuffix(out);
}
public void IntegerLiteral.pp(PrintStream out) {
......
......@@ -4,75 +4,23 @@ aspect Python_CodeGenEnv {
// handles qualid nesting, indentation, file writing and
// prefix propagation
public class Python_env {
public class Python_env extends PrintEnv {
final private class Python_printer {
private boolean newline = true;
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;
final private class Python_printer extends PrintEnv.Printer {
// public C_printer(PrintStream out) {
// super(out, " ");
// }
}
public void println(Python_env env) {
out.println();
newline = true;
}
}
private int indent;
private Python_printer printer;
public Python_env(PrintStream out) {
this.indent = 0;
this.printer = new Python_printer(out);
super(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 {
public void Program.Python_gen(PrintStream out, String baseName, int version) {
public void Specification.Python_gen(PrintStream out, String baseName, int version) {
Python_env env = new Python_env(out);
env.println("#!/usr/bin/python");
env.println("# Auto generated " + baseName);
......@@ -100,7 +48,7 @@ aspect Python_CodeGen {
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++) {
getDecl(i).Python_genSignatureAndTypedef(env);
}
......@@ -115,9 +63,11 @@ aspect PythonTypes {
public void TypeDecl.Python_genSignatureAndTypedef(Python_env env) {
env.println("class " + getName() + "(object):");
env.indent();
env.println("typedef = labcomm2014.typedef('" + getName() + "',");
env.print("typedef = labcomm2014.typedef(");
Python_genIntentions(env);
env.println(",");
env.indent();
getType().Python_genTypedef(env);
getTypeInstance().Python_genTypedef(env);
env.unindent();
env.println(")");
env.unindent();
......@@ -127,25 +77,49 @@ aspect PythonTypes {
public void SampleDecl.Python_genSignatureAndTypedef(Python_env env) {
env.println("class " + getName() + "(object):");
env.indent();
env.println("signature = labcomm2014.sample('" + getName() + "', ");
env.print("signature = labcomm2014.sample(");
Python_genIntentions(env);
env.println(",");
env.indent();
getType().Python_genSignature(env);
getDataType().Python_genSignature(env);
env.unindent();
env.println(")");
env.println("typedef = labcomm2014.sample('" + getName() + "', ");
env.print("typedef = labcomm2014.sample(");
Python_genIntentions(env);
env.println(",");
env.indent();
getType().Python_genTypedef(env);
getTypeInstance().Python_genTypedef(env);
env.unindent();
env.println(")");
env.unindent();
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) {
lookupType(getName()).getType().Python_genSignature(env);
lookupType(getName()).getDataType().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() +
".Python_genSignature(Python_env env)" +
" not declared");
......@@ -173,7 +147,7 @@ aspect PythonTypes {
}
env.println("],");
env.indent();
getType().Python_genSignature(env);
getDataType().Python_genSignature(env);
env.print(")");
env.unindent();
}
......@@ -194,8 +168,10 @@ aspect PythonTypes {
}
public void Field.Python_genSignature(Python_env env) {
env.print("('" + getName() + "', ");
getType().Python_genSignature(env);
env.print("(");
Python_genIntentions(env);
env.print(", ");
getDataType().Python_genSignature(env);
env.print(")");
}
......@@ -203,7 +179,7 @@ aspect PythonTypes {
env.println(getName() + ".typedef");
}
public void Type.Python_genTypedef(Python_env env) {
public void DataType.Python_genTypedef(Python_env env) {
throw new Error(this.getClass().getName() +
".Python_genTypedef(Python_env env)" +
" not declared");
......@@ -231,7 +207,7 @@ aspect PythonTypes {
}
env.println("],");
env.indent();
getType().Python_genTypedef(env);
getDataType().Python_genTypedef(env);
env.print(")");
env.unindent();
}
......@@ -252,8 +228,10 @@ aspect PythonTypes {
}
public void Field.Python_genTypedef(Python_env env) {
env.print("('" + getName() + "', ");
getType().Python_genTypedef(env);
env.print("(");
Python_genIntentions(env);
env.print(", ");
getDataType().Python_genTypedef(env);
env.print(")");
}
......
......@@ -77,7 +77,7 @@ aspect RAPID_CodeGen {
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
{
PrintStream ps = new PrintStream(new FileOutputStream(new File(file)));
......@@ -85,7 +85,7 @@ aspect RAPID_CodeGen {
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++) {
getDecl(i).RAPID_gen(env);
......@@ -126,7 +126,7 @@ aspect RAPID_CodeGen {
public void SampleDecl.RAPID_gen(RAPID_env env) {
// Add type declarations
String fullName = getType().RAPID_AddType(env, getName());
String fullName = getDataType().RAPID_AddType(env, getName());
// Add signature constants
String sig_len_name = "signature_len_" + getName();
String sig_name = "signature_" + getName();
......@@ -167,7 +167,7 @@ aspect RAPID_CodeGen {
params.add("VAR LabComm_Stream st");
params.add("VAR LabComm_Decoder_Sample s");
stmts.add("VAR " + fullName + " tmp;");
getType().RAPID_AddDecodeInstr(env, stmts, "tmp", "st");
getDataType().RAPID_AddDecodeInstr(env, stmts, "tmp", "st");
stmts.add("% s.handler % tmp;");
env.addProc("Decode_And_Handle_" + getName(), params, stmts);
......@@ -201,11 +201,11 @@ aspect RAPID_CodeGen {
params.add("VAR LabComm_Encoder_Sample s");
params.add("VAR " + fullName + " val");
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);
}
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());
}
......@@ -214,7 +214,7 @@ aspect RAPID_CodeGen {
for (int i = 0; i < getNumField(); i++) {
Field f = getField(i);
components.add(
f.getType().RAPID_AddType(env, name + "_" + f.getName()) +
f.getDataType().RAPID_AddType(env, name + "_" + f.getName()) +
" " + f.getName() + ";");
}
String typeName = env.addRecord(name, components);
......@@ -222,7 +222,7 @@ aspect RAPID_CodeGen {
}
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) {
throw new UnsupportedOperationException("RAPID generation only (currently) supports one-dimensional arrays");
}
......@@ -251,7 +251,7 @@ aspect RAPID_CodeGen {
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,
String var_name, String stream_name) {
throw new UnsupportedOperationException("RAPID code generation does not (currently) support "+getClass().getSimpleName());
......@@ -261,7 +261,7 @@ aspect RAPID_CodeGen {
java.util.List<String> instrs,
String var_name, String stream_name) {
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);
}
}
......@@ -270,7 +270,7 @@ aspect RAPID_CodeGen {
java.util.List<String> instrs,
String var_name, String stream_name) {
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);
}
}
......@@ -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,
String var_name, String stream_name) {
throw new UnsupportedOperationException("RAPID code generation does not (currently) support "+getClass().getSimpleName());
......@@ -315,7 +315,7 @@ aspect RAPID_CodeGen {
java.util.List<String> instrs,
String var_name, String stream_name) {
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);
}
}
......@@ -324,7 +324,7 @@ aspect RAPID_CodeGen {
java.util.List<String> instrs,
String var_name, String stream_name) {
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);
}
}
......
/* 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);
}