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
Showing
with 1281 additions and 238 deletions
...@@ -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");
...@@ -68,6 +68,10 @@ aspect PrettyPrint { ...@@ -68,6 +68,10 @@ aspect PrettyPrint {
out.print("void"); out.print("void");
} }
// public void SampleRefType.ppPrefix(PrintStream out) {
// out.print("sample");
// }
public void PrimType.ppPrefix(PrintStream out) { public void PrimType.ppPrefix(PrintStream out) {
out.print(getName()); out.print(getName());
} }
...@@ -77,7 +81,7 @@ aspect PrettyPrint { ...@@ -77,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) {
...@@ -90,7 +94,7 @@ aspect PrettyPrint { ...@@ -90,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("[");
...@@ -99,7 +103,7 @@ aspect PrettyPrint { ...@@ -99,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,142 +4,122 @@ aspect Python_CodeGenEnv { ...@@ -4,142 +4,122 @@ 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);
env.println(); env.println();
env.println("import labcomm"); env.println("import labcomm2014");
env.println(); env.println();
Python_genTypes(env); Python_genTypes(env);
env.println("typedef = ["); env.println("typedef = tuple([");
env.indent(); env.indent();
for (int i = 0 ; i < getNumDecl() ; i++) { for (int i = 0 ; i < getNumDecl() ; i++) {
getDecl(i).Python_genTypedefListEntry(env); getDecl(i).Python_genTypedefListEntry(env);
} }
env.unindent(); env.unindent();
env.println("]"); env.println("])");
env.println("sample = ["); env.println("sample = tuple([");
env.indent(); env.indent();
for (int i = 0 ; i < getNumDecl() ; i++) { for (int i = 0 ; i < getNumDecl() ; i++) {
getDecl(i).Python_genSampleListEntry(env); getDecl(i).Python_genSampleListEntry(env);
} }
env.unindent(); env.unindent();
env.println("]"); env.println("])");
} }
} }
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++) {
env.println("class " + getDecl(i).getName() + "(object):"); getDecl(i).Python_genSignatureAndTypedef(env);
env.indent();
getDecl(i).Python_genSignature(env);
env.unindent();
env.println();
} }
} }
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("signature = labcomm.typedef('" + getName() + "',"); env.println("class " + getName() + "(object):");
env.indent();
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.println();
} }
public void SampleDecl.Python_genSignature(Python_env env) { public void SampleDecl.Python_genSignatureAndTypedef(Python_env env) {
env.println("signature = labcomm.sample('" + getName() + "', "); env.println("class " + getName() + "(object):");
env.indent();
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.unindent();
env.println(")"); env.println(")");
env.print("typedef = labcomm2014.sample(");
Python_genIntentions(env);
env.println(",");
env.indent();
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) { 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() + throw new Error(this.getClass().getName() +
".Python_genSignature(Python_env env)" + ".Python_genSignature(Python_env env)" +
" not declared"); " not declared");
...@@ -147,32 +127,33 @@ aspect PythonTypes { ...@@ -147,32 +127,33 @@ aspect PythonTypes {
public void PrimType.Python_genSignature(Python_env env) { public void PrimType.Python_genSignature(Python_env env) {
switch (getToken()) { switch (getToken()) {
case LABCOMM_BOOLEAN: { env.print("labcomm.BOOLEAN()"); } break; case LABCOMM_BOOLEAN: { env.print("labcomm2014.BOOLEAN()"); } break;
case LABCOMM_BYTE: { env.print("labcomm.BYTE()"); } break; case LABCOMM_BYTE: { env.print("labcomm2014.BYTE()"); } break;
case LABCOMM_SHORT: { env.print("labcomm.SHORT()"); } break; case LABCOMM_SHORT: { env.print("labcomm2014.SHORT()"); } break;
case LABCOMM_INT: { env.print("labcomm.INTEGER()"); } break; case LABCOMM_INT: { env.print("labcomm2014.INTEGER()"); } break;
case LABCOMM_LONG: { env.print("labcomm.LONG()"); } break; case LABCOMM_LONG: { env.print("labcomm2014.LONG()"); } break;
case LABCOMM_FLOAT: { env.print("labcomm.FLOAT()"); } break; case LABCOMM_FLOAT: { env.print("labcomm2014.FLOAT()"); } break;
case LABCOMM_DOUBLE: { env.print("labcomm.DOUBLE()"); } break; case LABCOMM_DOUBLE: { env.print("labcomm2014.DOUBLE()"); } break;
case LABCOMM_STRING: { env.print("labcomm.STRING()"); } break; case LABCOMM_STRING: { env.print("labcomm2014.STRING()"); } break;
case LABCOMM_SAMPLE: { env.print("labcomm2014.SAMPLE()"); } break;
} }
} }
public void ArrayType.Python_genSignature(Python_env env) { public void ArrayType.Python_genSignature(Python_env env) {
env.print("labcomm.array(["); env.print("labcomm2014.array([");
for (int i = 0 ; i < getNumExp() ; i++) { for (int i = 0 ; i < getNumExp() ; i++) {
if (i > 0) { env.print(", "); } if (i > 0) { env.print(", "); }
env.print(getExp(i).Python_getValue()); env.print(getExp(i).Python_getValue());
} }
env.println("],"); env.println("],");
env.indent(); env.indent();
getType().Python_genSignature(env); getDataType().Python_genSignature(env);
env.print(")"); env.print(")");
env.unindent(); env.unindent();
} }
public void StructType.Python_genSignature(Python_env env) { public void StructType.Python_genSignature(Python_env env) {
env.println("labcomm.struct(["); env.println("labcomm2014.struct([");
env.indent(); env.indent();
for (int i = 0 ; i < getNumField() ; i++) { for (int i = 0 ; i < getNumField() ; i++) {
if (i > 0) { env.println(","); } if (i > 0) { env.println(","); }
...@@ -183,12 +164,74 @@ aspect PythonTypes { ...@@ -183,12 +164,74 @@ aspect PythonTypes {
} }
public void VoidType.Python_genSignature(Python_env env) { public void VoidType.Python_genSignature(Python_env env) {
env.println("labcomm.struct([])"); env.println("labcomm2014.struct([])");
} }
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(")");
} }
...@@ -196,14 +239,14 @@ aspect PythonTypes { ...@@ -196,14 +239,14 @@ aspect PythonTypes {
} }
public void TypeDecl.Python_genTypedefListEntry(Python_env env) { public void TypeDecl.Python_genTypedefListEntry(Python_env env) {
env.println("('" + getName() + "', " + getName() + ".signature),"); env.println(getName() + ",");
} }
public void Decl.Python_genSampleListEntry(Python_env env) { public void Decl.Python_genSampleListEntry(Python_env env) {
} }
public void SampleDecl.Python_genSampleListEntry(Python_env env) { public void SampleDecl.Python_genSampleListEntry(Python_env env) {
env.println("('" + getName() + "', " + getName() + ".signature),"); env.println(getName()+ ",");
} }
public String Exp.Python_getValue() { public String Exp.Python_getValue() {
...@@ -221,3 +264,4 @@ aspect PythonTypes { ...@@ -221,3 +264,4 @@ aspect PythonTypes {
} }
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
aspect DeclNames {
inh String Type.declName();
eq Decl.getType().declName() = getName();
inh String Field.declName();
eq StructType.getField(int i).declName() = declName();
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#!/bin/sh
java -jar /lib/labcomm2014_compiler.jar "$@"
File added
This diff is collapsed.