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
280 files
+ 7026
13888
Compare changes
  • Side-by-side
  • Inline

Files

.bzrignore

deleted100644 → 0
+0 −41
Original line number Original line Diff line number Diff line
AST
AST/*
LabComm.class
labComm.jar
lib/java/se/lth/control/labcomm/LabComm.class
lib/java/se/lth/control/labcomm/LabCommDecoderChannel.class
lib/java/se/lth/control/labcomm/LabCommDecoder.class
lib/java/se/lth/control/labcomm/LabCommDecoderRegistry.class
lib/java/se/lth/control/labcomm/LabCommDecoderRegistry$Entry.class
lib/java/se/lth/control/labcomm/LabCommDispatcher.class
lib/java/se/lth/control/labcomm/LabCommEncoderChannel.class
lib/java/se/lth/control/labcomm/LabCommEncoder.class
lib/java/se/lth/control/labcomm/LabCommEncoderRegistry.class
lib/java/se/lth/control/labcomm/LabCommEncoderRegistry$Entry.class
lib/java/se/lth/control/labcomm/LabCommHandler.class
lib/java/se/lth/control/labcomm/LabCommReader.class
lib/java/se/lth/control/labcomm/LabCommSample.class
lib/java/se/lth/control/labcomm/LabCommType.class
lib/java/se/lth/control/labcomm/LabCommWriter.class
gen
labcomm.dll
labcomm.jar
example.c
example.h
example.py
examples/wiki_example/example.encoded
example.encoded
examples/simple/*.class
examples/simple/encoded_data
examples/simple/example_decoder
examples/simple/example_encoder
lib/c/test/test_labcomm_basic_type_encoding
lib/c/test/test_labcomm_generated_encoding
lib/java/se/lth/control/labcomm/WriterWrapper.class
lib/c/liblabcomm.so.1
lib/c/test/test_labcomm_pthread_scheduler
lib/c/liblabcomm_plain_c.so.1
lib/c/test/test_signature_plain_c
test/test_signature_numbers
lib/c/test/test_signature_numbers
lib/c/test/test_labcomm
+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
+12 −1
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/labcomm_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-%)
Original line number Original line Diff line number Diff line
gen
gen
labcomm2006_compiler.jar
labcomm2006_compiler.jar
labcomm2014_compiler.jar
labcomm2014_compiler.jar
labcomm_compiler.jar
labcomm2014_compiler.jar
+0 −43
Original line number Original line Diff line number Diff line
aspect ArrayRewrite {

  syn boolean Dim.isVariable() {
    for (int i = 0 ; i < getNumExp() ; i++) {
      if (getExp(i) instanceof VariableSize) {
	return true;
      }	
    }
    return false;
  }

  rewrite ParseArrayType {
    when (! getDim(0).isVariable()) 
    to FixedArrayType  { 
      if (getNumDim() == 1) {
        return new FixedArrayType(getType(), 
				  getDim(0).getExpList());
      } else {
        List l = new List();
        for (int i = 1 ; i < getNumDim() ; i++) {
	  l.add(getDim(i));
        }
        return new FixedArrayType(new ParseArrayType(getType(), l), 
				  getDim(0).getExpList());
      }
    }
    when (getDim(0).isVariable()) 
    to VariableArrayType  { 
      if (getNumDim() == 1) {
        return new VariableArrayType(getType(), 
				     getDim(0).getExpList());
      } else {
        List l = new List();
        for (int i = 1 ; i < getNumDim() ; i++) {
	  l.add(getDim(i));
        }
        return new VariableArrayType(new ParseArrayType(getType(), l), 
				     getDim(0).getExpList());
      }
    }
  }

}

compiler/2006/DeclNames.jrag

deleted100644 → 0
+0 −14
Original line number Original line Diff line number Diff line
aspect DeclNames {
	inh String Type.declName();
	eq Decl.getType().declName() = getName();

	inh String Field.declName();
	eq StructType.getField(int i).declName() = declName();
    
        //TODO: aspect should be renamed to parent-something

        inh Decl Type.parentDecl();
        inh Decl Field.parentDecl();
        eq Decl.getType().parentDecl() = this;
        eq StructType.getField(int i).parentDecl() = parentDecl();
}

compiler/2006/ErrorCheck.jrag

deleted100644 → 0
+0 −31
Original line number Original line Diff line number Diff line
import java.util.Collection;

aspect ErrorCheck {

	syn int ASTNode.lineNumber() = getLine(getStart());

	protected String ASTNode.errors = null;
	
	protected void ASTNode.error(String s) {
	    s = "Error at " + lineNumber() + ": " + s;
	    if(errors == null) {
	      errors = s;
	    } else {
	      errors = errors + "\n" + s;
	    }
	}

	protected boolean ASTNode.hasErrors() {
		return errors != null;
	}
	public void ASTNode.errorCheck(Collection collection) {
	    nameCheck();
            typeCheck();
	    if(hasErrors())
		collection.add(errors);
	    for(int i = 0; i < getNumChild(); i++) {
		getChild(i).errorCheck(collection);
	    }
	}

}

compiler/2006/FlatSignature.jrag

deleted100644 → 0
+0 −123
Original line number Original line Diff line number Diff line
import java.util.*;

aspect FlatSignature {  

  public SignatureList Decl.flatSignature(int version) {
    SignatureList result = getSignature().getFlatSignatureList();
    return result;
  }
  
  public void ASTNode.flatSignature(SignatureList list) {
    throw new Error(this.getClass().getName() + 
                    ".flatSignature(SignatureList list)" + 
                    " not declared");
  }

  public void TypeDecl.flatSignature(SignatureList list) {
    getType().flatSignature(list);
  }

  public void SampleDecl.flatSignature(SignatureList list) {
    getType().flatSignature(list);
  }

  public void SampleRefType.flatSignature(SignatureList list) {
    list.addInt(LABCOMM_SAMPLE_REF, "sample");
  }

  public void VoidType.flatSignature(SignatureList list) {
    list.addInt(LABCOMM_STRUCT, "void");
    list.addInt(0, null);
  }

  public void PrimType.flatSignature(SignatureList list) {
    list.addInt(getToken(), null);
  }

  public void UserType.flatSignature(SignatureList list) {
    lookupType(getName()).flatSignature(list);
  }

  public void ArrayType.flatSignature(SignatureList list) {
    list.addInt(LABCOMM_ARRAY, signatureComment());
    list.indent();
    list.addInt(getNumExp(), null);
    for (int i = 0 ; i < getNumExp() ; i++) {
      getExp(i).flatSignature(list);
    }
    getType().flatSignature(list);
    list.unindent();
    list.add(null, "}");
  }

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

  public void Field.flatSignature(SignatureList list) {
    list.addString(getName(), signatureComment());
    getType().flatSignature(list);
  }

  public void IntegerLiteral.flatSignature(SignatureList list) {
    list.addInt(Integer.parseInt(getValue()), null);
  }

  public void VariableSize.flatSignature(SignatureList list) {
    list.addInt(0, null);
  }

  public String ArrayType.signatureComment() {
    StringBuffer result = new StringBuffer("array [");
    for (int i = 0 ; i < getNumExp() ; i++) {
      if (i > 0) {
	result.append(", ");
      }
      result.append(getExp(i).signatureComment());
    }
    result.append("]");
    return result.toString();
  }

  public String ASTNode.signatureComment() {
    throw new Error(this.getClass().getName() + 
                    ".signatureComment()" + 
                    " not declared");
  }

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

  public String SampleRefType.signatureComment() {
    return "sample";
  }

  public String PrimType.signatureComment() {
    return getName();
  }

  public String UserType.signatureComment() {
    return getName();
  }

  public String StructType.signatureComment() {
    return "struct";
  }

  public String IntegerLiteral.signatureComment() {
    return getValue();
  }

  public String VariableSize.signatureComment() {
    return "_";
  }

}

compiler/2006/LabComm.ast

deleted100644 → 0
+0 −39
Original line number Original line Diff line number Diff line
Program ::= Decl*;

//TODO: Add signatures to the abstract grammar, so that
//they can be extended and refined by more than one aspect.
//sketch:
Signature		::= SignatureList FlatSignatureList:SignatureList; 
SignatureList		::= SignatureLine*;
abstract SignatureLine 	::= <Indent:int> <Comment:String>; 
abstract DataSignatureLine : SignatureLine;
ByteArraySignatureLine : DataSignatureLine ::= <Data:byte[]>;
IntSignatureLine : DataSignatureLine ::= <Data:int>;
StringSignatureLine : DataSignatureLine ::= <Data:String>;
TypeRefSignatureLine   	: SignatureLine ::= Decl;


//abstract Decl ::= Type <Name:String>;
// the signature list be defined as  a non-terminal attribute:
abstract Decl ::= Type <Name:String> /Signature/;
TypeDecl : Decl;
SampleDecl : Decl;

Field ::= Type <Name:String>;

abstract Type;
VoidType          : Type;
SampleRefType     : Type;
PrimType          : Type ::= <Name:String> <Token:int>;
UserType          : Type ::= <Name:String>;
StructType        : Type ::= Field*;
ParseArrayType    : Type ::= Type Dim*;
abstract ArrayType :Type ::= Type Exp*;
VariableArrayType : ArrayType;
FixedArrayType    : ArrayType;

Dim ::= Exp*;

abstract Exp;
IntegerLiteral : Exp ::= <Value:String>;
VariableSize : Exp;

compiler/2006/LabComm.java

deleted100644 → 0
+0 −404
Original line number Original line Diff line number Diff line
package se.lth.control.labcomm2006.compiler;

import java.io.*;
import java.util.*;

public class LabComm {

  private static void println(String s) {
    System.out.println(s);
  }

  private static void print_help() {
    println("\n Usage: java -jar labcom.jar [options*] FILE");
    println("");
    println(" --help                  Shows this help text");
    println(" -v                      Be verbose");
    println(" --ver=VERSION           Generate code for labcomm VERSION (=2006 or 2013)");
    println("[ C options ]");
    println(" -C                      Generates C/H code in FILE.[ch]");
    println(" --cprefix=PREFIX        Prefixes C types with PREFIX");
    println(" --cinclude=FILE         Include FILE in generated .c");
    println(" --c=CFILE               Generates C code in CFILE");
    println(" --h=HFILE               Generates H code in HFILE");
    println("[ C# options]");
    println(" --cs                    Generates C# code in FILE.cs");
    println(" --cs=CSFILE             Generates C# code in CSFILE");
    println(" --csnamespace=NAMESPACE Place C# classes in NAMESPACE");
    println("[ Java options ]");
    println(" --java=JDIR             Generates Java files in JDIR");
    println(" --javapackage=PACKAGE   Place Java classes in PACKAGE");
    println("[ Python options ]");
    println(" -P                      Generates Python code in FILE.py");
    println(" --python=PFILE          Generates Python code in PFILE");
    println("[ RAPID options ]");
    println(" --rapid                 Generates RAPID code in FILE.sys");
    println("[ Misc options ]");
    println(" --pretty=PFILE          Pretty prints to PFILE");
    println(" --typeinfo=TIFILE       Generates typeinfo in TIFILE");
  }
    
  /** To be cleaned up.
   */
  private static void checkVersion(int v) {
     if(! (v == 2006 || v == 2013) ) {
	System.err.println(" Unknown version: " + v);
	System.err.println(" Supported versions: 2006, 2013 ");
	System.exit(2);
     }
  }

  private static void genH(Program p, String hName, 
			   Vector cIncludes, String coreName, String prefix, int ver) {
    try {
      FileOutputStream f;
      PrintStream out;
      
      f = new FileOutputStream(hName);
      out = new PrintStream(f);
      p.C_genH(out, cIncludes, coreName, prefix, ver);
      out.close();
    } catch (IOException e) {
      System.err.println("IOException: " + hName + " " + e);
    }
  }

  private static void genC(Program p, String cName, 
			   Vector cIncludes, String coreName, String prefix, int ver) {
    try {
      FileOutputStream f;
      PrintStream out;

      f = new FileOutputStream(cName);
      out = new PrintStream(f);
      p.C_genC(out, cIncludes, coreName, prefix, ver);
      out.close();
    } catch (IOException e) {
      System.err.println("IOException: " + cName + " " + e);
    }
  }

  private static void genCS(Program p, String csName, String csNamespace, int ver) {
//      throw new Error("C# generation currently disabled");
    try {
      p.CS_gen(csName, csNamespace, ver);
    } catch (IOException e) {
      System.err.println("IOException: " + csName + " " + 
			 csNamespace + " " + e);
    }
  }

  private static void genJava(Program p,  String dirName, String packageName, int ver) {
    try {
      p.J_gen(dirName, packageName, ver);
    } catch (IOException e) {
      System.err.println("IOException: " + dirName + " " + 
			 packageName + " " + e);
    }
  }

  private static void genPython(Program p, String filename, String prefix, int ver) {
    try {
      FileOutputStream f;
      PrintStream out;

      f = new FileOutputStream(filename);
      out = new PrintStream(f);
      p.Python_gen(out, prefix, ver);
      out.close();
    } catch (IOException e) {
      System.err.println("IOException: " + filename + " " + e);
    }
  }

  private static void genRAPID(Program p, String filename, String prefix, int ver) {
    try {
      p.RAPID_gen(filename, prefix, ver);
    } catch (IOException e) {
      System.err.println("IOException: " + filename + " " + e);
    }
  }

  /** Helper class to contain command line options 
      and their associated behaviour
   **/
  private static class Opts {
    final String[] args;
    String coreName = null;
    String prefix = null;
    boolean verbose = false;
    int ver = 2006; // Version 2006 fixed
    String cFile = null;
    String hFile = null;
    Vector cIncludes = new Vector();
    String cPrefix; // gets default value (prefix) in processFilename
    String csFile = null;
    String csNamespace = null;
    String javaDir = null;
    String javaPackage = "";
    String pythonFile = null;
    String prettyFile = null;
    String typeinfoFile = null;
    String rapidFile = null;
    String fileName = null;

   Opts(String[] args) {
     this.args = args;
   }

    private static String getCoreName(String s) {
      int i = s.lastIndexOf('.');
      return s.substring(0, i > 0 ? i : s.length());
    }
  
    private static String getFileName(String s) {
      return s.substring(s.lastIndexOf('/') + 1, s.length());
    }
  
    private static String getBaseName(String s) {
      s = getFileName(s);
      int i = s.lastIndexOf('.');
      return s.substring(0, i > 0 ? i : s.length());
    }
  
    private static String getPrefix(String s) {
      return s.substring(s.lastIndexOf('/') + 1, s.length());
    }
  
    boolean processFilename(){
      // Scan for first non-option
      for (int i = 0 ; i < args.length ; i++) {
        if (! args[i].startsWith("-")) {
  	fileName = args[i];
  	break;
        }
      }
      if (fileName != null) {
        coreName = getBaseName(fileName);
        prefix = getPrefix(coreName);
       cPrefix = prefix;
      }
      return fileName != null;
    }
    
    void processArgs(){
      for (int i = 0 ; i < args.length ; i++) {
        if (fileName == null ||
  	  args[i].equals("-help") || 
  	  args[i].equals("-h") || 
  	  args[i].equals("--help")) {
  	print_help();
  	System.exit(0);
        } else if (args[i].equals("-v")) {
  	verbose=true;
        } else if (args[i].startsWith("--ver=")) {
          /* ver = Integer.parseInt(args[i].substring(6));
             checkVersion(ver); */
        } else if (args[i].equals("-C")) {
  	cFile = coreName + ".c";
  	hFile = coreName + ".h";
        } else if (args[i].startsWith("--cinclude=")) {
  	cIncludes.add(args[i].substring(11));
        } else if (args[i].startsWith("--cprefix=")) {
  	cPrefix = args[i].substring(10);
        } else if (args[i].startsWith("--c=")) {
  	cFile = args[i].substring(4);
        } else if (args[i].startsWith("--h=")) {
  	hFile = args[i].substring(4);
        } else if (args[i].equals("--cs")) {
  	csFile = coreName + ".cs";
        } else if (args[i].startsWith("--cs=")) {
  	csFile = args[i].substring(5);
        } else if (args[i].startsWith("--csnamespace=")) {
  	csNamespace = args[i].substring(14);
        } else if (args[i].startsWith("--java=")) {
  	javaDir = args[i].substring(7);
        } else if (args[i].startsWith("--javapackage=")) {
  	javaPackage = args[i].substring(14);
        } else if (args[i].equals("-P")) {
  	pythonFile = coreName + ".py";
        } else if (args[i].startsWith("--python=")) {
  	pythonFile = args[i].substring(9);
        } else if (args[i].startsWith("--pretty=")) {
  	prettyFile = args[i].substring(9);
        } else if (args[i].startsWith("--typeinfo=")) {
  	typeinfoFile = args[i].substring(11);
        } else if (args[i].equals("--rapid")) {
  	rapidFile = coreName + ".sys";
        } else if (i == args.length - 1) {
  	fileName = args[i];
        } else {
  	System.err.println(" Unknown argument " + args[i]);
  	print_help();
  	System.exit(2);
        }
      }
     if(prefix==null){
  	System.err.println("   WARNING! prefix==null");
        prefix="";
     }
   }

   Program parseFile(){
     Program ast = null;
     try {
       // Check for errors
       LabCommScanner scanner = new LabCommScanner(
                                  new FileReader(fileName));
       LabCommParser parser = new LabCommParser();
       Program p = (Program)parser.parse(scanner);
       Collection errors = new LinkedList();
       p.errorCheck(errors);
         
       if (errors.isEmpty()) {
         ast = p;
       } else {
         for (Iterator iter = errors.iterator(); iter.hasNext(); ) {
           String s = (String)iter.next();
           System.out.println(s);
         }
       }
     } catch (FileNotFoundException e) {
       System.err.println("Could not find file: " + fileName);
     } catch (IOException e) {
       System.err.println("IOException: " + fileName + " " + e);
     } catch (beaver.Parser.Exception e) {
       System.err.println(e.getMessage());
     }
     return ast;
   }

   boolean generateC(Program ast) {
     boolean wroteFile = false; 
     Vector hIncludes = new Vector(cIncludes);
     if (hFile != null) {
       cIncludes.add(hFile);
     }
     if (cFile != null) {
       printStatus("C: " , cFile);
       genC(ast, cFile, cIncludes, coreName, cPrefix, ver);
       wroteFile = true;
     }
     if (hFile != null) {
       printStatus("H: " , hFile);
       genH(ast, hFile, hIncludes, coreName, cPrefix, ver);
       wroteFile = true;
     }
     return wroteFile;
   }
  
   boolean generateCS(Program ast) {
     boolean wroteFile = false; 
     if (csFile != null) {
       printStatus("C#: " , csFile); 
       genCS(ast, csFile, csNamespace, ver);
       wroteFile = true;
     }
     return wroteFile;
   }
  
   boolean generateJava(Program ast) {
     boolean wroteFile = false; 
     if (javaDir != null) {
       printStatus("Java: " , javaDir);
       genJava(ast, javaDir, javaPackage, ver);
       wroteFile = true;
     }
     return wroteFile;
   }
  
   boolean generatePython(Program ast) {
     boolean wroteFile = false; 
     if (pythonFile != null) {
       printStatus("Python: " , pythonFile); 
       genPython(ast, pythonFile, prefix, ver);
       wroteFile = true;
     }
     return wroteFile;
   }
  
   boolean generateRAPID(Program ast) {
     boolean wroteFile = false; 
     if (rapidFile != null) {
       printStatus("RAPID: " , rapidFile);
       genRAPID(ast, rapidFile, coreName, ver);
       wroteFile = true;
     }
     return wroteFile;
   }
   boolean generatePrettyPrint(Program ast) {
     boolean wroteFile = false; 
     if (prettyFile != null) {
       printStatus("Pretty: " , prettyFile); 
       try {
         FileOutputStream f = new FileOutputStream(prettyFile);
         PrintStream out = new PrintStream(f);
         ast.pp(out);
         out.close();
         wroteFile = true;
       } catch (IOException e) {
         System.err.println("IOException: " + prettyFile + " " + e);
       } 
     }
     return wroteFile;
   }
  
   boolean generateTypeinfo(Program ast) {
     boolean wroteFile = false; 
     if (typeinfoFile != null) {
       printStatus("TypeInfo: " , typeinfoFile); 
       try {
         FileOutputStream f = new FileOutputStream(typeinfoFile);
         PrintStream out = new PrintStream(f);
         ast.C_info(out, cPrefix, ver);
         ast.Java_info(out, ver);
         ast.CS_info(out, csNamespace, ver);
         wroteFile = true;
       } catch (IOException e) {
         System.err.println("IOException: " + typeinfoFile + " " + e);
       }
     }
     return wroteFile;
    }

    private void printStatus(String kind, String filename){
       if (verbose) { 
         System.err.println("Generating "+kind+": " + filename); 
       }
    }
  }


  public static void main(String[] args) {
    Opts opts = new Opts(args);
    if(!opts.processFilename()) {
      print_help();
      System.exit(1);
    } else {
      opts.processArgs();
      Program ast =  opts.parseFile();

      if (ast != null) {
	
	boolean fileWritten = false;

        fileWritten |= opts.generateC(ast);
        fileWritten |= opts.generateCS(ast);
        fileWritten |= opts.generateJava(ast);
        fileWritten |= opts.generatePython(ast);
        fileWritten |= opts.generateRAPID(ast);
        fileWritten |= opts.generatePrettyPrint(ast);
        fileWritten |= opts.generateTypeinfo(ast);

        // if no output to files, prettyprint on stdout
	if (!fileWritten) {
	  ast.pp(System.out);
	}
      } else {
          // Catch-all for compilation errors
          System.err.println("Error in specification");
          System.exit(3);
      }
    }
  } 
}
+0 −133
Original line number Original line Diff line number Diff line
%header {:
package se.lth.control.labcomm2006.compiler;
import se.lth.control.labcomm2006.compiler.*;
:};
%embed {:
  public static class SourceError extends Error {
    public SourceError(String msg) {
      super(msg);
    }
  }
  class Events extends Parser.Events {
    public void syntaxError(Symbol token) {
      StringBuffer s = new StringBuffer();
      s.append(token.getLine(token.getStart()) + ", " + token.getColumn(token.getStart()) + "\n");
      s.append("  *** Syntactic error: unexpected token " + Terminals.NAMES[token.getId()]);
      throw new SourceError(s.toString());
        //super.syntaxError(token);
        //throw new RuntimeException(token.getLine(token.getStart()) + ", " +
	// token.getColumn(token.getStart()) + ": Syntax Error");
    }
    public void scannerError(Scanner.Exception e) {
      StringBuffer s = new StringBuffer();
      s.append(e.line + ", " + e.column + "\n");
      s.append("  *** Lexical error: " + e.getMessage());
      throw new SourceError(s.toString());
        //super.scannerError(e);
        //throw new RuntimeException("Unexpected token");
    }

  }

        {
            report = new Events(); // Use error handler in parser
        }
:};

