Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • anders_blomdell/labcomm
  • klaren/labcomm
  • tommyo/labcomm
  • erikj/labcomm
  • sven/labcomm
5 results
Select Git revision
Show changes
Showing
with 646 additions and 96 deletions
......@@ -4,6 +4,8 @@ namespace se.lth.control.labcomm2014 {
public interface Decoder {
void runOne();
void run();
void register(SampleDispatcher dispatcher,
SampleHandler handler);
void registerSampleRef(SampleDispatcher dispatcher);
......@@ -17,7 +19,7 @@ namespace se.lth.control.labcomm2014 {
double decodeDouble();
String decodeString();
int decodePacked32();
Type decodeSampleRef();
SampleDispatcher decodeSampleRef();
}
......
......@@ -31,7 +31,7 @@ namespace se.lth.control.labcomm2014 {
} break;
case Constant.SAMPLE_DEF: {
int index = decodePacked32();
String name = decodeString();
String name = decodeIntentions();
int signature_length = decodePacked32();
byte[] signature = new byte[signature_length];
ReadBytes(signature, signature_length);
......@@ -39,7 +39,7 @@ namespace se.lth.control.labcomm2014 {
} break;
case Constant.SAMPLE_REF: {
int index = decodePacked32();
String name = decodeString();
String name = decodeIntentions();
int signature_length = decodePacked32();
byte[] signature = new byte[signature_length];
ReadBytes(signature, signature_length);
......@@ -166,11 +166,35 @@ namespace se.lth.control.labcomm2014 {
return (int) (res & 0xffffffff);
}
public Type decodeSampleRef() {
private byte[] decodeBytes() {
int len = decodePacked32();
byte[] result = new byte[len];
for(int i=0; i<len; i++) {
result[i] = decodeByte();
}
return result;
}
private String decodeIntentions() {
int numIntentions = decodePacked32();
string name = "";
for(int i = 0; i<numIntentions; i++) {
byte[] key = decodeBytes();
byte[] val = decodeBytes();
if(key.Length == 0) {
name = Encoding.UTF8.GetString(val, 0, val.Length);
}
}
return name;
}
public SampleDispatcher decodeSampleRef() {
int index = (int)ReadInt(4);
try {
DecoderRegistry.Entry e = ref_registry.get(index);
return e.getSampleDispatcher().getSampleClass();
return e.getSampleDispatcher();
} catch (NullReferenceException) {
return null;
}
......
......@@ -90,11 +90,11 @@ namespace se.lth.control.labcomm2014 {
}
}
private Dictionary<Type, Entry> byClass;
private Dictionary<SampleDispatcher, Entry> byDispatcher;
private Dictionary<int, Entry> byIndex;
public DecoderRegistry() {
byClass = new Dictionary<Type, Entry>();
byDispatcher = 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);
byDispatcher.TryGetValue(dispatcher, 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);
byDispatcher.Add(dispatcher, 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 byDispatcher.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);
}
......
......@@ -26,7 +26,7 @@ namespace se.lth.control.labcomm2014 {
int index = def_registry.add(dispatcher);
begin(Constant.SAMPLE_DEF);
encodePacked32(index);
encodeString(dispatcher.getName());
encodeIntentions(dispatcher.getName());
byte[] signature = dispatcher.getSignature();
encodePacked32(signature.Length);
for (int i = 0 ; i < signature.Length ; i++) {
......@@ -39,7 +39,7 @@ namespace se.lth.control.labcomm2014 {
int index = ref_registry.add(dispatcher);
begin(Constant.SAMPLE_REF);
encodePacked32(index);
encodeString(dispatcher.getName());
encodeIntentions(dispatcher.getName());
byte[] signature = dispatcher.getSignature();
encodePacked32(signature.Length);
for (int i = 0 ; i < signature.Length ; i++) {
......@@ -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,13 @@ namespace se.lth.control.labcomm2014 {
WritePacked32(bytes, value);
}
public void encodeSampleRef(Type value) {
private void encodeIntentions(String name) {
encodePacked32(1); // one intention field
encodePacked32(0); // empty key: name
encodeString(name);
}
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> byDispatcher;
public EncoderRegistry() {
byClass = new Dictionary<Type, Entry>();
byDispatcher = new Dictionary<SampleDispatcher, Entry>();
}
public int add(SampleDispatcher dispatcher) {
lock(this) {
Entry e;
byClass.TryGetValue(dispatcher.getSampleClass(), out e);
byDispatcher.TryGetValue(dispatcher, out e);
if (e == null) {
e = new Entry(dispatcher, userIndex);
byClass.Add(dispatcher.getSampleClass(), e);
byDispatcher.Add(dispatcher, e);
userIndex++;
}
return e.getIndex();
}
}
public int getTag(Type sample) {
public int getTag(SampleDispatcher sample) {
lock(this) {
Entry e;
byClass.TryGetValue(sample, out e);
byDispatcher.TryGetValue(sample, out e);
if (e == null) {
throw new Exception("'" +
sample.ToString() +
......
namespace se.lth.control.labcomm2014 {
using System;
public class RenamingDecoder : WrappingDecoder {
private Decoder decoder;
private RenamingRegistry registry;
private Func<String,String> rename;
public RenamingDecoder(Decoder decoder,
RenamingRegistry registry,
Func<String,String> rename)
: base(decoder) {
this.decoder = decoder;
this.registry = registry;
this.rename = rename;
}
public override void register(SampleDispatcher dispatcher,
SampleHandler handler) {
decoder.register(registry.add(
dispatcher, rename(dispatcher.getName())), handler);
}
public override void registerSampleRef(SampleDispatcher dispatcher) {
decoder.registerSampleRef(registry.add(
dispatcher, rename(dispatcher.getName())));
}
}
}
namespace se.lth.control.labcomm2014 {
using System;
using System.Collections.Generic;
public class RenamingEncoder : WrappingEncoder {
private Encoder encoder;
private RenamingRegistry registry;
private Func<String,String> rename;
private Dictionary<SampleDispatcher, SampleDispatcher> alias;
public RenamingEncoder(Encoder encoder,
RenamingRegistry registry,
Func<String,String> rename)
: base(encoder) {
this.encoder = encoder;
this.registry = registry;
this.rename = rename;
alias = new Dictionary<SampleDispatcher, SampleDispatcher>();
}
private SampleDispatcher add(SampleDispatcher identity) {
SampleDispatcher renamed;
lock(this) {
if (! alias.TryGetValue(identity, out renamed)) {
renamed = registry.add(identity, rename(identity.getName()));
alias.Add(identity, renamed);
}
}
get(identity);
return renamed;
}
private SampleDispatcher get(SampleDispatcher identity) {
SampleDispatcher renamed;
lock(this) {
alias.TryGetValue(identity, out renamed);
}
return renamed;
}
public override void register(SampleDispatcher identity) {
encoder.register(add(identity));
}
public override void registerSampleRef(SampleDispatcher identity) {
encoder.registerSampleRef(add(identity));
}
public override void begin(SampleDispatcher identity) {
base.begin(get(identity));
}
public override void end(SampleDispatcher identity) {
base.end(get(identity));
}
}
}
namespace se.lth.control.labcomm2014 {
using System;
using System.Collections.Generic;
public class RenamingRegistry {
public class Dispatcher : SampleDispatcher, IEquatable<Dispatcher> {
private SampleDispatcher dispatcher;
private String name;
public Dispatcher(SampleDispatcher dispatcher,
String name) {
this.dispatcher = dispatcher;
this.name = name;
}
public String getName() {
return name;
}
public byte[] getSignature() {
return dispatcher.getSignature();
}
public void decodeAndHandle(Decoder decoder,
SampleHandler handler) {
dispatcher.decodeAndHandle(decoder, handler);
}
public bool Equals(Dispatcher obj) {
Dispatcher other = obj as Dispatcher;
return (other != null &&
dispatcher == other.dispatcher &&
name.Equals(other.name));
}
public override int GetHashCode() {
return dispatcher.GetHashCode() ^ name.GetHashCode();
}
public override string ToString() {
return "RenamingRegistry.Dispatcher(" + name + ")";
}
}
private Dictionary<Dispatcher, Dispatcher> registry;
public RenamingRegistry() {
registry = new Dictionary<Dispatcher, Dispatcher>();
}
public SampleDispatcher add(SampleDispatcher dispatcher,
String newName) {
Dispatcher result;
Dispatcher tmp = new Dispatcher(dispatcher, newName);
lock(this) {
registry.TryGetValue(tmp, out result);
if (result == null) {
registry.Add(tmp, tmp);
result = tmp;
}
}
return result;
}
}
}
......@@ -4,8 +4,6 @@ namespace se.lth.control.labcomm2014 {
public interface SampleDispatcher {
Type getSampleClass();
String getName();
byte[] getSignature();
......
using System;
namespace se.lth.control.labcomm2014 {
public class WrappingDecoder: Decoder {
private Decoder decoder;
public WrappingDecoder(Decoder decoder) {
this.decoder = decoder;
}
public virtual void runOne() {
decoder.runOne();
}
public virtual void run() {
decoder.run();
}
public virtual void register(SampleDispatcher dispatcher,
SampleHandler handler) {
decoder.register(dispatcher, handler);
}
public virtual void registerSampleRef(SampleDispatcher dispatcher) {
decoder.registerSampleRef(dispatcher);
}
public virtual bool decodeBoolean() {
return decoder.decodeBoolean();
}
public virtual byte decodeByte() {
return decoder.decodeByte();
}
public virtual short decodeShort() {
return decoder.decodeShort();
}
public virtual int decodeInt() {
return decoder.decodeInt();
}
public virtual long decodeLong() {
return decoder.decodeLong();
}
public virtual float decodeFloat() {
return decoder.decodeFloat();
}
public virtual double decodeDouble() {
return decoder.decodeDouble();
}
public virtual String decodeString() {
return decoder.decodeString();
}
public virtual int decodePacked32() {
return decoder.decodePacked32();
}
public virtual SampleDispatcher decodeSampleRef() {
return decoder.decodeSampleRef();
}
}
}
namespace se.lth.control.labcomm2014 {
using System;
public class WrappingEncoder : Encoder {
private Encoder encoder;
public WrappingEncoder(Encoder encoder) {
this.encoder = encoder;
}
public virtual void register(SampleDispatcher dispatcher) {
encoder.register(dispatcher);
}
public virtual void registerSampleRef(SampleDispatcher dispatcher) {
encoder.registerSampleRef(dispatcher);
}
public virtual void begin(SampleDispatcher dispatcher) {
encoder.begin(dispatcher);
}
public virtual void end(SampleDispatcher dispatcher) {
encoder.end(dispatcher);
}
public virtual void encodeBoolean(bool value) {
encoder.encodeBoolean(value);
}
public virtual void encodeByte(byte value) {
encoder.encodeByte(value);
}
public virtual void encodeShort(short value) {
encoder.encodeShort(value);
}
public virtual void encodeInt(int value) {
encoder.encodeInt(value);
}
public virtual void encodeLong(long value) {
encoder.encodeLong(value);
}
public virtual void encodeFloat(float value) {
encoder.encodeFloat(value);
}
public virtual void encodeDouble(double value) {
encoder.encodeDouble(value);
}
public virtual void encodeString(String value) {
encoder.encodeString(value);
}
public virtual void encodePacked32(Int64 value) {
encoder.encodePacked32(value);
}
public virtual void encodeSampleRef(SampleDispatcher value) {
encoder.encodeSampleRef(value);
}
}
}
......@@ -15,8 +15,27 @@ MODULES=Constant \
TypeBinding \
ASTbuilder \
TypeDefParser \
SigTypeDef \
SigSampleDef \
ParsedTypeDef \
ParsedSampleDef \
Writer \
WriterWrapper
WriterWrapper \
DataType \
VoidType \
SignatureSymbolVisitor \
SignatureSymbol \
TypeSymbol \
SampleSymbol \
NameSymbol \
SigPrimitiveType \
SigStructType \
SigField \
SigArrayType \
SigUserType
.PHONY: all
all: labcomm2014.jar
......
......@@ -10,18 +10,16 @@ import java.io.DataInputStream;
import java.io.IOException;
import java.io.EOFException;
import se.lth.control.labcomm2014.TypeDef;
import se.lth.control.labcomm2014.TypeDefParser;
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.Type;
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;
import se.lth.control.labcomm2014.compiler.UserType;
......@@ -39,13 +37,13 @@ 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 ASTbuilder implements TypeDefParser.ParsedSymbolVisitor {
public class ASTbuilder implements SignatureSymbolVisitor {
private LinkedList<Type> typeStack;
private LinkedList<DataType> typeStack;
private LinkedList<Field> fieldStack;
public ASTbuilder() {
this.typeStack = new LinkedList<Type>();
this.typeStack = new LinkedList<DataType>();
this.fieldStack = new LinkedList<Field>();
}
......@@ -58,19 +56,19 @@ public class ASTbuilder implements TypeDefParser.ParsedSymbolVisitor {
}
}
public void visit(TypeDefParser.TypeSymbol s){
public void visit(TypeSymbol s){
throw new Error("not implemented? needed?");
}
public void visit(TypeDefParser.SampleSymbol s){
public void visit(SampleSymbol s){
throw new Error("not implemented? needed?");
}
public void visit(TypeDefParser.NameSymbol s){
public void visit(NameSymbol s){
throw new Error("not implemented? needed?");
}
public void visit(TypeDefParser.PrimitiveType t){
public void visit(SigPrimitiveType t){
typeStack.push(new PrimType(t.getName(), t.getTag()));
}
......@@ -80,24 +78,24 @@ public class ASTbuilder implements TypeDefParser.ParsedSymbolVisitor {
// typeStack.push(new SampleRefType());
// }
public void visit(TypeDefParser.ParsedStructType t){
public void visit(SigStructType t){
if(t.isVoid()) {
typeStack.push(new VoidType());
} else {
List<Field> tmpF = new List<Field>();
for( TypeDefParser.ParsedField f : t.getFields()) {
for( SigField f : t.getFields()) {
f.accept(this);
tmpF.add(fieldStack.pop());
}
typeStack.push(new StructType(tmpF));
}
}
public void visit(TypeDefParser.ParsedField t){
public void visit(SigField 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){
public void visit(SigArrayType t){
boolean isFixed = true;
List<Exp> dim = new List<Exp>();
for(int i : t.getIdx()) {
......@@ -110,25 +108,25 @@ public class ASTbuilder implements TypeDefParser.ParsedSymbolVisitor {
}
t.getType().accept(this);
if(isFixed) {
typeStack.push(new FixedArrayType(typeStack.pop(), dim));
typeStack.push(new FixedArrayType(typeStack.pop(), new Dim(dim)));
} else {
typeStack.push(new VariableArrayType(typeStack.pop(), dim));
typeStack.push(new VariableArrayType(typeStack.pop(), new Dim(dim)));
}
}
public void visit(TypeDefParser.ParsedUserType t){
public void visit(SigUserType t){
typeStack.push(new UserType(t.getName()));
}
public Decl makeDecl(TypeDefParser.ParsedTypeDef d) {
public Decl makeDecl(SigTypeDef 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,33 +143,40 @@ public class ASTbuilder implements TypeDefParser.ParsedSymbolVisitor {
}
}
public Program makeProgram(TypeDefParser.ParsedTypeDef d) {
public Specification makeSpecification(SigTypeDef 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) {
public Decl makeDecl(SigSampleDef 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) {
assertStacksEmpty();
List<Decl> ds = new List<Decl>();
Iterator<TypeDefParser.ParsedTypeDef> it = d.getDepIterator();
private void addAllDeps(List<Decl> ds, SigTypeDef d) {
Iterator<SigTypeDef> it = d.getDepIterator();
while(it.hasNext()){
ds.add(makeDecl(it.next()));
SigTypeDef dd = it.next();
addAllDeps(ds,dd);
ds.add(makeDecl(dd));
}
}
public Specification makeSpecification(ParsedSampleDef d) {
assertStacksEmpty();
List<Decl> ds = new List<Decl>();
addAllDeps(ds, d);
ds.add(makeDecl(d));
assertStacksEmpty();
return createAndCheckProgram(ds);
return createAndCheckSpecification(ds);
}
}
package se.lth.control.labcomm2014;
import java.io.PrintStream;
import java.util.Iterator;
public abstract class DataType implements SignatureSymbol{
private final String name;
private final int typeTag;
public static String tagName(int typeTag) {
switch(typeTag) {
case Constant.BOOLEAN : return "boolean";
case Constant.BYTE : return "byte";
case Constant.SHORT : return "short";
case Constant.INT : return "int";
case Constant.LONG : return "long";
case Constant.FLOAT : return "float";
case Constant.DOUBLE : return "double";
case Constant.STRING : return "string";
case Constant.SAMPLE : return "sample";
}
throw new Error("not primitive type tag : " +Integer.toHexString(typeTag));
}
protected DataType(String name, int typeTag) {
this.name = name;
this.typeTag = typeTag;
}
// protected DataType(int typeTag) {
// this(tagName(typeTag), typeTag);
// }
//
public String getName() {
return name;
}
public int getTag() {
return typeTag;
}
public boolean isArray() {
return false;
}
public boolean isStruct(){
return false;
}
public boolean isUserType(){
return false;
}
public void addField(String name, DataType type) {
throw new Error("cannot add field to "+getClass().getSimpleName());
}
public final void print(PrintStream out) {
print(out, "");
}
public void print(PrintStream out, String indent) {
out.print(name);
}
private static void printDependencies(PrintStream out, SampleDispatcher sd, String indent) throws java.io.IOException {
Iterator<SampleDispatcher> it = sd.getDependencyIterator();
if(it.hasNext()) {
out.println(indent+"dependencies:");
}
while(it.hasNext()){
SampleDispatcher d = it.next();
printDataType(out, d, indent);
out.println(indent+"---");
}
}
public static void printDataType(PrintStream out, SampleDispatcher sd, String indent) throws java.io.IOException{
out.print(indent+"typedef ");
sd.getDataType().print(out,indent);
out.println(" "+sd.getName()+";");
printDependencies(out, sd, "...."+indent);
}
public static void printDataType(PrintStream out, SampleDispatcher sd) throws java.io.IOException{
printDataType(out, sd, "");
}
private static void printDependencies(PrintStream out, SigTypeDef td, String indent) throws java.io.IOException {
Iterator<SigTypeDef> it = td.getDepIterator();
if(it.hasNext()) {
out.println(indent+"dependencies:");
}
while(it.hasNext()){
SigTypeDef d = it.next();
printDataType(out, d, indent);
out.println(indent+"---");
}
}
public static void printDataType(PrintStream out, SigTypeDef d, String indent) throws java.io.IOException{
if(d==null) {
System.out.println("********* WARNING: printDataType(null)???");
return;
}
out.print(indent+d.defType()+" ");
d.getType().print(out,indent);
out.println(" "+d.getName()+";");
printDependencies(out, d, "...."+indent);
}
public static void printDataType(PrintStream out, SigTypeDef d) throws java.io.IOException{
printDataType(out, d, "");
}
}
......@@ -16,9 +16,33 @@ public class DecoderChannel implements Decoder {
this.in = new DataInputStream(in);
}
private byte[] decodeBytes() throws IOException {
int len = decodePacked32();
byte result[] = new byte[len];
for(int i=0; i<len; i++) {
result[i] = decodeByte();
}
return result;
}
private String decodeIntentions() throws IOException {
int numIntentions = decodePacked32();
String name = "";
for(int i = 0; i<numIntentions; i++) {
byte key[] = decodeBytes();
byte val[] = decodeBytes();
if(key.length == 0) {
name = new String(val);
}
}
return name;
}
private void processSampleDef() throws IOException {
int index = decodePacked32();
String name = decodeString();
String name = decodeIntentions();
int signature_length = decodePacked32();
byte[] signature = new byte[signature_length];
ReadBytes(signature, signature_length);
......@@ -27,7 +51,7 @@ public class DecoderChannel implements Decoder {
private void processSampleRef() throws IOException {
int index = decodePacked32();
String name = decodeString();
String name = decodeIntentions();
int signature_length = decodePacked32();
byte[] signature = new byte[signature_length];
ReadBytes(signature, signature_length);
......@@ -39,7 +63,7 @@ public class DecoderChannel implements Decoder {
processSample(Constant.TYPE_DEF);
} catch(Exception ex) {
int idx = decodePacked32();
String name = decodeString();
String name = decodeIntentions();
int siglen = decodePacked32();
for(int i=0; i<siglen; i++) {
byte b = decodeByte();
......
......@@ -46,7 +46,15 @@ public class EncoderChannel implements Encoder {
int index = sample_def_registry.add(dispatcher);
begin(dispatcher.getTypeDeclTag());
encodePacked32(index);
//HERE BE DRAGONS! numintentions does not include name
// encodePacked32(dispatcher.getNumIntentions()+1);
encodePacked32(1);
encodePacked32(0); // the empty key == name
encodeString(dispatcher.getName());
// byte[] intentions = dispatcher.getIntentionBytes();
// for (int k = 0 ; k < intentions.length ; k++) {
// encodeByte(intentions[k]);
// }
byte[] signature = dispatcher.getSignature();
encodePacked32(signature.length);
for (int i = 0 ; i < signature.length ; i++) {
......@@ -92,6 +100,10 @@ public class EncoderChannel implements Encoder {
begin(Constant.TYPE_DEF);
encodePacked32(index);
//HERE BE DRAGONS! numintentions does not include name
// encodePacked32(dispatcher.getNumIntentions()+1);
encodePacked32(1);
encodePacked32(0); // the empty key == name
encodeString(dispatcher.getName());
encodePacked32(b.length);
for(int i = 0; i<b.length; i++) {
......@@ -123,6 +135,10 @@ public class EncoderChannel implements Encoder {
int index = sample_ref_registry.add(dispatcher);
begin(Constant.SAMPLE_REF);
encodePacked32(index);
//HERE BE DRAGONS! numintentions does not include name
// encodePacked32(dispatcher.getNumIntentions()+1);
encodePacked32(1);
encodePacked32(0); // the empty key == name
encodeString(dispatcher.getName());
byte[] signature = dispatcher.getSignature();
encodePacked32(signature.length);
......
package se.lth.control.labcomm2014;
public class NameSymbol implements SignatureSymbol {
private String name;
public NameSymbol(String name) {
this.name = name;
}
public String toString() {
return name;
}
public void accept(SignatureSymbolVisitor v){
v.visit(this);
}
}
package se.lth.control.labcomm2014;
public class ParsedSampleDef extends ParsedTypeDef{
int idx;
ParsedSampleDef(ParsedTypeDef td) {
super(td);
}
@Override
public boolean isSampleDef() {
return true;
}
public String defType() {
return "sample";
}
}