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
No results found
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 99

128 files
+ 6227
2333
Compare changes
  • Side-by-side
  • Inline

Files

+1 −0
Original line number Original line Diff line number Diff line
@@ -2,3 +2,4 @@
*.class
*.class
*.o
*.o
*.pyc
*.pyc
examples/dynamic/gen
+11 −0
Original line number Original line Diff line number Diff line
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-%)
+130 −0
Original line number Original line Diff line number Diff line
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

}
Original line number Original line Diff line number Diff line
@@ -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));
      }
      }
    }
    }
  }
  }
Original line number Original line Diff line number Diff line
@@ -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 {
      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 {
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 {


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 {


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 {
	    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 {
  }
  }


  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 {
      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 {
    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 {
    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 {
    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 {
    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 {
    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 {
    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 {
        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 {
  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 {
    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 {
    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 {
      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 {
      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 {
        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 {
    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 {
    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 {
  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 {
    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 {
      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 {
  }
  }


  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 {
  }
  }


  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 {
    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 {
  }
  }


  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 {
      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 {


  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 {
    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 {


    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 {


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 {


  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();
  }
  }
Original line number Original line Diff line number Diff line
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();
}
}
Original line number Original line Diff line number Diff line
@@ -27,5 +27,4 @@ aspect ErrorCheck {
        getChild(i).errorCheck(collection);
        getChild(i).errorCheck(collection);
        }
        }
    }
    }

}
}
Original line number Original line Diff line number Diff line
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 {
  }
  }


  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 {
    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 {
  }
  }


  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 {
  }
  }


  public String Field.signatureComment() {
  public String Field.signatureComment() {
    return getType().signatureComment() + " '" + getName() +"'";
    return getDataType().signatureComment() + " '" + getName() +"'";
  }
  }


//  public String SampleRefType.signatureComment() {
//  public String SampleRefType.signatureComment() {
+36 −0
Original line number Original line Diff line number Diff line
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;");
        }
    }

}
Original line number Original line Diff line number Diff line
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;
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;


Original line number Original line Diff line number Diff line
@@ -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 {
     }
     }
  }
  }


  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 {
    }
    }
  }
  }


  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 {
    }
    }
  }
  }


  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 {
    }
    }
  }
  }


  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 {
    }
    }
  }
  }


  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 {
    }
    }
  }
  }


  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 {
    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 {
          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 {
     }
     }
   }
   }


   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 {
     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 {
     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 {
     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 {
     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 {
     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 {
     }
     }
     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 {
     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 {
     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 {
      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 {
        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) {
Original line number Original line Diff line number Diff line
@@ -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 =
  | 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; :}
Original line number Original line Diff line number Diff line
@@ -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]
  "}"                            { 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
Original line number Original line Diff line number Diff line
@@ -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 {


  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 {
    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
  
  
Original line number Original line Diff line number Diff line
@@ -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 {
		    " 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 {
   // 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 {
  }
  }


  // 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 {
  }
  }


  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 {
  }
  }


  // 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 {
      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) {
Original line number Original line Diff line number Diff line
@@ -4,75 +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) {
    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);
@@ -100,7 +48,7 @@ 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_genSignatureAndTypedef(env);
      getDecl(i).Python_genSignatureAndTypedef(env);
    }
    }
@@ -115,9 +63,11 @@ aspect PythonTypes {
  public void TypeDecl.Python_genSignatureAndTypedef(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("typedef = labcomm2014.typedef('" + getName() + "',");
    env.print("typedef = labcomm2014.typedef(");
    Python_genIntentions(env);
    env.println(",");
    env.indent();
    env.indent();
    getType().Python_genTypedef(env);
    getTypeInstance().Python_genTypedef(env);
    env.unindent();
    env.unindent();
    env.println(")");
    env.println(")");
    env.unindent();
    env.unindent();
@@ -127,25 +77,49 @@ aspect PythonTypes {
  public void SampleDecl.Python_genSignatureAndTypedef(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.unindent();
    env.println(")");
    env.println(")");
    env.println("typedef = labcomm2014.sample('" + getName() + "', ");
    env.print("typedef = labcomm2014.sample(");
    Python_genIntentions(env);
    env.println(",");
    env.indent();
    env.indent();
    getType().Python_genTypedef(env);
    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) {
    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");
@@ -173,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();
  }
  }
@@ -194,8 +168,10 @@ 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(")");
    env.print(")");
  }
  }


@@ -203,7 +179,7 @@ aspect PythonTypes {
    env.println(getName() + ".typedef");
    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() +
    throw new Error(this.getClass().getName() +
                    ".Python_genTypedef(Python_env env)" +
                    ".Python_genTypedef(Python_env env)" +
                    " not declared");
                    " not declared");
@@ -231,7 +207,7 @@ aspect PythonTypes {
    }
    }
    env.println("],");
    env.println("],");
    env.indent();
    env.indent();
    getType().Python_genTypedef(env);
    getDataType().Python_genTypedef(env);
    env.print(")");
    env.print(")");
    env.unindent();
    env.unindent();
  }
  }