Program goal =
     /* Empty program */               {: return new Program(); :}
  |  decl_list.l                       {: return new Program(l); :}
  ;

List decl_list =
    decl.d                          {: return new List().add(d); :}
  | decl_list.l decl.d              {: return l.add(d); :}
  ;

Decl decl =
    type_decl.t                     {: return t; :}
  | sample_decl.s	            {: return s; :}
  ;

List var_decl_list =
    var_decl.v                      {: return new List().add(v); :}
  | var_decl_list.l var_decl.v      {: return l.add(v); :}
  ;

Field var_decl =
    type.t IDENTIFIER SEMICOLON     {: return new Field(t, IDENTIFIER); :}
  | type.t IDENTIFIER dim_list.d SEMICOLON
    {: return new Field(new ParseArrayType(t, d), IDENTIFIER); :}
  ;

TypeDecl type_decl =
    TYPEDEF type.t IDENTIFIER SEMICOLON {: return new TypeDecl(t, IDENTIFIER); :}
  | TYPEDEF type.t IDENTIFIER dim_list.d SEMICOLON
    {: return new TypeDecl(new ParseArrayType(t, d), IDENTIFIER); :}
  ;

SampleDecl sample_decl =
    SAMPLE type.t IDENTIFIER SEMICOLON
      {: return new SampleDecl(t, IDENTIFIER); :}
  | SAMPLE type.t IDENTIFIER dim_list.d SEMICOLON
      {: return new SampleDecl(new ParseArrayType(t, d), IDENTIFIER); :}
  ;

