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

Target

Select target project
  • anders_blomdell/labcomm
  • klaren/labcomm
  • tommyo/labcomm
  • erikj/labcomm
  • sven/labcomm
5 results
Show changes
Showing
with 1195 additions and 2 deletions
package se.lth.control.labcomm2014;
public interface Sample extends SampleType {
public SampleDispatcher getDispatcher();
}
package se.lth.control.labcomm2014;
import java.util.Iterator;
import java.io.IOException;
public interface SampleDispatcher <T extends SampleType>{
public Class<T> getSampleClass();
public String getName();
public byte[] getSignature();
public int getNumIntentions();
public byte[] getIntentionBytes();
public void decodeAndHandle(Decoder decoder,
SampleHandler handler) throws Exception;
/** @return true if the type depends on one or more typedefs
*/
public boolean hasDependencies();
public void encodeTypeDef(Encoder e, int index) throws IOException;
/** return the tag SAMPLE_DEF or TYPE_DEF, for use
* by encoder.register.
* TODO: refactor types, moving this to a super-interface
* applicable to both type and sample defs.
*/
public byte getTypeDeclTag();
public void registerTypeDeps(Encoder e) throws IOException;
public Iterator<SampleDispatcher> getDependencyIterator();
public DataType getDataType();
}
package se.lth.control.labcomm2014;
public interface SampleHandler {
}
package se.lth.control.labcomm2014;
public class SampleSymbol implements SignatureSymbol {
public String toString() {
return "sample ";
}
public void accept(SignatureSymbolVisitor v){
v.visit(this);
}
}
package se.lth.control.labcomm2014;
public interface SampleType {
}
package se.lth.control.labcomm2014;
import java.io.PrintStream;
public class SigArrayType extends DataType {
private int idx[];
private DataType type;
public SigArrayType(DataType elementType, int idx[]) {
super("array", Constant.ARRAY);
this.idx = idx;
this.type = elementType;
}
public DataType getType() {
return type;
}
public int[] getIdx() {
return idx;
}
public boolean isArray() {
return true;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(type.toString());
for(int i : idx) {
sb.append("["+(i>0 ? i : "_")+"]");
}
return sb.toString();
}
public void accept(SignatureSymbolVisitor v) {
v.visit(this);
}
public void print(PrintStream out, String indent) {
type.print(out,indent);
out.print("[");
for(int i =0; i<idx.length;i++) {
int d = idx[i];
out.print( (d==-1?"-":d));
if(i<idx.length-1) {
out.print(", ");
}
}
out.print("]");
}
}
package se.lth.control.labcomm2014;
import java.io.PrintStream;
public class SigField implements SignatureSymbol{
private DataType type;
private String name;
SigField(String name, DataType type) {
this.name = name;
this.type = type;
}
public DataType getType() {
return type;
}
public String getName() {
return name;
}
public String toString() {
return type.toString() + " " + name;
}
public void accept(SignatureSymbolVisitor v) {
v.visit(this);
}
public void print(PrintStream out, String indent) {
type.print(out, indent);
out.println(" "+name+";");
}
}
package se.lth.control.labcomm2014;
public class SigPrimitiveType extends DataType {
public SigPrimitiveType(int tag) {
super(tagName(tag), tag);
}
public void accept(SignatureSymbolVisitor v) {
v.visit(this);
}
public String toString() {
return getName();}
}
package se.lth.control.labcomm2014;
public class SigSampleDef extends SigTypeDef{
SigSampleDef(SigTypeDef td) {
super(td.getName(), td.getType());
}
@Override
public boolean isSampleDef() {
return true;
}
public String defType() {
return "sample";
}
}
package se.lth.control.labcomm2014;
import java.io.PrintStream;
import java.util.List;
import java.util.LinkedList;
import java.util.Iterator;
public class SigStructType extends DataType {
private List<SigField> fields;
SigStructType(int nSigFields) {
super("struct", Constant.STRUCT);
this.fields = new LinkedList<SigField>();
}
public SigStructType() {
this("struct");
}
protected SigStructType(String name) {
super(name, Constant.STRUCT);
this.fields = new LinkedList<SigField>();
}
public SigField[] getFields() {
return fields.toArray(new SigField[0]);
}
public Iterator<SigField> getFieldIterator() {
return fields.iterator();
}
public void addField(String name, DataType type) {
fields.add(new SigField(name, type));
}
public void addField(SigField f) {
fields.add(f);
}
public boolean isStruct() {
return true;
}
public boolean isVoid() {
return fields.size() == 0;
}
public String toString() {
if(isVoid()) { //void type is empty struct
return "void";
} else {
StringBuilder sb = new StringBuilder();
sb.append("struct {\n");
for(SigField f : fields) {
sb.append(f.toString());
sb.append(";\n");
}
sb.append("}");
return sb.toString();
}
}
public void accept(SignatureSymbolVisitor v) {
v.visit(this);
}
public void print(PrintStream out, String indent) {
out.println("struct {");
String newIndent=indent+" ";
out.print(newIndent);
Iterator<SigField> it = getFieldIterator();
while(it.hasNext()) {
it.next().print(out, newIndent);
if(it.hasNext()) {
out.print(newIndent);
}
}
out.print(indent+"}");
}
}
package se.lth.control.labcomm2014;
import java.util.HashSet;
import java.util.Iterator;
public class SigTypeDef{
private String name;
private DataType type;
protected HashSet<SigTypeDef> deps;
SigTypeDef(SigTypeDef td) {
this(td.getName(), td.getType());
this.deps = new HashSet<SigTypeDef>(td.deps);
}
SigTypeDef( String name){
this.name = name;
this.deps = new HashSet<SigTypeDef>();
}
SigTypeDef(String name, DataType type) {
this(name);
this.type = type;
}
void addDependency(SigTypeDef d) {
deps.add(d);
}
HashSet<SigTypeDef> getDependencies() {
return deps;
}
Iterator<SigTypeDef> getDepIterator() {
return deps.iterator();
}
/** To be overridden in SigSampleDef
*/
public boolean isSampleDef() {
return false;
}
public String defType() {
return "typedef";
}
void setType(DataType type) {
this.type = type;
}
public DataType getType() {
if(type==null) {
System.out.println("******** WARNING! SigTypeDef.getType returning null");
}
return type;
}
int getIndex() {
return 0;
}
public String getName() {
return name;
}
public String toString() {
return type.toString();
}
public int hashCode() {
return name.hashCode();
}
public boolean equals(Object o) {
if(! (o instanceof SigTypeDef)){
return false;
} else {
SigTypeDef other = (SigTypeDef) o;
return other.getIndex() == getIndex() && other.name.equals(name);
}
}
public void accept(SignatureSymbolVisitor v) {
type.accept(v);
}
}
package se.lth.control.labcomm2014;
public class SigUserType extends DataType {
public String toString() {
return getName();
}
public SigUserType(String name) {
super(name, 0);
}
public boolean isUserType() {
return true;
}
public void accept(SignatureSymbolVisitor v) {
v.visit(this);
}
}
package se.lth.control.labcomm2014;
public interface SignatureSymbol{
public void accept(SignatureSymbolVisitor v);
}
package se.lth.control.labcomm2014;
/* An interface for using Visitor pattern to traverse
* the type tree
*/
public interface SignatureSymbolVisitor {
void visit(TypeSymbol s);
void visit(SampleSymbol s);
void visit(NameSymbol s);
void visit(SigPrimitiveType t);
//sampleRefs are sent as primitive types
//Put this back if that is changed to SampleRefType
//void visit(SampleRefType t);
void visit(SigStructType t);
void visit(SigField t);
void visit(SigArrayType t);
void visit(SigUserType t);
}
package se.lth.control.labcomm2014;
import java.io.IOException;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.util.Iterator;
import java.util.NoSuchElementException;
import se.lth.control.labcomm2014.Decoder;
import se.lth.control.labcomm2014.DecoderChannel;
import se.lth.control.labcomm2014.SampleDispatcher;
import se.lth.control.labcomm2014.SampleHandler;
public class TypeBinding implements BuiltinType {
private int sampleIndex;
private int typeIndex;
public TypeBinding(int sampleIndex, int typeIndex) {
this.sampleIndex = sampleIndex;
this.typeIndex = typeIndex;
}
public int getSampleIndex() {
return sampleIndex;
}
public int getTypeIndex() {
return typeIndex;
}
public boolean isSelfBinding() {
return typeIndex == Constant.TYPE_BIND_SELF;
}
public interface Handler extends SampleHandler {
public void handle_TypeBinding(TypeBinding value) throws Exception;
}
public static void register(Decoder d, Handler h) throws IOException {
d.register(Dispatcher.singleton(), h);
}
public static void register(Encoder e) throws IOException {
register(e,false);
}
public static void register(Encoder e, boolean sendMetaData) throws IOException {
throw new IOException("cannot send TypeDefs");
}
static class Dispatcher implements SampleDispatcher<TypeBinding> {
private static Dispatcher singleton;
public synchronized static Dispatcher singleton() {
if(singleton==null) singleton=new Dispatcher();
return singleton;
}
public Class<TypeBinding> getSampleClass() {
return TypeBinding.class;
}
public String getName() {
return "TypeBinding";
}
public byte getTypeDeclTag() {
throw new Error("Should not be called");
}
public boolean isSample() {
throw new Error("Should not be called");
}
public boolean hasStaticSignature() {
throw new Error("Should not be called");
}
public byte[] getSignature() {
return null; // not used for matching
}
public int getNumIntentions() {
return 0;
}
public byte[] getIntentionBytes() {
return null; // not used for matching
}
public void encodeTypeDef(Encoder e, int index) throws IOException{
throw new Error("Should not be called");
}
public void registerTypeDeps(Encoder e) throws IOException{
throw new Error("Should not be called");
}
public void decodeAndHandle(Decoder d,
SampleHandler h) throws Exception {
((Handler)h).handle_TypeBinding(TypeBinding.decode(d));
}
public boolean hasDependencies() {
return false;
}
public Iterator<SampleDispatcher> getDependencyIterator() {
return new Iterator<SampleDispatcher>() {
public boolean hasNext() {
return false;
}
public SampleDispatcher next() throws NoSuchElementException {
throw new NoSuchElementException();
}
public void remove() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
};
}
public DataType getDataType() {
throw new Error("not implemented");
}
}
public static void encode(Encoder e, TypeBinding value) throws IOException {
throw new Error("Should not be called");
}
/* HERE BE DRAGONS!
* This exposes (and relies on the stability of) indices that are
* internal to a decoder.
*
* The SAMPLE_DEF and TYPE_DEF must already have been received for the
* indices to be known, so this can be changed to instead return
* references to the SampleDispactcher corresponding to the sample type
* and the matching TypeDef.
*
* Sketch:
*
* SampleDispatcher sd = d.getDispatcherForId(sampleIndex);
* TypeDef td = d.getTypeDefForId(typeIndex);
*
* return new TypeBinding(sd, td);
*
* assuming that the Decoder keeps a registry for TypeDefs
*/
public static TypeBinding decode(Decoder d) throws IOException {
TypeBinding result;
int sampleIndex = d.decodePacked32();
int typeIndex = d.decodePacked32();
result = new TypeBinding(sampleIndex, typeIndex);
return result;
}
}
package se.lth.control.labcomm2014;
import java.io.IOException;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.util.Iterator;
import java.util.NoSuchElementException;
import se.lth.control.labcomm2014.Decoder;
import se.lth.control.labcomm2014.DecoderChannel;
import se.lth.control.labcomm2014.SampleDispatcher;
import se.lth.control.labcomm2014.SampleHandler;
public class TypeDef implements BuiltinType {
private int index;
private String name;
private byte signature[];
public int getIndex() {
return index;
}
public String getName() {
return name;
}
public String toString() {
return getName();
}
public byte[] getSignature() {
return signature;
}
public void dump() {
System.out.print("=== TypeDef "+getName()+"( "+Integer.toHexString(getIndex())+") : ");
for (byte b : signature) {
System.out.print(String.format("0x%02X ", b));
}
System.out.println();
}
public interface Handler extends SampleHandler {
public void handle_TypeDef(TypeDef value) throws Exception;
}
public static void register(Decoder d, Handler h) throws IOException {
d.register(Dispatcher.singleton(), h);
}
public static void register(Encoder e) throws IOException {
register(e,false);
}
public static void register(Encoder e, boolean sendMetaData) throws IOException {
throw new IOException("cannot send TypeDefs");
}
static class Dispatcher implements SampleDispatcher<TypeDef> {
private static Dispatcher singleton;
public synchronized static Dispatcher singleton() {
if(singleton==null) singleton=new Dispatcher();
return singleton;
}
public Class<TypeDef> getSampleClass() {
return TypeDef.class;
}
public String getName() {
return "TypeDef";
}
public byte getTypeDeclTag() {
throw new Error("Should not be called");
}
public boolean isSample() {
throw new Error("Should not be called");
}
public boolean hasStaticSignature() {
throw new Error("Should not be called");
}
/** return the flat signature. Intended use is on decoder side */
public byte[] getSignature() {
return null; // not used for matching
}
public int getNumIntentions() {
return 0;
}
public byte[] getIntentionBytes() {
return new byte[0];
}
public void encodeTypeDef(Encoder e, int index) throws IOException{
throw new Error("Should not be called");
}
public void registerTypeDeps(Encoder e) throws IOException{
throw new Error("Should not be called");
}
// public boolean canDecodeAndHandle() {
// return true;
// }
public void decodeAndHandle(Decoder d,
SampleHandler h) throws Exception {
((Handler)h).handle_TypeDef(TypeDef.decode(d));
}
public boolean hasDependencies() {
return false;
}
public Iterator<SampleDispatcher> getDependencyIterator() {
return new Iterator<SampleDispatcher>() {
public boolean hasNext() {
return false;
}
public SampleDispatcher next() throws NoSuchElementException {
throw new NoSuchElementException();
}
public void remove() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
};
}
public DataType getDataType() {
throw new Error("not implemented");
}
}
public static void encode(Encoder e, TypeDef value) throws IOException {
throw new Error("Should not be called");
}
protected TypeDef() {
}
public TypeDef(int index, String name, byte sig[]) {
this.index = index;
this.name = name;
this.signature = sig;
}
public static TypeDef decode(Decoder d) throws IOException {
TypeDef result;
int index = d.decodePacked32();
int numIntentions = d.decodePacked32();
if(numIntentions != 1) {
System.out.println("WARNING: #intentions == "+numIntentions);
}
int keylen = d.decodePacked32();
if(keylen != 0) {
System.out.println("WARNING: keylen == "+keylen);
}
String name = d.decodeString();
int siglen= d.decodePacked32();
byte sig[] = new byte[siglen];
for(int i=0; i<siglen;i++){
sig[i] = d.decodeByte();
}
result = new TypeDef(index, name, sig);
return result;
}
}
package se.lth.control.labcomm2014;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.EOFException;
import se.lth.control.labcomm2014.Decoder;
import se.lth.control.labcomm2014.DecoderChannel;
import se.lth.control.labcomm2014.TypeDef;
import se.lth.control.labcomm2014.TypeBinding;
public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
static class SelfBinding extends TypeDef {
private int sampleIndex;
private Decoder decoder;
private byte[] dummy = new byte[0];
public String toString() {return "self";}
public String getName() {
if(decoder instanceof DecoderChannel) {
DecoderChannel dc = (DecoderChannel) decoder;
return dc.getSampleName(sampleIndex);
} else {
return "self";
}
}
public int getIndex() {return 0;}
public byte[] getSignature() {
if(decoder instanceof DecoderChannel) {
DecoderChannel dc = (DecoderChannel) decoder;
return dc.getSampleSignature(sampleIndex);
} else {
return dummy;
}
}
public SelfBinding(int sampleIndex, Decoder decoder) {
super();
this.sampleIndex = sampleIndex;
this.decoder = decoder;
}
}
public interface TypeDefListener {
void onTypeDef(SigTypeDef d);
}
private HashMap<Integer,TypeDef> typeDefs;
private HashMap<Integer,Integer> typeBindings;
private HashSet<TypeDefListener> listeners;
private LinkedList<ParsedSampleDef> sampleDefs;
private HashMap<Integer,ParsedTypeDef> pts;
private Decoder decoder;
protected TypeDefParser(Decoder d) {
this.decoder = d;
typeDefs = new HashMap<Integer,TypeDef>();
typeBindings = new HashMap<Integer,Integer>();
listeners = new HashSet<TypeDefListener>();
sampleDefs = new LinkedList<ParsedSampleDef>();
pts = new HashMap<Integer,ParsedTypeDef>();
}
public void addListener(TypeDefListener l) {
listeners.add(l);
}
public Iterator<ParsedSampleDef> sampleDefIterator() {
return sampleDefs.iterator();
}
public void handle_TypeDef(TypeDef d) throws java.io.IOException {
System.out.println("handle_TypeDef: "+d.getIndex());
typeDefs.put(d.getIndex(), d);
ParsedTypeDef td = parseSignatureTD(d);
pts.put(d.getIndex(), td);
}
public void handle_TypeBinding(TypeBinding d) throws java.io.IOException {
TypeDef td;
if(d.isSelfBinding()){
td = new SelfBinding(d.getSampleIndex(), decoder);
} else {
typeBindings.put(d.getSampleIndex(), d.getTypeIndex());
td = getTypeDefForIndex(d.getSampleIndex());
}
System.out.println("handle_TypeBinding: "+d.getSampleIndex());
ParsedSampleDef result = parseSignature(td);
sampleDefs.add(result);
Iterator<TypeDefListener> it = listeners.iterator();
while(it.hasNext()){
notifyListener(it.next(), result);
}
}
private void notifyListener(TypeDefListener l, ParsedTypeDef d) {
l.onTypeDef(d);
if(d instanceof ParsedSampleDef) {
for(SigTypeDef dep : ((ParsedSampleDef)d).getDependencies()) {
//do we want to change ParseTypeDef to have dependencies,
//and do recursion here?
//if so, do notifyListener(l, dep);
l.onTypeDef(dep);
}
}
}
private TypeDef getTypeDefForIndex(int sampleIndex) {
return typeDefs.get(typeBindings.get(sampleIndex));
}
/** Factory method for use by application programs:
* registers a TypeDefParser for handling TypeDef and TypeBinding
* on the Decoder d.
*
* @return a new TypeDefParser registered on d
*/
public static TypeDefParser registerTypeDefParser(Decoder d) throws java.io.IOException {
TypeDefParser res = new TypeDefParser(d);
TypeDef.register(d,res);
TypeBinding.register(d,res);
return res;
}
public LinkedList<SignatureSymbol> symbolify() {
LinkedList<SignatureSymbol> result = new LinkedList<SignatureSymbol>();
Iterator<ParsedSampleDef> sdi = sampleDefIterator();
while(sdi.hasNext()) {
SigTypeDef sd = sdi.next();
result.add(new SampleSymbol());
result.add(sd.getType());
result.add(new NameSymbol(sd.getName()));
Iterator<SigTypeDef> di = sd.getDepIterator();
while(di.hasNext()) {
SigTypeDef d = di.next();
result.add(new TypeSymbol());
result.add(d.getType());
result.add(new NameSymbol(d.getName()));
}
}
return result;
}
public String symbolString() {
Iterator<SignatureSymbol> i = symbolify().iterator();
StringBuilder sb = new StringBuilder();
while(i.hasNext()) {
sb.append(i.next().toString());
}
return sb.toString();
}
// SampleRefType currently not sent, se above
// public class SampleRefType extends DataType {
// public void accept(SignatureSymbolVisitor v) {
// v.visit(this);
// }
//
// public String toString() {
// return "sample";}
// }
private class ParserState {
private ByteArrayInputStream bis;
private DataInputStream in;
private TypeDef current;
private ParsedTypeDef currentParsed;
private LinkedList<TypeDef> typeStack;
ParsedTypeDef newTypeDef() {
currentParsed =new ParsedTypeDef(getCurrentIndex(), getCurrentName());
return currentParsed;
}
private ParserState() {
typeStack = new LinkedList<TypeDef>();
}
ParserState(int typeIdx) {
this();
pushType(typeIdx);
}
ParserState(TypeDef td) {
this();
pushType(td);
}
ParserState(byte sig[]) {
this();
bis= new ByteArrayInputStream(sig);
in = new DataInputStream(bis);
}
void pushType(TypeDef td) {
if(!typeStack.contains(td)) {
typeStack.push(td);
}
}
void pushType(int typeIdx) {
if(typeIdx >= 0x40 && !typeStack.contains(typeIdx)) {
typeStack.push(typeDefs.get(typeIdx));
}
}
void popType() {
TypeDef td2 = typeStack.pop();
current = td2;
bis =new ByteArrayInputStream(td2.getSignature());
in = new DataInputStream(bis);
}
boolean moreTypes() {
return !typeStack.isEmpty();
}
int getCurrentIndex() {
return current.getIndex();
}
String getCurrentName() {
return current.getName();
}
void addTypeUse(int tag) {
SigTypeDef td = pts.get(tag);
if(td != null) {
currentParsed.addDependency(td);
} else {
System.out.println("******* WARNING: TypeDefParser:addTypeUse ("+tag+"): null???");
}
}
/** return name, (if any, or "") for now */
String decodeIntentions() throws IOException {
int n = decodePacked32() & 0xffffffff;
if(n==0) return "";
String name = "";
for(int i=0; i<n;i++) {
int klen = decodePacked32() & 0xffffffff;
byte[] kchars = new byte[klen];
for(int k=0; k<klen; k++) {
kchars[k] = in.readByte();
}
int vlen = decodePacked32() & 0xffffffff;
byte[] vchars = new byte[vlen];
for(int j=0; j<vlen; j++) {
vchars[j] = in.readByte();
}
if(klen==0) {
name = new String(vchars);
}
}
return name;
}
String decodeString() throws IOException {
int len = decodePacked32() & 0xffffffff;
byte[] chars = new byte[len];
for(int i=0; i<len; i++) {
chars[i] = in.readByte();
}
return new String(chars);
}
int decodePacked32() throws IOException {
long res=0;
byte i=0;
boolean cont=true;
do {
byte c = in.readByte();
res = (res << 7) | (c & 0x7f);
cont = (c & 0x80) != 0;
i++;
} while(cont);
return (int) (res & 0xffffffff);
}
void skipBytes(int len) throws IOException {
for(int i=0; i<len; i++) {
in.readByte();
}
}
}
private ParsedTypeDef parseSignatureTD(TypeDef td) throws IOException{
return parseSignatureTD(td, new ParserState(td));
}
private ParsedTypeDef parseSignatureTD(TypeDef td, ParserState s) throws IOException{
ParsedTypeDef result=null;
s.popType();
result = parseTypeDef(s);
return result;
}
public ParsedSampleDef parseSignature(TypeDef td) throws IOException{
ParserState s = new ParserState(td);
ParsedSampleDef result=null;
try {
result = new ParsedSampleDef(parseSignatureTD(td,s));
// while(s.moreTypes()) {
// s.popType();
// result.addDependency(parseTypeDef(s));
// }
} catch(java.io.EOFException ex) {
System.out.println("EOF: self_binding");
}
return result;
}
private SigArrayType parseArray(ParserState in) throws IOException {
int numIdx = in.decodePacked32();
int idx[] = new int[numIdx];
for(int i=0; i<numIdx; i++){
idx[i] = in.decodePacked32();
}
int type = in.decodePacked32();
DataType elementType = lookupType(type, in);
SigArrayType result = new SigArrayType(elementType, idx);
for(int i=0; i<numIdx; i++){
idx[i] = in.decodePacked32();
}
return result;
}
private SigStructType parseStruct(ParserState in) throws IOException {
int numSigFields = in.decodePacked32();
SigStructType result = new SigStructType(numSigFields);
for(int i=0; i<numSigFields; i++) {
result.addField(parseSigField(in));
}
return result;
}
private SigField parseSigField(ParserState in) throws IOException {
String name = in.decodeIntentions();
return new SigField(name, parseType(in, false));
}
private DataType lookupType(int tag, ParserState in) {
DataType result;
if(tag >= Constant.FIRST_USER_INDEX) {
TypeDef td = typeDefs.get(tag);
result = new SigUserType(td.getName());
in.addTypeUse(tag);
in.pushType(tag);
// sampleRefs are sent as primitive types, see above
// } else if(tag == Constant.SAMPLE) {
// result = new SampleRefType();
} else {
result = new SigPrimitiveType(tag);
}
return result;
}
private ParsedSampleDef parseSampleTypeDef(ParserState in) throws IOException {
ParsedTypeDef td = parseTypeDef(in, true);
return new ParsedSampleDef(td);
}
private ParsedTypeDef parseTypeDef(ParserState in) throws IOException {
return parseTypeDef(in, false);
}
private void addParsedTypeDef(ParsedTypeDef td) {
int idx = td.getIndex();
if(idx>=0x40) {
pts.put(idx, td);
}
}
private ParsedTypeDef parseTypeDef(ParserState in, boolean parseIntentions) throws IOException {
ParsedTypeDef result = in.newTypeDef();
result.setType(parseType(in, false));
addParsedTypeDef(result);
return result;
}
private DataType parseType(ParserState in, boolean parseIntentions) throws IOException {
if(parseIntentions) {
String intentions = in.decodeIntentions();
if(intentions.length()>0) {
System.out.println("parseType intentions ("+intentions);
} else {
System.out.println("no intentions");
}
} else {
// System.out.println("not parsing intentions");
}
int tag = in.decodePacked32();
DataType result = null;
switch(tag) {
case 0:
System.out.println("SELF");
break;
case Constant.ARRAY:
result = parseArray(in);
break;
case Constant.STRUCT:
result = parseStruct(in);
break;
default:
result = lookupType(tag, in);
break;
}
return result;
}
}
package se.lth.control.labcomm2014;
public class TypeSymbol implements SignatureSymbol {
public String toString() {
return "typedef ";
}
public void accept(SignatureSymbolVisitor v){
v.visit(this);
}
}
package se.lth.control.labcomm2014;
import java.io.PrintStream;
public class VoidType extends SigStructType{
public VoidType() {
super("void");
}
public void print(PrintStream out, String indent) {
out.print("void");
}
}
package se.lth.control.labcomm;
package se.lth.control.labcomm2014;
import java.io.IOException;
public interface LabCommWriter {
public interface Writer {
public void write(byte[] data) throws IOException;
......