@@ -252,8 +228,10 @@ aspect PythonTypes {
  }
  }


  public void Field.Python_genTypedef(Python_env env) {
  public void Field.Python_genTypedef(Python_env env) {
    env.print("('" + getName() + "', ");
    env.print("(");
    getType().Python_genTypedef(env);
    Python_genIntentions(env);
    env.print(", ");
    getDataType().Python_genTypedef(env);
    env.print(")");
    env.print(")");
  }
  }


Original line number Original line Diff line number Diff line
@@ -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 {
		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 {


	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 {
		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 {
		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 {
		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 {
	}
	}


	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 {
		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 {
			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 {
			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 {
		}
		}
	}
	}


	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 {
			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 {
			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);
		}
		}
	}
	}
+30 −0
Original line number Original line Diff line number Diff line
/* 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);
}
Original line number Original line Diff line number Diff line
@@ -14,10 +14,9 @@ aspect Signature {
    inh Decl Signature.parentDecl();
    inh Decl Signature.parentDecl();
    inh Decl SignatureList.parentDecl();
    inh Decl SignatureList.parentDecl();



    syn nta Signature Decl.getSignature() {
    syn nta Signature Decl.getSignature() {
        SignatureList sl = new SignatureList();
        SignatureList sl = new SignatureList();
    genSigLineForDecl(sl, true);
        genSigLineForDecl(sl, true, this);
        SignatureList fsl = new SignatureList();
        SignatureList fsl = new SignatureList();
        flatSignature(fsl);
        flatSignature(fsl);
        Signature sig = new Signature();
        Signature sig = new Signature();
@@ -100,6 +99,29 @@ aspect Signature {
            return getIntBytes(getData(), version);
            return getIntBytes(getData(), version);
        }
        }


        public void SignatureList.addIntentions(Set<Intention> data, String comment) {
                //addString(TypeInstance.getIntentionString(data), comment);
                //create IntenionSignatureLine
                IntentionSignatureLine line = new IntentionSignatureLine(indent, comment, new List());
                //TODO: refactor out creation of sorted list of intentions

                java.util.ArrayList<Intention> sorted = new ArrayList(data);
                java.util.Collections.sort(sorted, TypeInstance.intentionComp);
                for(Intention i : sorted) {
                        line.addIntention(i);
                }

                addSignatureLine(line);
        }

        eq IntentionSignatureLine.getData(int version) {
            //String tmpString = TypeInstance.getIntentionString(getIntentions());

            byte[] bs = TypeInstance.getIntentionBytes(getIntentions());
            return bs;
        }


        public void SignatureList.addString(String data, String comment) {
        public void SignatureList.addString(String data, String comment) {
            addSignatureLine(new StringSignatureLine(indent, comment, data));
            addSignatureLine(new StringSignatureLine(indent, comment, data));
        }
        }
@@ -151,79 +173,200 @@ aspect Signature {
        }
        }




  public void ASTNode.genSigLineForDecl(SignatureList list, boolean decl) {
    public void ASTNode.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
        throw new Error(this.getClass().getName() +
        throw new Error(this.getClass().getName() +
                                        ".genSigLineForDecl(SignatureList list)" +
                                        ".genSigLineForDecl(SignatureList list)" +
                                        " not declared");
                                        " not declared");
    }
    }


  public void TypeDecl.genSigLineForDecl(SignatureList list, boolean decl) {
    public String TypeInstance.getIntentionString() {
            return getIntentionString(intentions());
    }

    public static String TypeInstance.getIntentionString(List<Intention> intentions) {
        if(intentions==null) return "";
        Iterator<Intention> it = intentions.iterator();
        return getIntentionString(it);

    }
    public static String TypeInstance.getIntentionString(Set<Intention> intentions) {
        if(intentions==null) return "";
        Iterator<Intention> it = intentions.iterator();
        return getIntentionString(it);
    }

    public static String TypeInstance.getIntentionString(Iterator<Intention> it) {
        StringBuilder sb = new StringBuilder();
        while(it.hasNext()) {
                Intention i = it.next();
                sb.append(i.toString());
        }
        return sb.toString();
    }

    syn byte[] Intention.keyBytes() = getKey().getBytes();
    syn byte[] Intention.valBytes() = getValue();

    syn byte[] Intention.toByteArray() {
            byte[] k = keyBytes();
            byte[] v = valBytes();
            int klen = Utilities.size_packed32(k.length);
            int vlen = Utilities.size_packed32(v.length);
            int tlen = k.length + v.length + Utilities.size_packed32(klen) + Utilities.size_packed32(vlen);
            //int size = Utilities.size_packed32(tlen)+tlen;

            byte result[] = new byte[tlen];

            int pos=0;

//           pos = Utilities.encodePacked32(tlen, result, pos, Utilities.size_packed32(tlen));
           pos = Utilities.encodePacked32(k.length, result, pos, klen);
           for(byte kb : k) {
                result[pos++] = kb;
           }
           pos = Utilities.encodePacked32(v.length, result, pos, vlen);
           for(byte vb : v) {
                result[pos++] = vb;
           }
           return result;
    }


    public byte[] TypeInstance.getIntentionBytes() {
            return getIntentionBytes(intentions());
    }

    public static byte[] TypeInstance.getIntentionBytes(List<Intention> intentions) {
        if(intentions==null) return new byte[0];

        Iterator<Intention> it = intentions.iterator();
        return getIntentionBytes(it);
    }

    public static byte[] TypeInstance.getIntentionBytes(Set<Intention> intentions) {
        if(intentions==null) return new byte[0];

        Iterator<Intention> it = intentions.iterator();
        return getIntentionBytes(it);
    }

    public static byte[] TypeInstance.getIntentionBytes(Iterator<Intention> it) {
        java.util.ArrayList<byte[]> tmp = new java.util.ArrayList<byte[]>();
        int tmpLen=0;
        int numIntentions=0;

        while(it.hasNext()) {
                Intention i = it.next();
                byte[] bs = i.toByteArray();
                tmp.add(bs);
                tmpLen+=bs.length;
                numIntentions++;
        }

        byte result[] = new byte[tmpLen + Utilities.size_packed32(numIntentions)];

        int pos = 0;
        pos = Utilities.encodePacked32(numIntentions, result, 0, Utilities.size_packed32(numIntentions));
        for(byte[] bs : tmp) {
           for(byte b : bs) {
               result[pos++] = b;
           }
        }
        return result;
    }


    syn Set<Intention> Specification.emptyIntentions() = new HashSet<Intention>();

    inh Set<Intention> ASTNode.noIntentions();
    eq Specification.getChild(int i).noIntentions() = emptyIntentions();

    syn Set<Intention> ASTNode.intentions();

    eq ASTNode.intentions() = noIntentions();
    eq TypeInstance.intentions() = intentionSet();

    public void TypeInstance.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
//      debugAnnotations(this.getName());
//      list.addString(inst.getIntentionString(), "intention string");
        if(addIntentions()) {
          list.addIntentions(intentionSet(), "intentions");
        }
        getDataType().genSigLineForDecl(list, decl, this);
    }


    public void TypeDecl.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
                //TODO intent
        if(decl){
        if(decl){
      getType().genSigLineForDecl(list, decl);
            getTypeInstance().genSigLineForDecl(list, decl, this);
        }else{
        }else{
            list.addTypeRef(this, "//TODO (from list.addTypeRef)");
            list.addTypeRef(this, "//TODO (from list.addTypeRef)");
        }
        }
    }
    }


  public void SampleDecl.genSigLineForDecl(SignatureList list, boolean decl) {
    public void SampleDecl.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
    getType().genSigLineForDecl(list, decl);
                //TODO intent
        getTypeInstance().genSigLineForDecl(list, decl, this);
    }
    }


  public void VoidType.genSigLineForDecl(SignatureList list, boolean decl) {
    public void VoidType.genSigLineForDecl(SignatureList list, boolean decl,    ASTNode inst) {
        list.addInt(LABCOMM_STRUCT, "void");
        list.addInt(LABCOMM_STRUCT, "void");
        list.addInt(0, null);
        list.addInt(0, null);
    }
    }


//  public void SampleRefType.genSigLineForDecl(SignatureList list, boolean decl) {
//  public void SampleRefType.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
//      list.addInt(LABCOMM_SAMPLE_REF, "sample");
//      list.addInt(LABCOMM_SAMPLE_REF, "sample");
//  }
//  }
  public void PrimType.genSigLineForDecl(SignatureList list, boolean decl) {
    public void PrimType.genSigLineForDecl(SignatureList list, boolean decl,    ASTNode inst) {
        list.addInt(getToken(), null);
        list.addInt(getToken(), null);
    }
    }


    /* For UserType, the decl parameter is ignored, as a UserType
    /* For UserType, the decl parameter is ignored, as a UserType
     * will always be a TypeRef
     * will always be a TypeRef
     */
     */
  public void UserType.genSigLineForDecl(SignatureList list, boolean decl) {
    public void UserType.genSigLineForDecl(SignatureList list, boolean decl,    ASTNode inst) {


            TypeDecl thet = lookupType(getName());
            TypeDecl thet = lookupType(getName());
            list.addTypeRef(thet, null);
            list.addTypeRef(thet, null);
    }
    }


  public void ArrayType.genSigLineForDecl(SignatureList list, boolean decl) {
    public void ArrayType.genSigLineForDecl(SignatureList list, boolean decl,  ASTNode inst) {
        list.addInt(LABCOMM_ARRAY, signatureComment());
        list.addInt(LABCOMM_ARRAY, signatureComment());
        list.indent();
        list.indent();
        list.addInt(getNumExp(), null);
        list.addInt(getNumExp(), null);
        for (int i = 0 ; i < getNumExp() ; i++) {
        for (int i = 0 ; i < getNumExp() ; i++) {
      getExp(i).genSigLineForDecl(list, false);
            getExp(i).genSigLineForDecl(list, false, null);
        }
        }
    getType().genSigLineForDecl(list, false);
        getDataType().genSigLineForDecl(list, false, null);
        list.unindent();
        list.unindent();
        list.add(null, "}");
        list.add(null, "}");
    }
    }


  public void StructType.genSigLineForDecl(SignatureList list, boolean decl) {
    public void StructType.genSigLineForDecl(SignatureList list, boolean decl,  ASTNode inst) {
        list.addInt(LABCOMM_STRUCT, "struct { " + getNumField() + " fields");
        list.addInt(LABCOMM_STRUCT, "struct { " + getNumField() + " fields");
        list.indent();
        list.indent();
        list.addInt(getNumField(), null);
        list.addInt(getNumField(), null);
        for (int i = 0 ; i < getNumField() ; i++) {
        for (int i = 0 ; i < getNumField() ; i++) {
      getField(i).genSigLineForDecl(list, false);
            getField(i).genSigLineForDecl(list, false, inst);
        }
        }
        list.unindent();
        list.unindent();
        list.add(null, "}");
        list.add(null, "}");
    }
    }


  public void Field.genSigLineForDecl(SignatureList list, boolean decl) {
//    public void Field.genSigLineForDecl(SignatureList list, boolean decl,  ASTNode inst) {
    list.addString(getName(), signatureComment());
//        //XXX make intention
    getType().genSigLineForDecl(list, decl);
//        list.addString(getName(), signatureComment());
  }
//        super.genSigLineForDecl(list, decl, inst);
//        //TODOintent
//       //getDataType().genSigLineForDecl(list, decl, inst);
//    }


  public void IntegerLiteral.genSigLineForDecl(SignatureList list, boolean decl) {
    public void IntegerLiteral.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
        list.addInt(Integer.parseInt(getValue()), null);
        list.addInt(Integer.parseInt(getValue()), null);
    }
    }


  public void VariableSize.genSigLineForDecl(SignatureList list, boolean decl) {
    public void VariableSize.genSigLineForDecl(SignatureList list, boolean decl, ASTNode inst) {
        list.addInt(0, null);
        list.addInt(0, null);
    }
    }

}
}
Original line number Original line Diff line number Diff line
@@ -6,31 +6,49 @@ aspect TypeCheck {


// void is not allowed as a field in a struct or an array element
// void is not allowed as a field in a struct or an array element


  syn boolean Type.isNull();
  syn boolean DataType.isNull();
  eq Type.isNull() = false;
  eq DataType.isNull() = false;
  eq VoidType.isNull() = true;
  eq VoidType.isNull() = true;
  eq UserType.isNull() = decl().isNull();
  eq UserType.isNull() = decl().isNull();


  syn boolean TypeDecl.isNull();
  syn boolean TypeDecl.isNull();
  eq TypeDecl.isNull() = getType().isNull();
  eq TypeDecl.isNull() = getDataType().isNull();


  public void ASTNode.nullTypeCheck() {}
  public void ASTNode.nullTypeCheck() {}


  public void Field.nullTypeCheck() {
  public void Field.nullTypeCheck() {
    if(getType().isNull()) {
    if(getDataType().isNull()) {
      error("field " + getName() + " of struct "+ declName()+ " may not be of type void");
      error("field " + getName() + " of struct "+ declName()+ " may not be of type void");
    }
    }
  }
  }


  public void ParseArrayType.nullTypeCheck() {
  public void ParseArrayType.nullTypeCheck() {
    if(getType().isNull()) {
    if(getDataType().isNull()) {
      error("elements of array "+declName()+" may not be of type void");
      error("elements of array "+declName()+" may not be of type void");
    }
    }
  }
  }


  public void ArrayType.nullTypeCheck() {
  public void ArrayType.nullTypeCheck() {
    if(getType().isNull()) {
    if(getDataType().isNull()) {
      error("elements of array "+declName()+" may not be of type void");
      error("elements of array "+declName()+" may not be of type void");
    }
    }
  }
  }
}
}

