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

commented out unused SampleRefType in compiler, and added ref tests in examples/user_types

parent 7d7fd2be
...@@ -21,9 +21,9 @@ aspect FlatSignature { ...@@ -21,9 +21,9 @@ aspect FlatSignature {
getType().flatSignature(list); getType().flatSignature(list);
} }
public void SampleRefType.flatSignature(SignatureList list) { // public void SampleRefType.flatSignature(SignatureList list) {
list.addInt(LABCOMM_SAMPLE_REF, "sample"); // list.addInt(LABCOMM_SAMPLE_REF, "sample");
} // }
public void VoidType.flatSignature(SignatureList list) { public void VoidType.flatSignature(SignatureList list) {
list.addInt(LABCOMM_STRUCT, "void"); list.addInt(LABCOMM_STRUCT, "void");
...@@ -96,9 +96,9 @@ aspect FlatSignature { ...@@ -96,9 +96,9 @@ aspect FlatSignature {
return getType().signatureComment() + " '" + getName() +"'"; return getType().signatureComment() + " '" + getName() +"'";
} }
public String SampleRefType.signatureComment() { // public String SampleRefType.signatureComment() {
return "sample"; // return "sample";
} // }
public String PrimType.signatureComment() { public String PrimType.signatureComment() {
return getName(); return getName();
......
...@@ -21,7 +21,7 @@ Field ::= Type <Name:String>; ...@@ -21,7 +21,7 @@ Field ::= Type <Name:String>;
abstract Type; abstract Type;
VoidType : Type; VoidType : Type;
SampleRefType : Type; //SampleRefType : Type;
PrimType : Type ::= <Name:String> <Token:int>; PrimType : Type ::= <Name:String> <Token:int>;
UserType : Type ::= <Name:String>; UserType : Type ::= <Name:String>;
StructType : Type ::= Field*; StructType : Type ::= Field*;
......
...@@ -68,9 +68,9 @@ aspect PrettyPrint { ...@@ -68,9 +68,9 @@ aspect PrettyPrint {
out.print("void"); out.print("void");
} }
public void SampleRefType.ppPrefix(PrintStream out) { // public void SampleRefType.ppPrefix(PrintStream out) {
out.print("sample"); // out.print("sample");
} // }
public void PrimType.ppPrefix(PrintStream out) { public void PrimType.ppPrefix(PrintStream out) {
out.print(getName()); out.print(getName());
......
...@@ -174,9 +174,9 @@ aspect Signature { ...@@ -174,9 +174,9 @@ aspect Signature {
list.addInt(0, null); list.addInt(0, null);
} }
public void SampleRefType.genSigLineForDecl(SignatureList list, boolean decl) { // public void SampleRefType.genSigLineForDecl(SignatureList list, boolean decl) {
list.addInt(LABCOMM_SAMPLE_REF, "sample"); // list.addInt(LABCOMM_SAMPLE_REF, "sample");
} // }
public void PrimType.genSigLineForDecl(SignatureList list, boolean decl) { public void PrimType.genSigLineForDecl(SignatureList list, boolean decl) {
list.addInt(getToken(), null); list.addInt(getToken(), null);
} }
......
...@@ -16,7 +16,8 @@ public class Decoder ...@@ -16,7 +16,8 @@ public class Decoder
twoInts.Handler, twoInts.Handler,
theFirstInt.Handler, theFirstInt.Handler,
theSecondInt.Handler, theSecondInt.Handler,
doavoid.Handler doavoid.Handler,
intAndRef.Handler
{ {
private DecoderChannel decoder; private DecoderChannel decoder;
...@@ -31,6 +32,8 @@ public class Decoder ...@@ -31,6 +32,8 @@ public class Decoder
twoLines.register(decoder, this); twoLines.register(decoder, this);
theFirstInt.register(decoder, this); theFirstInt.register(decoder, this);
theSecondInt.register(decoder, this); theSecondInt.register(decoder, this);
intAndRef.register(decoder, this);
doavoid.registerSampleRef(decoder);
this.tdp = TypeDefParser.registerTypeDefParser(decoder); this.tdp = TypeDefParser.registerTypeDefParser(decoder);
// TypeDef.register(decoder, this); // TypeDef.register(decoder, this);
// TypeBinding.register(decoder, this); // TypeBinding.register(decoder, this);
...@@ -92,6 +95,10 @@ public class Decoder ...@@ -92,6 +95,10 @@ public class Decoder
System.out.println("Got theSecondInt: "+d); System.out.println("Got theSecondInt: "+d);
} }
public void handle_intAndRef(intAndRef d) throws java.io.IOException {
System.out.println("Got intAndRef: "+d.x+", "+d.reference);
}
public void handle_twoLines(twoLines d) throws java.io.IOException { public void handle_twoLines(twoLines d) throws java.io.IOException {
System.out.print("Got twoLines: "); System.out.print("Got twoLines: ");
System.out.println("Line l1: "+genLine(d.l1)); System.out.println("Line l1: "+genLine(d.l1));
......
...@@ -21,16 +21,25 @@ public class Encoder ...@@ -21,16 +21,25 @@ public class Encoder
twoLines.register(encoder); twoLines.register(encoder);
theFirstInt.register(encoder); theFirstInt.register(encoder);
theSecondInt.register(encoder); theSecondInt.register(encoder);
intAndRef.register(encoder);
doavoid.registerSampleRef(encoder);
} }
public void doEncode() throws java.io.IOException { public void doEncode() throws java.io.IOException {
System.out.println("Encoding doavoid");
doavoid.encode(encoder);
intAndRef iar = new intAndRef();
iar.x = 17;
iar.reference = doavoid.class;
System.out.println("Encoding intAndRef");
intAndRef.encode(encoder, iar);
twoInts ti = new twoInts(); twoInts ti = new twoInts();
ti.a = 12; ti.a = 12;
ti.b = 21; ti.b = 21;
System.out.println("Encoding doavoid");
doavoid.encode(encoder);
System.out.println("Encoding twoInts"); System.out.println("Encoding twoInts");
twoInts.encode(encoder, ti); twoInts.encode(encoder, ti);
......
...@@ -11,7 +11,8 @@ namespace user_types ...@@ -11,7 +11,8 @@ namespace user_types
twoInts.Handler, twoInts.Handler,
theFirstInt.Handler, theFirstInt.Handler,
theSecondInt.Handler, theSecondInt.Handler,
doavoid.Handler doavoid.Handler,
intAndRef.Handler
{ {
DecoderChannel dec; DecoderChannel dec;
...@@ -23,6 +24,8 @@ namespace user_types ...@@ -23,6 +24,8 @@ namespace user_types
theFirstInt.register(dec, this); theFirstInt.register(dec, this);
theSecondInt.register(dec, this); theSecondInt.register(dec, this);
doavoid.register(dec, this); doavoid.register(dec, this);
intAndRef.register(dec, this);
doavoid.registerSampleRef(dec);
try try
{ {
Console.WriteLine("Running decoder."); Console.WriteLine("Running decoder.");
...@@ -71,6 +74,11 @@ namespace user_types ...@@ -71,6 +74,11 @@ namespace user_types
Console.WriteLine("Got a void."); Console.WriteLine("Got a void.");
} }
void intAndRef.Handler.handle(intAndRef d)
{
Console.WriteLine("Got intAndRef: "+d.x+" : "+d.reference);
}
static void Main(string[] args) static void Main(string[] args)
{ {
new Decoder(new FileStream(args[0], FileMode.Open)); new Decoder(new FileStream(args[0], FileMode.Open));
......
...@@ -26,7 +26,8 @@ public class TDDecoder ...@@ -26,7 +26,8 @@ public class TDDecoder
twoInts.Handler, twoInts.Handler,
theFirstInt.Handler, theFirstInt.Handler,
theSecondInt.Handler, theSecondInt.Handler,
doavoid.Handler doavoid.Handler,
intAndRef.Handler
{ {
private DecoderChannel decoder; private DecoderChannel decoder;
...@@ -41,6 +42,8 @@ public class TDDecoder ...@@ -41,6 +42,8 @@ public class TDDecoder
theFirstInt.register(decoder, this); theFirstInt.register(decoder, this);
theSecondInt.register(decoder, this); theSecondInt.register(decoder, this);
doavoid.register(decoder, this); doavoid.register(decoder, this);
intAndRef.register(decoder, this);
doavoid.registerSampleRef(decoder);
this.tdp = TypeDefParser.registerTypeDefParser(decoder); this.tdp = TypeDefParser.registerTypeDefParser(decoder);
// TypeDef.register(decoder, this); // TypeDef.register(decoder, this);
// TypeBinding.register(decoder, this); // TypeBinding.register(decoder, this);
...@@ -84,7 +87,7 @@ public class TDDecoder ...@@ -84,7 +87,7 @@ public class TDDecoder
//FileOutputStream f = new FileOutputStream("/tmp/foopp"+d.getName()+".txt"); //FileOutputStream f = new FileOutputStream("/tmp/foopp"+d.getName()+".txt");
//PrintStream out = new PrintStream(f); //PrintStream out = new PrintStream(f);
p.pp(System.out); p.pp(System.out);
p.C_genC(System.out, new Vector(), "lcname", "prefix", 2014); //p.C_genC(System.out, new Vector(), "lcname", "prefix", 2014);
//p.J_gen(out, "testpackage", 2014); //p.J_gen(out, "testpackage", 2014);
//out.close(); //out.close();
} catch (Throwable e) { } catch (Throwable e) {
...@@ -125,6 +128,10 @@ public class TDDecoder ...@@ -125,6 +128,10 @@ public class TDDecoder
System.out.println("Got a void."); System.out.println("Got a void.");
} }
public void handle_intAndRef(intAndRef d) throws java.io.IOException {
System.out.println("Got intAndRef: "+d.x+", "+d.reference);
}
public void handle_twoLines(twoLines d) throws java.io.IOException { public void handle_twoLines(twoLines d) throws java.io.IOException {
System.out.print("Got twoLines: "); System.out.print("Got twoLines: ");
System.out.println("Line l1: "+genLine(d.l1)); System.out.println("Line l1: "+genLine(d.l1));
......
...@@ -12,6 +12,10 @@ static void handle_test_doavoid(test_doavoid *v,void *context) { ...@@ -12,6 +12,10 @@ static void handle_test_doavoid(test_doavoid *v,void *context) {
printf("Got a void.\n"); printf("Got a void.\n");
} }
static void handle_test_intAndRef(test_intAndRef *v,void *context) {
printf("Got intAndRef. (%d : %s) \n", v->x, v->reference->name);
}
static void handle_test_twoInts(test_twoInts *v,void *context) { static void handle_test_twoInts(test_twoInts *v,void *context) {
printf("Got twoInts. (%d,%d) \n", v->a, v->b); printf("Got twoInts. (%d,%d) \n", v->a, v->b);
} }
...@@ -58,6 +62,9 @@ int main(int argc, char *argv[]) { ...@@ -58,6 +62,9 @@ int main(int argc, char *argv[]) {
} }
labcomm_decoder_register_test_doavoid(decoder, handle_test_doavoid, context); labcomm_decoder_register_test_doavoid(decoder, handle_test_doavoid, context);
labcomm_decoder_register_test_intAndRef(decoder, handle_test_intAndRef, context);
labcomm_decoder_sample_ref_register(decoder,labcomm_signature_test_doavoid );
labcomm_decoder_register_test_twoInts(decoder, handle_test_twoInts, context); labcomm_decoder_register_test_twoInts(decoder, handle_test_twoInts, context);
labcomm_decoder_register_test_theFirstInt(decoder, handle_test_theFirstInt, context); labcomm_decoder_register_test_theFirstInt(decoder, handle_test_theFirstInt, context);
labcomm_decoder_register_test_theSecondInt(decoder, handle_test_theSecondInt, context); labcomm_decoder_register_test_theSecondInt(decoder, handle_test_theSecondInt, context);
......
...@@ -7,6 +7,11 @@ typedef int anInt; ...@@ -7,6 +7,11 @@ typedef int anInt;
typedef void avoid; typedef void avoid;
sample avoid doavoid; sample avoid doavoid;
sample struct {
int x;
sample reference;
} intAndRef;
typedef struct { typedef struct {
coord x; coord x;
coord y; coord y;
......
...@@ -181,7 +181,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler { ...@@ -181,7 +181,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
void visit(SampleSymbol s); void visit(SampleSymbol s);
void visit(NameSymbol s); void visit(NameSymbol s);
void visit(PrimitiveType t); void visit(PrimitiveType t);
void visit(SampleRefType t); //void visit(SampleRefType t);
void visit(ParsedStructType t); void visit(ParsedStructType t);
void visit(ParsedField t); void visit(ParsedField t);
void visit(ArrayType t); void visit(ArrayType t);
...@@ -227,14 +227,14 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler { ...@@ -227,14 +227,14 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
public abstract class ParsedType extends ParsedSymbol{ public abstract class ParsedType extends ParsedSymbol{
} }
public class SampleRefType extends ParsedType { // public class SampleRefType extends ParsedType {
public void accept(ParsedSymbolVisitor v) { // public void accept(ParsedSymbolVisitor v) {
v.visit(this); // v.visit(this);
} // }
//
public String toString() { // public String toString() {
return "sample";} // return "sample";}
} // }
public class PrimitiveType extends ParsedType { public class PrimitiveType extends ParsedType {
private final String name; private final String name;
...@@ -274,6 +274,9 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler { ...@@ -274,6 +274,9 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
case Constant.STRING: case Constant.STRING:
this.name = "string"; this.name = "string";
break; break;
case Constant.SAMPLE:
this.name = "sample";
break;
default: default:
this.name = "??? unknown tag 0x"+Integer.toHexString(tag); this.name = "??? unknown tag 0x"+Integer.toHexString(tag);
} }
...@@ -643,8 +646,8 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler { ...@@ -643,8 +646,8 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
TypeDef td = typeDefs.get(tag); TypeDef td = typeDefs.get(tag);
result = new ParsedUserType(td.getName()); result = new ParsedUserType(td.getName());
in.pushType(tag); in.pushType(tag);
} else if(tag == Constant.SAMPLE) { // } else if(tag == Constant.SAMPLE) {
result = new SampleRefType(); // result = new SampleRefType();
} else { } else {
result = new PrimitiveType(tag); result = new PrimitiveType(tag);
} }
......
...@@ -23,7 +23,7 @@ import se.lth.control.labcomm2014.compiler.TypeDecl; ...@@ -23,7 +23,7 @@ import se.lth.control.labcomm2014.compiler.TypeDecl;
import se.lth.control.labcomm2014.compiler.SampleDecl; import se.lth.control.labcomm2014.compiler.SampleDecl;
import se.lth.control.labcomm2014.compiler.Type; import se.lth.control.labcomm2014.compiler.Type;
import se.lth.control.labcomm2014.compiler.VoidType; import se.lth.control.labcomm2014.compiler.VoidType;
import se.lth.control.labcomm2014.compiler.SampleRefType; //import se.lth.control.labcomm2014.compiler.SampleRefType;
import se.lth.control.labcomm2014.compiler.PrimType; import se.lth.control.labcomm2014.compiler.PrimType;
import se.lth.control.labcomm2014.compiler.UserType; import se.lth.control.labcomm2014.compiler.UserType;
import se.lth.control.labcomm2014.compiler.StructType; import se.lth.control.labcomm2014.compiler.StructType;
...@@ -69,9 +69,9 @@ public class TypeDefVisitor implements TypeDefParser.ParsedSymbolVisitor { ...@@ -69,9 +69,9 @@ public class TypeDefVisitor implements TypeDefParser.ParsedSymbolVisitor {
typeStack.push(new PrimType(t.getName(), t.getTag())); typeStack.push(new PrimType(t.getName(), t.getTag()));
} }
public void visit(TypeDefParser.SampleRefType t){ // public void visit(TypeDefParser.SampleRefType t){
typeStack.push(new SampleRefType()); // typeStack.push(new SampleRefType());
} // }
public void visit(TypeDefParser.ParsedStructType t){ public void visit(TypeDefParser.ParsedStructType t){
if(t.isVoid()) { if(t.isVoid()) {
......
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