Type type =
    prim_type.p                     {: return p; :}
  | user_type.u                     {: return u; :}
  | struct_type.s                   {: return s; :}
  | void_type.v                     {: return v; :}
  ;

PrimType prim_type =
    BOOLEAN
      {: return new PrimType(BOOLEAN, ASTNode.LABCOMM_BOOLEAN); :}
  | BYTE
      {: return new PrimType(BYTE, ASTNode.LABCOMM_BYTE); :}
  | SHORT
      {: return new PrimType(SHORT, ASTNode.LABCOMM_SHORT); :}
  | INT
      {: return new PrimType(INT, ASTNode.LABCOMM_INT); :}
  | LONG
      {: return new PrimType(LONG, ASTNode.LABCOMM_LONG); :}
  | FLOAT
      {: return new PrimType(FLOAT, ASTNode.LABCOMM_FLOAT); :}
  | DOUBLE
      {: return new PrimType(DOUBLE, ASTNode.LABCOMM_DOUBLE); :}
  | STRING
      {: return new PrimType(STRING, ASTNode.LABCOMM_STRING); :}
  | SAMPLE
      {: return new PrimType(SAMPLE, ASTNode.LABCOMM_SAMPLE); :}
  ;

UserType user_type =
    IDENTIFIER                      {: return new UserType(IDENTIFIER); :}
  ;

