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
Showing
with 1281 additions and 238 deletions
......@@ -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");
......@@ -68,6 +68,10 @@ aspect PrettyPrint {
out.print("void");
}
// public void SampleRefType.ppPrefix(PrintStream out) {
// out.print("sample");
// }
public void PrimType.ppPrefix(PrintStream out) {
out.print(getName());
}
......@@ -77,7 +81,7 @@ aspect PrettyPrint {
}
public void ArrayType.ppPrefix(PrintStream out) {
getType().ppPrefix(out);
getDataType().ppPrefix(out);
}
public void StructType.ppPrefix(PrintStream out) {
......@@ -90,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("[");
......@@ -99,7 +103,7 @@ aspect PrettyPrint {
getExp(i).pp(out);
}
out.print("]");
getType().ppSuffix(out);
getDataType().ppSuffix(out);
}
public void IntegerLiteral.pp(PrintStream out) {
......
......@@ -4,142 +4,122 @@ 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;
}
public void println(Python_env env) {
out.println();
newline = true;
final private class Python_printer extends PrintEnv.Printer {
// public C_printer(PrintStream out) {
// super(out, " ");
// }
}
}
private int indent;
private Python_printer printer;
public Python_env(PrintStream out) {
this.indent = 0;
this.printer = new Python_printer(out);
}
public void indent() {
indent++;
super(out);
}
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) {
// 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);
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);
env.println();
env.println("import labcomm");
env.println("import labcomm2014");
env.println();
Python_genTypes(env);
env.println("typedef = [");
env.println("typedef = tuple([");
env.indent();
for (int i = 0 ; i < getNumDecl() ; i++) {
getDecl(i).Python_genTypedefListEntry(env);
}
env.unindent();
env.println("]");
env.println("sample = [");
env.println("])");
env.println("sample = tuple([");
env.indent();
for (int i = 0 ; i < getNumDecl() ; i++) {
getDecl(i).Python_genSampleListEntry(env);
}
env.unindent();
env.println("]");
env.println("])");
}
}
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++) {
env.println("class " + getDecl(i).getName() + "(object):");
env.indent();
getDecl(i).Python_genSignature(env);
env.unindent();
env.println();
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() +
".Python_genSignature(Python_env env)" +
".Python_genSignatureAndTypedef(Python_env env)" +
" not declared");
}
public void TypeDecl.Python_genSignature(Python_env env) {
env.println("signature = labcomm.typedef('" + getName() + "',");
public void TypeDecl.Python_genSignatureAndTypedef(Python_env env) {
env.println("class " + getName() + "(object):");
env.indent();
env.print("typedef = labcomm2014.typedef(");
Python_genIntentions(env);
env.println(",");
env.indent();
getType().Python_genSignature(env);
getTypeInstance().Python_genTypedef(env);
env.unindent();
env.println(")");
env.unindent();
env.println();
}
public void SampleDecl.Python_genSignature(Python_env env) {
env.println("signature = labcomm.sample('" + getName() + "', ");
public void SampleDecl.Python_genSignatureAndTypedef(Python_env env) {
env.println("class " + getName() + "(object):");
env.indent();
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.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) {
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");
......@@ -147,32 +127,33 @@ aspect PythonTypes {
public void PrimType.Python_genSignature(Python_env env) {
switch (getToken()) {
case LABCOMM_BOOLEAN: { env.print("labcomm.BOOLEAN()"); } break;
case LABCOMM_BYTE: { env.print("labcomm.BYTE()"); } break;
case LABCOMM_SHORT: { env.print("labcomm.SHORT()"); } break;
case LABCOMM_INT: { env.print("labcomm.INTEGER()"); } break;
case LABCOMM_LONG: { env.print("labcomm.LONG()"); } break;
case LABCOMM_FLOAT: { env.print("labcomm.FLOAT()"); } break;
case LABCOMM_DOUBLE: { env.print("labcomm.DOUBLE()"); } break;
case LABCOMM_STRING: { env.print("labcomm.STRING()"); } break;
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_genSignature(Python_env env) {
env.print("labcomm.array([");
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();
getType().Python_genSignature(env);
getDataType().Python_genSignature(env);
env.print(")");
env.unindent();
}
public void StructType.Python_genSignature(Python_env env) {
env.println("labcomm.struct([");
env.println("labcomm2014.struct([");
env.indent();
for (int i = 0 ; i < getNumField() ; i++) {
if (i > 0) { env.println(","); }
......@@ -183,12 +164,74 @@ aspect PythonTypes {
}
public void VoidType.Python_genSignature(Python_env env) {
env.println("labcomm.struct([])");
env.println("labcomm2014.struct([])");
}
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(")");
}
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(")");
}
......@@ -196,14 +239,14 @@ aspect PythonTypes {
}
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 SampleDecl.Python_genSampleListEntry(Python_env env) {
env.println("('" + getName() + "', " + getName() + ".signature),");
env.println(getName()+ ",");
}
public String Exp.Python_getValue() {
......@@ -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.