Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #159 - Use LinkedHashSet to store sets #161

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bbcd122
fix issue #159, also modified BoaJava.stg, passed all tests
CheShianHung Oct 11, 2017
970890b
Fixes #159 type updated
CheShianHung Oct 12, 2017
b3f0fb4
Fixed #159, change types to general set as much as possible
CheShianHung Oct 12, 2017
207cdc8
fix issue #159, change most LinkedHashSet to Set, change codegen
CheShianHung Jan 19, 2018
b263206
fix issue #159, toInterdaceJavaType and toParameterJavaType methods a…
CheShianHung Jan 22, 2018
081e731
fix #159, simplify setType and stackType in codegen
CheShianHung Jan 22, 2018
668fe6b
Merge branch 'master' of github.com:boalang/compiler into issue159
psybers Jan 22, 2018
1316b9e
fix #159, inhattr stack type added
CheShianHung Jan 22, 2018
1a582b6
fix #159, Map field type fixed
CheShianHung Jan 22, 2018
7521adb
fix #159, spacing and template fixed
CheShianHung Jan 22, 2018
6ecdbe6
merge master
psybers Aug 13, 2019
e3b1449
remove unneeded type templates
psybers Aug 13, 2019
af992b8
convert more HashSet to LinkedHashSet
psybers Aug 13, 2019
e6ec701
fix test errors and simplify some code
psybers Aug 15, 2019
683c817
code cleanup
psybers Aug 15, 2019
bf3e47e
Merge branch 'master' into issue159
psybers Aug 31, 2019
1c8a28a
Merge branch 'master' into issue159
psybers Sep 1, 2023
9961c74
fix bad merge that lost types2
psybers Sep 3, 2023
b73f2d8
fix compile error with template
psybers Sep 3, 2023
a240174
fix boxing issue with arrays
psybers Sep 3, 2023
6a2ccf9
make sure set aggregator sorts output
psybers Sep 3, 2023
e63b9b3
the set aggregator does not need to be a linked set, since we sort it
psybers Sep 3, 2023
cfe85ab
Merge branch 'master' into issue159
psybers Sep 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/java/boa/aggregators/GraphAggregator.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class GraphAggregator extends Aggregator {
public void start(final EmitKey key) {
super.start(key);

this.neighbors = new HashSet<String>();
this.neighbors = new LinkedHashSet<String>();
this.weights = new HashMap<String,String>();
}

Expand Down
6 changes: 3 additions & 3 deletions src/java/boa/aggregators/SetAggregator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package boa.aggregators;

import java.io.IOException;
import java.util.HashSet;
import java.util.LinkedHashSet;

import boa.io.EmitKey;

Expand All @@ -28,7 +28,7 @@
*/
@AggregatorSpec(name = "set", canCombine = true)
public class SetAggregator extends Aggregator {
private HashSet<String> set;
private LinkedHashSet<String> set;
psybers marked this conversation as resolved.
Show resolved Hide resolved
private final long max;

/**
Expand Down Expand Up @@ -60,7 +60,7 @@ public void start(final EmitKey key) {
super.start(key);

// the set of data to be collected
this.set = new HashSet<String>();
this.set = new LinkedHashSet<String>();
}

/** {@inheritDoc} */
Expand Down
20 changes: 10 additions & 10 deletions src/java/boa/functions/BoaGraphIntrinsics.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public static CFG getcfg(final Method method) {
}

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

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

if (node.getExpression() != null) {
Expand Down Expand Up @@ -86,8 +86,8 @@ else if (tnode.getExpression().getKind() == ExpressionKind.ASSIGN) {
}

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

@FunctionSpec(name = "get_variable_used", returnType = "set of string", formalParameters = { "CFGNode" })
public static HashSet<String> getVariableUsed(final CFGNode node) {
final HashSet<String> varused = new HashSet<String>();
public static LinkedHashSet<String> getVariableUsed(final CFGNode node) {
final LinkedHashSet<String> varused = new LinkedHashSet<String>();
if (node.getExpression() != null) {
traverseExpr(varused,node.getExpression());
}
return varused;
}

public static void traverseExpr(final HashSet<String> varused, final Expression expr) {
public static void traverseExpr(final LinkedHashSet<String> varused, final Expression expr) {
if (expr.getVariable() != null) {
varused.add(expr.getVariable());
}
Expand All @@ -123,7 +123,7 @@ public static void traverseExpr(final HashSet<String> varused, final Expression
}
}

public static void traverseVarDecls(final HashSet<String> varused, final Variable vardecls) {
public static void traverseVarDecls(final LinkedHashSet<String> varused, final Variable vardecls) {
if (vardecls.getInitializer() != null) {
traverseExpr(varused, vardecls.getInitializer());
}
Expand Down
14 changes: 7 additions & 7 deletions src/java/boa/functions/BoaIntrinsics.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,25 +306,25 @@ public static boolean[] concat(final boolean[] first, final boolean[]... rest) {
return result;
}

public static <T> java.util.HashSet<T> set_union(final java.util.Set<T> s1, final java.util.Set<T> s2) {
final java.util.HashSet<T> s = new java.util.HashSet<T>(s1);
public static <T> java.util.LinkedHashSet<T> set_union(final java.util.Set<T> s1, final java.util.Set<T> s2) {
psybers marked this conversation as resolved.
Show resolved Hide resolved
final java.util.LinkedHashSet<T> s = new java.util.LinkedHashSet<T>(s1);
psybers marked this conversation as resolved.
Show resolved Hide resolved
s.addAll(s2);
return s;
}

public static <T> java.util.HashSet<T> set_intersect(final java.util.Set<T> s1, final java.util.Set<T> s2) {
final java.util.HashSet<T> s = new java.util.HashSet<T>(s1);
public static <T> java.util.LinkedHashSet<T> set_intersect(final java.util.Set<T> s1, final java.util.Set<T> s2) {
psybers marked this conversation as resolved.
Show resolved Hide resolved
final java.util.LinkedHashSet<T> s = new java.util.LinkedHashSet<T>(s1);
psybers marked this conversation as resolved.
Show resolved Hide resolved
s.retainAll(s2);
return s;
}

public static <T> java.util.HashSet<T> set_difference(final java.util.Set<T> s1, final java.util.Set<T> s2) {
final java.util.HashSet<T> s = new java.util.HashSet<T>(s1);
public static <T> java.util.LinkedHashSet<T> set_difference(final java.util.Set<T> s1, final java.util.Set<T> s2) {
psybers marked this conversation as resolved.
Show resolved Hide resolved
final java.util.LinkedHashSet<T> s = new java.util.LinkedHashSet<T>(s1);
psybers marked this conversation as resolved.
Show resolved Hide resolved
s.removeAll(s2);
return s;
}

public static <T> java.util.HashSet<T> set_symdiff(final java.util.Set<T> s1, final java.util.Set<T> s2) {
public static <T> java.util.LinkedHashSet<T> set_symdiff(final java.util.Set<T> s1, final java.util.Set<T> s2) {
psybers marked this conversation as resolved.
Show resolved Hide resolved
return set_union(set_difference(s1, s2), set_difference(s2, s1));
}
}
22 changes: 11 additions & 11 deletions src/java/boa/graphs/cfg/CFG.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package boa.graphs.cfg;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;

Expand All @@ -43,11 +43,11 @@ public class CFG {
public String class_name;
static boolean endFlag = false;
static boolean switchFlag=false;
protected HashSet<CFGNode> nodes = new HashSet<CFGNode>();
private HashSet<CFGNode> outs = new HashSet<CFGNode>();
private HashSet<CFGNode> ins = new HashSet<CFGNode>();
private HashSet<CFGNode> breaks = new HashSet<CFGNode>();
private HashSet<CFGNode> returns = new HashSet<CFGNode>();
protected LinkedHashSet<CFGNode> nodes = new LinkedHashSet<CFGNode>();
private LinkedHashSet<CFGNode> outs = new LinkedHashSet<CFGNode>();
private LinkedHashSet<CFGNode> ins = new LinkedHashSet<CFGNode>();
private LinkedHashSet<CFGNode> breaks = new LinkedHashSet<CFGNode>();
private LinkedHashSet<CFGNode> returns = new LinkedHashSet<CFGNode>();
private CFGNode entryNode ;
private CFGNode exitNode ;
private boolean isLoopPresent = false;
Expand Down Expand Up @@ -97,15 +97,15 @@ public String getClass_name() {
return class_name;
}

public HashSet<CFGNode> getNodes() {
public LinkedHashSet<CFGNode> getNodes() {
return nodes;
}

public HashSet<CFGNode> getOuts() {
public LinkedHashSet<CFGNode> getOuts() {
return outs;
}

public HashSet<CFGNode> getIns() {
public LinkedHashSet<CFGNode> getIns() {
return ins;
}

Expand Down Expand Up @@ -204,7 +204,7 @@ public void mergeSeq(CFGNode branch) {
outs.add(branch);
}

public void mergeBranches(CFG target, HashSet<CFGNode> saveOuts) {
public void mergeBranches(CFG target, LinkedHashSet<CFGNode> saveOuts) {
if (target.getNodes().size() == 0)
return;

Expand Down Expand Up @@ -297,7 +297,7 @@ public void addReturnNode(CFGNode node) {
}

public void adjustBreakNodes(String id) {
for (CFGNode node : new HashSet<CFGNode>(this.breaks)) {
for (CFGNode node : new LinkedHashSet<CFGNode>(this.breaks)) {
if (node.getObjectName().equals(id)) {
this.outs.add(node);
this.breaks.remove(node);
Expand Down
42 changes: 21 additions & 21 deletions src/java/boa/graphs/cfg/CFGNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package boa.graphs.cfg;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;

import boa.types.Ast.Expression;
import boa.types.Ast.Statement;
Expand All @@ -41,7 +41,7 @@ public class CFGNode implements Comparable<CFGNode> {
private int objectNameId;
private int classNameId;
private int numOfParameters = 0;
private HashSet<Integer> parameters;
private LinkedHashSet<Integer> parameters;
psybers marked this conversation as resolved.
Show resolved Hide resolved
private int kind = TYPE_OTHER;
private String pid;
private Statement stmt;
Expand All @@ -52,13 +52,13 @@ public class CFGNode implements Comparable<CFGNode> {
public static HashMap<String, Integer> idOfLabel = new HashMap<String, Integer>();
public static HashMap<Integer, String> labelOfID = new HashMap<Integer, String>();

public HashSet<CFGEdge> inEdges = new HashSet<CFGEdge>();
public HashSet<CFGEdge> outEdges = new HashSet<CFGEdge>();
public LinkedHashSet<CFGEdge> inEdges = new LinkedHashSet<CFGEdge>();
psybers marked this conversation as resolved.
Show resolved Hide resolved
public LinkedHashSet<CFGEdge> outEdges = new LinkedHashSet<CFGEdge>();
psybers marked this conversation as resolved.
Show resolved Hide resolved

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

public HashSet<String> useVariables = new HashSet<String>();
public LinkedHashSet<String> useVariables = new LinkedHashSet<String>();
psybers marked this conversation as resolved.
Show resolved Hide resolved
public String defVariables;

@Override
Expand All @@ -84,7 +84,7 @@ public CFGNode(String methodName, int kind, String className,
}

public CFGNode(String methodName, int kind, String className,
String objectName, int numOfParameters, HashSet<Integer> datas) {
String objectName, int numOfParameters, LinkedHashSet<Integer> datas) {
psybers marked this conversation as resolved.
Show resolved Hide resolved
this.id = ++numOfNodes;
this.methodId = convertLabel(methodName);
this.kind = kind;
Expand All @@ -96,7 +96,7 @@ public CFGNode(String methodName, int kind, String className,
}

this.objectNameId = convertLabel(objectName);
this.parameters = new HashSet<Integer>(datas);
this.parameters = new LinkedHashSet<Integer>(datas);
this.numOfParameters = numOfParameters;
}

Expand All @@ -114,8 +114,8 @@ public Statement getStmt() {
return this.stmt;
}

public HashSet<String> getDefUse() {
HashSet<String> defUse = new HashSet<String>(useVariables);
public LinkedHashSet<String> getDefUse() {
psybers marked this conversation as resolved.
Show resolved Hide resolved
LinkedHashSet<String> defUse = new LinkedHashSet<String>(useVariables);
psybers marked this conversation as resolved.
Show resolved Hide resolved
defUse.add(defVariables);
return defUse;
}
Expand Down Expand Up @@ -182,15 +182,15 @@ public int getNumOfParameters() {
return numOfParameters;
}

public void setParameters(HashSet<Integer> parameters) {
public void setParameters(LinkedHashSet<Integer> parameters) {
psybers marked this conversation as resolved.
Show resolved Hide resolved
this.parameters = parameters;
}

public HashSet<Integer> getParameters() {
public LinkedHashSet<Integer> getParameters() {
psybers marked this conversation as resolved.
Show resolved Hide resolved
return parameters;
}

public void setUseVariables(HashSet<String> useVariables) {
public void setUseVariables(LinkedHashSet<String> useVariables) {
psybers marked this conversation as resolved.
Show resolved Hide resolved
this.useVariables = useVariables;
}

Expand All @@ -214,7 +214,7 @@ public String getClassName() {
return labelOfID.get(classNameId);
}

public HashSet<String> getUseVariables() {
public LinkedHashSet<String> getUseVariables() {
psybers marked this conversation as resolved.
Show resolved Hide resolved
return useVariables;
}

Expand All @@ -230,11 +230,11 @@ public boolean hasFalseBranch() {
return false;
}

public HashSet<CFGEdge> getInEdges() {
public LinkedHashSet<CFGEdge> getInEdges() {
psybers marked this conversation as resolved.
Show resolved Hide resolved
return inEdges;
}

public HashSet<CFGEdge> getOutEdges() {
public LinkedHashSet<CFGEdge> getOutEdges() {
psybers marked this conversation as resolved.
Show resolved Hide resolved
return outEdges;
}

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

public java.util.ArrayList<CFGNode> getInNodes() {
HashSet<CFGNode> nodes = new HashSet<CFGNode>();
LinkedHashSet<CFGNode> nodes = new LinkedHashSet<CFGNode>();
psybers marked this conversation as resolved.
Show resolved Hide resolved
for (CFGEdge e : inEdges)
nodes.add(e.getSrc());
java.util.ArrayList<CFGNode> pred = new java.util.ArrayList<CFGNode>(nodes);
Expand All @@ -264,7 +264,7 @@ public java.util.ArrayList<CFGNode> getInNodes() {
}

public java.util.ArrayList<CFGNode> getOutNodes() {
HashSet<CFGNode> nodes = new HashSet<CFGNode>();
LinkedHashSet<CFGNode> nodes = new LinkedHashSet<CFGNode>();
psybers marked this conversation as resolved.
Show resolved Hide resolved
for (CFGEdge e : outEdges)
nodes.add(e.getDest());
java.util.ArrayList<CFGNode> succ = new java.util.ArrayList<CFGNode>(nodes);
Expand Down Expand Up @@ -377,8 +377,8 @@ public String processDef() {
return defVar;
}

public HashSet<String> processUse() {
HashSet<String> useVar= new HashSet<String>();
public LinkedHashSet<String> processUse() {
psybers marked this conversation as resolved.
Show resolved Hide resolved
LinkedHashSet<String> useVar= new LinkedHashSet<String>();
psybers marked this conversation as resolved.
Show resolved Hide resolved
if(this.expr!=null) {
if(this.expr.getKind().toString().equals("ASSIGN")) {
traverseExpr(useVar, this.rhs);
Expand All @@ -390,7 +390,7 @@ public HashSet<String> processUse() {
return useVar;
}

public static void traverseExpr(HashSet<String> useVar, final boa.types.Ast.Expression expr) {
public static void traverseExpr(LinkedHashSet<String> useVar, final boa.types.Ast.Expression expr) {
psybers marked this conversation as resolved.
Show resolved Hide resolved
if(expr.hasVariable()) {
if(expr.getExpressionsList().size()!=0) {
useVar.add("this");
Expand All @@ -416,7 +416,7 @@ public static void traverseExpr(HashSet<String> useVar, final boa.types.Ast.Expr
}
}

public static void traverseVarDecls(HashSet<String> useVar, final boa.types.Ast.Variable vardecls) {
public static void traverseVarDecls(LinkedHashSet<String> useVar, final boa.types.Ast.Variable vardecls) {
psybers marked this conversation as resolved.
Show resolved Hide resolved
if(vardecls.hasInitializer()) {
traverseExpr(useVar, vardecls.getInitializer());
}
Expand Down
2 changes: 1 addition & 1 deletion src/java/boa/runtime/BoaAbstractTraversal.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public final void traverse(final boa.graphs.cfg.CFG cfg, final Traversal.Travers
prevOutputMapObj = new java.util.HashMap<Integer,T1>(outputMapObj);
traverse(cfg, direction, kind);
fixpFlag=true;
java.util.HashSet<CFGNode> nl=cfg.getNodes();
java.util.LinkedHashSet<CFGNode> nl=cfg.getNodes();
for (CFGNode node : nl) {
boolean curFlag=outputMapObj.containsKey(node.getId());
if (curFlag) {
Expand Down
2 changes: 1 addition & 1 deletion src/java/boa/types/BoaSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public String toString() {
/** {@inheritDoc} */
@Override
public String toJavaType() {
return "java.util.HashSet<" + this.type.toBoxedJavaType() + ">";
return "java.util.LinkedHashSet<" + this.type.toBoxedJavaType() + ">";
}

/** {@inheritDoc} */
Expand Down
2 changes: 1 addition & 1 deletion templates/BoaJava.stg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ VarDecl(isstatic, type, id) ::= "<if(isstatic)>static <endif><type> ___<id>;<\n>
ArrayType(type) ::= "<type>[]"
MapType(key, value) ::= "java.util.HashMap\<<key>, <value>>"
StackType(value) ::= "java.util.Stack\<<value>>"
SetType(value) ::= "java.util.HashSet\<<value>>"
SetType(value) ::= "java.util.LinkedHashSet\<<value>>"
Block(statements) ::= <<
{
<statements:{s | <s>}>}
Expand Down