StructType struct_type =
    STRUCT LBRACE var_decl_list.l RBRACE {: return new StructType(l); :}
  ;

VoidType void_type = 
    VOID {: return new VoidType(); :} 
;

List dim_list =
    dim.d                           {: return new List().add(d); :}
  | dim_list.l  dim.d               {: return l.add(d); :}
  ;

Dim dim =
    LBRACK exp_list.e RBRACK        {: return new Dim(e); :}
  ;

List exp_list =
    exp.e                           {: return new List().add(e); :}
  | exp_list.l COMMA exp.e          {: return l.add(e); :}
  ;

Exp exp =
    INTEGER_LITERAL                 {: return new IntegerLiteral(INTEGER_LITERAL); :}
  | UNDERSCORE                      {: return new VariableSize(); :}
  ;

compiler/2006/LabCommScanner.flex

deleted100644 → 0
+0 −87
Original line number Original line Diff line number Diff line
package se.lth.control.labcomm2006.compiler;

import beaver.Symbol;
import beaver.Scanner;
import se.lth.control.labcomm2006.compiler.LabCommParser.Terminals;

%%

%public 
%final 
%class LabCommScanner
%extends Scanner

%type Symbol 
%function nextToken 
%yylexthrow Scanner.Exception

%unicode
%line %column

