Commit bdceaa13 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Changed notion of sample identity for C# to enable renaming

parent e6e5f5e8
......@@ -13,7 +13,6 @@ aspect CS_CodeGenEnv {
private int indent;
private int depth;
private CS_printer printer;
private HashMap unique = new HashMap();
final private static class CS_printer {
......@@ -159,15 +158,6 @@ aspect CS_CodeGenEnv {
println("}");
}
public String getUnique(Object o) {
String result = (String)unique.get(o);
if (result == null) {
result = "_" + (unique.size() + 1) + "_";
}
unique.put(o, result);
return result;
}
}
}
......@@ -377,6 +367,7 @@ aspect CS_Class {
CS_emitSignature(env);
env.println("}");
env.unindent();
}
public void Decl.CS_emitSignature(CS_env env) {
......@@ -422,12 +413,12 @@ aspect CS_Class {
env.unindent();
env.println("}");
env.println();
env.println("private class Dispatcher : SampleDispatcher{");
env.println("private class Dispatcher : SampleDispatcher {");
env.indent();
env.println();
env.println("public Type getSampleClass() {");
env.println("public SampleDispatcher getSampleIdentity() {");
env.indent();
env.println("return typeof(" + getName() + ");");
env.println("return dispatcher;");
env.unindent();
env.println("}");
env.println();
......@@ -459,21 +450,6 @@ aspect CS_Class {
env.unindent();
env.println("}");
env.println();
// env.println("public void encodeSignature(Encoder e) throws IOException{");
// env.indent();
// env.println("emitSignature(e);");
// env.unindent();
// env.println("}");
// env.println();
// env.println("public void encodeSignatureMetadata(Encoder e, int index){");
// env.indent();
// env.println("e.encodePacked32(Constant.TYPE_DEF);");
// env.println("e.encodePacked32(index);");
// env.println("e.encodeString(getName());");
// env.println("emitSignature(e);");
// env.unindent();
// env.println("}");
// env.println();
env.println("public bool canDecodeAndHandle() {");
env.indent();
env.println("return "+isSample+";");
......@@ -499,7 +475,6 @@ aspect CS_Class {
env.unindent();
env.println("}");
env.println("");
} //TODO, fix above method
public void TypeDecl.CS_emitEncoder(CS_env env) {
......@@ -526,9 +501,9 @@ aspect CS_Class {
}
env.println(") {");
env.indent();
env.println("e.begin(typeof(" + getName() + "));");
env.println("e.begin(dispatcher);");
getDataType().CS_emitEncoder(env, "value");
env.println("e.end(typeof(" + getName() + "));");
env.println("e.end(dispatcher);");
env.unindent();
env.println("}");
env.println();
......@@ -736,7 +711,7 @@ aspect CS_Class {
public void PrimType.CS_emitTypePrefix(CS_env env) {
switch (getToken()) {
case LABCOMM_STRING: { env.print("String"); } break;
case LABCOMM_SAMPLE: { env.print("Type"); } break;
case LABCOMM_SAMPLE: { env.print("SampleDispatcher"); } break;
default: { env.print(getName()); } break;
}
}
......@@ -866,7 +841,7 @@ aspect CS_Class {
switch (getToken()) {
case LABCOMM_STRING: { env.print("String"); } break;
case LABCOMM_BOOLEAN: { env.print("bool"); } break;
case LABCOMM_SAMPLE: { env.print("Type"); } break;
case LABCOMM_SAMPLE: { env.print("SampleDispatcher"); } break;
default: { env.print(getName()); } break;
}
}
......
MODULES=Constant\
MODULES=AbstractDecoder \
Constant\
Decoder \
DecoderChannel \
DecoderRegistry \
......@@ -8,7 +9,7 @@ MODULES=Constant\
Sample \
SampleDispatcher \
SampleHandler \
SampleType
SampleType
.PHONY: all
all: labcomm2014.dll
......
using System;
namespace se.lth.control.labcomm2014 {
public interface AbstractDecoder {
void runOne();
void run();
void register(SampleDispatcher dispatcher,
SampleHandler handler);
void registerSampleRef(SampleDispatcher dispatcher);
}
}
......@@ -2,11 +2,7 @@ using System;
namespace se.lth.control.labcomm2014 {
public interface Decoder {
void register(SampleDispatcher dispatcher,
SampleHandler handler);
void registerSampleRef(SampleDispatcher dispatcher);
public interface Decoder : AbstractDecoder {
bool decodeBoolean();
byte decodeByte();
......@@ -17,7 +13,7 @@ namespace se.lth.control.labcomm2014 {
double decodeDouble();
String decodeString();
int decodePacked32();
Type decodeSampleRef();
SampleDispatcher decodeSampleRef();
}
......
......@@ -166,11 +166,11 @@ namespace se.lth.control.labcomm2014 {
return (int) (res & 0xffffffff);
}
public Type decodeSampleRef() {
public SampleDispatcher decodeSampleRef() {
int index = (int)ReadInt(4);
try {
DecoderRegistry.Entry e = ref_registry.get(index);
return e.getSampleDispatcher().getSampleClass();
return e.getSampleDispatcher().getSampleIdentity();
} catch (NullReferenceException) {
return null;
}
......
......@@ -90,11 +90,11 @@ namespace se.lth.control.labcomm2014 {
}
}
private Dictionary<Type, Entry> byClass;
private Dictionary<SampleDispatcher, Entry> byIdentity;
private Dictionary<int, Entry> byIndex;
public DecoderRegistry() {
byClass = new Dictionary<Type, Entry>();
byIdentity = new Dictionary<SampleDispatcher, Entry>();
byIndex = new Dictionary<int, Entry>();
}
......@@ -102,7 +102,7 @@ namespace se.lth.control.labcomm2014 {
SampleHandler handler) {
lock(this) {
Entry e;
byClass.TryGetValue(dispatcher.getSampleClass(), out e);
byIdentity.TryGetValue(dispatcher.getSampleIdentity(), out e);
if (e != null) {
e.check(dispatcher.getName(), dispatcher.getSignature());
e.setHandler(handler);
......@@ -117,7 +117,7 @@ namespace se.lth.control.labcomm2014 {
}
if (e == null) {
e = new Entry(dispatcher, handler);
byClass.Add(dispatcher.getSampleClass(), e);
byIdentity.Add(dispatcher.getSampleIdentity(), e);
}
}
}
......@@ -132,7 +132,7 @@ namespace se.lth.control.labcomm2014 {
if (e != null) {
e.check(name, signature);
} else {
foreach (Entry e2 in byClass.Values) {
foreach (Entry e2 in byIdentity.Values) {
if (e2.match(name, signature)) {
e2.setIndex(index);
e = e2;
......
......@@ -6,8 +6,8 @@ namespace se.lth.control.labcomm2014 {
void register(SampleDispatcher dispatcher);
void registerSampleRef(SampleDispatcher dispatcher);
void begin(Type c);
void end(Type c);
void begin(SampleDispatcher dispatcher);
void end(SampleDispatcher dispatcher);
void encodeBoolean(bool value);
void encodeByte(byte value);
......@@ -18,7 +18,7 @@ namespace se.lth.control.labcomm2014 {
void encodeDouble(double value);
void encodeString(String value);
void encodePacked32(Int64 value);
void encodeSampleRef(Type value);
void encodeSampleRef(SampleDispatcher value);
}
......
......@@ -53,11 +53,11 @@ namespace se.lth.control.labcomm2014 {
bytes.SetLength(0);
}
public void begin(Type c) {
begin(def_registry.getTag(c));
public void begin(SampleDispatcher identity) {
begin(def_registry.getTag(identity));
}
public void end(Type c) {
public void end(SampleDispatcher identity) {
WritePacked32(writer, current_tag);
WritePacked32(writer, bytes.Length);
bytes.WriteTo(writer);
......@@ -132,7 +132,7 @@ namespace se.lth.control.labcomm2014 {
WritePacked32(bytes, value);
}
public void encodeSampleRef(Type value) {
public void encodeSampleRef(SampleDispatcher value) {
int index = 0;
try {
index = ref_registry.getTag(value);
......
......@@ -26,29 +26,29 @@ namespace se.lth.control.labcomm2014 {
}
private int userIndex = Constant.FIRST_USER_INDEX;
private Dictionary<Type, Entry> byClass;
private Dictionary<SampleDispatcher, Entry> byIdentity;
public EncoderRegistry() {
byClass = new Dictionary<Type, Entry>();
byIdentity = new Dictionary<SampleDispatcher, Entry>();
}
public int add(SampleDispatcher dispatcher) {
lock(this) {
Entry e;
byClass.TryGetValue(dispatcher.getSampleClass(), out e);
byIdentity.TryGetValue(dispatcher.getSampleIdentity(), out e);
if (e == null) {
e = new Entry(dispatcher, userIndex);
byClass.Add(dispatcher.getSampleClass(), e);
byIdentity.Add(dispatcher.getSampleIdentity(), e);
userIndex++;
}
return e.getIndex();
}
}
public int getTag(Type sample) {
public int getTag(SampleDispatcher sample) {
lock(this) {
Entry e;
byClass.TryGetValue(sample, out e);
byIdentity.TryGetValue(sample, out e);
if (e == null) {
throw new Exception("'" +
sample.ToString() +
......
......@@ -4,12 +4,12 @@ namespace se.lth.control.labcomm2014 {
public interface SampleDispatcher {
Type getSampleClass();
SampleDispatcher getSampleIdentity();
String getName();
byte[] getSignature();
void decodeAndHandle(Decoder decoder,
SampleHandler handler);
......
Markdown is supported
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