aspect AnnotationCheck {

  refine TypeCheck void ASTNode.typeCheck() {
    refined(); // similar to call to super
    annotationCheck();
  }
  public void ASTNode.annotationCheck() {}

  public void TypeDecl.annotationCheck() {
    Iterator<Intention> it = getTypeInstance().intentions().iterator();;
    while(it.hasNext()) {
     if(!it.next().getKey().equals("")) {
       error("TypeDecl " + getName() + " has intentions. (Not allowed for typedefs)");
     }
    }
  }
}
Original line number Original line Diff line number Diff line
aspect User_Types {
aspect User_Types {
  syn String Type.getTypeName();
  syn String DataType.getTypeName();
  eq Type.getTypeName() = getClass().getName();
  eq DataType.getTypeName() = getClass().getName();
  eq PrimType.getTypeName() = getName();
  eq PrimType.getTypeName() = getName();
  eq UserType.getTypeName() = getName();
  eq UserType.getTypeName() = getName();


  syn boolean Type.isUserType();
  syn boolean DataType.isUserType();
  eq Type.isUserType() = false;
  eq DataType.isUserType() = false;
  eq UserType.isUserType() = true;
  eq UserType.isUserType() = true;
}
}


@@ -14,8 +14,8 @@ aspect Type_References {
  // The dependencies on other type declarations for a Decl.
  // The dependencies on other type declarations for a Decl.
  coll Set<Decl> Decl.type_dependencies() [new HashSet<Decl>()] with add;
  coll Set<Decl> Decl.type_dependencies() [new HashSet<Decl>()] with add;


  Field contributes ((UserType)getType()).decl()   
  Field contributes ((UserType)getDataType()).decl()
  when parentDecl() != null && getType().isUserType()
  when parentDecl() != null && getDataType().isUserType()
  to Decl.type_dependencies()
  to Decl.type_dependencies()
  for parentDecl();
  for parentDecl();


@@ -24,8 +24,8 @@ aspect Type_References {
  to Decl.type_dependencies()
  to Decl.type_dependencies()
  for parentDecl();
  for parentDecl();
  /*
  /*
  Field contributes getType().decl()   
  Field contributes getDataType().decl()
  when parentDecl() != null && getType().isLeafType()
  when parentDecl() != null && getDataType().isLeafType()
  to Decl.type_dependencies()
  to Decl.type_dependencies()
  for parentDecl();
  for parentDecl();
  */
  */
+233 −0
Original line number Original line Diff line number Diff line
aspect Encoding {

    public class Utilities {
        /* Size of packed32 variable */
        public static int size_packed32(long data)
            {
            long d = data & 0xffffffff;
            int result = 0;
            int i;

            for (i = 0 ; i == 0 || d != 0; i++, d = (d >>> 7)) {
                result++;
            }
            return result;
        }

        public static int encodePacked32(long value, byte[] buf, int start, int len) {
            int pos = start;
            byte[] tmp = new byte[5];
            long v = value & 0xffffffff;
            int i;

            for (i = 0 ; i == 0 || v != 0 ; i++, v = (v >> 7)) {
            tmp[i] = (byte)(v & 0x7f);
            }

            if(i != len) {
                throw new Error("wrong length, was: "+i+", expected "+len);
            }

            for (i = i - 1 ; i >= 0 ; i--) {
                buf[pos++] = (byte)(tmp[i] | (i!=0?0x80:0x00));
            }

            return pos;
        }
    }
}

aspect PrintEnv {
  public abstract class PrintEnv {

    protected static class Printer {
      private final String indentString = "    ";
      private boolean newline = true; // last print ended with newline
      protected PrintStream out;
      private Printer printer;


      /** dummy constructor motivated by the FilePrinter subclass */
      protected Printer() {
        this.out = null;
      }
      public Printer(PrintStream out) {
        this.out = out;
       }

      public void print(PrintEnv env, String s) {
        if (newline) {
          newline = false;
          for (int i = 0 ; i < env.getIndent() ; i++) {
            out.print(indentString);
          }
        }
        out.print(s);
      }

      public void println(PrintEnv env, String s) {
        print(env, s);
        out.println();
        newline = true;
      }

      public void println(PrintEnv env) {
        out.println();
        newline = true;
      }

      public PrintStream getPrintStream() {
        return(out);
      }

      public void close() throws IOException {
        //do nothing
      }
    }

    protected static class FilePrinter extends Printer {

      private File file;
      private IOException exception;

      public FilePrinter(PrintStream out) {
          super(out);
      }

      public FilePrinter(File f) {

        file = f;
        File parentFile = f.getParentFile();
        if(parentFile != null) {
            parentFile.mkdirs();
        }
      }

      public void close() throws IOException {
        if (out != null) {
          out.close();
        }
        if (exception != null) {
          throw exception;
        }
      }

      public void checkOpen() {
        if (out == null && exception == null) {
          try {
            out = new PrintStream(new FileOutputStream(file));
          } catch (IOException e) {
            exception = e;
          }
        }
      }

      public void print(PrintEnv env, String s) {
        checkOpen();
        super.print(env,s);
      }

      public void println(PrintEnv env, String s) {
	      checkOpen();
        super.println(env, s);
      }
    }

    public final int version; //labcomm version (2006 or 2014)
    public final String verStr; // version suffix to append (currently _2006 and empty string)
    private Printer printer;
    private int indent;
    private int depth;

    protected PrintEnv(PrintStream out) {
      this(new Printer(out));
    }

    protected PrintEnv(Printer printer) {
      this(printer, 2014);
    }
    protected PrintEnv(Printer printer, int version) {
      this(0, printer, version);
    }
    protected PrintEnv(int indent, Printer printer, int version) {
      this(indent, printer, version, 0);
    }

    protected PrintEnv(int indent, Printer printer, int version, int depth) {
      this.version = version;
      this.indent = indent;
      this.printer = printer;
      this.verStr = LabCommVersion.versionString(version);
      this.depth = depth;
    }

    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 void incDepth() {
      depth++;
    }

    public void decDepth() {
      if(depth<=0) {
        throw new RuntimeException("decDepth() called when depth = "+depth);
      }
      depth--;
    }

    public int getDepth() {
      return depth;
    }

    public int getVersion() {
      return version;
    }

    public int getIndent() {
      return indent;
    }

    public Printer getPrinter() {
      return printer;
    }

    public boolean versionHasMetaData() {
      return version != 2006;
    }
  }
}
Original line number Original line Diff line number Diff line
@@ -5,7 +5,14 @@ aspect Version {
     */
     */
    class LabCommVersion {
    class LabCommVersion {
        public static String versionString(int version) {
        public static String versionString(int version) {
            return (version == 2006) ? "2006" : "";
            switch(version) {
                case 2006:
                    return "2006";
                case 2014:
                    return "2014";
                default:
                    throw new Error("no versionString for version "+version);
            }
        }
        }


        public static boolean versionHasPragma(int version) {
        public static boolean versionHasPragma(int version) {
+1 −1

File changed.

Contains only whitespace changes.

Original line number Original line Diff line number Diff line
@@ -778,22 +778,22 @@ Avro has multiple codecs (for compression of the data):


\subsection{Abstract syntax}
\subsection{Abstract syntax}
\begin{verbatim}
\begin{verbatim}
Program ::= Decl*;
Specification ::= Decl*;


abstract Decl ::= Type <Name:String>;
abstract Decl ::= DataType <Name:String>;
TypeDecl : Decl;
TypeDecl : Decl;
SampleDecl : Decl;
SampleDecl : Decl;


Field ::= Type <Name:String>;
Field ::= DataType <Name:String>;


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 Exp*;
VariableArrayType : ArrayType;
VariableArrayType : ArrayType;
FixedArrayType    : ArrayType;
FixedArrayType    : ArrayType;


Original line number Original line Diff line number Diff line
@@ -17,7 +17,7 @@ ifeq ($(UNAME_S),Darwin)
else	
else	
	cd simple ; sh compile.sh && sh run.sh
	cd simple ; sh compile.sh && sh run.sh
	$(MAKE) -C  wiki_example test
	$(MAKE) -C  wiki_example test
	$(MAKE) -C user_types test 
	$(MAKE) -C user_types all 
endif	
endif	
	$(MAKE) -C duck_typing test
	$(MAKE) -C duck_typing test
	$(MAKE) -C twoway test 
	$(MAKE) -C twoway test 
Original line number Original line Diff line number Diff line
@@ -27,7 +27,7 @@ if __name__ == '__main__':
        while True:
        while True:
            value,decl = decoder.decode()
            value,decl = decoder.decode()
            if value:
            if value:
                print decl.name, 'says', value.says
                print decl.name, 'says', value
                pass
                pass
            pass
            pass
        pass
        pass
Original line number Original line Diff line number Diff line
all:
all:
	sh dynamic.sh
	sh dynamic_type.sh
	sh test.sh
	sh test_type.sh


clean:
clean:
	-rm test/*.class
	-rm encoded_data
	-rm dynamic_out


distclean:
distclean: clean
Original line number Original line Diff line number Diff line
@@ -158,7 +158,7 @@ public class DynamicPart {
	}
	}


	public static InRAMCompiler generateCode(String lcDecl, HashMap<String, String> handlers) {
	public static InRAMCompiler generateCode(String lcDecl, HashMap<String, String> handlers) {
		Program ast = null;
		Specification ast = null;
		InputStream in = new ByteArrayInputStream(lcDecl.getBytes());
		InputStream in = new ByteArrayInputStream(lcDecl.getBytes());
		LabCommScanner scanner = new LabCommScanner(in);
		LabCommScanner scanner = new LabCommScanner(in);
		LabCommParser parser = new LabCommParser();
		LabCommParser parser = new LabCommParser();
@@ -166,7 +166,7 @@ public class DynamicPart {


		InRAMCompiler irc = null;
		InRAMCompiler irc = null;
		try {
		try {
			Program p = (Program)parser.parse(scanner);
			Specification p = (Specification)parser.parse(scanner);
			p.errorCheck(errors);
			p.errorCheck(errors);
			if (errors.isEmpty()) {
			if (errors.isEmpty()) {
				ast = p;
				ast = p;
@@ -197,7 +197,7 @@ public class DynamicPart {
	 * @param handlers - a map <name, source> of handlers for the types in ast
	 * @param handlers - a map <name, source> of handlers for the types in ast
	 * @return an InRAMCompiler object containing the generated clases
	 * @return an InRAMCompiler object containing the generated clases
	 */
	 */
	private static InRAMCompiler handleAst(Program lcAST, HashMap<String, String> handlers) {
	private static InRAMCompiler handleAst(Specification lcAST, HashMap<String, String> handlers) {
		Map<String, String> genCode = new HashMap<String, String>();
		Map<String, String> genCode = new HashMap<String, String>();
		try {
		try {
			lcAST.J_gen(genCode, "labcomm.generated", 2014);
			lcAST.J_gen(genCode, "labcomm.generated", 2014);