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

rename and cleanup

parent 64a8c45d
......@@ -6,7 +6,7 @@ import java.io.IOException;
import se.lth.control.labcomm.DecoderChannel;
import se.lth.control.labcomm.TypeDef;
import se.lth.control.labcomm.TypeDefParser;
import se.lth.control.labcomm.TypeDefVisitor;
import se.lth.control.labcomm.ASTbuilder;
//import se.lth.control.labcomm.TypeBinding;
import se.lth.control.labcomm2014.compiler.Program;
......@@ -78,11 +78,8 @@ public class TDDecoder
public void onTypeDef(TypeDefParser.ParsedTypeDef d) {
if(d.isSampleDef()){
System.out.println("onTypeDef (sample): ");
TypeDefVisitor v = new TypeDefVisitor();
ASTbuilder v = new ASTbuilder();
Program p = v.makeProgram((TypeDefParser.ParsedSampleDef) d);
LinkedList errors = new LinkedList();
p.errorCheck(errors);
if(errors.isEmpty()) {
try {
//FileOutputStream f = new FileOutputStream("/tmp/foopp"+d.getName()+".txt");
//PrintStream out = new PrintStream(f);
......@@ -94,12 +91,6 @@ public class TDDecoder
System.err.println("Exception: " + e);
e.printStackTrace();
}
} else {
for (Iterator iter = errors.iterator(); iter.hasNext(); ) {
String s = (String)iter.next();
System.out.println(s);
}
}
}
//System.out.println(" "+d.getName()+";");
//for(byte b: d.getSignature()) {
......
......@@ -13,7 +13,7 @@ MODULES=Constant \
BuiltinType \
TypeDef \
TypeBinding \
TypeDefVisitor \
ASTbuilder \
TypeDefParser \
Writer \
WriterWrapper
......
......@@ -40,7 +40,7 @@ import se.lth.control.labcomm2014.compiler.VariableSize;
/** A class for building a JastAdd AST from the parsed types
* created by a TypeDefParser. This class depends on the LabComm compiler.
*/
public class TypeDefVisitor implements TypeDefParser.ParsedSymbolVisitor {
public class ASTbuilder implements TypeDefParser.ParsedSymbolVisitor {
///// tree building
//
......@@ -48,11 +48,20 @@ public class TypeDefVisitor implements TypeDefParser.ParsedSymbolVisitor {
private LinkedList<Type> typeStack;
private LinkedList<Field> fieldStack;
public TypeDefVisitor() {
public ASTbuilder() {
this.typeStack = new LinkedList<Type>();
this.fieldStack = new LinkedList<Field>();
}
private void assertStacksEmpty() throws RuntimeException {
if(!typeStack.isEmpty()) {
throw new RuntimeException("Error: type stack not empty");
}
if(!fieldStack.isEmpty()) {
throw new RuntimeException("Error: field stack not empty");
}
}
public void visit(TypeDefParser.TypeSymbol s){
throw new Error("not implemented? needed?");
......@@ -120,11 +129,30 @@ public class TypeDefVisitor implements TypeDefParser.ParsedSymbolVisitor {
return result;
}
private Program createAndCheckProgram(List<Decl> ds) {
Program p = new Program(ds);
LinkedList errors = new LinkedList();
p.errorCheck(errors);
if(errors.isEmpty()) {
return p;
} else {
//XXX temporary debug printout
for (Iterator iter = errors.iterator(); iter.hasNext(); ) {
String s = (String)iter.next();
System.err.println(s);
}
// This should not happen
throw new RuntimeException("Internal error: parsed labcomm declaration has errors");
}
}
public Program makeProgram(TypeDefParser.ParsedTypeDef d) {
assertStacksEmpty();
List<Decl> ds = new List<Decl>();
ds.add(makeDecl(d));
return new Program(ds);
assertStacksEmpty();
return createAndCheckProgram(ds);
}
public Decl makeDecl(TypeDefParser.ParsedSampleDef d) {
......@@ -133,6 +161,7 @@ public class TypeDefVisitor implements TypeDefParser.ParsedSymbolVisitor {
return result;
}
public Program makeProgram(TypeDefParser.ParsedSampleDef d) {
assertStacksEmpty();
List<Decl> ds = new List<Decl>();
Iterator<TypeDefParser.ParsedTypeDef> it = d.getDepIterator();
......@@ -142,7 +171,8 @@ public class TypeDefVisitor implements TypeDefParser.ParsedSymbolVisitor {
ds.add(makeDecl(d));
return new Program(ds);
assertStacksEmpty();
return createAndCheckProgram(ds);
}
}
package se.lth.control.labcomm2006;
public class TypeDefVisitor {
public class ASTbuilder {
}
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