Skip to main content
Sign in
Snippets Groups Projects
Commit eccd4e90 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

Passes tests for files without intentions

parent be3a4abc
Branches
No related tags found
No related merge requests found
...@@ -34,12 +34,12 @@ public class Decoder ...@@ -34,12 +34,12 @@ public class Decoder
theSecondInt.register(decoder, this); theSecondInt.register(decoder, this);
intAndRef.register(decoder, this); intAndRef.register(decoder, this);
doavoid.registerSampleRef(decoder); 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);
tdp.addListener(this); // tdp.addListener(this);
try { try {
System.out.println("Running decoder."); System.out.println("Running decoder.");
... ...
......
typedef struct { typedef struct {
(foo:bar) int val; int val;
} coord; } coord;
typedef int anInt; typedef int anInt;
typedef void avoid; typedef void avoid;
sample (function:trigger)(foo:bar) avoid doavoid; sample avoid doavoid;
sample (a:b) "a struct with an int and a ref" struct { sample struct {
(c:d)(e:f) int x; int x;
sample reference; sample reference;
} intAndRef; } intAndRef;
... ...
......
File changed. Contains only whitespace changes. Show whitespace changes.
...@@ -569,6 +569,12 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler { ...@@ -569,6 +569,12 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
return (int) (res & 0xffffffff); return (int) (res & 0xffffffff);
} }
void skipBytes(int len) throws IOException {
for(int i=0; i<len; i++) {
in.readByte();
}
}
} }
public ParsedSampleDef parseSignature(TypeDef td) throws IOException{ public ParsedSampleDef parseSignature(TypeDef td) throws IOException{
...@@ -642,6 +648,13 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler { ...@@ -642,6 +648,13 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
return result; return result;
} }
private ParsedType parseType(ParserState in) throws IOException { private ParsedType parseType(ParserState in) throws IOException {
String intentions = in.decodeString();
if(intentions.length()>0) {
System.out.println("parseType intentions ("+intentions);
} else {
System.out.println("no intentions");
}
int tag = in.decodePacked32(); int tag = in.decodePacked32();
ParsedType result = null; ParsedType result = null;
switch(tag) { switch(tag) {
... ...
......
...@@ -403,6 +403,7 @@ class sampledef_or_sampleref_or_typedef(type_decl): ...@@ -403,6 +403,7 @@ class sampledef_or_sampleref_or_typedef(type_decl):
e1.encode_type(self.get_index(encoder)) e1.encode_type(self.get_index(encoder))
e1.encode_string(self.name) e1.encode_string(self.name)
with length_encoder(e1) as e2: with length_encoder(e1) as e2:
self.encode_empty_intentions(e2)
self.decl.encode_decl(e2) self.decl.encode_decl(e2)
def encode(self, encoder, value): def encode(self, encoder, value):
...@@ -413,6 +414,7 @@ class sampledef_or_sampleref_or_typedef(type_decl): ...@@ -413,6 +414,7 @@ class sampledef_or_sampleref_or_typedef(type_decl):
name = decoder.decode_string() name = decoder.decode_string()
if usePacketLength(decoder.version): if usePacketLength(decoder.version):
length = decoder.decode_packed32() length = decoder.decode_packed32()
self.decode_intentions(decoder)
decl = decoder.decode_decl() decl = decoder.decode_decl()
result = self.__class__.__new__(self.__class__) result = self.__class__.__new__(self.__class__)
result.__init__(name=name, decl=decl) result.__init__(name=name, decl=decl)
...@@ -454,6 +456,11 @@ class sample_def(sampledef_or_sampleref_or_typedef): ...@@ -454,6 +456,11 @@ class sample_def(sampledef_or_sampleref_or_typedef):
def rename(self, name): def rename(self, name):
return sample_def(name=name, decl=self.decl) return sample_def(name=name, decl=self.decl)
def decode_intentions(self, d):
return d.decode_string()
def encode_empty_intentions(self, e):
e.encode_empty_intentions()
class sample_ref(sampledef_or_sampleref_or_typedef): class sample_ref(sampledef_or_sampleref_or_typedef):
type_index = i_SAMPLE_REF type_index = i_SAMPLE_REF
...@@ -467,6 +474,12 @@ class sample_ref(sampledef_or_sampleref_or_typedef): ...@@ -467,6 +474,12 @@ class sample_ref(sampledef_or_sampleref_or_typedef):
else: else:
self.sample = sample self.sample = sample
def decode_intentions(self, d):
return d.decode_string()
def encode_empty_intentions(self, e):
e.encode_empty_intentions()
def get_index(self, encoder): def get_index(self, encoder):
return encoder.ref_to_index[self.sample] return encoder.ref_to_index[self.sample]
...@@ -477,6 +490,12 @@ class typedef(sampledef_or_sampleref_or_typedef): ...@@ -477,6 +490,12 @@ class typedef(sampledef_or_sampleref_or_typedef):
type_index = i_TYPE_DEF type_index = i_TYPE_DEF
type_name = 'typedef' type_name = 'typedef'
def decode_intentions(self, d):
pass
def encode_empty_intentions(self, e):
pass
def encode_decl(self, encoder): def encode_decl(self, encoder):
self.decl.encode_decl(encoder) self.decl.encode_decl(encoder)
...@@ -628,6 +647,7 @@ class struct(type_decl): ...@@ -628,6 +647,7 @@ class struct(type_decl):
encoder.encode_type(i_STRUCT) encoder.encode_type(i_STRUCT)
encoder.encode_packed32(len(self.field)) encoder.encode_packed32(len(self.field))
for (name, decl) in self.field: for (name, decl) in self.field:
encoder.encode_empty_intentions()
encoder.encode_string(name) encoder.encode_string(name)
encoder.encode_type_number(decl) encoder.encode_type_number(decl)
...@@ -643,6 +663,7 @@ class struct(type_decl): ...@@ -643,6 +663,7 @@ class struct(type_decl):
n_field = decoder.decode_packed32() n_field = decoder.decode_packed32()
field = [] field = []
for i in range(n_field): for i in range(n_field):
intentions = decoder.decode_intentions()
name = decoder.decode_string() name = decoder.decode_string()
decl = decoder.decode_decl() decl = decoder.decode_decl()
field.append((name, decl)) field.append((name, decl))
...@@ -870,6 +891,10 @@ class Encoder(Codec): ...@@ -870,6 +891,10 @@ class Encoder(Codec):
self.encode_packed32(len(s)); self.encode_packed32(len(s));
self.pack("%ds" % len(s),s) self.pack("%ds" % len(s),s)
def encode_empty_intentions(self):
# pass
self.encode_string("")
class Decoder(Codec): class Decoder(Codec):
def __init__(self, reader, version=DEFAULT_VERSION): def __init__(self, reader, version=DEFAULT_VERSION):
super(Decoder, self).__init__() super(Decoder, self).__init__()
...@@ -1001,6 +1026,9 @@ class Decoder(Codec): ...@@ -1001,6 +1026,9 @@ class Decoder(Codec):
index = self.decode_int() index = self.decode_int()
return self.index_to_ref.get(index, None) return self.index_to_ref.get(index, None)
def decode_intentions(self):
return self.decode_string()
class signature_reader: class signature_reader:
def __init__(self, signature): def __init__(self, signature):
self.signature = packer.pack("!%db" % len(signature), *signature) self.signature = packer.pack("!%db" % len(signature), *signature)
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment