From 991de20eb45f8fc4a3c24dcf9c645f0ccbc4ac36 Mon Sep 17 00:00:00 2001 From: Sven Gestegard Robertz <sven.robertz@cs.lth.se> Date: Tue, 12 May 2015 09:44:36 +0200 Subject: [PATCH] refactored grammar: added TypeInstance :: DataType Name and renamed Program to Specification (based on cherry-picked (parts of) 9d2ca1) --- compiler/2014/CS_CodeGen.jrag | 10 +++--- compiler/2014/C_CodeGen.jrag | 16 ++++----- compiler/2014/DeclNames.jrag | 4 +-- compiler/2014/Java_CodeGen.jrag | 12 +++---- compiler/2014/LabComm.ast | 8 +++-- compiler/2014/LabComm.java | 34 +++++++++---------- compiler/2014/LabCommParser.parser | 27 +++++++-------- compiler/2014/NameAnalysis.jrag | 4 +-- compiler/2014/PrettyPrint.jrag | 4 +-- compiler/2014/Python_CodeGen.jrag | 4 +-- compiler/2014/RAPID_CodeGen.jrag | 4 +-- compiler/2014/Refactoring.jrag | 9 +++++ compiler/2014/Signature.jrag | 13 ++++--- doc/.gitignore | 2 +- doc/tech_report.tex | 2 +- examples/duck_typing/animal.lc | 2 +- examples/dynamic/test/DynamicPart.java | 6 ++-- .../dynamic/test/TestLabCommCompiler.java | 8 ++--- examples/dynamic/test/TestLabcommGen.java | 8 ++--- examples/robot/App.config | 2 +- examples/robot/Follow.mod | 2 +- examples/robot/LCRobot.lc | 2 +- examples/robot/Program.cs | 4 +-- examples/robot/RobotCtrl.csproj | 4 +-- examples/twoway/decimating_messages.lc | 2 +- examples/twoway/types.lc | 2 +- examples/user_types/TDDecoder.java | 4 +-- lib/RAPID/LabComm.sys | 2 +- .../control/labcomm2014/EncoderRegistry.cs | 2 +- .../lth/control/labcomm2014/SampleHandler.cs | 2 +- .../lth/control/labcomm2014/ASTbuilder.java | 22 ++++++------ test/basic.lc | 2 +- test/simple.lc | 2 +- 33 files changed, 120 insertions(+), 111 deletions(-) create mode 100644 compiler/2014/Refactoring.jrag diff --git a/compiler/2014/CS_CodeGen.jrag b/compiler/2014/CS_CodeGen.jrag index 1dfb818..c05e6b2 100644 --- a/compiler/2014/CS_CodeGen.jrag +++ b/compiler/2014/CS_CodeGen.jrag @@ -176,11 +176,11 @@ aspect CS_StructName { inh int Decl.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; 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() { if (CS_Depth() == 0) { return "struct_" + getField(i).getName(); @@ -201,7 +201,7 @@ aspect CS_Void { aspect CS_CodeGen { - public void Program.CS_gen(String file, + public void Specification.CS_gen(String file, String namespace, int version) throws IOException { // Registration class CS_env env = new CS_env(new File(file), version); @@ -230,7 +230,7 @@ aspect CS_CodeGen { aspect CS_Register { - public void Program.CS_emitTypeRegister(CS_env env) { + public void Specification.CS_emitTypeRegister(CS_env env) { } public void Decl.CS_emitTypeRegister(CS_env env) { @@ -935,7 +935,7 @@ aspect CS_Signature { aspect CS_Info { - public void Program.CS_info(PrintStream out, String namespace, int version) { + public void Specification.CS_info(PrintStream out, String namespace, int version) { CS_env env = new CS_env(out, version); if (namespace == null) { namespace = ""; diff --git a/compiler/2014/C_CodeGen.jrag b/compiler/2014/C_CodeGen.jrag index 526b2ad..afa7f04 100644 --- a/compiler/2014/C_CodeGen.jrag +++ b/compiler/2014/C_CodeGen.jrag @@ -177,7 +177,7 @@ aspect C_IsDynamic { aspect C_CodeGen { - public void Program.C_genH(PrintStream out, Vector includes, + public void Specification.C_genH(PrintStream out, Vector includes, String lcName, String prefix, int version) { C_env env = new C_env("", lcName, prefix, out, version); @@ -203,7 +203,7 @@ aspect C_CodeGen { env.println("#endif"); } - public void Program.C_genC(PrintStream out, Vector includes, + public void Specification.C_genC(PrintStream out, Vector includes, String lcName, String prefix, int version) { C_env env = new C_env("", lcName, prefix, out, version); @@ -219,7 +219,7 @@ aspect C_CodeGen { C_emitC(env); } - public void Program.C_emitH(C_env env) { + public void Specification.C_emitH(C_env env) { for (int i = 0; i < getNumDecl(); i++) { getDecl(i).C_emitType(env); getDecl(i).C_emitDecoderDeclaration(env); @@ -233,7 +233,7 @@ aspect C_CodeGen { C_emitForAll(env); } - public void Program.C_emitC(C_env env) { + public void Specification.C_emitC(C_env env) { for (int i = 0; i < getNumDecl(); i++) { getDecl(i).C_emitSignature(env); getDecl(i).C_emitDecoder(env); @@ -1462,7 +1462,7 @@ aspect C_Constructor { " not declared"); } - public void Program.C_emitConstructor(C_env env) { + public void Specification.C_emitConstructor(C_env env) { env.println("LABCOMM_CONSTRUCTOR void init_" + env.prefix + "_signatures(void)"); env.println("{"); @@ -1499,7 +1499,7 @@ aspect C_Constructor { " not declared"); } - public void Program.C_emitConstructorDeclaration(C_env env) { + public void Specification.C_emitConstructorDeclaration(C_env env) { env.println("void init_" + env.prefix + "_signatures(void);"); } @@ -1688,7 +1688,7 @@ aspect C_Sizeof { aspect C_forAll { - public void Program.C_emitForAll(C_env env) { + public void Specification.C_emitForAll(C_env env) { env.print("#define LABCOMM_FORALL_SAMPLES_" + env.lcName + "(func, sep)"); env.indent(); @@ -1718,7 +1718,7 @@ aspect C_forAll { aspect C_Info { - public void Program.C_info(PrintStream out, String prefix, int version) { + public void Specification.C_info(PrintStream out, String prefix, int version) { C_env env = new C_env("", "", prefix, out, version); for (int i = 0; i < getNumDecl(); i++) { getDecl(i).C_info(env); diff --git a/compiler/2014/DeclNames.jrag b/compiler/2014/DeclNames.jrag index c448c6d..c82ad18 100644 --- a/compiler/2014/DeclNames.jrag +++ b/compiler/2014/DeclNames.jrag @@ -1,6 +1,6 @@ aspect DeclNames { inh String DataType.declName(); - eq Decl.DataType().declName() = getName(); + eq Decl.getTypeInstance().declName() = getName(); inh String Field.declName(); eq StructType.getField(int i).declName() = declName(); @@ -9,6 +9,6 @@ aspect DeclNames { inh Decl DataType.parentDecl(); inh Decl Field.parentDecl(); - eq Decl.getDataType().parentDecl() = this; + eq Decl.getTypeInstance().parentDecl() = this; eq StructType.getField(int i).parentDecl() = parentDecl(); } diff --git a/compiler/2014/Java_CodeGen.jrag b/compiler/2014/Java_CodeGen.jrag index 90a641d..456ada2 100644 --- a/compiler/2014/Java_CodeGen.jrag +++ b/compiler/2014/Java_CodeGen.jrag @@ -179,11 +179,11 @@ aspect Java_StructName { inh int Decl.Java_Depth(); inh int DataType.Java_Depth(); - eq Program.getDecl(int i).Java_Depth() = 0; + eq Specification.getDecl(int i).Java_Depth() = 0; eq StructType.getField(int i).Java_Depth() = Java_Depth() + 1; inh String DataType.Java_structName(); - eq Program.getDecl(int i).Java_structName() = getDecl(i).getName(); + eq Specification.getDecl(int i).Java_structName() = getDecl(i).getName(); eq StructType.getField(int i).Java_structName() { if (Java_Depth() == 0) { return "struct_" + getField(i).getName(); @@ -204,7 +204,7 @@ aspect Java_Void { aspect Java_CodeGen { - public void Program.J_gen(PrintStream ps, String pack, int version) throws IOException { + public void Specification.J_gen(PrintStream ps, String pack, int version) throws IOException { Java_env env; env = new Java_env(version, ps); for (int i = 0; i < getNumDecl(); i++) { @@ -219,7 +219,7 @@ aspect Java_CodeGen { env.close(); } - public void Program.J_gen(String dir, String pack, int version) throws IOException { + public void Specification.J_gen(String dir, String pack, int version) throws IOException { Java_env env; for (int i = 0; i < getNumDecl(); i++) { Decl d = getDecl(i); @@ -236,7 +236,7 @@ aspect Java_CodeGen { /** Experimental method for generating code to a map <classname, source> */ - public void Program.J_gen(Map<String,String> src, String pack, int version) throws IOException { + public void Specification.J_gen(Map<String,String> src, String pack, int version) throws IOException { Java_env env; for (int i = 0; i < getNumDecl(); i++) { Decl d = getDecl(i); @@ -1032,7 +1032,7 @@ aspect Java_Signature { aspect Java_Info { - public void Program.Java_info(PrintStream out, int version) { + public void Specification.Java_info(PrintStream out, int version) { Java_env env = new Java_env(version, out); for (int i = 0; i < getNumDecl(); i++) { getDecl(i).Java_info(env); diff --git a/compiler/2014/LabComm.ast b/compiler/2014/LabComm.ast index e861eaf..3e1015e 100644 --- a/compiler/2014/LabComm.ast +++ b/compiler/2014/LabComm.ast @@ -1,6 +1,8 @@ -Program ::= Decl*; +Specification ::= Decl*; -abstract Decl ::= DataType <Name:String> /Signature/; +abstract Decl ::= TypeInstance /Signature/; + +TypeInstance ::= DataType <Name:String>; TypeDecl : Decl; SampleDecl : Decl; @@ -17,7 +19,7 @@ IntSignatureLine : DataSignatureLine ::= <Data:int>; StringSignatureLine : DataSignatureLine ::= <Data:String>; TypeRefSignatureLine : SignatureLine ::= Decl; -Field ::= DataType <Name:String>; +Field : TypeInstance; abstract DataType; VoidType : DataType; diff --git a/compiler/2014/LabComm.java b/compiler/2014/LabComm.java index 2844ed2..de6f619 100644 --- a/compiler/2014/LabComm.java +++ b/compiler/2014/LabComm.java @@ -48,7 +48,7 @@ public class LabComm { } } - private static void genH(Program p, String hName, + private static void genH(Specification p, String hName, Vector cIncludes, String coreName, String prefix, int ver) { try { FileOutputStream f; @@ -63,7 +63,7 @@ public class LabComm { } } - private static void genC(Program p, String cName, + private static void genC(Specification p, String cName, Vector cIncludes, String coreName, String prefix, int ver) { try { FileOutputStream f; @@ -78,7 +78,7 @@ public class LabComm { } } - private static void genCS(Program p, String csName, String csNamespace, int ver) { + private static void genCS(Specification p, String csName, String csNamespace, int ver) { // throw new Error("C# generation currently disabled"); try { p.CS_gen(csName, csNamespace, ver); @@ -88,7 +88,7 @@ public class LabComm { } } - private static void genJava(Program p, String dirName, String packageName, int ver) { + private static void genJava(Specification p, String dirName, String packageName, int ver) { try { p.J_gen(dirName, packageName, ver); } catch (IOException e) { @@ -97,7 +97,7 @@ public class LabComm { } } - private static void genPython(Program p, String filename, String prefix, int ver) { + private static void genPython(Specification p, String filename, String prefix, int ver) { try { FileOutputStream f; PrintStream out; @@ -111,7 +111,7 @@ public class LabComm { } } - private static void genRAPID(Program p, String filename, String prefix, int ver) { + private static void genRAPID(Specification p, String filename, String prefix, int ver) { try { p.RAPID_gen(filename, prefix, ver); } catch (IOException e) { @@ -239,14 +239,14 @@ public class LabComm { } } - Program parseFile(){ - Program ast = null; + Specification parseFile(){ + Specification ast = null; try { // Check for errors LabCommScanner scanner = new LabCommScanner( new FileReader(fileName)); LabCommParser parser = new LabCommParser(); - Program p = (Program)parser.parse(scanner); + Specification p = (Specification)parser.parse(scanner); Collection errors = new LinkedList(); p.errorCheck(errors); @@ -268,7 +268,7 @@ public class LabComm { return ast; } - boolean generateC(Program ast) { + boolean generateC(Specification ast) { boolean wroteFile = false; Vector hIncludes = new Vector(cIncludes); if (hFile != null) { @@ -287,7 +287,7 @@ public class LabComm { return wroteFile; } - boolean generateCS(Program ast) { + boolean generateCS(Specification ast) { boolean wroteFile = false; if (csFile != null) { printStatus("C#: " , csFile); @@ -297,7 +297,7 @@ public class LabComm { return wroteFile; } - boolean generateJava(Program ast) { + boolean generateJava(Specification ast) { boolean wroteFile = false; if (javaDir != null) { printStatus("Java: " , javaDir); @@ -307,7 +307,7 @@ public class LabComm { return wroteFile; } - boolean generatePython(Program ast) { + boolean generatePython(Specification ast) { boolean wroteFile = false; if (pythonFile != null) { printStatus("Python: " , pythonFile); @@ -317,7 +317,7 @@ public class LabComm { return wroteFile; } - boolean generateRAPID(Program ast) { + boolean generateRAPID(Specification ast) { boolean wroteFile = false; if (rapidFile != null) { printStatus("RAPID: " , rapidFile); @@ -326,7 +326,7 @@ public class LabComm { } return wroteFile; } - boolean generatePrettyPrint(Program ast) { + boolean generatePrettyPrint(Specification ast) { boolean wroteFile = false; if (prettyFile != null) { printStatus("Pretty: " , prettyFile); @@ -343,7 +343,7 @@ public class LabComm { return wroteFile; } - boolean generateTypeinfo(Program ast) { + boolean generateTypeinfo(Specification ast) { boolean wroteFile = false; if (typeinfoFile != null) { printStatus("TypeInfo: " , typeinfoFile); @@ -376,7 +376,7 @@ public class LabComm { System.exit(1); } else { opts.processArgs(); - Program ast = opts.parseFile(); + Specification ast = opts.parseFile(); if (ast != null) { diff --git a/compiler/2014/LabCommParser.parser b/compiler/2014/LabCommParser.parser index 7719936..b1252ac 100644 --- a/compiler/2014/LabCommParser.parser +++ b/compiler/2014/LabCommParser.parser @@ -34,9 +34,9 @@ } :}; -Program goal = - /* Empty program */ {: return new Program(); :} - | decl_list.l {: return new Program(l); :} +Specification goal = + /* Empty program */ {: return new Specification(); :} + | decl_list.l {: return new Specification(l); :} ; List decl_list = @@ -54,6 +54,12 @@ List var_decl_list = | var_decl_list.l var_decl.v {: return l.add(v); :} ; +TypeInstance type_instance = + type.t IDENTIFIER {: return new TypeInstance(t, IDENTIFIER); :} + | type.t IDENTIFIER dim_list.d + {: return new TypeInstance(new ParseArrayType(t, d), IDENTIFIER); :} + ; + Field var_decl = type.t IDENTIFIER SEMICOLON {: return new Field(t, IDENTIFIER); :} | type.t IDENTIFIER dim_list.d SEMICOLON @@ -61,17 +67,10 @@ Field var_decl = ; TypeDecl type_decl = - TYPEDEF type.t IDENTIFIER SEMICOLON {: return new TypeDecl(t, IDENTIFIER); :} - | TYPEDEF type.t IDENTIFIER dim_list.d SEMICOLON - {: return new TypeDecl(new ParseArrayType(t, d), IDENTIFIER); :} - ; + TYPEDEF type_instance.t SEMICOLON {: return new TypeDecl(t); :} ; SampleDecl sample_decl = - SAMPLE type.t IDENTIFIER SEMICOLON - {: return new SampleDecl(t, IDENTIFIER); :} - | SAMPLE type.t IDENTIFIER dim_list.d SEMICOLON - {: return new SampleDecl(new ParseArrayType(t, d), IDENTIFIER); :} - ; + SAMPLE type_instance.t SEMICOLON {: return new SampleDecl(t); :} ; DataType type = prim_type.p {: return p; :} @@ -109,8 +108,8 @@ StructType struct_type = STRUCT LBRACE var_decl_list.l RBRACE {: return new StructType(l); :} ; -VoidType void_type = - VOID {: return new VoidType(); :} +VoidType void_type = + VOID {: return new VoidType(); :} ; List dim_list = diff --git a/compiler/2014/NameAnalysis.jrag b/compiler/2014/NameAnalysis.jrag index f901210..dfa80a2 100644 --- a/compiler/2014/NameAnalysis.jrag +++ b/compiler/2014/NameAnalysis.jrag @@ -2,7 +2,7 @@ aspect NameAnalysis { inh String Decl.lookupName(String name); - eq Program.getDecl(int index).lookupName(String name) { + eq Specification.getDecl(int index).lookupName(String name) { for (int i = 0; i < index; i++) { String s = getDecl(i).getName(); if (s.equals(name)) { @@ -24,7 +24,7 @@ aspect NameAnalysis { inh TypeDecl Decl.lookupType(String name); inh TypeDecl UserType.lookupType(String name); - eq Program.getDecl(int index).lookupType(String name) { + eq Specification.getDecl(int index).lookupType(String name) { for(int i = 0; i < index; i++) { Decl d = getDecl(i); if(d instanceof TypeDecl && d.getName().equals(name)) { diff --git a/compiler/2014/PrettyPrint.jrag b/compiler/2014/PrettyPrint.jrag index 35904da..f778d00 100644 --- a/compiler/2014/PrettyPrint.jrag +++ b/compiler/2014/PrettyPrint.jrag @@ -6,7 +6,7 @@ aspect PPIndentation { inh String Field.pp_indent(); inh String StructType.pp_indent(); eq StructType.getField(int index).pp_indent() = pp_indent() + " "; - eq Program.getDecl(int index).pp_indent() = ""; + eq Specification.getDecl(int index).pp_indent() = ""; } @@ -18,7 +18,7 @@ aspect PrettyPrint { " not declared"); } - public void Program.pp(PrintStream out) { + public void Specification.pp(PrintStream out) { for(int i = 0; i < getNumDecl(); i++) { getDecl(i).pp(out); } diff --git a/compiler/2014/Python_CodeGen.jrag b/compiler/2014/Python_CodeGen.jrag index cc238d7..ac74601 100644 --- a/compiler/2014/Python_CodeGen.jrag +++ b/compiler/2014/Python_CodeGen.jrag @@ -72,7 +72,7 @@ aspect Python_CodeGenEnv { aspect Python_CodeGen { - public void Program.Python_gen(PrintStream out, String baseName, int version) { + public void Specification.Python_gen(PrintStream out, String baseName, int version) { Python_env env = new Python_env(out); env.println("#!/usr/bin/python"); env.println("# Auto generated " + baseName); @@ -100,7 +100,7 @@ aspect Python_CodeGen { aspect PythonTypes { - public void Program.Python_genTypes(Python_env env) { + public void Specification.Python_genTypes(Python_env env) { for (int i = 0 ; i < getNumDecl() ; i++) { getDecl(i).Python_genSignatureAndTypedef(env); } diff --git a/compiler/2014/RAPID_CodeGen.jrag b/compiler/2014/RAPID_CodeGen.jrag index dc3f343..78f9c97 100644 --- a/compiler/2014/RAPID_CodeGen.jrag +++ b/compiler/2014/RAPID_CodeGen.jrag @@ -77,7 +77,7 @@ aspect RAPID_CodeGen { throw new UnsupportedOperationException(); } - public void Program.RAPID_gen(String file, String prefix, int version) + public void Specification.RAPID_gen(String file, String prefix, int version) throws IOException { PrintStream ps = new PrintStream(new FileOutputStream(new File(file))); @@ -85,7 +85,7 @@ aspect RAPID_CodeGen { RAPID_gen(env); } - public void Program.RAPID_gen(RAPID_env env) + public void Specification.RAPID_gen(RAPID_env env) { for (int i = 0; i < getNumDecl(); i++) { getDecl(i).RAPID_gen(env); diff --git a/compiler/2014/Refactoring.jrag b/compiler/2014/Refactoring.jrag new file mode 100644 index 0000000..9f0d20c --- /dev/null +++ b/compiler/2014/Refactoring.jrag @@ -0,0 +1,9 @@ +/* Temporary aspect with forwarding methods */ +aspect Refactoring { + syn String Decl.getName() = getTypeInstance().getName(); + syn DataType Decl.getDataType() = getTypeInstance().getDataType(); + + public Field.Field(TypeInstance t) { + this(t.getDataType(), t.getName()); + } +} diff --git a/compiler/2014/Signature.jrag b/compiler/2014/Signature.jrag index f3f0119..fb911b6 100644 --- a/compiler/2014/Signature.jrag +++ b/compiler/2014/Signature.jrag @@ -1,6 +1,6 @@ import java.util.*; -aspect Signature { +aspect Signature { syn boolean Decl.isSampleDecl(); eq TypeDecl.isSampleDecl() = false; @@ -14,8 +14,7 @@ aspect Signature { inh Decl Signature.parentDecl(); inh Decl SignatureList.parentDecl(); - - syn nta Signature Decl.getSignature() { + syn nta Signature Decl.getSignature() { SignatureList sl = new SignatureList(); genSigLineForDecl(sl, true); SignatureList fsl = new SignatureList(); @@ -90,7 +89,7 @@ aspect Signature { //add(packed, comment); data = packed; break; - default: + default: throw new RuntimeException("Unsupported version = "+version+". This should never happen."); } return data; @@ -152,8 +151,8 @@ aspect Signature { public void ASTNode.genSigLineForDecl(SignatureList list, boolean decl) { - throw new Error(this.getClass().getName() + - ".genSigLineForDecl(SignatureList list)" + + throw new Error(this.getClass().getName() + + ".genSigLineForDecl(SignatureList list)" + " not declared"); } @@ -185,7 +184,7 @@ aspect Signature { * will always be a TypeRef */ public void UserType.genSigLineForDecl(SignatureList list, boolean decl) { - + TypeDecl thet = lookupType(getName()); list.addTypeRef(thet, null); } diff --git a/doc/.gitignore b/doc/.gitignore index df2a6e6..5021072 100644 --- a/doc/.gitignore +++ b/doc/.gitignore @@ -4,4 +4,4 @@ tech_report.blg tech_report.fdb_latexmk tech_report.fls tech_report.log -tech_report.pdf \ No newline at end of file +tech_report.pdf diff --git a/doc/tech_report.tex b/doc/tech_report.tex index 883fd4c..e55ecc2 100644 --- a/doc/tech_report.tex +++ b/doc/tech_report.tex @@ -778,7 +778,7 @@ Avro has multiple codecs (for compression of the data): \subsection{Abstract syntax} \begin{verbatim} -Program ::= Decl*; +Specification ::= Decl*; abstract Decl ::= DataType <Name:String>; TypeDecl : Decl; diff --git a/examples/duck_typing/animal.lc b/examples/duck_typing/animal.lc index 3272ae9..187c772 100644 --- a/examples/duck_typing/animal.lc +++ b/examples/duck_typing/animal.lc @@ -6,4 +6,4 @@ sample animal cow; sample animal dog; sample struct { string says; -} duck; \ No newline at end of file +} duck; diff --git a/examples/dynamic/test/DynamicPart.java b/examples/dynamic/test/DynamicPart.java index 8a420aa..d245cbc 100644 --- a/examples/dynamic/test/DynamicPart.java +++ b/examples/dynamic/test/DynamicPart.java @@ -158,7 +158,7 @@ public class DynamicPart { } public static InRAMCompiler generateCode(String lcDecl, HashMap<String, String> handlers) { - Program ast = null; + Specification ast = null; InputStream in = new ByteArrayInputStream(lcDecl.getBytes()); LabCommScanner scanner = new LabCommScanner(in); LabCommParser parser = new LabCommParser(); @@ -166,7 +166,7 @@ public class DynamicPart { InRAMCompiler irc = null; try { - Program p = (Program)parser.parse(scanner); + Specification p = (Specification)parser.parse(scanner); p.errorCheck(errors); if (errors.isEmpty()) { ast = p; @@ -197,7 +197,7 @@ public class DynamicPart { * @param handlers - a map <name, source> of handlers for the types in ast * @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>(); try { lcAST.J_gen(genCode, "labcomm.generated", 2014); diff --git a/examples/dynamic/test/TestLabCommCompiler.java b/examples/dynamic/test/TestLabCommCompiler.java index b078345..6141cff 100644 --- a/examples/dynamic/test/TestLabCommCompiler.java +++ b/examples/dynamic/test/TestLabCommCompiler.java @@ -22,7 +22,7 @@ import se.lth.control.labcomm2014.Encoder; import se.lth.control.labcomm2014.EncoderChannel; import AST.Parser; import AST.Scanner; -import AST.Program; +import AST.Specification; import beaver.Parser.Exception; @@ -121,7 +121,7 @@ public class TestCompiler { } public static InRAMCompiler generateCode(String lcDecl, HashMap<String, String> handlers) { - Program ast = null; + Specification ast = null; InputStream in = new ByteArrayInputStream(lcDecl.getBytes()); Scanner scanner = new Scanner(in); Parser parser = new Parser(); @@ -129,7 +129,7 @@ public class TestCompiler { InRAMCompiler irc = null; try { - Program p = (Program)parser.parse(scanner); + Specification p = (Specification)parser.parse(scanner); p.errorCheck(errors); if (errors.isEmpty()) { ast = p; @@ -207,7 +207,7 @@ public class TestCompiler { * @param handlers - a map <name, source> of handlers for the types in ast * @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>(); try { lcAST.J_gen(genCode, "labcomm.generated", 2013); diff --git a/examples/dynamic/test/TestLabcommGen.java b/examples/dynamic/test/TestLabcommGen.java index 3f968d9..f5b1005 100644 --- a/examples/dynamic/test/TestLabcommGen.java +++ b/examples/dynamic/test/TestLabcommGen.java @@ -161,7 +161,7 @@ public class TestLabcommGen { } public static InRAMCompiler generateCode(String lcDecl, HashMap<String, String> handlers) { - Program ast = null; + Specification ast = null; InputStream in = new ByteArrayInputStream(lcDecl.getBytes()); LabCommScanner scanner = new LabCommScanner(in); LabCommParser parser = new LabCommParser(); @@ -169,7 +169,7 @@ public class TestLabcommGen { InRAMCompiler irc = null; try { - Program p = (Program)parser.parse(scanner); + Specification p = (Specification)parser.parse(scanner); p.errorCheck(errors); if (errors.isEmpty()) { ast = p; @@ -200,7 +200,7 @@ public class TestLabcommGen { * @param handlers - a map <name, source> of handlers for the types in ast * @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>(); try { lcAST.J_gen(genCode, "labcomm.generated", 2014); @@ -284,7 +284,7 @@ public class TestLabcommGen { * @param handlers - a map <name, source> of handlers for the types in ast * @return an InRAMCompiler object containing the generated clases */ - private static InRAMCompiler handleAstSeparate(Program lcAST, HashMap<String, String> handlers) { + private static InRAMCompiler handleAstSeparate(Specification lcAST, HashMap<String, String> handlers) { Map<String, String> genCode = new HashMap<String, String>(); try { lcAST.J_gen(genCode, "labcomm.generated", 2013); diff --git a/examples/robot/App.config b/examples/robot/App.config index 8e15646..6a845b9 100644 --- a/examples/robot/App.config +++ b/examples/robot/App.config @@ -3,4 +3,4 @@ <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> -</configuration> \ No newline at end of file +</configuration> diff --git a/examples/robot/Follow.mod b/examples/robot/Follow.mod index fb86d9f..200a0cb 100644 --- a/examples/robot/Follow.mod +++ b/examples/robot/Follow.mod @@ -46,4 +46,4 @@ MODULE Follow RETURN; ENDPROC -ENDMODULE \ No newline at end of file +ENDMODULE diff --git a/examples/robot/LCRobot.lc b/examples/robot/LCRobot.lc index 971767d..fd0eefa 100644 --- a/examples/robot/LCRobot.lc +++ b/examples/robot/LCRobot.lc @@ -35,4 +35,4 @@ sample struct { float eax_e; float eax_f; } extax; -} jointtarget; \ No newline at end of file +} jointtarget; diff --git a/examples/robot/Program.cs b/examples/robot/Program.cs index 49a0a92..5468019 100644 --- a/examples/robot/Program.cs +++ b/examples/robot/Program.cs @@ -10,7 +10,7 @@ using System.Threading.Tasks; namespace RobotCtrl { - class Program + class Specification { public static string IP_ADDRESS = "127.0.0.1"; @@ -20,7 +20,7 @@ namespace RobotCtrl { jointtarget val = new jointtarget { robax = new jointtarget.struct_robax(), extax = new jointtarget.struct_extax() }; TcpClient client = new TcpClient(); - IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(Program.IP_ADDRESS), Program.PORT); + IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(Specification.IP_ADDRESS), Specification.PORT); try { client.Connect(serverEndPoint); diff --git a/examples/robot/RobotCtrl.csproj b/examples/robot/RobotCtrl.csproj index 7dcdcb0..c8a1201 100644 --- a/examples/robot/RobotCtrl.csproj +++ b/examples/robot/RobotCtrl.csproj @@ -42,7 +42,7 @@ </ItemGroup> <ItemGroup> <Compile Include="LCRobot.cs" /> - <Compile Include="Program.cs" /> + <Compile Include="Specification.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <ItemGroup> @@ -62,4 +62,4 @@ <Target Name="AfterBuild"> </Target> --> -</Project> \ No newline at end of file +</Project> diff --git a/examples/twoway/decimating_messages.lc b/examples/twoway/decimating_messages.lc index 8763873..62dc707 100644 --- a/examples/twoway/decimating_messages.lc +++ b/examples/twoway/decimating_messages.lc @@ -1,4 +1,4 @@ sample struct { int decimation; int signature_index; -} set_decimation; \ No newline at end of file +} set_decimation; diff --git a/examples/twoway/types.lc b/examples/twoway/types.lc index 54c03ec..ace9bd4 100644 --- a/examples/twoway/types.lc +++ b/examples/twoway/types.lc @@ -3,4 +3,4 @@ sample int B; sample int Sum; sample int Diff; sample int Product; -sample void Terminate; \ No newline at end of file +sample void Terminate; diff --git a/examples/user_types/TDDecoder.java b/examples/user_types/TDDecoder.java index 1c56a72..52b3eb9 100644 --- a/examples/user_types/TDDecoder.java +++ b/examples/user_types/TDDecoder.java @@ -9,7 +9,7 @@ import se.lth.control.labcomm2014.TypeDefParser; import se.lth.control.labcomm2014.ASTbuilder; //import se.lth.control.labcomm2014.TypeBinding; -import se.lth.control.labcomm2014.compiler.Program; +import se.lth.control.labcomm2014.compiler.Specification; import java.io.FileOutputStream; import java.io.PrintStream; @@ -79,7 +79,7 @@ public class TDDecoder if(d.isSampleDef()){ System.out.println("onTypeDef (sample): "); ASTbuilder v = new ASTbuilder(); - Program p = v.makeProgram((TypeDefParser.ParsedSampleDef) d); + Specification p = v.makeSpecification((TypeDefParser.ParsedSampleDef) d); try { //FileOutputStream f = new FileOutputStream("/tmp/foopp"+d.getName()+".txt"); //PrintStream out = new PrintStream(f); diff --git a/lib/RAPID/LabComm.sys b/lib/RAPID/LabComm.sys index 8d31dce..73f9d66 100644 --- a/lib/RAPID/LabComm.sys +++ b/lib/RAPID/LabComm.sys @@ -314,4 +314,4 @@ MODULE LabComm(SYSMODULE) RAISE ; ENDPROC -ENDMODULE \ No newline at end of file +ENDMODULE diff --git a/lib/csharp/se/lth/control/labcomm2014/EncoderRegistry.cs b/lib/csharp/se/lth/control/labcomm2014/EncoderRegistry.cs index 6c29929..5d35ecb 100644 --- a/lib/csharp/se/lth/control/labcomm2014/EncoderRegistry.cs +++ b/lib/csharp/se/lth/control/labcomm2014/EncoderRegistry.cs @@ -60,4 +60,4 @@ namespace se.lth.control.labcomm2014 { } -} \ No newline at end of file +} diff --git a/lib/csharp/se/lth/control/labcomm2014/SampleHandler.cs b/lib/csharp/se/lth/control/labcomm2014/SampleHandler.cs index fa6e9a3..dfc08bd 100644 --- a/lib/csharp/se/lth/control/labcomm2014/SampleHandler.cs +++ b/lib/csharp/se/lth/control/labcomm2014/SampleHandler.cs @@ -3,4 +3,4 @@ namespace se.lth.control.labcomm2014 { public interface SampleHandler { } -} \ No newline at end of file +} diff --git a/lib/java/se/lth/control/labcomm2014/ASTbuilder.java b/lib/java/se/lth/control/labcomm2014/ASTbuilder.java index 8e36736..c21c881 100644 --- a/lib/java/se/lth/control/labcomm2014/ASTbuilder.java +++ b/lib/java/se/lth/control/labcomm2014/ASTbuilder.java @@ -17,10 +17,11 @@ import se.lth.control.labcomm2014.compiler.LabComm; import se.lth.control.labcomm2014.compiler.LabCommParser; import se.lth.control.labcomm2014.compiler.List; -import se.lth.control.labcomm2014.compiler.Program; +import se.lth.control.labcomm2014.compiler.Specification; import se.lth.control.labcomm2014.compiler.Decl; import se.lth.control.labcomm2014.compiler.TypeDecl; import se.lth.control.labcomm2014.compiler.SampleDecl; +import se.lth.control.labcomm2014.compiler.TypeInstance; import se.lth.control.labcomm2014.compiler.DataType; import se.lth.control.labcomm2014.compiler.VoidType; import se.lth.control.labcomm2014.compiler.PrimType; @@ -94,8 +95,7 @@ public class ASTbuilder implements TypeDefParser.ParsedSymbolVisitor { } public void visit(TypeDefParser.ParsedField t){ t.getType().accept(this); - fieldStack.push(new Field(typeStack.pop(),t.getName())); - + fieldStack.push(new Field(new TypeInstance(typeStack.pop(),t.getName()))); } public void visit(TypeDefParser.ArrayType t){ boolean isFixed = true; @@ -123,12 +123,12 @@ public class ASTbuilder implements TypeDefParser.ParsedSymbolVisitor { public Decl makeDecl(TypeDefParser.ParsedTypeDef d) { d.getType().accept(this); - Decl result = new TypeDecl(typeStack.pop(), d.getName()); + Decl result = new TypeDecl(new TypeInstance(typeStack.pop(), d.getName())); return result; } - private Program createAndCheckProgram(List<Decl> ds) { - Program p = new Program(ds); + private Specification createAndCheckSpecification(List<Decl> ds) { + Specification p = new Specification(ds); LinkedList errors = new LinkedList(); p.errorCheck(errors); if(errors.isEmpty()) { @@ -145,21 +145,21 @@ public class ASTbuilder implements TypeDefParser.ParsedSymbolVisitor { } } - public Program makeProgram(TypeDefParser.ParsedTypeDef d) { + public Specification makeSpecification(TypeDefParser.ParsedTypeDef d) { assertStacksEmpty(); List<Decl> ds = new List<Decl>(); ds.add(makeDecl(d)); assertStacksEmpty(); - return createAndCheckProgram(ds); + return createAndCheckSpecification(ds); } public Decl makeDecl(TypeDefParser.ParsedSampleDef d) { d.getType().accept(this); - Decl result = new SampleDecl(typeStack.pop(), d.getName()); + Decl result = new SampleDecl(new TypeInstance(typeStack.pop(), d.getName())); return result; } - public Program makeProgram(TypeDefParser.ParsedSampleDef d) { + public Specification makeSpecification(TypeDefParser.ParsedSampleDef d) { assertStacksEmpty(); List<Decl> ds = new List<Decl>(); @@ -171,7 +171,7 @@ public class ASTbuilder implements TypeDefParser.ParsedSymbolVisitor { ds.add(makeDecl(d)); assertStacksEmpty(); - return createAndCheckProgram(ds); + return createAndCheckSpecification(ds); } } diff --git a/test/basic.lc b/test/basic.lc index 6c87af5..de60d2c 100644 --- a/test/basic.lc +++ b/test/basic.lc @@ -6,4 +6,4 @@ sample long s_long; sample float s_float; sample double s_double; sample boolean s_boolean; -sample string s_string; \ No newline at end of file +sample string s_string; diff --git a/test/simple.lc b/test/simple.lc index 3041319..d6ff7c7 100644 --- a/test/simple.lc +++ b/test/simple.lc @@ -9,4 +9,4 @@ sample struct { int a; int b; } an_int_struct; -sample void a_void; \ No newline at end of file +sample void a_void; -- GitLab