Commit 991de20e authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

refactored grammar: added TypeInstance :: DataType Name and renamed Program...

refactored grammar: added TypeInstance :: DataType Name  and renamed Program to Specification (based on cherry-picked (parts of) 9d2ca1)
parent e2a0f191
......@@ -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 = "";
......
......@@ -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);
......
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();
}
......@@ -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);
......
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;
......
......@@ -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) {
......
......@@ -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; :}
......
......@@ -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)) {
......
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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);
......
/* 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());
}
}
......@@ -14,7 +14,6 @@ aspect Signature {
inh Decl Signature.parentDecl();
inh Decl SignatureList.parentDecl();
syn nta Signature Decl.getSignature() {
SignatureList sl = new SignatureList();
genSigLineForDecl(sl, true);
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment