Skip to content

Commit bbcd122

Browse files
committed
fix issue #159, also modified BoaJava.stg, passed all tests
1 parent 279ea24 commit bbcd122

File tree

9 files changed

+56
-56
lines changed

9 files changed

+56
-56
lines changed

src/java/boa/aggregators/GraphAggregator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public abstract class GraphAggregator extends Aggregator {
4040
public void start(final EmitKey key) {
4141
super.start(key);
4242

43-
this.neighbors = new HashSet<String>();
43+
this.neighbors = new LinkedHashSet<String>();
4444
this.weights = new HashMap<String,String>();
4545
}
4646

src/java/boa/aggregators/SetAggregator.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package boa.aggregators;
1818

1919
import java.io.IOException;
20-
import java.util.HashSet;
20+
import java.util.LinkedHashSet;
2121

2222
import boa.io.EmitKey;
2323

@@ -28,7 +28,7 @@
2828
*/
2929
@AggregatorSpec(name = "set", canCombine = true)
3030
public class SetAggregator extends Aggregator {
31-
private HashSet<String> set;
31+
private LinkedHashSet<String> set;
3232
private final long max;
3333

3434
/**
@@ -60,7 +60,7 @@ public void start(final EmitKey key) {
6060
super.start(key);
6161

6262
// the set of data to be collected
63-
this.set = new HashSet<String>();
63+
this.set = new LinkedHashSet<String>();
6464
}
6565

6666
/** {@inheritDoc} */

src/java/boa/functions/BoaGraphIntrinsics.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public static CFG getcfg(final Method method) {
4040
}
4141

4242
@FunctionSpec(name = "get_nodes_with_definition", returnType = "set of string", formalParameters = { "CFGNode" })
43-
public static HashSet<String> getNodesWithDefinition(final CFGNode node) {
44-
final HashSet<String> vardef = new HashSet<String>();
43+
public static LinkedHashSet<String> getNodesWithDefinition(final CFGNode node) {
44+
final LinkedHashSet<String> vardef = new LinkedHashSet<String>();
4545
if (node.getExpression() != null) {
4646
if (node.getExpression().getKind() == ExpressionKind.VARDECL || node.getExpression().getKind() == ExpressionKind.ASSIGN) {
4747
vardef.add(String.valueOf(node.getId()));
@@ -51,8 +51,8 @@ public static HashSet<String> getNodesWithDefinition(final CFGNode node) {
5151
}
5252

5353
@FunctionSpec(name = "get_variable_killed", returnType = "set of string", formalParameters = {"CFG", "CFGNode" })
54-
public static HashSet<String> getVariableKilled(final boa.types.Control.CFG cfg, final CFGNode node) {
55-
final HashSet<String> varkilled = new HashSet<String>();
54+
public static LinkedHashSet<String> getVariableKilled(final boa.types.Control.CFG cfg, final CFGNode node) {
55+
final LinkedHashSet<String> varkilled = new LinkedHashSet<String>();
5656
String vardef = "";
5757

5858
if (node.getExpression() != null) {
@@ -86,8 +86,8 @@ else if (tnode.getExpression().getKind() == ExpressionKind.ASSIGN) {
8686
}
8787

8888
@FunctionSpec(name = "get_variable_def", returnType = "set of string", formalParameters = { "CFGNode" })
89-
public static HashSet<String> getVariableDef(final CFGNode node) {
90-
final HashSet<String> vardef = new HashSet<String>();
89+
public static LinkedHashSet<String> getVariableDef(final CFGNode node) {
90+
final LinkedHashSet<String> vardef = new LinkedHashSet<String>();
9191
if (node.getExpression() != null) {
9292
if (node.getExpression().getKind() == ExpressionKind.VARDECL) {
9393
vardef.add(node.getExpression().getVariableDeclsList().get(0).getName());
@@ -100,15 +100,15 @@ else if (node.getExpression().getKind() == ExpressionKind.ASSIGN) {
100100
}
101101

102102
@FunctionSpec(name = "get_variable_used", returnType = "set of string", formalParameters = { "CFGNode" })
103-
public static HashSet<String> getVariableUsed(final CFGNode node) {
104-
final HashSet<String> varused = new HashSet<String>();
103+
public static LinkedHashSet<String> getVariableUsed(final CFGNode node) {
104+
final LinkedHashSet<String> varused = new LinkedHashSet<String>();
105105
if (node.getExpression() != null) {
106106
traverseExpr(varused,node.getExpression());
107107
}
108108
return varused;
109109
}
110110

111-
public static void traverseExpr(final HashSet<String> varused, final Expression expr) {
111+
public static void traverseExpr(final LinkedHashSet<String> varused, final Expression expr) {
112112
if (expr.getVariable() != null) {
113113
varused.add(expr.getVariable());
114114
}
@@ -123,7 +123,7 @@ public static void traverseExpr(final HashSet<String> varused, final Expression
123123
}
124124
}
125125

126-
public static void traverseVarDecls(final HashSet<String> varused, final Variable vardecls) {
126+
public static void traverseVarDecls(final LinkedHashSet<String> varused, final Variable vardecls) {
127127
if (vardecls.getInitializer() != null) {
128128
traverseExpr(varused, vardecls.getInitializer());
129129
}

src/java/boa/functions/BoaIntrinsics.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -306,25 +306,25 @@ public static boolean[] concat(final boolean[] first, final boolean[]... rest) {
306306
return result;
307307
}
308308

309-
public static <T> java.util.HashSet<T> set_union(final java.util.Set<T> s1, final java.util.Set<T> s2) {
310-
final java.util.HashSet<T> s = new java.util.HashSet<T>(s1);
309+
public static <T> java.util.LinkedHashSet<T> set_union(final java.util.Set<T> s1, final java.util.Set<T> s2) {
310+
final java.util.LinkedHashSet<T> s = new java.util.LinkedHashSet<T>(s1);
311311
s.addAll(s2);
312312
return s;
313313
}
314314

315-
public static <T> java.util.HashSet<T> set_intersect(final java.util.Set<T> s1, final java.util.Set<T> s2) {
316-
final java.util.HashSet<T> s = new java.util.HashSet<T>(s1);
315+
public static <T> java.util.LinkedHashSet<T> set_intersect(final java.util.Set<T> s1, final java.util.Set<T> s2) {
316+
final java.util.LinkedHashSet<T> s = new java.util.LinkedHashSet<T>(s1);
317317
s.retainAll(s2);
318318
return s;
319319
}
320320

321-
public static <T> java.util.HashSet<T> set_difference(final java.util.Set<T> s1, final java.util.Set<T> s2) {
322-
final java.util.HashSet<T> s = new java.util.HashSet<T>(s1);
321+
public static <T> java.util.LinkedHashSet<T> set_difference(final java.util.Set<T> s1, final java.util.Set<T> s2) {
322+
final java.util.LinkedHashSet<T> s = new java.util.LinkedHashSet<T>(s1);
323323
s.removeAll(s2);
324324
return s;
325325
}
326326

327-
public static <T> java.util.HashSet<T> set_symdiff(final java.util.Set<T> s1, final java.util.Set<T> s2) {
327+
public static <T> java.util.LinkedHashSet<T> set_symdiff(final java.util.Set<T> s1, final java.util.Set<T> s2) {
328328
return set_union(set_difference(s1, s2), set_difference(s2, s1));
329329
}
330330
}

src/java/boa/graphs/cfg/CFG.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package boa.graphs.cfg;
1818

1919
import java.util.HashMap;
20-
import java.util.HashSet;
20+
import java.util.LinkedHashSet;
2121
import java.util.List;
2222
import java.util.Map;
2323

@@ -43,11 +43,11 @@ public class CFG {
4343
public String class_name;
4444
static boolean endFlag = false;
4545
static boolean switchFlag=false;
46-
protected HashSet<CFGNode> nodes = new HashSet<CFGNode>();
47-
private HashSet<CFGNode> outs = new HashSet<CFGNode>();
48-
private HashSet<CFGNode> ins = new HashSet<CFGNode>();
49-
private HashSet<CFGNode> breaks = new HashSet<CFGNode>();
50-
private HashSet<CFGNode> returns = new HashSet<CFGNode>();
46+
protected LinkedHashSet<CFGNode> nodes = new LinkedHashSet<CFGNode>();
47+
private LinkedHashSet<CFGNode> outs = new LinkedHashSet<CFGNode>();
48+
private LinkedHashSet<CFGNode> ins = new LinkedHashSet<CFGNode>();
49+
private LinkedHashSet<CFGNode> breaks = new LinkedHashSet<CFGNode>();
50+
private LinkedHashSet<CFGNode> returns = new LinkedHashSet<CFGNode>();
5151
private CFGNode entryNode ;
5252
private CFGNode exitNode ;
5353
private boolean isLoopPresent = false;
@@ -97,15 +97,15 @@ public String getClass_name() {
9797
return class_name;
9898
}
9999

100-
public HashSet<CFGNode> getNodes() {
100+
public LinkedHashSet<CFGNode> getNodes() {
101101
return nodes;
102102
}
103103

104-
public HashSet<CFGNode> getOuts() {
104+
public LinkedHashSet<CFGNode> getOuts() {
105105
return outs;
106106
}
107107

108-
public HashSet<CFGNode> getIns() {
108+
public LinkedHashSet<CFGNode> getIns() {
109109
return ins;
110110
}
111111

@@ -204,7 +204,7 @@ public void mergeSeq(CFGNode branch) {
204204
outs.add(branch);
205205
}
206206

207-
public void mergeBranches(CFG target, HashSet<CFGNode> saveOuts) {
207+
public void mergeBranches(CFG target, LinkedHashSet<CFGNode> saveOuts) {
208208
if (target.getNodes().size() == 0)
209209
return;
210210

@@ -297,7 +297,7 @@ public void addReturnNode(CFGNode node) {
297297
}
298298

299299
public void adjustBreakNodes(String id) {
300-
for (CFGNode node : new HashSet<CFGNode>(this.breaks)) {
300+
for (CFGNode node : new LinkedHashSet<CFGNode>(this.breaks)) {
301301
if (node.getObjectName().equals(id)) {
302302
this.outs.add(node);
303303
this.breaks.remove(node);

src/java/boa/graphs/cfg/CFGNode.java

+21-21
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package boa.graphs.cfg;
1818

1919
import java.util.HashMap;
20-
import java.util.HashSet;
20+
import java.util.LinkedHashSet;
2121

2222
import boa.types.Ast.Expression;
2323
import boa.types.Ast.Statement;
@@ -41,7 +41,7 @@ public class CFGNode implements Comparable<CFGNode> {
4141
private int objectNameId;
4242
private int classNameId;
4343
private int numOfParameters = 0;
44-
private HashSet<Integer> parameters;
44+
private LinkedHashSet<Integer> parameters;
4545
private int kind = TYPE_OTHER;
4646
private String pid;
4747
private Statement stmt;
@@ -52,13 +52,13 @@ public class CFGNode implements Comparable<CFGNode> {
5252
public static HashMap<String, Integer> idOfLabel = new HashMap<String, Integer>();
5353
public static HashMap<Integer, String> labelOfID = new HashMap<Integer, String>();
5454

55-
public HashSet<CFGEdge> inEdges = new HashSet<CFGEdge>();
56-
public HashSet<CFGEdge> outEdges = new HashSet<CFGEdge>();
55+
public LinkedHashSet<CFGEdge> inEdges = new LinkedHashSet<CFGEdge>();
56+
public LinkedHashSet<CFGEdge> outEdges = new LinkedHashSet<CFGEdge>();
5757

5858
public java.util.ArrayList<CFGNode> predecessors = new java.util.ArrayList<CFGNode>();
5959
public java.util.ArrayList<CFGNode> successors = new java.util.ArrayList<CFGNode>();
6060

61-
public HashSet<String> useVariables = new HashSet<String>();
61+
public LinkedHashSet<String> useVariables = new LinkedHashSet<String>();
6262
public String defVariables;
6363

6464
@Override
@@ -84,7 +84,7 @@ public CFGNode(String methodName, int kind, String className,
8484
}
8585

8686
public CFGNode(String methodName, int kind, String className,
87-
String objectName, int numOfParameters, HashSet<Integer> datas) {
87+
String objectName, int numOfParameters, LinkedHashSet<Integer> datas) {
8888
this.id = ++numOfNodes;
8989
this.methodId = convertLabel(methodName);
9090
this.kind = kind;
@@ -96,7 +96,7 @@ public CFGNode(String methodName, int kind, String className,
9696
}
9797

9898
this.objectNameId = convertLabel(objectName);
99-
this.parameters = new HashSet<Integer>(datas);
99+
this.parameters = new LinkedHashSet<Integer>(datas);
100100
this.numOfParameters = numOfParameters;
101101
}
102102

@@ -114,8 +114,8 @@ public Statement getStmt() {
114114
return this.stmt;
115115
}
116116

117-
public HashSet<String> getDefUse() {
118-
HashSet<String> defUse = new HashSet<String>(useVariables);
117+
public LinkedHashSet<String> getDefUse() {
118+
LinkedHashSet<String> defUse = new LinkedHashSet<String>(useVariables);
119119
defUse.add(defVariables);
120120
return defUse;
121121
}
@@ -182,15 +182,15 @@ public int getNumOfParameters() {
182182
return numOfParameters;
183183
}
184184

185-
public void setParameters(HashSet<Integer> parameters) {
185+
public void setParameters(LinkedHashSet<Integer> parameters) {
186186
this.parameters = parameters;
187187
}
188188

189-
public HashSet<Integer> getParameters() {
189+
public LinkedHashSet<Integer> getParameters() {
190190
return parameters;
191191
}
192192

193-
public void setUseVariables(HashSet<String> useVariables) {
193+
public void setUseVariables(LinkedHashSet<String> useVariables) {
194194
this.useVariables = useVariables;
195195
}
196196

@@ -214,7 +214,7 @@ public String getClassName() {
214214
return labelOfID.get(classNameId);
215215
}
216216

217-
public HashSet<String> getUseVariables() {
217+
public LinkedHashSet<String> getUseVariables() {
218218
return useVariables;
219219
}
220220

@@ -230,11 +230,11 @@ public boolean hasFalseBranch() {
230230
return false;
231231
}
232232

233-
public HashSet<CFGEdge> getInEdges() {
233+
public LinkedHashSet<CFGEdge> getInEdges() {
234234
return inEdges;
235235
}
236236

237-
public HashSet<CFGEdge> getOutEdges() {
237+
public LinkedHashSet<CFGEdge> getOutEdges() {
238238
return outEdges;
239239
}
240240

@@ -255,7 +255,7 @@ public void setSuccessors(java.util.ArrayList<CFGNode> successors) {
255255
}
256256

257257
public java.util.ArrayList<CFGNode> getInNodes() {
258-
HashSet<CFGNode> nodes = new HashSet<CFGNode>();
258+
LinkedHashSet<CFGNode> nodes = new LinkedHashSet<CFGNode>();
259259
for (CFGEdge e : inEdges)
260260
nodes.add(e.getSrc());
261261
java.util.ArrayList<CFGNode> pred = new java.util.ArrayList<CFGNode>(nodes);
@@ -264,7 +264,7 @@ public java.util.ArrayList<CFGNode> getInNodes() {
264264
}
265265

266266
public java.util.ArrayList<CFGNode> getOutNodes() {
267-
HashSet<CFGNode> nodes = new HashSet<CFGNode>();
267+
LinkedHashSet<CFGNode> nodes = new LinkedHashSet<CFGNode>();
268268
for (CFGEdge e : outEdges)
269269
nodes.add(e.getDest());
270270
java.util.ArrayList<CFGNode> succ = new java.util.ArrayList<CFGNode>(nodes);
@@ -377,8 +377,8 @@ public String processDef() {
377377
return defVar;
378378
}
379379

380-
public HashSet<String> processUse() {
381-
HashSet<String> useVar= new HashSet<String>();
380+
public LinkedHashSet<String> processUse() {
381+
LinkedHashSet<String> useVar= new LinkedHashSet<String>();
382382
if(this.expr!=null) {
383383
if(this.expr.getKind().toString().equals("ASSIGN")) {
384384
traverseExpr(useVar, this.rhs);
@@ -390,7 +390,7 @@ public HashSet<String> processUse() {
390390
return useVar;
391391
}
392392

393-
public static void traverseExpr(HashSet<String> useVar, final boa.types.Ast.Expression expr) {
393+
public static void traverseExpr(LinkedHashSet<String> useVar, final boa.types.Ast.Expression expr) {
394394
if(expr.hasVariable()) {
395395
if(expr.getExpressionsList().size()!=0) {
396396
useVar.add("this");
@@ -416,7 +416,7 @@ public static void traverseExpr(HashSet<String> useVar, final boa.types.Ast.Expr
416416
}
417417
}
418418

419-
public static void traverseVarDecls(HashSet<String> useVar, final boa.types.Ast.Variable vardecls) {
419+
public static void traverseVarDecls(LinkedHashSet<String> useVar, final boa.types.Ast.Variable vardecls) {
420420
if(vardecls.hasInitializer()) {
421421
traverseExpr(useVar, vardecls.getInitializer());
422422
}

src/java/boa/runtime/BoaAbstractTraversal.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public final void traverse(final boa.graphs.cfg.CFG cfg, final Traversal.Travers
271271
prevOutputMapObj = new java.util.HashMap<Integer,T1>(outputMapObj);
272272
traverse(cfg, direction, kind);
273273
fixpFlag=true;
274-
java.util.HashSet<CFGNode> nl=cfg.getNodes();
274+
java.util.LinkedHashSet<CFGNode> nl=cfg.getNodes();
275275
for (CFGNode node : nl) {
276276
boolean curFlag=outputMapObj.containsKey(node.getId());
277277
if (curFlag) {

src/java/boa/types/BoaSet.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public String toString() {
124124
/** {@inheritDoc} */
125125
@Override
126126
public String toJavaType() {
127-
return "java.util.HashSet<" + this.type.toBoxedJavaType() + ">";
127+
return "java.util.LinkedHashSet<" + this.type.toBoxedJavaType() + ">";
128128
}
129129

130130
/** {@inheritDoc} */

templates/BoaJava.stg

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ VarDecl(isstatic, type, id) ::= "<if(isstatic)>static <endif><type> ___<id>;<\n>
2020
ArrayType(type) ::= "<type>[]"
2121
MapType(key, value) ::= "java.util.HashMap\<<key>, <value>>"
2222
StackType(value) ::= "java.util.Stack\<<value>>"
23-
SetType(value) ::= "java.util.HashSet\<<value>>"
23+
SetType(value) ::= "java.util.LinkedHashSet\<<value>>"
2424
Block(statements) ::= <<
2525
{
2626
<statements:{s | <s>}>}

0 commit comments

Comments
 (0)