Commit 7014aa3a authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

changed intention encoding to be struct {byte key[_] , byte val[_]}[_]

instead of just a string
parent 32370bb3
......@@ -16,3 +16,79 @@ aspect Annotations {
}
aspect SigAnnotations {
inh Decl TypeInstance.parentDecl();
coll Set Decl.allAnnotations() [new HashSet()] with add;
TypeInstance contributes getAnnotationString()
to Decl.allAnnotations()
for parentDecl();
public DocString.DocString(byte[] bs) {
super("DOCSTRING", bs);
}
public DocString.DocString(String s) {
super("DOCSTRING", s.getBytes());
}
public String Intention.toString() {
return "("+getKey() + ":"+new String(getValue())+")";
}
public String DocString.toString() {
return "\""+new String(getValue())+"\"";
}
syn boolean ASTNode.isTypeInstance() = false;
eq TypeInstance.isTypeInstance() = true;
/// TESTING
syn String Decl.getAnnotationString() {
StringBuilder sb = new StringBuilder();
Iterator<String> iti = allAnnotations().iterator();
while(iti.hasNext()) {
//Annotation i = iti.next();
//sb.append("("+i.getKey()+" : "+i.getValue()+") ");
String i = iti.next();
sb.append(i);
}
return sb.toString();
}
syn int TypeInstance.fooHash() {
List<Annotation> ints = getAnnotationList();
int result=0;
for(Annotation i : ints) {
if(i.isIntention()) {
result += i.toString().hashCode();
}
}
return result;
}
syn String TypeInstance.getAnnotationString() {
StringBuilder sb = new StringBuilder();
List<Annotation> ints = getAnnotationList();
for(Annotation i : ints) {
sb.append(i.toString());
}
return sb.toString();
}
public void Decl.debugAnnotations() {
getTypeInstance().debugAnnotations(getName());
}
public void TypeInstance.debugAnnotations(String context) {
if(hasAnnotations()){
System.out.println(context+".annotations: " + fooHash() + " : " + getAnnotationString());
} else {
//System.out.println(context + " : " + fooHash() + " : " + ": NO ANNOTATIONS ");
}
}
// TESTING END
}
......@@ -4,7 +4,7 @@ abstract Decl ::= TypeInstance /Signature/;
TypeInstance ::= DataType <Name:String> Annotation*;
Annotation ::= <Key:String> <Value:String>;
Annotation ::= <Key:String> <Value:byte[]>;
Intention : Annotation;
DocString : Annotation;
......@@ -22,7 +22,7 @@ abstract DataSignatureLine : SignatureLine;
ByteArraySignatureLine : DataSignatureLine ::= <Data:byte[]>;
IntSignatureLine : DataSignatureLine ::= <Data:int>;
StringSignatureLine : DataSignatureLine ::= <Data:String>;
IntentionSignatureLine : DataSignatureLine ::= <Data:java.util.Map> ;
IntentionSignatureLine : DataSignatureLine ::= Intention* ;
TypeRefSignatureLine : SignatureLine ::= Decl;
Field : TypeInstance;
......
......@@ -68,8 +68,8 @@ String key = IDENTIFIER;
String stringliteral = IDENTIFIER | QUOTEDSTRING;
Annotation annotation = intention.i | docstring.d;
Annotation intention = LPAREN key.k COLON stringliteral.v RPAREN {: return new Intention(k,v); :};
Annotation docstring = QUOTEDSTRING.s {: return new DocString(s.substring(1,s.length()-1)); :};
Annotation intention = LPAREN key.k COLON stringliteral.v RPAREN {: return new Intention(k,v.getBytes()); :};
Annotation docstring = QUOTEDSTRING.s {: return new DocString(s.substring(1,s.length()-1).getBytes()); :};
TypeInstance type_instance =
annotations.a type.t IDENTIFIER {: return new TypeInstance(t, IDENTIFIER, a); :}
......
This diff is collapsed.
aspect Encoding {
public class Utilities {
/* Size of packed32 variable */
public static int size_packed32(long data)
{
long d = data & 0xffffffff;
int result = 0;
int i;
for (i = 0 ; i == 0 || d != 0; i++, d = (d >>> 7)) {
result++;
}
return result;
}
public static int encodePacked32(long value, byte[] buf, int start, int len) {
int pos = start;
byte[] tmp = new byte[5];
long v = value & 0xffffffff;
int i;
for (i = 0 ; i == 0 || v != 0 ; i++, v = (v >> 7)) {
tmp[i] = (byte)(v & 0x7f);
}
if(i != len) {
throw new Error("wrong length, was: "+i+", expected "+len);
}
for (i = i - 1 ; i >= 0 ; i--) {
buf[pos++] = (byte)(tmp[i] | (i!=0?0x80:0x00));
}
return pos;
}
}
}
......@@ -8,7 +8,7 @@ typedef void avoid;
sample (function:"a trigger")(foo:bar) avoid doavoid;
sample (a:b) "A struct: an int and a ref." struct {
(c:d)(e:f) int x;
(e:f)(c:d) int x;
sample reference;
} intAndRef;
......@@ -29,9 +29,9 @@ typedef struct {
} foo;
sample struct {
line l1;
line l2;
foo f;
(name:l1)line l1;
(name:l2)line l2;
(b:"kalle anka")(c:hejdu)(a:"kalle anka")foo f;
} twoLines;
sample struct {
......
......@@ -547,6 +547,33 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
String getCurrentName() {
return current.getName();
}
String decodeIntentions() throws IOException {
int n = decodePacked32() & 0xffffffff;
if(n==0) return "";
StringBuilder sb = new StringBuilder();
for(int i=0; i<n;i++) {
sb.append("(");
int klen = decodePacked32() & 0xffffffff;
byte[] kchars = new byte[klen];
for(int k=0; k<klen; k++) {
kchars[k] = in.readByte();
}
sb.append(new String(kchars));
sb.append(":");
int vlen = decodePacked32() & 0xffffffff;
byte[] vchars = new byte[vlen];
for(int j=0; j<vlen; j++) {
vchars[j] = in.readByte();
}
sb.append(new String(vchars));
sb.append(")");
}
return sb.toString();
}
String decodeString() throws IOException {
int len = decodePacked32() & 0xffffffff;
......@@ -661,7 +688,7 @@ public class TypeDefParser implements TypeDef.Handler, TypeBinding.Handler {
private ParsedType parseType(ParserState in, boolean parseIntentions) throws IOException {
if(parseIntentions) {
String intentions = in.decodeString();
String intentions = in.decodeIntentions();
if(intentions.length()>0) {
System.out.println("parseType intentions ("+intentions);
} else {
......
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