%{
  StringBuffer strbuf = new StringBuffer(128);

  private Symbol sym(short id) {
    return new Symbol(id, yyline + 1, yycolumn + 1, len(), str());
  }

  private Symbol sym(short id, String value) {
    return new Symbol(id, yyline + 1, yycolumn + 1, len(), value);
  }

  private String str() { return yytext(); }
  private int len() { return yylength(); }
%}

LineTerminator = \n|\r|\r\n
InputCharacter = [^\r\n]

WhiteSpace = [ ] | \t | \f | {LineTerminator}

Comment = {TraditionalComment}
        | {EndOfLineComment}

TraditionalComment = "/*" [^*] ~"*/" | "/*" "*"+ "/" | "/*" "*"+ [^/*] ~"*/"
EndOfLineComment = "//" {InputCharacter}* {LineTerminator}?

Identifier = [:jletter:][:jletterdigit:]*

DecimalNumeral = 0 | {NonZeroDigit} {Digits}? 
Digits = {Digit}+
Digit = 0 | {NonZeroDigit}
NonZeroDigit = [1-9]

%%

<YYINITIAL> {
  {WhiteSpace}                   { }
  {Comment}                      { }

  "sample"                       { return sym(Terminals.SAMPLE); }
  "typedef"                      { return sym(Terminals.TYPEDEF); }
  "struct"                       { return sym(Terminals.STRUCT); }
  "void"                         { return sym(Terminals.VOID); }
  "boolean"                      { return sym(Terminals.BOOLEAN); }
  "byte"                         { return sym(Terminals.BYTE); }
  "short"                        { return sym(Terminals.SHORT); }
  "int"                          { return sym(Terminals.INT); }
  "long"                         { return sym(Terminals.LONG); }
  "float"                        { return sym(Terminals.FLOAT); }
  "double"                       { return sym(Terminals.DOUBLE); }
  "string"                       { return sym(Terminals.STRING); }

  {DecimalNumeral}               { return sym(Terminals.INTEGER_LITERAL); }
  "_"                            { return sym(Terminals.UNDERSCORE); }
  "{"                            { return sym(Terminals.LBRACE); }
  "}"                            { return sym(Terminals.RBRACE); }
  "["                            { return sym(Terminals.LBRACK); }
  "]"                            { return sym(Terminals.RBRACK); }
  ";"                            { return sym(Terminals.SEMICOLON); }
  ","                            { return sym(Terminals.COMMA); }
  
  {Identifier}                   { return sym(Terminals.IDENTIFIER); }
}

// fall through errors
.|\n                             { throw new RuntimeException("Illegal character \""+str()+ "\" at line "+yyline+", column "+yycolumn); }
<<EOF>>                          { return sym(Terminals.EOF); }

compiler/2006/LabCommTokens.jrag

deleted100644 → 0
+0 −21
Original line number Original line Diff line number Diff line
aspect LabCommTokens {

  public static final int ASTNode.LABCOMM_VERSION =    0x01;  
  public static final int ASTNode.LABCOMM_SAMPLE_DEF = 0x02;  // The flat signature
  public static final int ASTNode.LABCOMM_SAMPLE_REF = 0x03;
  public static final int ASTNode.LABCOMM_TYPE_DEF  =  0x04;  // and type declarations, hierarchically

  public static final int ASTNode.LABCOMM_ARRAY =      0x10;
  public static final int ASTNode.LABCOMM_STRUCT =     0x11;

  public static final int ASTNode.LABCOMM_BOOLEAN =    0x20; 
  public static final int ASTNode.LABCOMM_BYTE =       0x21;
  public static final int ASTNode.LABCOMM_SHORT =      0x22;
  public static final int ASTNode.LABCOMM_INT =        0x23;
  public static final int ASTNode.LABCOMM_LONG =       0x24;
  public static final int ASTNode.LABCOMM_FLOAT =      0x25;
  public static final int ASTNode.LABCOMM_DOUBLE =     0x26;
  public static final int ASTNode.LABCOMM_STRING =     0x27;
  public static final int ASTNode.LABCOMM_SAMPLE =     0x28;

}

compiler/2006/NameAnalysis.jrag

deleted100644 → 0
+0 −67
Original line number Original line Diff line number Diff line

aspect NameAnalysis {

  inh String Decl.lookupName(String name);
  eq Program.getDecl(int index).lookupName(String name) {
    for (int i = 0; i < index; i++) {
      String s = getDecl(i).getName();
      if (s.equals(name)) {
      	return s;
      }
    }
    return null;
  }
  inh String Field.lookupName(String name);
  eq StructType.getField(int index).lookupName(String name) {
    for (int i = 0; i < index; i++) {
      String s = getField(i).getName();
      if (s.equals(name)) {
      	return s;
      }
    }
    return null;
  }

  inh TypeDecl Decl.lookupType(String name);
  inh TypeDecl UserType.lookupType(String name);
  eq Program.getDecl(int index).lookupType(String name) {
    for(int i = 0; i < index; i++) {
      Decl d = getDecl(i);  
      if(d instanceof TypeDecl && d.getName().equals(name)) {
	return (TypeDecl)d;
      }
    }
    return null;
  }

  syn TypeDecl Type.decl(); 
  eq Type.decl() = null;
  eq UserType.decl() = lookupType(getName());
  eq PrimType.decl() = null; //HERE BE DRAGONS XXX
  
  
  public void ASTNode.nameCheck() {
    for (int i = 0; i < getNumChild(); i++) {
      getChild(i).nameCheck();
    }
  }
  
  public void Decl.nameCheck() {
    if (lookupType(getName()) != null || lookupName(getName()) != null) {
      error(getName() + " multiply declared");
    }
  }
  
  public void Field.nameCheck() {
    if(lookupName(getName()) != null) {
      error(getName() + " multiply declared");
    }
  }
  
  public void UserType.nameCheck() {
    if (decl() == null) {
      error("Use of undeclared type");
    } 
  }

}

compiler/2006/PrettyPrint.jrag

deleted100644 → 0
+0 −117
Original line number Original line Diff line number Diff line
import java.io.PrintStream;

aspect PPIndentation {

  inh String Exp.pp_indent();
  inh String Field.pp_indent();
  inh String StructType.pp_indent();
  eq StructType.getField(int index).pp_indent() = pp_indent() + "  ";
  eq Program.getDecl(int index).pp_indent() = "";
  
}

aspect PrettyPrint {
  
  public void ASTNode.pp(PrintStream out) {
    throw new Error(this.getClass().getName() + 
		    ".pp(PrintStream out)" + 
		    " not declared");
  }

  public void Program.pp(PrintStream out) {
    for(int i = 0; i < getNumDecl(); i++) {
    	getDecl(i).pp(out);
    }
  }

   // Pretty print declarations
  public void TypeDecl.pp(PrintStream out) {
    out.print("typedef ");
    getType().ppIdentifier(out, getName());
    out.println(";");
  }

  public void SampleDecl.pp(PrintStream out) {
    out.print("sample ");
    getType().ppIdentifier(out, getName());
    out.println(";");
  }

  public void Field.pp(PrintStream out) {
    out.print(pp_indent());
    getType().ppIdentifier(out, getName());
    out.println(";");
  }

  // Pretty print variable of a given type 
  public void Type.ppIdentifier(PrintStream out, String id) { 
    ppPrefix(out);
    out.print(" ");
    out.print(id);
  }

  public void ArrayType.ppIdentifier(PrintStream out, String id) {
    ppPrefix(out);
    out.print(" ");
    out.print(id);
    ppSuffix(out);
  }

  // PrettyPrint prefix type info
  public void Type.ppPrefix(PrintStream out) {
    throw new Error(this.getClass().getName() + 
		    ".ppPrefix(PrintStream out)" + 
		    " not declared");
  }

  public void VoidType.ppPrefix(PrintStream out) { 
    out.print("void");
  }

  public void SampleRefType.ppPrefix(PrintStream out) { 
    out.print("sample");
  }

  public void PrimType.ppPrefix(PrintStream out) { 
    out.print(getName());
  }

  public void UserType.ppPrefix(PrintStream out) { 
    out.print(getName());
  }

  public void ArrayType.ppPrefix(PrintStream out) {
    getType().ppPrefix(out);
  }

  public void StructType.ppPrefix(PrintStream out) {
    out.println("struct {");
    for (int i = 0 ; i < getNumField() ; i++) {
      getField(i).pp(out);
    }
    out.print(pp_indent());
    out.print("}");
  }

  // PrettyPrint suffix type info (array dimensions)
  public void Type.ppSuffix(PrintStream out) { }

  public void ArrayType.ppSuffix(PrintStream out) { 
    out.print("[");
    for (int i = 0 ; i < getNumExp() ; i++) {
      if (i > 0) { out.print(", "); }
      getExp(i).pp(out);
    }
    out.print("]");
    getType().ppSuffix(out);
  }

  public void IntegerLiteral.pp(PrintStream out) {
    out.print(getValue());
  }

  public void VariableSize.pp(PrintStream out) {
    out.print("_");
  }

}

compiler/2006/TypeCheck.jrag

deleted100644 → 0
+0 −36
Original line number Original line Diff line number Diff line
aspect TypeCheck {
  public void ASTNode.typeCheck() {
      // calls to the different type checks to be performed
      nullTypeCheck();
  }

// void is not allowed as a field in a struct or an array element
  
  syn boolean Type.isNull();
  eq Type.isNull() = false;
  eq VoidType.isNull() = true;
  eq UserType.isNull() = decl().isNull();

  syn boolean TypeDecl.isNull();
  eq TypeDecl.isNull() = getType().isNull();
  
  public void ASTNode.nullTypeCheck() {}
 
  public void Field.nullTypeCheck() {
    if(getType().isNull()) {
      error("field " + getName() + " of struct "+ declName()+ " may not be of type void");
    }
  }

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

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

compiler/2006/TypeReferences.jrag

deleted100644 → 0
+0 −46
Original line number Original line Diff line number Diff line
aspect User_Types {
  syn String Type.getTypeName();
  eq Type.getTypeName() = getClass().getName();
  eq PrimType.getTypeName() = getName();
  eq UserType.getTypeName() = getName();

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

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

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

  UserType contributes decl()   
  when parentDecl() != null 
  to Decl.type_dependencies() 
  for parentDecl();
  /*
  Field contributes getType().decl()   
  when parentDecl() != null && getType().isLeafType()
  to Decl.type_dependencies() 
  for parentDecl();
  */


  // The references from other type declarations to a Decl.
  coll Set<Decl> Decl.type_references() [new HashSet<Decl>()] with add;

  Decl contributes this
  to Decl.type_references()
  for each type_dependencies();

  syn boolean Decl.hasDependencies();
  eq Decl.hasDependencies() = !type_dependencies().isEmpty();

  syn boolean Decl.isReferenced();
  eq Decl.isReferenced() = !type_references().isEmpty();
}

compiler/2006/Version.jrag

deleted100644 → 0
+0 −15
Original line number Original line Diff line number Diff line
aspect Version {

    /* An auxilliary class for handling naming and prefixes connected
     * to the LabComm version
     */
    class LabCommVersion {
        public static String versionString(int version) {
            return (version == 2006) ? "2006" : "";
        }       

        public static boolean versionHasPragma(int version) {
            return version != 2006;
        }
    }
}
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
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);
        }
        }
    }
    }

}
}

compiler/LabComm.java

deleted100644 → 0
+0 −36

File deleted.

Preview size limit exceeded, changes collapsed.

File changed.

Preview size limit exceeded, changes collapsed.

File changed.

Preview size limit exceeded, changes collapsed.

compiler/labcomm

deleted100755 → 0
+0 −2
Original line number Original line Diff line number Diff line
#!/bin/sh
java -jar /lib/labcomm_compiler.jar "$@"

compiler/labcomm2006

deleted100755 → 0
+0 −2

File deleted.

Preview size limit exceeded, changes collapsed.

+1 −1

File changed.

Contains only whitespace changes.

File changed.

Preview size limit exceeded, changes collapsed.

File changed.

Preview size limit exceeded, changes collapsed.

File changed.

Preview size limit exceeded, changes collapsed.