From 52e78cef2e689738ed8e93a92f9b98dbf0e59d64 Mon Sep 17 00:00:00 2001 From: Sven Gestegard Robertz <sven.robertz@cs.lth.se> Date: Thu, 21 May 2015 13:20:27 +0200 Subject: [PATCH] WiP: refactoring to separate out 'outermost' intentions. tests broken --- compiler/2014/Annotations.jrag | 26 ++++++++++++++++++++++++++ compiler/2014/FlatSignature.jrag | 3 +-- compiler/2014/Java_CodeGen.jrag | 16 +++++++++++++++- compiler/2014/Signature.jrag | 11 ++--------- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/compiler/2014/Annotations.jrag b/compiler/2014/Annotations.jrag index 57c88d4..25e145d 100644 --- a/compiler/2014/Annotations.jrag +++ b/compiler/2014/Annotations.jrag @@ -36,6 +36,32 @@ aspect SigAnnotations { to Decl.allAnnotations() for parentDecl(); + // Helper attribute to get the "outermost" intentions for Decls + + syn byte[] TypeInstance.intentionBytes() = getIntentionBytes(sortedIntentions()); + syn byte[] Decl.getIntentionBytes() = getTypeInstance().intentionBytes(); + + static Comparator TypeInstance.intentionComp = + new Comparator<Intention>() { + public int compare(Intention i1, Intention i2) { + return i1.getKey().compareTo(i2.getKey()); + } + }; + + syn List<Intention> TypeInstance.sortedIntentions() { + List<Intention> res = new List<Intention>(); + + //TODO: refactor out creation of sorted list of intentions + + java.util.ArrayList<Intention> sorted = new ArrayList(intentionSet()); + java.util.Collections.sort(sorted, intentionComp); + for(Intention i : sorted) { + res.add(i); + } + return res; + } + + public DocString.DocString(byte[] bs) { super("DOCSTRING", bs); } diff --git a/compiler/2014/FlatSignature.jrag b/compiler/2014/FlatSignature.jrag index c3f92b3..42e768a 100644 --- a/compiler/2014/FlatSignature.jrag +++ b/compiler/2014/FlatSignature.jrag @@ -1,9 +1,8 @@ import java.util.*; -aspect NoIntentionForTypedefs { +aspect NoIntentionForTypeOrSampledefs { inh boolean TypeInstance.addIntentions(); eq Decl.getTypeInstance().addIntentions() = false; - eq SampleDecl.getTypeInstance().addIntentions() = true; eq StructType.getField(int i).addIntentions() = true; } diff --git a/compiler/2014/Java_CodeGen.jrag b/compiler/2014/Java_CodeGen.jrag index 6a042ed..3578002 100644 --- a/compiler/2014/Java_CodeGen.jrag +++ b/compiler/2014/Java_CodeGen.jrag @@ -464,6 +464,7 @@ aspect Java_Class { //for matching at the decoder side (which cannot know //the type_ids of dependent types. Therefore, flat sigs //are used for matching + Java_emitIntentions(env); Java_emitFlatSignature(env); if(isReferenced() || (isSampleDecl() && hasDependencies() )){ Signature signature = getSignature(); @@ -471,6 +472,20 @@ aspect Java_Class { } } + public void Decl.Java_emitIntentions(Java_env env){ + env.println("private static byte[] intentions = new byte[] {"); + env.indent(); + byte[] data = getIntentionBytes(); + if (data != null) { + for (int j = 0 ; j < data.length ; j++) { + env.print(data[j] + ", "); + } + } + env.unindent(); + env.println("};"); + env.println(); + } + public void Decl.Java_emitFlatSignature(Java_env env){ env.println("private static byte[] signature = new byte[] {"); env.indent(); @@ -491,7 +506,6 @@ aspect Java_Class { } env.unindent(); env.println("};"); - env.unindent(); env.println(); } diff --git a/compiler/2014/Signature.jrag b/compiler/2014/Signature.jrag index 7928697..bdad9bc 100644 --- a/compiler/2014/Signature.jrag +++ b/compiler/2014/Signature.jrag @@ -99,21 +99,14 @@ aspect Signature { return getIntBytes(getData(), version); } - private static Comparator SignatureList.intentionComp = - new Comparator<Intention>() { - public int compare(Intention i1, Intention i2) { - return i1.getKey().compareTo(i2.getKey()); - } - }; - public void SignatureList.addIntentions(Set<Intention> data, String comment) { //addString(TypeInstance.getIntentionString(data), comment); //create IntenionSignatureLine IntentionSignatureLine line = new IntentionSignatureLine(indent, comment, new List()); - //TODO: create sorted list of intentions + //TODO: refactor out creation of sorted list of intentions java.util.ArrayList<Intention> sorted = new ArrayList(data); - java.util.Collections.sort(sorted, intentionComp); + java.util.Collections.sort(sorted, TypeInstance.intentionComp); for(Intention i : sorted) { line.addIntention(i); } -- GitLab