From bbcd1222bb6d69d3b56d714320bf74bb3af32e4d Mon Sep 17 00:00:00 2001 From: Che Shian Hung Date: Wed, 11 Oct 2017 15:17:48 -0400 Subject: [PATCH 01/18] fix issue #159, also modified BoaJava.stg, passed all tests --- src/java/boa/aggregators/GraphAggregator.java | 2 +- src/java/boa/aggregators/SetAggregator.java | 6 +-- .../boa/functions/BoaGraphIntrinsics.java | 20 ++++----- src/java/boa/functions/BoaIntrinsics.java | 14 +++---- src/java/boa/graphs/cfg/CFG.java | 22 +++++----- src/java/boa/graphs/cfg/CFGNode.java | 42 +++++++++---------- .../boa/runtime/BoaAbstractTraversal.java | 2 +- src/java/boa/types/BoaSet.java | 2 +- templates/BoaJava.stg | 2 +- 9 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/java/boa/aggregators/GraphAggregator.java b/src/java/boa/aggregators/GraphAggregator.java index 8249309c3..688db348b 100644 --- a/src/java/boa/aggregators/GraphAggregator.java +++ b/src/java/boa/aggregators/GraphAggregator.java @@ -40,7 +40,7 @@ public abstract class GraphAggregator extends Aggregator { public void start(final EmitKey key) { super.start(key); - this.neighbors = new HashSet(); + this.neighbors = new LinkedHashSet(); this.weights = new HashMap(); } diff --git a/src/java/boa/aggregators/SetAggregator.java b/src/java/boa/aggregators/SetAggregator.java index 6eeb1a49f..80a9e6926 100644 --- a/src/java/boa/aggregators/SetAggregator.java +++ b/src/java/boa/aggregators/SetAggregator.java @@ -17,7 +17,7 @@ package boa.aggregators; import java.io.IOException; -import java.util.HashSet; +import java.util.LinkedHashSet; import boa.io.EmitKey; @@ -28,7 +28,7 @@ */ @AggregatorSpec(name = "set", canCombine = true) public class SetAggregator extends Aggregator { - private HashSet set; + private LinkedHashSet set; private final long max; /** @@ -60,7 +60,7 @@ public void start(final EmitKey key) { super.start(key); // the set of data to be collected - this.set = new HashSet(); + this.set = new LinkedHashSet(); } /** {@inheritDoc} */ diff --git a/src/java/boa/functions/BoaGraphIntrinsics.java b/src/java/boa/functions/BoaGraphIntrinsics.java index e1d770831..185543094 100644 --- a/src/java/boa/functions/BoaGraphIntrinsics.java +++ b/src/java/boa/functions/BoaGraphIntrinsics.java @@ -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 getNodesWithDefinition(final CFGNode node) { - final HashSet vardef = new HashSet(); + public static LinkedHashSet getNodesWithDefinition(final CFGNode node) { + final LinkedHashSet vardef = new LinkedHashSet(); if (node.getExpression() != null) { if (node.getExpression().getKind() == ExpressionKind.VARDECL || node.getExpression().getKind() == ExpressionKind.ASSIGN) { vardef.add(String.valueOf(node.getId())); @@ -51,8 +51,8 @@ public static HashSet getNodesWithDefinition(final CFGNode node) { } @FunctionSpec(name = "get_variable_killed", returnType = "set of string", formalParameters = {"CFG", "CFGNode" }) - public static HashSet getVariableKilled(final boa.types.Control.CFG cfg, final CFGNode node) { - final HashSet varkilled = new HashSet(); + public static LinkedHashSet getVariableKilled(final boa.types.Control.CFG cfg, final CFGNode node) { + final LinkedHashSet varkilled = new LinkedHashSet(); String vardef = ""; if (node.getExpression() != null) { @@ -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 getVariableDef(final CFGNode node) { - final HashSet vardef = new HashSet(); + public static LinkedHashSet getVariableDef(final CFGNode node) { + final LinkedHashSet vardef = new LinkedHashSet(); if (node.getExpression() != null) { if (node.getExpression().getKind() == ExpressionKind.VARDECL) { vardef.add(node.getExpression().getVariableDeclsList().get(0).getName()); @@ -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 getVariableUsed(final CFGNode node) { - final HashSet varused = new HashSet(); + public static LinkedHashSet getVariableUsed(final CFGNode node) { + final LinkedHashSet varused = new LinkedHashSet(); if (node.getExpression() != null) { traverseExpr(varused,node.getExpression()); } return varused; } - public static void traverseExpr(final HashSet varused, final Expression expr) { + public static void traverseExpr(final LinkedHashSet varused, final Expression expr) { if (expr.getVariable() != null) { varused.add(expr.getVariable()); } @@ -123,7 +123,7 @@ public static void traverseExpr(final HashSet varused, final Expression } } - public static void traverseVarDecls(final HashSet varused, final Variable vardecls) { + public static void traverseVarDecls(final LinkedHashSet varused, final Variable vardecls) { if (vardecls.getInitializer() != null) { traverseExpr(varused, vardecls.getInitializer()); } diff --git a/src/java/boa/functions/BoaIntrinsics.java b/src/java/boa/functions/BoaIntrinsics.java index 3c35570b1..2bfb81b36 100644 --- a/src/java/boa/functions/BoaIntrinsics.java +++ b/src/java/boa/functions/BoaIntrinsics.java @@ -306,25 +306,25 @@ public static boolean[] concat(final boolean[] first, final boolean[]... rest) { return result; } - public static java.util.HashSet set_union(final java.util.Set s1, final java.util.Set s2) { - final java.util.HashSet s = new java.util.HashSet(s1); + public static java.util.LinkedHashSet set_union(final java.util.Set s1, final java.util.Set s2) { + final java.util.LinkedHashSet s = new java.util.LinkedHashSet(s1); s.addAll(s2); return s; } - public static java.util.HashSet set_intersect(final java.util.Set s1, final java.util.Set s2) { - final java.util.HashSet s = new java.util.HashSet(s1); + public static java.util.LinkedHashSet set_intersect(final java.util.Set s1, final java.util.Set s2) { + final java.util.LinkedHashSet s = new java.util.LinkedHashSet(s1); s.retainAll(s2); return s; } - public static java.util.HashSet set_difference(final java.util.Set s1, final java.util.Set s2) { - final java.util.HashSet s = new java.util.HashSet(s1); + public static java.util.LinkedHashSet set_difference(final java.util.Set s1, final java.util.Set s2) { + final java.util.LinkedHashSet s = new java.util.LinkedHashSet(s1); s.removeAll(s2); return s; } - public static java.util.HashSet set_symdiff(final java.util.Set s1, final java.util.Set s2) { + public static java.util.LinkedHashSet set_symdiff(final java.util.Set s1, final java.util.Set s2) { return set_union(set_difference(s1, s2), set_difference(s2, s1)); } } diff --git a/src/java/boa/graphs/cfg/CFG.java b/src/java/boa/graphs/cfg/CFG.java index 8967e3fca..fa0b26682 100644 --- a/src/java/boa/graphs/cfg/CFG.java +++ b/src/java/boa/graphs/cfg/CFG.java @@ -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; @@ -43,11 +43,11 @@ public class CFG { public String class_name; static boolean endFlag = false; static boolean switchFlag=false; - protected HashSet nodes = new HashSet(); - private HashSet outs = new HashSet(); - private HashSet ins = new HashSet(); - private HashSet breaks = new HashSet(); - private HashSet returns = new HashSet(); + protected LinkedHashSet nodes = new LinkedHashSet(); + private LinkedHashSet outs = new LinkedHashSet(); + private LinkedHashSet ins = new LinkedHashSet(); + private LinkedHashSet breaks = new LinkedHashSet(); + private LinkedHashSet returns = new LinkedHashSet(); private CFGNode entryNode ; private CFGNode exitNode ; private boolean isLoopPresent = false; @@ -97,15 +97,15 @@ public String getClass_name() { return class_name; } - public HashSet getNodes() { + public LinkedHashSet getNodes() { return nodes; } - public HashSet getOuts() { + public LinkedHashSet getOuts() { return outs; } - public HashSet getIns() { + public LinkedHashSet getIns() { return ins; } @@ -204,7 +204,7 @@ public void mergeSeq(CFGNode branch) { outs.add(branch); } - public void mergeBranches(CFG target, HashSet saveOuts) { + public void mergeBranches(CFG target, LinkedHashSet saveOuts) { if (target.getNodes().size() == 0) return; @@ -297,7 +297,7 @@ public void addReturnNode(CFGNode node) { } public void adjustBreakNodes(String id) { - for (CFGNode node : new HashSet(this.breaks)) { + for (CFGNode node : new LinkedHashSet(this.breaks)) { if (node.getObjectName().equals(id)) { this.outs.add(node); this.breaks.remove(node); diff --git a/src/java/boa/graphs/cfg/CFGNode.java b/src/java/boa/graphs/cfg/CFGNode.java index 83443878c..ffa3e3414 100644 --- a/src/java/boa/graphs/cfg/CFGNode.java +++ b/src/java/boa/graphs/cfg/CFGNode.java @@ -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; @@ -41,7 +41,7 @@ public class CFGNode implements Comparable { private int objectNameId; private int classNameId; private int numOfParameters = 0; - private HashSet parameters; + private LinkedHashSet parameters; private int kind = TYPE_OTHER; private String pid; private Statement stmt; @@ -52,13 +52,13 @@ public class CFGNode implements Comparable { public static HashMap idOfLabel = new HashMap(); public static HashMap labelOfID = new HashMap(); - public HashSet inEdges = new HashSet(); - public HashSet outEdges = new HashSet(); + public LinkedHashSet inEdges = new LinkedHashSet(); + public LinkedHashSet outEdges = new LinkedHashSet(); public java.util.ArrayList predecessors = new java.util.ArrayList(); public java.util.ArrayList successors = new java.util.ArrayList(); - public HashSet useVariables = new HashSet(); + public LinkedHashSet useVariables = new LinkedHashSet(); public String defVariables; @Override @@ -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 datas) { + String objectName, int numOfParameters, LinkedHashSet datas) { this.id = ++numOfNodes; this.methodId = convertLabel(methodName); this.kind = kind; @@ -96,7 +96,7 @@ public CFGNode(String methodName, int kind, String className, } this.objectNameId = convertLabel(objectName); - this.parameters = new HashSet(datas); + this.parameters = new LinkedHashSet(datas); this.numOfParameters = numOfParameters; } @@ -114,8 +114,8 @@ public Statement getStmt() { return this.stmt; } - public HashSet getDefUse() { - HashSet defUse = new HashSet(useVariables); + public LinkedHashSet getDefUse() { + LinkedHashSet defUse = new LinkedHashSet(useVariables); defUse.add(defVariables); return defUse; } @@ -182,15 +182,15 @@ public int getNumOfParameters() { return numOfParameters; } - public void setParameters(HashSet parameters) { + public void setParameters(LinkedHashSet parameters) { this.parameters = parameters; } - public HashSet getParameters() { + public LinkedHashSet getParameters() { return parameters; } - public void setUseVariables(HashSet useVariables) { + public void setUseVariables(LinkedHashSet useVariables) { this.useVariables = useVariables; } @@ -214,7 +214,7 @@ public String getClassName() { return labelOfID.get(classNameId); } - public HashSet getUseVariables() { + public LinkedHashSet getUseVariables() { return useVariables; } @@ -230,11 +230,11 @@ public boolean hasFalseBranch() { return false; } - public HashSet getInEdges() { + public LinkedHashSet getInEdges() { return inEdges; } - public HashSet getOutEdges() { + public LinkedHashSet getOutEdges() { return outEdges; } @@ -255,7 +255,7 @@ public void setSuccessors(java.util.ArrayList successors) { } public java.util.ArrayList getInNodes() { - HashSet nodes = new HashSet(); + LinkedHashSet nodes = new LinkedHashSet(); for (CFGEdge e : inEdges) nodes.add(e.getSrc()); java.util.ArrayList pred = new java.util.ArrayList(nodes); @@ -264,7 +264,7 @@ public java.util.ArrayList getInNodes() { } public java.util.ArrayList getOutNodes() { - HashSet nodes = new HashSet(); + LinkedHashSet nodes = new LinkedHashSet(); for (CFGEdge e : outEdges) nodes.add(e.getDest()); java.util.ArrayList succ = new java.util.ArrayList(nodes); @@ -377,8 +377,8 @@ public String processDef() { return defVar; } - public HashSet processUse() { - HashSet useVar= new HashSet(); + public LinkedHashSet processUse() { + LinkedHashSet useVar= new LinkedHashSet(); if(this.expr!=null) { if(this.expr.getKind().toString().equals("ASSIGN")) { traverseExpr(useVar, this.rhs); @@ -390,7 +390,7 @@ public HashSet processUse() { return useVar; } - public static void traverseExpr(HashSet useVar, final boa.types.Ast.Expression expr) { + public static void traverseExpr(LinkedHashSet useVar, final boa.types.Ast.Expression expr) { if(expr.hasVariable()) { if(expr.getExpressionsList().size()!=0) { useVar.add("this"); @@ -416,7 +416,7 @@ public static void traverseExpr(HashSet useVar, final boa.types.Ast.Expr } } - public static void traverseVarDecls(HashSet useVar, final boa.types.Ast.Variable vardecls) { + public static void traverseVarDecls(LinkedHashSet useVar, final boa.types.Ast.Variable vardecls) { if(vardecls.hasInitializer()) { traverseExpr(useVar, vardecls.getInitializer()); } diff --git a/src/java/boa/runtime/BoaAbstractTraversal.java b/src/java/boa/runtime/BoaAbstractTraversal.java index 7459a9558..c452b577f 100644 --- a/src/java/boa/runtime/BoaAbstractTraversal.java +++ b/src/java/boa/runtime/BoaAbstractTraversal.java @@ -271,7 +271,7 @@ public final void traverse(final boa.graphs.cfg.CFG cfg, final Traversal.Travers prevOutputMapObj = new java.util.HashMap(outputMapObj); traverse(cfg, direction, kind); fixpFlag=true; - java.util.HashSet nl=cfg.getNodes(); + java.util.LinkedHashSet nl=cfg.getNodes(); for (CFGNode node : nl) { boolean curFlag=outputMapObj.containsKey(node.getId()); if (curFlag) { diff --git a/src/java/boa/types/BoaSet.java b/src/java/boa/types/BoaSet.java index e6f715f59..f492f0b5b 100644 --- a/src/java/boa/types/BoaSet.java +++ b/src/java/boa/types/BoaSet.java @@ -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} */ diff --git a/templates/BoaJava.stg b/templates/BoaJava.stg index 0ee53d47d..f8846a5b8 100644 --- a/templates/BoaJava.stg +++ b/templates/BoaJava.stg @@ -20,7 +20,7 @@ VarDecl(isstatic, type, id) ::= "static ___;<\n> ArrayType(type) ::= "[]" MapType(key, value) ::= "java.util.HashMap\<, >" StackType(value) ::= "java.util.Stack\<>" -SetType(value) ::= "java.util.HashSet\<>" +SetType(value) ::= "java.util.LinkedHashSet\<>" Block(statements) ::= << { }>} From 970890b4b912c450c444fac5e1d276b8a5eff809 Mon Sep 17 00:00:00 2001 From: Che Shian Hung Date: Thu, 12 Oct 2017 13:28:42 -0400 Subject: [PATCH 02/18] Fixes #159 type updated --- .../boa/functions/BoaGraphIntrinsics.java | 20 +++++++++---------- src/java/boa/graphs/cfg/CFG.java | 19 +++++++++--------- .../boa/runtime/BoaAbstractTraversal.java | 2 +- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/java/boa/functions/BoaGraphIntrinsics.java b/src/java/boa/functions/BoaGraphIntrinsics.java index 185543094..3bee232bd 100644 --- a/src/java/boa/functions/BoaGraphIntrinsics.java +++ b/src/java/boa/functions/BoaGraphIntrinsics.java @@ -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 LinkedHashSet getNodesWithDefinition(final CFGNode node) { - final LinkedHashSet vardef = new LinkedHashSet(); + public static Set getNodesWithDefinition(final CFGNode node) { + final Set vardef = new LinkedHashSet(); if (node.getExpression() != null) { if (node.getExpression().getKind() == ExpressionKind.VARDECL || node.getExpression().getKind() == ExpressionKind.ASSIGN) { vardef.add(String.valueOf(node.getId())); @@ -51,8 +51,8 @@ public static LinkedHashSet getNodesWithDefinition(final CFGNode node) { } @FunctionSpec(name = "get_variable_killed", returnType = "set of string", formalParameters = {"CFG", "CFGNode" }) - public static LinkedHashSet getVariableKilled(final boa.types.Control.CFG cfg, final CFGNode node) { - final LinkedHashSet varkilled = new LinkedHashSet(); + public static Set getVariableKilled(final boa.types.Control.CFG cfg, final CFGNode node) { + final Set varkilled = new LinkedHashSet(); String vardef = ""; if (node.getExpression() != null) { @@ -86,8 +86,8 @@ else if (tnode.getExpression().getKind() == ExpressionKind.ASSIGN) { } @FunctionSpec(name = "get_variable_def", returnType = "set of string", formalParameters = { "CFGNode" }) - public static LinkedHashSet getVariableDef(final CFGNode node) { - final LinkedHashSet vardef = new LinkedHashSet(); + public static Set getVariableDef(final CFGNode node) { + final Set vardef = new LinkedHashSet(); if (node.getExpression() != null) { if (node.getExpression().getKind() == ExpressionKind.VARDECL) { vardef.add(node.getExpression().getVariableDeclsList().get(0).getName()); @@ -100,15 +100,15 @@ else if (node.getExpression().getKind() == ExpressionKind.ASSIGN) { } @FunctionSpec(name = "get_variable_used", returnType = "set of string", formalParameters = { "CFGNode" }) - public static LinkedHashSet getVariableUsed(final CFGNode node) { - final LinkedHashSet varused = new LinkedHashSet(); + public static Set getVariableUsed(final CFGNode node) { + final Set varused = new LinkedHashSet(); if (node.getExpression() != null) { traverseExpr(varused,node.getExpression()); } return varused; } - public static void traverseExpr(final LinkedHashSet varused, final Expression expr) { + public static void traverseExpr(final Set varused, final Expression expr) { if (expr.getVariable() != null) { varused.add(expr.getVariable()); } @@ -123,7 +123,7 @@ public static void traverseExpr(final LinkedHashSet varused, final Expre } } - public static void traverseVarDecls(final LinkedHashSet varused, final Variable vardecls) { + public static void traverseVarDecls(final Set varused, final Variable vardecls) { if (vardecls.getInitializer() != null) { traverseExpr(varused, vardecls.getInitializer()); } diff --git a/src/java/boa/graphs/cfg/CFG.java b/src/java/boa/graphs/cfg/CFG.java index fa0b26682..c085f2110 100644 --- a/src/java/boa/graphs/cfg/CFG.java +++ b/src/java/boa/graphs/cfg/CFG.java @@ -17,6 +17,7 @@ package boa.graphs.cfg; import java.util.HashMap; +import java.util.Set; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -43,11 +44,11 @@ public class CFG { public String class_name; static boolean endFlag = false; static boolean switchFlag=false; - protected LinkedHashSet nodes = new LinkedHashSet(); - private LinkedHashSet outs = new LinkedHashSet(); - private LinkedHashSet ins = new LinkedHashSet(); - private LinkedHashSet breaks = new LinkedHashSet(); - private LinkedHashSet returns = new LinkedHashSet(); + protected Set nodes = new LinkedHashSet(); + private Set outs = new LinkedHashSet(); + private Set ins = new LinkedHashSet(); + private Set breaks = new LinkedHashSet(); + private Set returns = new LinkedHashSet(); private CFGNode entryNode ; private CFGNode exitNode ; private boolean isLoopPresent = false; @@ -97,15 +98,15 @@ public String getClass_name() { return class_name; } - public LinkedHashSet getNodes() { + public Set getNodes() { return nodes; } - public LinkedHashSet getOuts() { + public Set getOuts() { return outs; } - public LinkedHashSet getIns() { + public Set getIns() { return ins; } @@ -204,7 +205,7 @@ public void mergeSeq(CFGNode branch) { outs.add(branch); } - public void mergeBranches(CFG target, LinkedHashSet saveOuts) { + public void mergeBranches(CFG target, Set saveOuts) { if (target.getNodes().size() == 0) return; diff --git a/src/java/boa/runtime/BoaAbstractTraversal.java b/src/java/boa/runtime/BoaAbstractTraversal.java index c452b577f..a931ade1d 100644 --- a/src/java/boa/runtime/BoaAbstractTraversal.java +++ b/src/java/boa/runtime/BoaAbstractTraversal.java @@ -271,7 +271,7 @@ public final void traverse(final boa.graphs.cfg.CFG cfg, final Traversal.Travers prevOutputMapObj = new java.util.HashMap(outputMapObj); traverse(cfg, direction, kind); fixpFlag=true; - java.util.LinkedHashSet nl=cfg.getNodes(); + java.util.Set nl=cfg.getNodes(); for (CFGNode node : nl) { boolean curFlag=outputMapObj.containsKey(node.getId()); if (curFlag) { From b3f0fb48f299a990a348806a60b3367e16f45ba3 Mon Sep 17 00:00:00 2001 From: Che Shian Hung Date: Thu, 12 Oct 2017 17:36:02 -0400 Subject: [PATCH 03/18] Fixed #159, change types to general set as much as possible --- src/java/boa/aggregators/SetAggregator.java | 3 ++- src/java/boa/graphs/cfg/CFGNode.java | 25 +++++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/java/boa/aggregators/SetAggregator.java b/src/java/boa/aggregators/SetAggregator.java index 80a9e6926..00239847a 100644 --- a/src/java/boa/aggregators/SetAggregator.java +++ b/src/java/boa/aggregators/SetAggregator.java @@ -17,6 +17,7 @@ package boa.aggregators; import java.io.IOException; +import java.util.Set; import java.util.LinkedHashSet; import boa.io.EmitKey; @@ -28,7 +29,7 @@ */ @AggregatorSpec(name = "set", canCombine = true) public class SetAggregator extends Aggregator { - private LinkedHashSet set; + private Set set; private final long max; /** diff --git a/src/java/boa/graphs/cfg/CFGNode.java b/src/java/boa/graphs/cfg/CFGNode.java index ffa3e3414..70cd2428e 100644 --- a/src/java/boa/graphs/cfg/CFGNode.java +++ b/src/java/boa/graphs/cfg/CFGNode.java @@ -17,6 +17,7 @@ package boa.graphs.cfg; import java.util.HashMap; +import java.util.Set; import java.util.LinkedHashSet; import boa.types.Ast.Expression; @@ -41,7 +42,7 @@ public class CFGNode implements Comparable { private int objectNameId; private int classNameId; private int numOfParameters = 0; - private LinkedHashSet parameters; + private Set parameters; private int kind = TYPE_OTHER; private String pid; private Statement stmt; @@ -52,8 +53,8 @@ public class CFGNode implements Comparable { public static HashMap idOfLabel = new HashMap(); public static HashMap labelOfID = new HashMap(); - public LinkedHashSet inEdges = new LinkedHashSet(); - public LinkedHashSet outEdges = new LinkedHashSet(); + public Set inEdges = new LinkedHashSet(); + public Set outEdges = new LinkedHashSet(); public java.util.ArrayList predecessors = new java.util.ArrayList(); public java.util.ArrayList successors = new java.util.ArrayList(); @@ -84,7 +85,7 @@ public CFGNode(String methodName, int kind, String className, } public CFGNode(String methodName, int kind, String className, - String objectName, int numOfParameters, LinkedHashSet datas) { + String objectName, int numOfParameters, Set datas) { this.id = ++numOfNodes; this.methodId = convertLabel(methodName); this.kind = kind; @@ -114,8 +115,8 @@ public Statement getStmt() { return this.stmt; } - public LinkedHashSet getDefUse() { - LinkedHashSet defUse = new LinkedHashSet(useVariables); + public Set getDefUse() { + Set defUse = new LinkedHashSet(useVariables); defUse.add(defVariables); return defUse; } @@ -182,11 +183,11 @@ public int getNumOfParameters() { return numOfParameters; } - public void setParameters(LinkedHashSet parameters) { + public void setParameters(Set parameters) { this.parameters = parameters; } - public LinkedHashSet getParameters() { + public Set getParameters() { return parameters; } @@ -230,11 +231,11 @@ public boolean hasFalseBranch() { return false; } - public LinkedHashSet getInEdges() { + public Set getInEdges() { return inEdges; } - public LinkedHashSet getOutEdges() { + public Set getOutEdges() { return outEdges; } @@ -255,7 +256,7 @@ public void setSuccessors(java.util.ArrayList successors) { } public java.util.ArrayList getInNodes() { - LinkedHashSet nodes = new LinkedHashSet(); + Set nodes = new LinkedHashSet(); for (CFGEdge e : inEdges) nodes.add(e.getSrc()); java.util.ArrayList pred = new java.util.ArrayList(nodes); @@ -264,7 +265,7 @@ public java.util.ArrayList getInNodes() { } public java.util.ArrayList getOutNodes() { - LinkedHashSet nodes = new LinkedHashSet(); + Set nodes = new LinkedHashSet(); for (CFGEdge e : outEdges) nodes.add(e.getDest()); java.util.ArrayList succ = new java.util.ArrayList(nodes); From 207cdc84223b726054b42e5b52c7616cd13b0b3d Mon Sep 17 00:00:00 2001 From: Che Shian Hung Date: Fri, 19 Jan 2018 12:21:31 -0500 Subject: [PATCH 04/18] fix issue #159, change most LinkedHashSet to Set, change codegen --- .../compiler/visitors/CodeGeneratingVisitor.java | 14 ++++++++++---- src/java/boa/functions/BoaIntrinsics.java | 14 +++++++------- src/java/boa/graphs/cfg/CFGNode.java | 14 +++++++------- src/java/boa/types/BoaSet.java | 2 +- templates/BoaJava.stg | 10 +++++----- 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java index 711c4587c..b8e75e39e 100644 --- a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java +++ b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java @@ -280,7 +280,8 @@ public void visit(final TupleType n) { final List members = n.getMembers(); final List fields = new ArrayList(); - final List types = new ArrayList(); + final List fieldTypes = new ArrayList(); + final List initializeTypes = new ArrayList(); int fieldCount = 0; for (final Component c : members) { @@ -290,12 +291,17 @@ public void visit(final TupleType n) { fields.add("f" + fieldCount); } fieldCount++; - types.add(c.getType().type.toBoxedJavaType()); + fieldTypes.add(c.getType().type.toBoxedJavaType()); + if(c.getType().type instanceof BoaSet) + initializeTypes.add(c.getType().type.toBoxedJavaType().replace("Set", "LinkedHashSet")); + else + initializeTypes.add(c.getType().type.toBoxedJavaType()); } st.add("name", tupType.toJavaType()); st.add("fields", fields); - st.add("types", types); + st.add("fieldTypes", fieldTypes); + st.add("initializeTypes", initializeTypes); code.add(st.render()); } @@ -1856,7 +1862,7 @@ public void visit(final MapType n) { n.env.setNeedsBoxing(false); - code.add(st.render()); + code.add(st.render().replaceAll("LinkedHashSet", "Set")); } /** {@inheritDoc} */ diff --git a/src/java/boa/functions/BoaIntrinsics.java b/src/java/boa/functions/BoaIntrinsics.java index 2bfb81b36..81c2a14ae 100644 --- a/src/java/boa/functions/BoaIntrinsics.java +++ b/src/java/boa/functions/BoaIntrinsics.java @@ -306,25 +306,25 @@ public static boolean[] concat(final boolean[] first, final boolean[]... rest) { return result; } - public static java.util.LinkedHashSet set_union(final java.util.Set s1, final java.util.Set s2) { - final java.util.LinkedHashSet s = new java.util.LinkedHashSet(s1); + public static java.util.Set set_union(final java.util.Set s1, final java.util.Set s2) { + final java.util.Set s = new java.util.LinkedHashSet(s1); s.addAll(s2); return s; } - public static java.util.LinkedHashSet set_intersect(final java.util.Set s1, final java.util.Set s2) { - final java.util.LinkedHashSet s = new java.util.LinkedHashSet(s1); + public static java.util.Set set_intersect(final java.util.Set s1, final java.util.Set s2) { + final java.util.Set s = new java.util.LinkedHashSet(s1); s.retainAll(s2); return s; } - public static java.util.LinkedHashSet set_difference(final java.util.Set s1, final java.util.Set s2) { - final java.util.LinkedHashSet s = new java.util.LinkedHashSet(s1); + public static java.util.Set set_difference(final java.util.Set s1, final java.util.Set s2) { + final java.util.Set s = new java.util.LinkedHashSet(s1); s.removeAll(s2); return s; } - public static java.util.LinkedHashSet set_symdiff(final java.util.Set s1, final java.util.Set s2) { + public static java.util.Set set_symdiff(final java.util.Set s1, final java.util.Set s2) { return set_union(set_difference(s1, s2), set_difference(s2, s1)); } } diff --git a/src/java/boa/graphs/cfg/CFGNode.java b/src/java/boa/graphs/cfg/CFGNode.java index 70cd2428e..d94cc4a65 100644 --- a/src/java/boa/graphs/cfg/CFGNode.java +++ b/src/java/boa/graphs/cfg/CFGNode.java @@ -59,7 +59,7 @@ public class CFGNode implements Comparable { public java.util.ArrayList predecessors = new java.util.ArrayList(); public java.util.ArrayList successors = new java.util.ArrayList(); - public LinkedHashSet useVariables = new LinkedHashSet(); + public Set useVariables = new LinkedHashSet(); public String defVariables; @Override @@ -191,7 +191,7 @@ public Set getParameters() { return parameters; } - public void setUseVariables(LinkedHashSet useVariables) { + public void setUseVariables(Set useVariables) { this.useVariables = useVariables; } @@ -215,7 +215,7 @@ public String getClassName() { return labelOfID.get(classNameId); } - public LinkedHashSet getUseVariables() { + public Set getUseVariables() { return useVariables; } @@ -378,8 +378,8 @@ public String processDef() { return defVar; } - public LinkedHashSet processUse() { - LinkedHashSet useVar= new LinkedHashSet(); + public Set processUse() { + Set useVar= new LinkedHashSet(); if(this.expr!=null) { if(this.expr.getKind().toString().equals("ASSIGN")) { traverseExpr(useVar, this.rhs); @@ -391,7 +391,7 @@ public LinkedHashSet processUse() { return useVar; } - public static void traverseExpr(LinkedHashSet useVar, final boa.types.Ast.Expression expr) { + public static void traverseExpr(Set useVar, final boa.types.Ast.Expression expr) { if(expr.hasVariable()) { if(expr.getExpressionsList().size()!=0) { useVar.add("this"); @@ -417,7 +417,7 @@ public static void traverseExpr(LinkedHashSet useVar, final boa.types.As } } - public static void traverseVarDecls(LinkedHashSet useVar, final boa.types.Ast.Variable vardecls) { + public static void traverseVarDecls(Set useVar, final boa.types.Ast.Variable vardecls) { if(vardecls.hasInitializer()) { traverseExpr(useVar, vardecls.getInitializer()); } diff --git a/src/java/boa/types/BoaSet.java b/src/java/boa/types/BoaSet.java index f492f0b5b..66e2b8da6 100644 --- a/src/java/boa/types/BoaSet.java +++ b/src/java/boa/types/BoaSet.java @@ -124,7 +124,7 @@ public String toString() { /** {@inheritDoc} */ @Override public String toJavaType() { - return "java.util.LinkedHashSet<" + this.type.toBoxedJavaType() + ">"; + return "java.util.Set<" + this.type.toBoxedJavaType() + ">"; } /** {@inheritDoc} */ diff --git a/templates/BoaJava.stg b/templates/BoaJava.stg index f8846a5b8..4cbaf40a8 100644 --- a/templates/BoaJava.stg +++ b/templates/BoaJava.stg @@ -124,15 +124,15 @@ new () } >> -TupleType(name, fields, types) ::= << +TupleType(name, fields, fieldTypes, initializeTypes) ::= << private class { - ___}; separator="; ">; - ( ___}; separator=", "> ){ - = new (___)}; separator="; ">; + ___}; separator="; ">; + ( ___}; separator=", "> ){ + = new (___)}; separator="; ">; } ( tmp){ - = new (tmp.___)}; separator="; ">; + = new (tmp.___)}; separator="; ">; } public clone() { return new (this); From b263206322373b2deeb1aa16f1ad695f2c4e7936 Mon Sep 17 00:00:00 2001 From: Che Shian Hung Date: Mon, 22 Jan 2018 08:45:15 -0500 Subject: [PATCH 05/18] fix issue #159, toInterdaceJavaType and toParameterJavaType methods added --- .../visitors/CodeGeneratingVisitor.java | 23 ++++--------------- src/java/boa/types/BoaFloat.java | 12 ++++++++++ src/java/boa/types/BoaInt.java | 12 ++++++++++ src/java/boa/types/BoaMap.java | 8 ++++++- src/java/boa/types/BoaProtoMap.java | 12 ++++++++++ src/java/boa/types/BoaSet.java | 14 ++++++++++- src/java/boa/types/BoaStack.java | 2 +- src/java/boa/types/BoaType.java | 22 ++++++++++++++++++ 8 files changed, 83 insertions(+), 22 deletions(-) diff --git a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java index b8e75e39e..9ed83593a 100644 --- a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java +++ b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java @@ -182,7 +182,7 @@ public void visit(final VarDeclStatement n) { final ST st = stg.getInstanceOf("VarDecl"); st.add("id", n.getId().getToken()); - st.add("type", n.type.toJavaType()); + st.add("type", n.type.toInterfaceJavaType()); if (n.isStatic()) st.add("isstatic", true); @@ -291,11 +291,8 @@ public void visit(final TupleType n) { fields.add("f" + fieldCount); } fieldCount++; - fieldTypes.add(c.getType().type.toBoxedJavaType()); - if(c.getType().type instanceof BoaSet) - initializeTypes.add(c.getType().type.toBoxedJavaType().replace("Set", "LinkedHashSet")); - else - initializeTypes.add(c.getType().type.toBoxedJavaType()); + fieldTypes.add(c.getType().type.toInterfaceJavaType()); + initializeTypes.add(c.getType().type.toBoxedJavaType()); } st.add("name", tupType.toJavaType()); @@ -1850,19 +1847,7 @@ public void visit(final FixPType n) { /** {@inheritDoc} */ @Override public void visit(final MapType n) { - final ST st = stg.getInstanceOf("MapType"); - - n.env.setNeedsBoxing(true); - - n.getIndex().accept(this); - st.add("key", code.removeLast()); - - n.getValue().accept(this); - st.add("value", code.removeLast()); - - n.env.setNeedsBoxing(false); - - code.add(st.render().replaceAll("LinkedHashSet", "Set")); + code.add(n.type.toJavaType()); } /** {@inheritDoc} */ diff --git a/src/java/boa/types/BoaFloat.java b/src/java/boa/types/BoaFloat.java index aad2a8b13..5661d6a67 100644 --- a/src/java/boa/types/BoaFloat.java +++ b/src/java/boa/types/BoaFloat.java @@ -69,6 +69,18 @@ public String toBoxedJavaType() { return "Double"; } + /** {@inheritDoc} */ + @Override + public String toInterfaceJavaType() { + return toJavaType(); + } + + /** {@inheritDoc} */ + @Override + public String toParameterJavaType() { + return toBoxedJavaType(); + } + /** {@inheritDoc} */ @Override public String toString() { diff --git a/src/java/boa/types/BoaInt.java b/src/java/boa/types/BoaInt.java index ac4219322..5efe3419d 100644 --- a/src/java/boa/types/BoaInt.java +++ b/src/java/boa/types/BoaInt.java @@ -65,4 +65,16 @@ public String toJavaType() { public String toBoxedJavaType() { return "Long"; } + + /** {@inheritDoc} */ + @Override + public String toInterfaceJavaType() { + return toJavaType(); + } + + /** {@inheritDoc} */ + @Override + public String toParameterJavaType() { + return toBoxedJavaType(); + } } diff --git a/src/java/boa/types/BoaMap.java b/src/java/boa/types/BoaMap.java index 129f6afae..082fc2241 100644 --- a/src/java/boa/types/BoaMap.java +++ b/src/java/boa/types/BoaMap.java @@ -148,7 +148,13 @@ public String toString() { /** {@inheritDoc} */ @Override public String toJavaType() { - return "java.util.HashMap<" + this.indexType.toBoxedJavaType() + ", " + this.valueType.toBoxedJavaType() + ">"; + return "java.util.HashMap<" + this.indexType.toParameterJavaType() + ", " + this.valueType.toParameterJavaType() + ">"; + } + + /** {@inheritDoc} */ + @Override + public String toInterfaceJavaType() { + return "java.util.HashMap<" + this.indexType.toParameterJavaType() + ", " + this.valueType.toParameterJavaType() + ">"; } /** {@inheritDoc} */ diff --git a/src/java/boa/types/BoaProtoMap.java b/src/java/boa/types/BoaProtoMap.java index 4bbab12c9..2cc8663e7 100644 --- a/src/java/boa/types/BoaProtoMap.java +++ b/src/java/boa/types/BoaProtoMap.java @@ -75,6 +75,18 @@ public String toJavaType() { return getEnumClass().getName().replace('$', '.'); } + /** {@inheritDoc} */ + @Override + public String toInterfaceJavaType() { + return toJavaType(); + } + + /** {@inheritDoc} */ + @Override + public String toParameterJavaType() { + return toJavaType(); + } + /** {@inheritDoc} */ @Override public String toString() { diff --git a/src/java/boa/types/BoaSet.java b/src/java/boa/types/BoaSet.java index 66e2b8da6..967ac1368 100644 --- a/src/java/boa/types/BoaSet.java +++ b/src/java/boa/types/BoaSet.java @@ -124,7 +124,19 @@ public String toString() { /** {@inheritDoc} */ @Override public String toJavaType() { - return "java.util.Set<" + this.type.toBoxedJavaType() + ">"; + return "java.util.LinkedHashSet<" + this.type.toParameterJavaType() + ">"; + } + + /** {@inheritDoc} */ + @Override + public String toInterfaceJavaType() { + return "java.util.Set<" + this.type.toParameterJavaType() + ">"; + } + + /** {@inheritDoc} */ + @Override + public String toParameterJavaType() { + return "java.util.Set<" + this.type.toParameterJavaType() + ">"; } /** {@inheritDoc} */ diff --git a/src/java/boa/types/BoaStack.java b/src/java/boa/types/BoaStack.java index 58b4696be..c5ff612f8 100644 --- a/src/java/boa/types/BoaStack.java +++ b/src/java/boa/types/BoaStack.java @@ -124,7 +124,7 @@ public String toString() { /** {@inheritDoc} */ @Override public String toJavaType() { - return "java.util.Stack<" + this.type.toBoxedJavaType() + ">"; + return "java.util.Stack<" + this.type.toParameterJavaType() + ">"; } /** {@inheritDoc} */ diff --git a/src/java/boa/types/BoaType.java b/src/java/boa/types/BoaType.java index cdc120b27..b53c39488 100644 --- a/src/java/boa/types/BoaType.java +++ b/src/java/boa/types/BoaType.java @@ -111,6 +111,28 @@ public String toBoxedJavaType() { return toJavaType(); } + /** + * Returns a string representation of the interface Java equivalent of this Boa + * type. + * + * @return A String containing the name of the interface Java type equivalent to this + * Boa type + */ + public String toInterfaceJavaType() { + return toBoxedJavaType(); + } + + /** + * Returns a string representation of the parameter Java equivalent of this Boa + * type. + * + * @return A String containing the name of the parameter Java type equivalent to this + * Boa type + */ + public String toParameterJavaType() { + return toBoxedJavaType(); + } + /** * Takes a type name and returns one suitable for use as an identifier. * From 081e73127beefe5dc09b20f467be6d813b9dd609 Mon Sep 17 00:00:00 2001 From: Che Shian Hung Date: Mon, 22 Jan 2018 09:37:51 -0500 Subject: [PATCH 06/18] fix #159, simplify setType and stackType in codegen --- .../visitors/CodeGeneratingVisitor.java | 29 ++++++------------- templates/BoaJava.stg | 2 -- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java index 9ed83593a..71b6ebe99 100644 --- a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java +++ b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java @@ -1872,31 +1872,20 @@ public void visit(final OutputType n) { /** {@inheritDoc} */ @Override public void visit(final StackType n) { - final ST st = stg.getInstanceOf("StackType"); - - n.env.setNeedsBoxing(true); - - n.getValue().accept(this); - st.add("value", code.removeLast()); - - n.env.setNeedsBoxing(false); - - code.add(st.render()); + if(n.type != null) + code.add(n.type.toJavaType()); + else{ + final ST st = stg.getInstanceOf("StackType"); + n.getValue().accept(this); + st.add("value", code.removeLast()); + code.add(st.render()); + } } /** {@inheritDoc} */ @Override public void visit(final SetType n) { - final ST st = stg.getInstanceOf("SetType"); - - n.env.setNeedsBoxing(true); - - n.getValue().accept(this); - st.add("value", code.removeLast()); - - n.env.setNeedsBoxing(false); - - code.add(st.render()); + code.add(n.type.toJavaType()); } /** {@inheritDoc} */ diff --git a/templates/BoaJava.stg b/templates/BoaJava.stg index 4cbaf40a8..031493ebb 100644 --- a/templates/BoaJava.stg +++ b/templates/BoaJava.stg @@ -18,9 +18,7 @@ identifierMap ::= [ VarDecl(isstatic, type, id) ::= "static ___;<\n>" ArrayType(type) ::= "[]" -MapType(key, value) ::= "java.util.HashMap\<, >" StackType(value) ::= "java.util.Stack\<>" -SetType(value) ::= "java.util.LinkedHashSet\<>" Block(statements) ::= << { }>} From 1316b9e0a838d1c707ae726cf5a539c4b08170df Mon Sep 17 00:00:00 2001 From: Che Shian Hung Date: Mon, 22 Jan 2018 10:21:08 -0500 Subject: [PATCH 07/18] fix #159, inhattr stack type added --- .../transforms/InheritedAttributeTransformer.java | 5 +++-- .../boa/compiler/visitors/CodeGeneratingVisitor.java | 9 +-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/java/boa/compiler/transforms/InheritedAttributeTransformer.java b/src/java/boa/compiler/transforms/InheritedAttributeTransformer.java index aef68b86d..ee71366b3 100644 --- a/src/java/boa/compiler/transforms/InheritedAttributeTransformer.java +++ b/src/java/boa/compiler/transforms/InheritedAttributeTransformer.java @@ -196,9 +196,10 @@ public void visit(final Program n) { // c) For each type T in the set from 1b: for (final BoaTuple b: currentSet.getCurrentTypes()) { env = e.env; - // i) Add a variable 's_T_#' of type 'stack of T' at the top-most scope of the AST - final VarDeclStatement v = ASTFactory.createVarDecl(stackPrefix + stackCounter++, new StackType(new Component(ASTFactory.createIdentifier(getTypeName(b), env))), new BoaStack(b), env); + final StackType st = new StackType(new Component(ASTFactory.createIdentifier(getTypeName(b), env))); + st.type = new BoaStack(b); + final VarDeclStatement v = ASTFactory.createVarDecl(stackPrefix + stackCounter++, st, new BoaStack(b), env); v.env = v.getType().env = ((StackType)v.getType()).getValue().getType().env = n.env; v.env.set(v.getId().getToken(), v.type); n.getStatements().add(0, v); diff --git a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java index 71b6ebe99..4a21cd791 100644 --- a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java +++ b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java @@ -1872,14 +1872,7 @@ public void visit(final OutputType n) { /** {@inheritDoc} */ @Override public void visit(final StackType n) { - if(n.type != null) - code.add(n.type.toJavaType()); - else{ - final ST st = stg.getInstanceOf("StackType"); - n.getValue().accept(this); - st.add("value", code.removeLast()); - code.add(st.render()); - } + code.add(n.type.toJavaType()); } /** {@inheritDoc} */ From 1a582b6eb730a0bc0d7dfdf8e7f6da6316884106 Mon Sep 17 00:00:00 2001 From: Che Shian Hung Date: Mon, 22 Jan 2018 11:22:17 -0500 Subject: [PATCH 08/18] fix #159, Map field type fixed --- src/java/boa/compiler/visitors/CodeGeneratingVisitor.java | 6 +++--- src/java/boa/types/BoaMap.java | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java index 4a21cd791..ee3970ed2 100644 --- a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java +++ b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java @@ -230,7 +230,7 @@ public void visit(final FunctionType n) { for (final Component c : params) { args.add(c.getIdentifier().getToken()); - types.add(c.getType().type.toJavaType()); + types.add(c.getType().type.toInterfaceJavaType()); } st.add("name", funcType.toJavaType()); @@ -1583,7 +1583,7 @@ public void visit(final FunctionExpression n) { if (!(c instanceof BoaName)) continue; args.add(((BoaName)c).getId()); - types.add(((BoaName)c).getType().toJavaType()); + types.add(((BoaName)c).getType().toInterfaceJavaType()); } this.varDecl.start(n); @@ -1815,7 +1815,7 @@ public void visit(final FunctionType n) { for (int i = 0; i < paramTypes.length; i++) { args.add(((BoaName) paramTypes[i]).getId()); - types.add(paramTypes[i].toJavaType()); + types.add(paramTypes[i].toInterfaceJavaType()); } st.add("name", funcType.toJavaType()); diff --git a/src/java/boa/types/BoaMap.java b/src/java/boa/types/BoaMap.java index 082fc2241..15da87eb0 100644 --- a/src/java/boa/types/BoaMap.java +++ b/src/java/boa/types/BoaMap.java @@ -154,7 +154,13 @@ public String toJavaType() { /** {@inheritDoc} */ @Override public String toInterfaceJavaType() { - return "java.util.HashMap<" + this.indexType.toParameterJavaType() + ", " + this.valueType.toParameterJavaType() + ">"; + return "java.util.Map<" + this.indexType.toParameterJavaType() + ", " + this.valueType.toParameterJavaType() + ">"; + } + + /** {@inheritDoc} */ + @Override + public String toParameterJavaType() { + return "java.util.Map<" + this.indexType.toParameterJavaType() + ", " + this.valueType.toParameterJavaType() + ">"; } /** {@inheritDoc} */ From 7521adbda4e1946c2b50924e2913ecac7c1a9687 Mon Sep 17 00:00:00 2001 From: Che Shian Hung Date: Mon, 22 Jan 2018 11:26:51 -0500 Subject: [PATCH 09/18] fix #159, spacing and template fixed --- .../boa/compiler/transforms/InheritedAttributeTransformer.java | 1 + templates/BoaJava.stg | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java/boa/compiler/transforms/InheritedAttributeTransformer.java b/src/java/boa/compiler/transforms/InheritedAttributeTransformer.java index ee71366b3..001f2353e 100644 --- a/src/java/boa/compiler/transforms/InheritedAttributeTransformer.java +++ b/src/java/boa/compiler/transforms/InheritedAttributeTransformer.java @@ -196,6 +196,7 @@ public void visit(final Program n) { // c) For each type T in the set from 1b: for (final BoaTuple b: currentSet.getCurrentTypes()) { env = e.env; + // i) Add a variable 's_T_#' of type 'stack of T' at the top-most scope of the AST final StackType st = new StackType(new Component(ASTFactory.createIdentifier(getTypeName(b), env))); st.type = new BoaStack(b); diff --git a/templates/BoaJava.stg b/templates/BoaJava.stg index 031493ebb..082727616 100644 --- a/templates/BoaJava.stg +++ b/templates/BoaJava.stg @@ -18,7 +18,6 @@ identifierMap ::= [ VarDecl(isstatic, type, id) ::= "static ___;<\n>" ArrayType(type) ::= "[]" -StackType(value) ::= "java.util.Stack\<>" Block(statements) ::= << { }>} From e3b144952564afdf8362a0968c346b6b65363453 Mon Sep 17 00:00:00 2001 From: Robert Dyer Date: Tue, 13 Aug 2019 11:09:33 -0400 Subject: [PATCH 10/18] remove unneeded type templates --- .../boa/compiler/visitors/CodeGeneratingVisitor.java | 11 +---------- templates/BoaJava.stg | 4 ---- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java index e99b75c8d..dbedfa689 100644 --- a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java +++ b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java @@ -1860,16 +1860,7 @@ public void visit(final StackType n) { /** {@inheritDoc} */ @Override public void visit(final QueueType n) { - final ST st = stg.getInstanceOf("QueueType"); - - n.env.setNeedsBoxing(true); - - n.getValue().accept(this); - st.add("value", code.removeLast()); - - n.env.setNeedsBoxing(false); - - code.add(st.render()); + code.add(n.type.toJavaType()); } /** {@inheritDoc} */ diff --git a/templates/BoaJava.stg b/templates/BoaJava.stg index 921a6b062..3dce9bbb5 100644 --- a/templates/BoaJava.stg +++ b/templates/BoaJava.stg @@ -18,10 +18,6 @@ identifierMap ::= [ VarDecl(isstatic, type, id) ::= "static ___;<\n>" ArrayType(type) ::= "[]" -MapType(key, value) ::= "java.util.HashMap\<, >" -StackType(value) ::= "java.util.Stack\<>" -QueueType(value) ::= "java.util.LinkedList\<>" -SetType(value) ::= "java.util.LinkedHashSet\<>" Block(statements) ::= << { }>} From af992b88f7154d0dd3179af3e54b2dc5fd481b24 Mon Sep 17 00:00:00 2001 From: Robert Dyer Date: Tue, 13 Aug 2019 12:23:53 -0400 Subject: [PATCH 11/18] convert more HashSet to LinkedHashSet --- .../aggregators/PreconditionAggregator.java | 20 +++++++++---------- src/java/boa/compiler/SymbolTable.java | 4 ++-- .../InheritedAttributeTransformer.java | 4 ++-- .../VisitorOptimizingTransformer.java | 8 ++++---- .../visitors/CodeGeneratingVisitor.java | 8 ++++---- .../visitors/IdentifierFindingVisitor.java | 4 ++-- .../visitors/TaskClassifyingVisitor.java | 6 +++--- .../visitors/TypeCheckingVisitor.java | 8 ++++---- .../visitors/analysis/CreateNodeId.java | 2 +- .../analysis/DataFlowSensitivityAnalysis.java | 6 +++--- .../analysis/InformationAnalysis.java | 10 +++++----- .../analysis/LocalMayAliasAnalysis.java | 6 +++--- .../analysis/LoopSensitivityAnalysis.java | 14 ++++++------- src/java/boa/functions/BoaIntrinsics.java | 12 +++++------ .../functions/BoaNormalFormIntrinsics.java | 4 ++-- src/java/boa/graphs/Node.java | 10 +++++----- src/java/boa/graphs/cdg/CDG.java | 4 ++-- src/java/boa/graphs/cdg/CDGNode.java | 6 +++--- src/java/boa/graphs/ddg/DDG.java | 16 +++++++-------- src/java/boa/graphs/pdg/PDG.java | 14 ++++++------- src/java/boa/graphs/pdg/PDGNode.java | 6 +++--- src/java/boa/graphs/slicers/CFGSlicer.java | 20 +++++++++---------- src/java/boa/graphs/slicers/PDGSlicer.java | 10 +++++----- src/java/boa/graphs/trees/DTree.java | 14 ++++++------- src/java/boa/graphs/trees/PDTree.java | 4 ++-- src/java/boa/types/BoaProtoList.java | 4 ++-- src/java/boa/types/BoaProtoTuple.java | 4 ++-- 27 files changed, 114 insertions(+), 114 deletions(-) diff --git a/src/java/boa/aggregators/PreconditionAggregator.java b/src/java/boa/aggregators/PreconditionAggregator.java index c70cb903f..2d3b499ea 100644 --- a/src/java/boa/aggregators/PreconditionAggregator.java +++ b/src/java/boa/aggregators/PreconditionAggregator.java @@ -67,8 +67,8 @@ public void aggregate(final String data, final String metadata) throws IOExcepti final Expression precondition = parseexpression(precond); if (!precondMethods.containsKey(precondition)) { - precondMethods.put(precondition, new HashSet()); - precondProjects.put(precondition, new HashSet()); + precondMethods.put(precondition, new LinkedHashSet()); + precondProjects.put(precondition, new LinkedHashSet()); } precondMethods.get(precondition).add(project + clientmethod); @@ -103,7 +103,7 @@ private void doInference() { */ private Map> infer(Map> precondMP) { final Map> infPreconditions = new HashMap>(precondMP); - final Set preconds = new HashSet(infPreconditions.keySet()); + final Set preconds = new LinkedHashSet(infPreconditions.keySet()); for (final Expression eqPrecond : preconds) { if (eqPrecond.getKind() == ExpressionKind.EQ) { @@ -121,10 +121,10 @@ private Map> infer(Map> precondM final Expression nsineqPrecond = builder.build(); if (!preconds.contains(nsineqPrecond)) - infPreconditions.put(nsineqPrecond, new HashSet()); + infPreconditions.put(nsineqPrecond, new LinkedHashSet()); if (infPreconditions.get(eqPrecond).size() == infPreconditions.get(sineqPrecond).size()) { - Set tempSet = new HashSet(infPreconditions.get(nsineqPrecond)); + Set tempSet = new LinkedHashSet(infPreconditions.get(nsineqPrecond)); tempSet.addAll(infPreconditions.get(eqPrecond)); infPreconditions.get(nsineqPrecond).addAll(tempSet); } @@ -151,7 +151,7 @@ else if (infPreconditions.get(eqPrecond).size() > infPreconditions.get(sineqPrec private Map> mergeConditionsWithImplication(final Map> precondMP) { final Map> mergedPreconditions = new HashMap>(precondMP); - final Set preconds = new HashSet(mergedPreconditions.keySet()); + final Set preconds = new LinkedHashSet(mergedPreconditions.keySet()); for (final Expression strongPrecond : preconds) { for (final Expression weakPrecond : preconds) { @@ -186,7 +186,7 @@ else if (strongPrecond.getKind() == ExpressionKind.LT && weakPrecond.getKind() = */ private Map> removeEquality(final Map> precondMP) { final Map> filtPreconditions = new HashMap>(precondMP); - final Set preconds = new HashSet(filtPreconditions.keySet()); + final Set preconds = new LinkedHashSet(filtPreconditions.keySet()); for (final Expression precond : preconds) { if (precond.getKind() == ExpressionKind.OTHER) { @@ -241,7 +241,7 @@ private Map calcConfidence(final Map> pr final Map precondConf = new HashMap(); final Set preconds = precondMP.keySet(); - final Set totalCalls = new HashSet(); + final Set totalCalls = new LinkedHashSet(); for (final Expression precond : preconds) if (precondMP.get(precond).size() > 1) totalCalls.addAll(precondMP.get(precond)); @@ -302,7 +302,7 @@ private List> doRanking(final Map filt * @return set of all combinations of arguments */ private Set> kCombinations() { - final Set> comb = new HashSet>(); + final Set> comb = new LinkedHashSet>(); final List argList = new ArrayList(); comb.add(new TreeSet(Collections.singletonList("rcv$"))); argList.add("rcv$"); @@ -313,7 +313,7 @@ private Set> kCombinations() { } for (final String arg : argList) { - final Set> tempComb = new HashSet>(comb); + final Set> tempComb = new LinkedHashSet>(comb); for (final SortedSet s : tempComb) { final SortedSet t = new TreeSet(s); t.add(arg); diff --git a/src/java/boa/compiler/SymbolTable.java b/src/java/boa/compiler/SymbolTable.java index 3651d5bca..91dca6512 100644 --- a/src/java/boa/compiler/SymbolTable.java +++ b/src/java/boa/compiler/SymbolTable.java @@ -204,7 +204,7 @@ public class SymbolTable { globalFunctions.addFunction("regex", new BoaFunction(new BoaString(), new BoaType[] { new BoaName(new BoaScalar()) }, "boa.functions.BoaSpecialIntrinsics.regex(\"${0}\")")); // clone functions - globalFunctions.addFunction("clone", new BoaFunction(new BoaSet(new BoaTypeVar("V")), new BoaType[] {new BoaSet(new BoaTypeVar("V"))},"(java.util.HashSet)${0}.clone()")); + globalFunctions.addFunction("clone", new BoaFunction(new BoaSet(new BoaTypeVar("V")), new BoaType[] {new BoaSet(new BoaTypeVar("V"))},"(java.util.LinkedHashSet)${0}.clone()")); globalFunctions.addFunction("clone", new BoaFunction(new BoaString(), new BoaType[] {new BoaString()},"new String(${0})")); // visitors @@ -247,7 +247,7 @@ public class SymbolTable { globalFunctions.addFunction("remove", new BoaFunction(new BoaAny(), new BoaType[] { new BoaSet(new BoaTypeVar("V")), new BoaTypeVar("V") }, "${0}.remove(${1})")); globalFunctions.addFunction("clear", new BoaFunction(new BoaAny(), new BoaType[] { new BoaSet(new BoaTypeVar("V")) }, "${0}.clear()")); globalFunctions.addFunction("values", new BoaFunction(new BoaArray(new BoaTypeVar("V")), new BoaType[] { new BoaSet(new BoaTypeVar("V")) }, "boa.functions.BoaIntrinsics.basic_array(${0}.toArray(new ${V}[0]))")); - globalFunctions.addFunction("values", new BoaFunction(new BoaArray(new BoaSet(new BoaString())), new BoaType[] { new BoaSet(new BoaSet(new BoaString())) }, "boa.functions.BoaIntrinsics.basic_array(${0}.toArray(new java.util.HashSet[0]))")); + globalFunctions.addFunction("values", new BoaFunction(new BoaArray(new BoaSet(new BoaString())), new BoaType[] { new BoaSet(new BoaSet(new BoaString())) }, "boa.functions.BoaIntrinsics.basic_array(${0}.toArray(new java.util.LinkedHashSet[0]))")); globalFunctions.addFunction("union", new BoaFunction(new BoaSet(new BoaTypeVar("V")), new BoaType[] { new BoaSet(new BoaTypeVar("V")), new BoaSet(new BoaTypeVar("V")) }, "boa.functions.BoaIntrinsics.set_union(${0}, ${1})")); globalFunctions.addFunction("intersect", new BoaFunction(new BoaSet(new BoaTypeVar("V")), new BoaType[] { new BoaSet(new BoaTypeVar("V")), new BoaSet(new BoaTypeVar("V")) }, "boa.functions.BoaIntrinsics.set_intersect(${0}, ${1})")); diff --git a/src/java/boa/compiler/transforms/InheritedAttributeTransformer.java b/src/java/boa/compiler/transforms/InheritedAttributeTransformer.java index 001f2353e..21243155b 100644 --- a/src/java/boa/compiler/transforms/InheritedAttributeTransformer.java +++ b/src/java/boa/compiler/transforms/InheritedAttributeTransformer.java @@ -19,7 +19,7 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -99,7 +99,7 @@ public void visit(final VisitorExpression n) { * mapping from each type T found to a list of all uses in current(T). */ private class FindCurrentForVisitors extends AbstractVisitorNoArgNoRet{ - protected final Set currents = new HashSet(); + protected final Set currents = new LinkedHashSet(); protected final Map> factorMap = new HashMap>(); /** @{inheritDoc} */ diff --git a/src/java/boa/compiler/transforms/VisitorOptimizingTransformer.java b/src/java/boa/compiler/transforms/VisitorOptimizingTransformer.java index 176a2a4f2..ce262af8e 100644 --- a/src/java/boa/compiler/transforms/VisitorOptimizingTransformer.java +++ b/src/java/boa/compiler/transforms/VisitorOptimizingTransformer.java @@ -16,7 +16,7 @@ */ package boa.compiler.transforms; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import java.util.Stack; @@ -39,7 +39,7 @@ * @author rdyer */ public class VisitorOptimizingTransformer extends AbstractVisitorNoArgNoRet { - protected final static Set> astTypes = new HashSet>(); + protected final static Set> astTypes = new LinkedHashSet>(); static { astTypes.addAll(new ASTRootProtoTuple().reachableTypes()); @@ -59,7 +59,7 @@ public class VisitorOptimizingTransformer extends AbstractVisitorNoArgNoRet { /** {@inheritDoc} */ @Override protected void initialize() { - types = new HashSet>(); + types = new LinkedHashSet>(); beforeChangedFile = afterChangedFile = null; typeStack.clear(); @@ -74,7 +74,7 @@ public void visit(final VisitorExpression n) { beforeStack.push(beforeChangedFile); afterStack.push(afterChangedFile); - types = new HashSet>(); + types = new LinkedHashSet>(); beforeChangedFile = afterChangedFile = null; n.getBody().accept(this); diff --git a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java index dbedfa689..5ff19b0b1 100644 --- a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java +++ b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java @@ -202,7 +202,7 @@ public void visit(final VarDeclStatement n) { * @author rdyer */ protected class FunctionDeclaratorCodeGeneratingVisitor extends AbstractCodeGeneratingVisitor { - protected final Set funcs = new HashSet(); + protected final Set funcs = new LinkedHashSet(); /** {@inheritDoc} */ @Override @@ -253,7 +253,7 @@ public void visit(final FunctionType n) { * @author ankuraga */ protected class TupleDeclaratorCodeGeneratingVisitor extends AbstractCodeGeneratingVisitor { - protected final Set tuples = new HashSet(); + protected final Set tuples = new LinkedHashSet(); /** {@inheritDoc} */ @Override @@ -429,7 +429,7 @@ protected class IndexeeFindingVisitor extends AbstractVisitorNoReturn { protected Node lastFactor; protected Map lastFactors = new HashMap(); - protected final Set indexees = new HashSet(); + protected final Set indexees = new LinkedHashSet(); /** {@inheritDoc} */ @Override @@ -1487,7 +1487,7 @@ public void visit(final TraverseStatement n) { createNodeId.start(cfgBuilder); final LocalMayAliasAnalysis localMayAliasAnalysis = new LocalMayAliasAnalysis(); - final HashSet aliastSet = localMayAliasAnalysis.start(cfgBuilder, traversalId); + final Set aliastSet = localMayAliasAnalysis.start(cfgBuilder, traversalId); final DataFlowSensitivityAnalysis dataFlowSensitivityAnalysis = new DataFlowSensitivityAnalysis(); dataFlowSensitivityAnalysis.start(cfgBuilder, aliastSet); diff --git a/src/java/boa/compiler/visitors/IdentifierFindingVisitor.java b/src/java/boa/compiler/visitors/IdentifierFindingVisitor.java index 7502b79d0..4dcded4c8 100644 --- a/src/java/boa/compiler/visitors/IdentifierFindingVisitor.java +++ b/src/java/boa/compiler/visitors/IdentifierFindingVisitor.java @@ -17,7 +17,7 @@ */ package boa.compiler.visitors; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import boa.compiler.ast.Identifier; @@ -27,7 +27,7 @@ * @author rdyer */ public class IdentifierFindingVisitor extends AbstractVisitorNoArgNoRet { - protected final Set names = new HashSet(); + protected final Set names = new LinkedHashSet(); public Set getNames() { return names; diff --git a/src/java/boa/compiler/visitors/TaskClassifyingVisitor.java b/src/java/boa/compiler/visitors/TaskClassifyingVisitor.java index 07fd29341..a0205646a 100644 --- a/src/java/boa/compiler/visitors/TaskClassifyingVisitor.java +++ b/src/java/boa/compiler/visitors/TaskClassifyingVisitor.java @@ -16,7 +16,7 @@ */ package boa.compiler.visitors; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import boa.compiler.ast.Call; @@ -34,13 +34,13 @@ * @author rdyer */ public class TaskClassifyingVisitor extends AbstractVisitorNoArgNoRet { - protected final static Set> astTypes = new HashSet>(); + protected final static Set> astTypes = new LinkedHashSet>(); static { astTypes.addAll(new ASTRootProtoTuple().reachableTypes()); } - protected final Set> types = new HashSet>(); + protected final Set> types = new LinkedHashSet>(); private boolean complex = false; diff --git a/src/java/boa/compiler/visitors/TypeCheckingVisitor.java b/src/java/boa/compiler/visitors/TypeCheckingVisitor.java index caee1ec43..883c5efa4 100644 --- a/src/java/boa/compiler/visitors/TypeCheckingVisitor.java +++ b/src/java/boa/compiler/visitors/TypeCheckingVisitor.java @@ -49,8 +49,8 @@ public class TypeCheckingVisitor extends AbstractVisitorNoReturn { * @author rdyer */ protected class VisitorCheckingVisitor extends AbstractVisitorNoArgNoRet { - protected Set befores = new HashSet(); - protected Set afters = new HashSet(); + protected Set befores = new LinkedHashSet(); + protected Set afters = new LinkedHashSet(); protected boolean nested = false; /** {@inheritDoc} */ @@ -94,7 +94,7 @@ public void visit(final VisitStatement n) { } protected class TraversalCheckingVisitor extends AbstractVisitorNoArgNoRet { - protected Set befores = new HashSet(); + protected Set befores = new LinkedHashSet(); protected boolean nested = false; /** {@inheritDoc} */ @@ -136,7 +136,7 @@ public void visit(final TraverseStatement n) { } protected class FixPCheckingVisitor extends AbstractVisitorNoArgNoRet { - protected Set befores = new HashSet(); + protected Set befores = new LinkedHashSet(); protected boolean nested = false; /** {@inheritDoc} */ diff --git a/src/java/boa/compiler/visitors/analysis/CreateNodeId.java b/src/java/boa/compiler/visitors/analysis/CreateNodeId.java index 6f64edd2d..547e9c131 100644 --- a/src/java/boa/compiler/visitors/analysis/CreateNodeId.java +++ b/src/java/boa/compiler/visitors/analysis/CreateNodeId.java @@ -38,7 +38,7 @@ public final void createNodeIds(final Node node, final java.util.Set visit } public void start(final CFGBuildingVisitor cfgBuilder) { - final java.util.Set visitedNodes = new java.util.HashSet(); + final Set visitedNodes = new LinkedHashSet(); visitedNodes.add(cfgBuilder.currentStartNodes.get(0)); createNodeIds(cfgBuilder.currentStartNodes.get(0), visitedNodes); } diff --git a/src/java/boa/compiler/visitors/analysis/DataFlowSensitivityAnalysis.java b/src/java/boa/compiler/visitors/analysis/DataFlowSensitivityAnalysis.java index 96434827f..1d2399b78 100644 --- a/src/java/boa/compiler/visitors/analysis/DataFlowSensitivityAnalysis.java +++ b/src/java/boa/compiler/visitors/analysis/DataFlowSensitivityAnalysis.java @@ -42,7 +42,7 @@ */ public class DataFlowSensitivityAnalysis extends AbstractVisitorNoArgNoRet { public boolean getValueFound = false; - public HashSet getValueNodes = new HashSet(); + public Set getValueNodes = new LinkedHashSet(); boolean flowSensitive = false; boolean argFlag = false; protected boolean abortGeneration = false; @@ -53,8 +53,8 @@ public boolean isFlowSensitive() { return flowSensitive; } - public void start(final CFGBuildingVisitor cfgBuilder, final HashSet aliastSet) { - final java.util.Set visitedNodes = new java.util.HashSet(); + public void start(final CFGBuildingVisitor cfgBuilder, final Set aliastSet) { + final Set visitedNodes = new LinkedHashSet(); visitedNodes.add(cfgBuilder.currentStartNodes.get(0).nodeId); dfs(cfgBuilder.currentStartNodes.get(0), visitedNodes); diff --git a/src/java/boa/compiler/visitors/analysis/InformationAnalysis.java b/src/java/boa/compiler/visitors/analysis/InformationAnalysis.java index ba26b6158..ee36736df 100644 --- a/src/java/boa/compiler/visitors/analysis/InformationAnalysis.java +++ b/src/java/boa/compiler/visitors/analysis/InformationAnalysis.java @@ -46,21 +46,21 @@ public class InformationAnalysis extends AbstractVisitorNoArgNoRet { public boolean intersectionFound = false; public boolean addFound = false; public boolean removeFound = false; - public HashSet getValueNodesAlias = new HashSet(); - public HashSet totalGetValueNodes = new HashSet(); + public Set getValueNodesAlias = new LinkedHashSet(); + public Set totalGetValueNodes = new LinkedHashSet(); protected final IdentifierFindingVisitor idFinder = new IdentifierFindingVisitor(); protected final CallFindingVisitor callFinder = new CallFindingVisitor(); protected boolean abortGeneration = false; public boolean argFlag = false; public boolean genFlag = false; public boolean killFlag = false; - HashSet mergeOperation = new HashSet(); + Set mergeOperation = new LinkedHashSet(); int satisfiedNodes = 0; - public void start(final CFGBuildingVisitor cfgBuilder, final HashSet getValueNodesAlias, final HashSet totalGetValueNodes) { + public void start(final CFGBuildingVisitor cfgBuilder, final Set getValueNodesAlias, final Set totalGetValueNodes) { this.getValueNodesAlias = getValueNodesAlias; this.totalGetValueNodes = totalGetValueNodes; - final java.util.Set visitedNodes = new java.util.HashSet(); + final Set visitedNodes = new LinkedHashSet(); visitedNodes.add(cfgBuilder.currentStartNodes.get(0).nodeId); dfs(cfgBuilder.currentStartNodes.get(0), visitedNodes); } diff --git a/src/java/boa/compiler/visitors/analysis/LocalMayAliasAnalysis.java b/src/java/boa/compiler/visitors/analysis/LocalMayAliasAnalysis.java index 74975a11e..62e0ad287 100644 --- a/src/java/boa/compiler/visitors/analysis/LocalMayAliasAnalysis.java +++ b/src/java/boa/compiler/visitors/analysis/LocalMayAliasAnalysis.java @@ -42,15 +42,15 @@ * @author rramu */ public class LocalMayAliasAnalysis extends AbstractVisitorNoArgNoRet { - HashSet aliastSet = new HashSet(); + Set aliastSet = new LinkedHashSet(); Identifier lastDefVariable; boolean cloneFound = false; protected final IdentifierFindingVisitor idFinder = new IdentifierFindingVisitor(); protected final CallFindingVisitor callFinder = new CallFindingVisitor(); - public HashSet start(CFGBuildingVisitor cfgBuilder, Identifier id) { + public Set start(CFGBuildingVisitor cfgBuilder, Identifier id) { aliastSet.add(id); - final java.util.Set visitedNodes = new java.util.HashSet(); + final Set visitedNodes = new LinkedHashSet(); visitedNodes.add(cfgBuilder.currentStartNodes.get(0).nodeId); dfs(cfgBuilder.currentStartNodes.get(0), visitedNodes); return aliastSet; diff --git a/src/java/boa/compiler/visitors/analysis/LoopSensitivityAnalysis.java b/src/java/boa/compiler/visitors/analysis/LoopSensitivityAnalysis.java index 4db051406..e2799df64 100644 --- a/src/java/boa/compiler/visitors/analysis/LoopSensitivityAnalysis.java +++ b/src/java/boa/compiler/visitors/analysis/LoopSensitivityAnalysis.java @@ -45,15 +45,15 @@ public class LoopSensitivityAnalysis extends AbstractVisitorNoArgNoRet { public CFGBuildingVisitor cfgBuilder; public boolean getValueFound = false; - public HashSet getValueNodes = new HashSet(); - public HashSet totalGetValueNodes = new HashSet(); - public HashSet getValueNodesAlias = new HashSet(); + public Set getValueNodes = new LinkedHashSet(); + public Set totalGetValueNodes = new LinkedHashSet(); + public Set getValueNodesAlias = new LinkedHashSet(); boolean loopSensitive = false; protected final IdentifierFindingVisitor idFinder = new IdentifierFindingVisitor(); protected final CallFindingVisitor callFinder = new CallFindingVisitor(); protected boolean abortGeneration = false; public boolean argFlag = false; - public HashSet aliastSet; + public Set aliastSet; public Identifier lastDeclVariable; boolean isRhs = false; @@ -61,16 +61,16 @@ public boolean isLoopSensitive() { return loopSensitive; } - public void start(CFGBuildingVisitor cfgBuilder, HashSet aliastSet) { + public void start(CFGBuildingVisitor cfgBuilder, Set aliastSet) { this.aliastSet = aliastSet; this.cfgBuilder = cfgBuilder; - final java.util.Set visitedNodes = new java.util.HashSet(); + final Set visitedNodes = new LinkedHashSet(); visitedNodes.add(cfgBuilder.currentStartNodes.get(0).nodeId); dfs(cfgBuilder.currentStartNodes.get(0), visitedNodes); for (final Identifier getValueNode : getValueNodes) { final LocalMayAliasAnalysis localMayAliasAnalysis = new LocalMayAliasAnalysis(); - final HashSet tmpAliastSet = localMayAliasAnalysis.start(this.cfgBuilder, getValueNode); + final Set tmpAliastSet = localMayAliasAnalysis.start(this.cfgBuilder, getValueNode); getValueNodesAlias.addAll(tmpAliastSet); } final InformationAnalysis informationAnalysis = new InformationAnalysis(); diff --git a/src/java/boa/functions/BoaIntrinsics.java b/src/java/boa/functions/BoaIntrinsics.java index ae087cad3..d662b3d8f 100644 --- a/src/java/boa/functions/BoaIntrinsics.java +++ b/src/java/boa/functions/BoaIntrinsics.java @@ -20,7 +20,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.Comparator; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.PriorityQueue; @@ -117,14 +117,14 @@ public static ChangedFile[] getSnapshotByIndex(final CodeRepository cr, final lo if (commitOffset == cr.getHead()) return getSnapshot(cr, kinds); List snapshot = new LinkedList(); - Set adds = new HashSet(), dels = new HashSet(); + Set adds = new LinkedHashSet(), dels = new LinkedHashSet(); PriorityQueue pq = new PriorityQueue(100, new Comparator() { @Override public int compare(Integer i1, Integer i2) { return i2 - i1; } }); - Set queuedCommitIds = new HashSet(); + Set queuedCommitIds = new LinkedHashSet(); pq.offer((int) commitOffset); queuedCommitIds.add((int) commitOffset); while (!pq.isEmpty()) { @@ -143,14 +143,14 @@ public static ChangedFile[] getSnapshot(final CodeRepository cr, final Revision @FunctionSpec(name = "getsnapshot", returnType = "array of ChangedFile", formalParameters = { "CodeRepository", "Revision", "string..." }) public static ChangedFile[] getSnapshot(final CodeRepository cr, final Revision commit, final String... kinds) { List snapshot = new LinkedList(); - Set adds = new HashSet(), dels = new HashSet(); + Set adds = new LinkedHashSet(), dels = new LinkedHashSet(); PriorityQueue pq = new PriorityQueue(100, new Comparator() { @Override public int compare(Integer i1, Integer i2) { return i2 - i1; } }); - Set queuedCommitIds = new HashSet(); + Set queuedCommitIds = new LinkedHashSet(); update(snapshot, commit, adds, dels, pq, queuedCommitIds, kinds); while (!pq.isEmpty()) { int offset = pq.poll(); @@ -292,7 +292,7 @@ public static ChangedFile[] getPreviousVersion(final CodeRepository cr, final Ch fb.setName(cf.getPreviousNames(i)); ChangedFile key = fb.build(); int revisionIndex = cf.getPreviousVersions(i); - Set queuedRevisionIds = new HashSet(); + Set queuedRevisionIds = new LinkedHashSet(); PriorityQueue pq = new PriorityQueue(100, new Comparator() { @Override public int compare(Integer i1, Integer i2) { diff --git a/src/java/boa/functions/BoaNormalFormIntrinsics.java b/src/java/boa/functions/BoaNormalFormIntrinsics.java index 2dbdd28da..b16aebc2c 100644 --- a/src/java/boa/functions/BoaNormalFormIntrinsics.java +++ b/src/java/boa/functions/BoaNormalFormIntrinsics.java @@ -2432,7 +2432,7 @@ public static Expression simplify(final Expression e, final ExpressionKind paren case LOGICAL_AND: case LOGICAL_OR: final List exps = new ArrayList(); - final Set seen = new HashSet(); + final Set seen = new LinkedHashSet(); // recurse in and simplify inner expressions OUTER: @@ -2913,7 +2913,7 @@ public static String getCryptHash(final PDGSlicer pdgslice, final String algorit * @throws UnsupportedEncodingException if the character encoding used is not supported by JVM */ private static String getCryptHash(final Stack nodes, final String algorithm) throws NoSuchAlgorithmException, UnsupportedEncodingException { - final Set visited = new HashSet(); + final Set visited = new LinkedHashSet(); final StringBuilder sb = new StringBuilder(); while (nodes.size() != 0) { diff --git a/src/java/boa/graphs/Node.java b/src/java/boa/graphs/Node.java index 9641c8a0b..28a7a53f9 100644 --- a/src/java/boa/graphs/Node.java +++ b/src/java/boa/graphs/Node.java @@ -17,7 +17,7 @@ package boa.graphs; import java.util.ArrayList; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -40,8 +40,8 @@ public abstract class Node, E extends Edge> implement protected Statement stmt; protected Expression expr; - protected final Set inEdges = new HashSet(); - protected final Set outEdges = new HashSet(); + protected final Set inEdges = new LinkedHashSet(); + protected final Set outEdges = new LinkedHashSet(); @Override public int compareTo(final N node) { @@ -110,14 +110,14 @@ public List getSuccessorsList() { } public List getPredecessors() { - final Set nodes = new HashSet(); + final Set nodes = new LinkedHashSet(); for (final E e : this.inEdges) nodes.add(e.getSrc()); return new ArrayList(nodes); } public List getSuccessors() { - final Set nodes = new HashSet(); + final Set nodes = new LinkedHashSet(); for (final E e : this.outEdges) nodes.add(e.getDest()); return new ArrayList(nodes); diff --git a/src/java/boa/graphs/cdg/CDG.java b/src/java/boa/graphs/cdg/CDG.java index be1545b7a..4b8e16f92 100644 --- a/src/java/boa/graphs/cdg/CDG.java +++ b/src/java/boa/graphs/cdg/CDG.java @@ -19,7 +19,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -43,7 +43,7 @@ public class CDG { private Method md; private CDGNode entryNode; - private final Set nodes = new HashSet(); + private final Set nodes = new LinkedHashSet(); /** * Constructs a control dependence graph diff --git a/src/java/boa/graphs/cdg/CDGNode.java b/src/java/boa/graphs/cdg/CDGNode.java index 21dcc5889..19ab16fd8 100644 --- a/src/java/boa/graphs/cdg/CDGNode.java +++ b/src/java/boa/graphs/cdg/CDGNode.java @@ -17,7 +17,7 @@ package boa.graphs.cdg; import java.util.ArrayList; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import java.util.List; @@ -59,7 +59,7 @@ public CDGNode(final TreeNode node) { */ public CDGNode(int id) { this.id = id; - this.useVariables = new HashSet(); + this.useVariables = new LinkedHashSet(); } public String getDefVariable() { @@ -74,7 +74,7 @@ public Set getUseVariables() { return useVariables; } - public void setUseVariables(final HashSet useVariables) { + public void setUseVariables(final Set useVariables) { this.useVariables = useVariables; } diff --git a/src/java/boa/graphs/ddg/DDG.java b/src/java/boa/graphs/ddg/DDG.java index 8ff8e71e0..963643359 100644 --- a/src/java/boa/graphs/ddg/DDG.java +++ b/src/java/boa/graphs/ddg/DDG.java @@ -31,7 +31,7 @@ public class DDG { private Method md; private DDGNode entryNode; - private final HashSet nodes = new HashSet(); + private final Set nodes = new LinkedHashSet(); private final HashMap> defUseChain = new HashMap>(); //private HashMap> useDefChain; //TODO: needs reaching-def analysis @@ -93,7 +93,7 @@ public Method getMethod() { * * @return the set of all the nodes in the graph */ - public HashSet getNodes() { return nodes; } + public Set getNodes() { return nodes; } public DDGNode[] sortNodes() { try { @@ -128,7 +128,7 @@ private Set getUseNodes(final DDGNode node) { * @return definition nodes */ public Set getDefNodes(final String var) { - final Set defNodes = new HashSet(); + final Set defNodes = new LinkedHashSet(); for (final DDGNode n : defUseChain.keySet()) { if (n.getDefVariable() != null && n.getDefVariable().equals(var)) defNodes.add(n); @@ -259,7 +259,7 @@ private void formDefUseChains(final Map liveVar, CFG cfg) { if (n.getDefVariables().equals(p.var)) { final DDGNode useNode = getNode(p.node); if (!defUseChain.containsKey(defNode)) - defUseChain.put(defNode, new HashSet()); + defUseChain.put(defNode, new LinkedHashSet()); defUseChain.get(defNode).add(useNode); // connect nodes for constructing the graph new DDGEdge(defNode, useNode, p.var); @@ -313,8 +313,8 @@ private static class InOut { Set out; InOut() { - in = new HashSet(); - out = new HashSet(); + in = new LinkedHashSet(); + out = new LinkedHashSet(); } InOut(final Set in, final Set out){ @@ -323,8 +323,8 @@ private static class InOut { } InOut(final InOut inout){ - this.in = new HashSet(inout.in); - this.out = new HashSet(inout.out); + this.in = new LinkedHashSet(inout.in); + this.out = new LinkedHashSet(inout.out); } } diff --git a/src/java/boa/graphs/pdg/PDG.java b/src/java/boa/graphs/pdg/PDG.java index 7dd5c7539..c911b418f 100644 --- a/src/java/boa/graphs/pdg/PDG.java +++ b/src/java/boa/graphs/pdg/PDG.java @@ -41,7 +41,7 @@ public class PDG { private Method md; private PDGNode entryNode; - private final HashSet nodes = new HashSet(); + private final Set nodes = new LinkedHashSet(); private boolean normalize = false; private int hashcode; @@ -117,7 +117,7 @@ public PDGNode getEntryNode() { * * @return the set of all the nodes in the graph */ - public HashSet getNodes() { + public Set getNodes() { return nodes; } @@ -192,7 +192,7 @@ public void normalize() throws Exception { return; final Stack nodes = new Stack(); nodes.add(entryNode); - final Set visited = new HashSet(); + final Set visited = new LinkedHashSet(); final Map normalizedVars = new HashMap(); int varCount = 1; // if normalization is enabled then normalize node expression @@ -212,7 +212,7 @@ public void normalize() throws Exception { node.setDefVariable(normalizedVars.get(node.getDefVariable())); } // use variables - final HashSet useVars = new HashSet(); + final Set useVars = new LinkedHashSet(); for (final String dVar : node.getUseVariables()) { if (dVar != null) { if (!normalizedVars.containsKey(dVar)) { @@ -297,8 +297,8 @@ public boolean equals(final Object o) { final Stack nodes1 = new Stack(); final Stack nodes2 = new Stack(); - final Set visited1 = new HashSet(); - final Set visited2 = new HashSet(); + final Set visited1 = new LinkedHashSet(); + final Set visited2 = new LinkedHashSet(); nodes1.add(entryNode); nodes2.add(pdg.getEntryNode()); @@ -366,7 +366,7 @@ public int hashCode() { if (hashcode == 0 && entryNode != null) { final Stack nodes = new Stack(); nodes.add(entryNode); - final Set visited = new HashSet(); + final Set visited = new LinkedHashSet(); final StringBuilder sb = new StringBuilder(); while (nodes.size() != 0) { final PDGNode node = nodes.pop(); diff --git a/src/java/boa/graphs/pdg/PDGNode.java b/src/java/boa/graphs/pdg/PDGNode.java index 391e5521f..9c39fdc5e 100644 --- a/src/java/boa/graphs/pdg/PDGNode.java +++ b/src/java/boa/graphs/pdg/PDGNode.java @@ -21,7 +21,7 @@ import boa.graphs.Node; import java.util.ArrayList; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -33,7 +33,7 @@ */ public class PDGNode extends Node { private String defVariable; - private Set useVariables = new HashSet(); + private Set useVariables = new LinkedHashSet(); /** * Constructs a PDG node. @@ -53,7 +53,7 @@ public void setDefVariable(final String defVariables) { this.defVariable = defVariables; } - public void setUseVariables(final HashSet useVariables) { + public void setUseVariables(final Set useVariables) { this.useVariables = useVariables; } diff --git a/src/java/boa/graphs/slicers/CFGSlicer.java b/src/java/boa/graphs/slicers/CFGSlicer.java index 2a3a8ab9e..486982f96 100644 --- a/src/java/boa/graphs/slicers/CFGSlicer.java +++ b/src/java/boa/graphs/slicers/CFGSlicer.java @@ -100,15 +100,15 @@ public ArrayList getSlice() { private void getSlice(final CFG cfg, final List slicingNodes) throws Exception { if (slicingNodes.size() == 0) return; - final Set inSlice = new HashSet(slicingNodes); - final Set controlInflNodes = new HashSet(); + final Set inSlice = new LinkedHashSet(slicingNodes); + final Set controlInflNodes = new LinkedHashSet(); final Map> infl = getInfluence(new PDTree(cfg), cfg); // TODO: get rid of the traversal final BoaAbstractTraversal slicer = new BoaAbstractTraversal>(true, true) { protected Set preTraverse(final CFGNode node) throws Exception { // in(n) = \/(pred) out(pred) - final Set in = new HashSet(); + final Set in = new LinkedHashSet(); for (final CFGNode p : node.getPredecessors()) { final Set pred = getValue(p); if (pred != null) @@ -117,7 +117,7 @@ protected Set preTraverse(final CFGNode node) throws Exception { // gen(n) = def(n) and (ref(n) /\ in(n) != {} or inSlice(n)) String gen = null; - final Set refIn = new HashSet(node.getUseVariables()); + final Set refIn = new LinkedHashSet(node.getUseVariables()); refIn.retainAll(in); if (refIn.size() != 0 || inSlice.contains(node)) if (node.getDefVariables() != null) @@ -127,14 +127,14 @@ protected Set preTraverse(final CFGNode node) throws Exception { // use def directly // out(n) = gen(n) \/ (in(n) - kill(n)) - final Set out = new HashSet(in); + final Set out = new LinkedHashSet(in); if (node.getDefVariables() != null) out.remove(node.getDefVariables()); if (gen != null) out.add(gen); // inSlice(n) if ref(n) /\ out(n) != {} - final Set refOut = new HashSet(node.getUseVariables()); + final Set refOut = new LinkedHashSet(node.getUseVariables()); refOut.retainAll(out); if (refOut.size() != 0) inSlice.add(node); @@ -150,7 +150,7 @@ protected Set preTraverse(final CFGNode node) throws Exception { public void traverse(final CFGNode node, boolean flag) throws Exception { if (flag) { currentResult = preTraverse(node); - outputMapObj.put(node.getId(), new HashSet(currentResult)); + outputMapObj.put(node.getId(), new LinkedHashSet(currentResult)); } else { outputMapObj.put(node.getId(), preTraverse(node)); } @@ -159,7 +159,7 @@ public void traverse(final CFGNode node, boolean flag) throws Exception { final BoaAbstractFixP fixp = new BoaAbstractFixP() { public boolean invoke1(final Set current, final Set previous) { - final Set curr = new HashSet(current); + final Set curr = new LinkedHashSet(current); curr.removeAll(previous); return curr.size() == 0; } @@ -167,7 +167,7 @@ public boolean invoke1(final Set current, final Set previous) { @Override @SuppressWarnings({"unchecked"}) public boolean invoke(final Object current, final Object previous) throws Exception { - return invoke1((HashSet) current, (HashSet) previous); + return invoke1((LinkedHashSet) current, (LinkedHashSet) previous); } }; @@ -204,7 +204,7 @@ private Map> getInfluence(final PDTree pdTree, final CFG c final TreeNode srcParent = pdTree.getNode(enodes[0]).getParent(); TreeNode destination = pdTree.getNode(enodes[1]); if (!contolDependentMap.containsKey(enodes[0])) - contolDependentMap.put(enodes[0], new HashSet()); + contolDependentMap.put(enodes[0], new LinkedHashSet()); while (!srcParent.equals(destination)) { contolDependentMap.get(enodes[0]).add(cfg.getNode(destination.getNodeId())); destination = destination.getParent(); diff --git a/src/java/boa/graphs/slicers/PDGSlicer.java b/src/java/boa/graphs/slicers/PDGSlicer.java index feefb264c..3a44cef8f 100644 --- a/src/java/boa/graphs/slicers/PDGSlicer.java +++ b/src/java/boa/graphs/slicers/PDGSlicer.java @@ -37,7 +37,7 @@ public class PDGSlicer { private final Method md; private final ArrayList entryNodes = new ArrayList(); - private final HashSet slice = new HashSet(); + private final Set slice = new LinkedHashSet(); private boolean normalize = false; private int hashcode = 0; @@ -176,7 +176,7 @@ public ArrayList getEntrynodesList() { * * @return all the nodes in the slice */ - public HashSet getSlice() { + public Set getSlice() { return slice; } @@ -254,7 +254,7 @@ private void traverse() throws Exception { node.setDefVariable(normalizedVars.get(node.getDefVariable())); } // use variables - final HashSet useVars = new HashSet(); + final Set useVars = new LinkedHashSet(); for (final String dVar : node.getUseVariables()) { if (dVar != null) { if (!normalizedVars.containsKey(dVar)) { @@ -307,8 +307,8 @@ public boolean equals(final Object o) { final Stack nodes1 = new Stack(); final Stack nodes2 = new Stack(); - final Set visited1 = new HashSet(); - final Set visited2 = new HashSet(); + final Set visited1 = new LinkedHashSet(); + final Set visited2 = new LinkedHashSet(); nodes1.addAll(entryNodes); nodes2.addAll(pdgSlicer.getEntrynodesList()); diff --git a/src/java/boa/graphs/trees/DTree.java b/src/java/boa/graphs/trees/DTree.java index b4ea38844..a70567bf2 100644 --- a/src/java/boa/graphs/trees/DTree.java +++ b/src/java/boa/graphs/trees/DTree.java @@ -32,7 +32,7 @@ public class DTree { private Method md; private TreeNode rootNode; - private final HashSet nodes = new HashSet(); + private final Set nodes = new LinkedHashSet(); private boolean isEntryNode = false; // as specified in ferrante-1987 paper on PDG /** @@ -106,7 +106,7 @@ public TreeNode getRootNode() { * * @return the set of all the nodes in the tree */ - public HashSet getNodes() { + public Set getNodes() { return nodes; } @@ -164,14 +164,14 @@ private Map> computeDominators(final CFG cfg) { if (cfg.getNodes().size() > 2) { for (final CFGNode n : cfg.getNodes()) { if (n.getNodeId() == 0) - pDomMap.put(n, new HashSet(Collections.singletonList(n))); + pDomMap.put(n, new LinkedHashSet(Collections.singletonList(n))); else pDomMap.put(n, cfg.getNodes()); } } else { final CFGNode startNode = cfg.getNode(0); - pDomMap.put(startNode, new HashSet(Collections.singletonList(startNode))); - pDomMap.put(cfg.getNode(1), new HashSet(cfg.getNodes())); + pDomMap.put(startNode, new LinkedHashSet(Collections.singletonList(startNode))); + pDomMap.put(cfg.getNode(1), new LinkedHashSet(cfg.getNodes())); } final Map> currentPDomMap = new HashMap>(); @@ -179,7 +179,7 @@ private Map> computeDominators(final CFG cfg) { while (!saturated) { // fix point iteration int changeCount = 0; for (final CFGNode n : cfg.getNodes()) { - final Set currentPDom = new HashSet(); + final Set currentPDom = new LinkedHashSet(); // Intersection[pred(node)] boolean first = true; @@ -194,7 +194,7 @@ private Map> computeDominators(final CFG cfg) { // D[n] = {n} Union (Intersection[pred[node]]) currentPDom.add(n); - final Set diff = new HashSet(pDomMap.get(n)); + final Set diff = new LinkedHashSet(pDomMap.get(n)); diff.removeAll(currentPDom); if (diff.size() > 0) changeCount++; diff --git a/src/java/boa/graphs/trees/PDTree.java b/src/java/boa/graphs/trees/PDTree.java index 8c5dc475a..8e8a956f9 100644 --- a/src/java/boa/graphs/trees/PDTree.java +++ b/src/java/boa/graphs/trees/PDTree.java @@ -32,7 +32,7 @@ public class PDTree { private Method md; private TreeNode rootNode; - private final HashSet nodes = new HashSet(); + private final Set nodes = new LinkedHashSet(); private boolean hasEntryNode = false; // as specified in ferrante-1987 paper on PDG /** @@ -108,7 +108,7 @@ public TreeNode getRootNode() { * * @return the set of all the nodes in the tree */ - public HashSet getNodes() { + public Set getNodes() { return nodes; } diff --git a/src/java/boa/types/BoaProtoList.java b/src/java/boa/types/BoaProtoList.java index 8b2aa2355..4d5254630 100644 --- a/src/java/boa/types/BoaProtoList.java +++ b/src/java/boa/types/BoaProtoList.java @@ -16,7 +16,7 @@ */ package boa.types; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; /** @@ -186,6 +186,6 @@ public Set> reachableTypes() { set.add((Class) this.type.getClass()); return set; } - return new HashSet>(); + return new LinkedHashSet>(); } } diff --git a/src/java/boa/types/BoaProtoTuple.java b/src/java/boa/types/BoaProtoTuple.java index 8db2fcc03..8e76f1ac2 100644 --- a/src/java/boa/types/BoaProtoTuple.java +++ b/src/java/boa/types/BoaProtoTuple.java @@ -16,7 +16,7 @@ */ package boa.types; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -86,7 +86,7 @@ public Set> reachableTypes() { if (reachableTypesCache != null) return reachableTypesCache; - reachableTypesCache = new HashSet>(); + reachableTypesCache = new LinkedHashSet>(); reachableTypesCache.add((Class) this.getClass()); for (final BoaType t : members) if (t instanceof BoaProtoTuple) { From e6ec7011be59022276e1beb6bb7caccc38a108a1 Mon Sep 17 00:00:00 2001 From: Robert Dyer Date: Thu, 15 Aug 2019 15:28:19 -0400 Subject: [PATCH 12/18] fix test errors and simplify some code --- src/java/boa/compiler/SymbolTable.java | 9 ++++ .../visitors/CodeGeneratingVisitor.java | 36 +++++++++----- src/java/boa/functions/BoaIntrinsics.java | 48 +++++++++---------- .../boa/functions/BoaSpecialIntrinsics.java | 16 +++---- src/java/boa/types/BoaArray.java | 12 +++++ src/java/boa/types/BoaFloat.java | 6 --- src/java/boa/types/BoaInt.java | 6 --- src/java/boa/types/BoaMap.java | 10 +--- src/java/boa/types/BoaProtoMap.java | 6 --- src/java/boa/types/BoaQueue.java | 2 +- src/java/boa/types/BoaSet.java | 10 +--- src/java/boa/types/BoaStack.java | 2 +- src/java/boa/types/BoaType.java | 11 ----- templates/BoaJava.stg | 6 +-- 14 files changed, 86 insertions(+), 94 deletions(-) diff --git a/src/java/boa/compiler/SymbolTable.java b/src/java/boa/compiler/SymbolTable.java index 91dca6512..79ad76930 100644 --- a/src/java/boa/compiler/SymbolTable.java +++ b/src/java/boa/compiler/SymbolTable.java @@ -53,6 +53,7 @@ public class SymbolTable { private Operand operand; private Stack operandType = new Stack(); private boolean needsBoxing; + private boolean needsCast; private Stack isVisitor = new Stack(); private boolean isTraverse = false; private boolean shadowing = false; @@ -696,6 +697,14 @@ public boolean getNeedsBoxing() { return this.needsBoxing; } + public void setNeedsCast(final boolean needsCast) { + this.needsCast = needsCast; + } + + public boolean getNeedsCast() { + return this.needsCast; + } + public void setIsTraverse(final boolean isTraverse) { this.isTraverse = isTraverse; } diff --git a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java index 5ff19b0b1..5ad4d387e 100644 --- a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java +++ b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java @@ -277,17 +277,20 @@ public void visit(final Composite n) { final List fields = new ArrayList(); final List types = new ArrayList(); + final List types2 = new ArrayList(); int counter = 0; for (final Expression e : n.getExprs()) { fields.add("f" + counter); - types.add(e.type.toBoxedJavaType()); + types.add(e.type.toInterfaceJavaType()); + types2.add(e.type.toBoxedJavaType()); counter++; } st.add("name", name); st.add("fields", fields); st.add("types", types); + st.add("types2", types2); code.add(st.render()); } @@ -311,6 +314,7 @@ public void visit(final TupleType n) { final List members = n.getMembers(); final List fields = new ArrayList(); final List types = new ArrayList(); + final List types2 = new ArrayList(); final List protos = new ArrayList(); int fieldCount = 0; @@ -323,12 +327,14 @@ public void visit(final TupleType n) { fieldCount++; BoaType type = c.getType().type; protos.add(type instanceof BoaProtoTuple); - types.add(type.toBoxedJavaType()); + types.add(type.toInterfaceJavaType()); + types2.add(type.toBoxedJavaType()); } st.add("name", tupType.toJavaType()); st.add("fields", fields); st.add("types", types); + st.add("types2", types2); st.add("protos", protos); code.add(st.render()); @@ -724,15 +730,18 @@ public void visit(final Composite n) { return; } + n.env.setNeedsCast(true); visit(n.getExprs()); + n.env.setNeedsCast(false); + st.add("exprlist", code.removeLast()); - if (t instanceof BoaArray && ((BoaArray)t).getType() instanceof BoaEnum) { + if (t instanceof BoaArray && ((BoaArray)t).getType() instanceof BoaScalar) { + st.add("type", t.toBoxedJavaType()); + } else if (t instanceof BoaArray && ((BoaArray)t).getType() instanceof BoaEnum) { st.add("type", "Object[] "); } else { st.add("type", t.toJavaType().replaceAll("<(.*)>", "")); } - - st.add("exprlist", code.removeLast()); } code.add(st.render()); @@ -780,32 +789,35 @@ public void visit(final Conjunction n) { /** {@inheritDoc} */ @Override public void visit(final Factor n) { + String s = ""; + if (n.getOpsSize() > 0) { n.env.setOperand(n.getOperand()); - String accept = ""; abortGeneration = false; if (!(n.getOp(0) instanceof Call)) { n.getOperand().accept(this); n.env.setOperandType(n.getOperand().type); - accept = code.removeLast(); + s = code.removeLast(); } for (int i = 0; !abortGeneration && i < n.getOpsSize(); i++) { final Node o = n.getOp(i); o.accept(this); - accept += code.removeLast(); + s += code.removeLast(); } n.env.getOperandType(); - - code.add(accept); } else { n.getOperand().accept(this); - code.add(code.removeLast()); + s = code.removeLast(); } + + if (n.env != null && n.env.getNeedsCast()) + s = "((" + n.type.toJavaType() + ")" + s + ")"; + code.add(s); } /** {@inheritDoc} */ @@ -856,7 +868,7 @@ public void visit(final Index n) { final BoaType indexType = n.getStart().type; n.getStart().accept(this); if (indexType instanceof BoaInt && !(t instanceof BoaMap)) - st.add("index", "(int)(" + code.removeLast() + ")"); + st.add("index", "(int)((long)" + code.removeLast() + ")"); else st.add("index", code.removeLast()); diff --git a/src/java/boa/functions/BoaIntrinsics.java b/src/java/boa/functions/BoaIntrinsics.java index d662b3d8f..71d9781fb 100644 --- a/src/java/boa/functions/BoaIntrinsics.java +++ b/src/java/boa/functions/BoaIntrinsics.java @@ -455,7 +455,7 @@ public static String arrayToString(final T[] arr) { return s; } - public static String arrayToString(final long[] arr) { + public static String arrayToString(final Long[] arr) { String s = ""; for (final long val : arr) if (s.isEmpty()) @@ -465,7 +465,7 @@ public static String arrayToString(final long[] arr) { return s; } - public static String arrayToString(final double[] arr) { + public static String arrayToString(final Double[] arr) { String s = ""; for (final double val : arr) if (s.isEmpty()) @@ -475,7 +475,7 @@ public static String arrayToString(final double[] arr) { return s; } - public static String arrayToString(final boolean[] arr) { + public static String arrayToString(final Boolean[] arr) { String s = ""; for (final boolean val : arr) if (s.isEmpty()) @@ -489,21 +489,21 @@ public static boolean deepEquals(final T[] arr, final T[] arr2) { return java.util.Arrays.deepEquals(arr, arr2); } - public static boolean deepEquals(final long[] arr, final long[] arr2) { + public static boolean deepEquals(final Long[] arr, final Long[] arr2) { if (arr.length != arr2.length) return false; for (int i = 0; i < arr.length; i++) if (arr2[i] != arr[i]) return false; return true; } - public static boolean deepEquals(final double[] arr, final double[] arr2) { + public static boolean deepEquals(final Double[] arr, final Double[] arr2) { if (arr.length != arr2.length) return false; for (int i = 0; i < arr.length; i++) if (arr2[i] != arr[i]) return false; return true; } - public static boolean deepEquals(final boolean[] arr, final boolean[] arr2) { + public static boolean deepEquals(final Boolean[] arr, final Boolean[] arr2) { if (arr.length != arr2.length) return false; for (int i = 0; i < arr.length; i++) if (arr2[i] != arr[i]) return false; @@ -515,22 +515,22 @@ public static T[] basic_array(final T[] arr) { return arr; } - public static long[] basic_array(final Long[] arr) { - long[] arr2 = new long[arr.length]; + public static Long[] basic_array(final Long[] arr) { + Long[] arr2 = new Long[arr.length]; for (int i = 0; i < arr.length; i++) arr2[i] = arr[i]; return arr2; } - public static double[] basic_array(final Double[] arr) { - double[] arr2 = new double[arr.length]; + public static Double[] basic_array(final Double[] arr) { + Double[] arr2 = new Double[arr.length]; for (int i = 0; i < arr.length; i++) arr2[i] = arr[i]; return arr2; } - public static boolean[] basic_array(final Boolean[] arr) { - boolean[] arr2 = new boolean[arr.length]; + public static Boolean[] basic_array(final Boolean[] arr) { + Boolean[] arr2 = new Boolean[arr.length]; for (int i = 0; i < arr.length; i++) arr2[i] = arr[i]; return arr2; @@ -550,48 +550,48 @@ public static T[] concat(final T[] first, final T[]... rest) { return result; } - public static long[] concat(final long[] first, final long[]... rest) { + public static Long[] concat(final Long[] first, final Long[]... rest) { int totalLength = first.length; - for (final long[] array : rest) + for (final Long[] array : rest) totalLength += array.length; - final long[] result = new long[totalLength]; + final Long[] result = new Long[totalLength]; System.arraycopy(first, 0, result, 0, first.length); int offset = first.length; - for (final long[] array : rest) { + for (final Long[] array : rest) { System.arraycopy(array, 0, result, offset, array.length); offset += array.length; } return result; } - public static double[] concat(final double[] first, final double[]... rest) { + public static Double[] concat(final Double[] first, final Double[]... rest) { int totalLength = first.length; - for (final double[] array : rest) + for (final Double[] array : rest) totalLength += array.length; - final double[] result = new double[totalLength]; + final Double[] result = new Double[totalLength]; System.arraycopy(first, 0, result, 0, first.length); int offset = first.length; - for (final double[] array : rest) { + for (final Double[] array : rest) { System.arraycopy(array, 0, result, offset, array.length); offset += array.length; } return result; } - public static boolean[] concat(final boolean[] first, final boolean[]... rest) { + public static Boolean[] concat(final Boolean[] first, final Boolean[]... rest) { int totalLength = first.length; - for (final boolean[] array : rest) + for (final Boolean[] array : rest) totalLength += array.length; - final boolean[] result = new boolean[totalLength]; + final Boolean[] result = new Boolean[totalLength]; System.arraycopy(first, 0, result, 0, first.length); int offset = first.length; - for (final boolean[] array : rest) { + for (final Boolean[] array : rest) { System.arraycopy(array, 0, result, offset, array.length); offset += array.length; } diff --git a/src/java/boa/functions/BoaSpecialIntrinsics.java b/src/java/boa/functions/BoaSpecialIntrinsics.java index fa55f66d2..447da8023 100644 --- a/src/java/boa/functions/BoaSpecialIntrinsics.java +++ b/src/java/boa/functions/BoaSpecialIntrinsics.java @@ -87,29 +87,29 @@ public static void azzert(final boolean condition) { * @return The array */ @FunctionSpec(name = "new", returnType = "array of int", formalParameters = { "array of int", "int", "int" }) - public static long[] newInt(long[] a, long size, long val) { - long[] arr = new long[(int)size]; + public static Long[] newInt(Long[] a, long size, long val) { + Long[] arr = new Long[(int)size]; for (int i = 0; i < size; i++) arr[i] = val; return arr; } @FunctionSpec(name = "new", returnType = "array of float", formalParameters = { "array of float", "int", "float" }) - public static double[] newDouble(double[] a, long size, double val) { - double[] arr = new double[(int)size]; + public static Double[] newDouble(Double[] a, long size, double val) { + Double[] arr = new Double[(int)size]; for (int i = 0; i < size; i++) arr[i] = val; return arr; } @FunctionSpec(name = "new", returnType = "array of bool", formalParameters = { "array of bool", "int", "bool" }) - public static boolean[] newBoolean(boolean[] a, long size, boolean val) { - boolean[] arr = new boolean[(int)size]; + public static Boolean[] newBoolean(Boolean[] a, long size, boolean val) { + Boolean[] arr = new Boolean[(int)size]; for (int i = 0; i < size; i++) arr[i] = val; return arr; } @FunctionSpec(name = "new", returnType = "array of time", formalParameters = { "array of time", "int", "time" }) - public static long[] newTime(long[] a, long size, long val) { - long[] arr = new long[(int)size]; + public static Long[] newTime(Long[] a, long size, long val) { + Long[] arr = new Long[(int)size]; for (int i = 0; i < size; i++) arr[i] = val; return arr; diff --git a/src/java/boa/types/BoaArray.java b/src/java/boa/types/BoaArray.java index 42aa44e86..4dcf0d065 100644 --- a/src/java/boa/types/BoaArray.java +++ b/src/java/boa/types/BoaArray.java @@ -173,6 +173,18 @@ public String toJavaType() { return this.type.toJavaType() + "[]"; } + /** {@inheritDoc} */ + @Override + public String toBoxedJavaType() { + return this.type.toBoxedJavaType() + "[]"; + } + + /** {@inheritDoc} */ + @Override + public String toInterfaceJavaType() { + return this.type.toInterfaceJavaType() + "[]"; + } + /** {@inheritDoc} */ @Override public String toString() { diff --git a/src/java/boa/types/BoaFloat.java b/src/java/boa/types/BoaFloat.java index 5661d6a67..a2fff3847 100644 --- a/src/java/boa/types/BoaFloat.java +++ b/src/java/boa/types/BoaFloat.java @@ -72,12 +72,6 @@ public String toBoxedJavaType() { /** {@inheritDoc} */ @Override public String toInterfaceJavaType() { - return toJavaType(); - } - - /** {@inheritDoc} */ - @Override - public String toParameterJavaType() { return toBoxedJavaType(); } diff --git a/src/java/boa/types/BoaInt.java b/src/java/boa/types/BoaInt.java index 5efe3419d..3c8a1a02b 100644 --- a/src/java/boa/types/BoaInt.java +++ b/src/java/boa/types/BoaInt.java @@ -69,12 +69,6 @@ public String toBoxedJavaType() { /** {@inheritDoc} */ @Override public String toInterfaceJavaType() { - return toJavaType(); - } - - /** {@inheritDoc} */ - @Override - public String toParameterJavaType() { return toBoxedJavaType(); } } diff --git a/src/java/boa/types/BoaMap.java b/src/java/boa/types/BoaMap.java index 15da87eb0..52fdb5985 100644 --- a/src/java/boa/types/BoaMap.java +++ b/src/java/boa/types/BoaMap.java @@ -148,19 +148,13 @@ public String toString() { /** {@inheritDoc} */ @Override public String toJavaType() { - return "java.util.HashMap<" + this.indexType.toParameterJavaType() + ", " + this.valueType.toParameterJavaType() + ">"; + return "java.util.HashMap<" + this.indexType.toInterfaceJavaType() + ", " + this.valueType.toInterfaceJavaType() + ">"; } /** {@inheritDoc} */ @Override public String toInterfaceJavaType() { - return "java.util.Map<" + this.indexType.toParameterJavaType() + ", " + this.valueType.toParameterJavaType() + ">"; - } - - /** {@inheritDoc} */ - @Override - public String toParameterJavaType() { - return "java.util.Map<" + this.indexType.toParameterJavaType() + ", " + this.valueType.toParameterJavaType() + ">"; + return "java.util.Map<" + this.indexType.toInterfaceJavaType() + ", " + this.valueType.toInterfaceJavaType() + ">"; } /** {@inheritDoc} */ diff --git a/src/java/boa/types/BoaProtoMap.java b/src/java/boa/types/BoaProtoMap.java index 2cc8663e7..850218c20 100644 --- a/src/java/boa/types/BoaProtoMap.java +++ b/src/java/boa/types/BoaProtoMap.java @@ -81,12 +81,6 @@ public String toInterfaceJavaType() { return toJavaType(); } - /** {@inheritDoc} */ - @Override - public String toParameterJavaType() { - return toJavaType(); - } - /** {@inheritDoc} */ @Override public String toString() { diff --git a/src/java/boa/types/BoaQueue.java b/src/java/boa/types/BoaQueue.java index ec03bbacc..c61bf81ba 100644 --- a/src/java/boa/types/BoaQueue.java +++ b/src/java/boa/types/BoaQueue.java @@ -124,7 +124,7 @@ public String toString() { /** {@inheritDoc} */ @Override public String toJavaType() { - return "java.util.LinkedList<" + this.type.toBoxedJavaType() + ">"; + return "java.util.LinkedList<" + this.type.toInterfaceJavaType() + ">"; } /** {@inheritDoc} */ diff --git a/src/java/boa/types/BoaSet.java b/src/java/boa/types/BoaSet.java index 967ac1368..59c4b5bcb 100644 --- a/src/java/boa/types/BoaSet.java +++ b/src/java/boa/types/BoaSet.java @@ -124,19 +124,13 @@ public String toString() { /** {@inheritDoc} */ @Override public String toJavaType() { - return "java.util.LinkedHashSet<" + this.type.toParameterJavaType() + ">"; + return "java.util.LinkedHashSet<" + this.type.toInterfaceJavaType() + ">"; } /** {@inheritDoc} */ @Override public String toInterfaceJavaType() { - return "java.util.Set<" + this.type.toParameterJavaType() + ">"; - } - - /** {@inheritDoc} */ - @Override - public String toParameterJavaType() { - return "java.util.Set<" + this.type.toParameterJavaType() + ">"; + return "java.util.Set<" + this.type.toInterfaceJavaType() + ">"; } /** {@inheritDoc} */ diff --git a/src/java/boa/types/BoaStack.java b/src/java/boa/types/BoaStack.java index c5ff612f8..44ba088a1 100644 --- a/src/java/boa/types/BoaStack.java +++ b/src/java/boa/types/BoaStack.java @@ -124,7 +124,7 @@ public String toString() { /** {@inheritDoc} */ @Override public String toJavaType() { - return "java.util.Stack<" + this.type.toParameterJavaType() + ">"; + return "java.util.Stack<" + this.type.toInterfaceJavaType() + ">"; } /** {@inheritDoc} */ diff --git a/src/java/boa/types/BoaType.java b/src/java/boa/types/BoaType.java index 60c06bbbc..3fe357f43 100644 --- a/src/java/boa/types/BoaType.java +++ b/src/java/boa/types/BoaType.java @@ -123,17 +123,6 @@ public String toInterfaceJavaType() { return toBoxedJavaType(); } - /** - * Returns a string representation of the parameter Java equivalent of this Boa - * type. - * - * @return A String containing the name of the parameter Java type equivalent to this - * Boa type - */ - public String toParameterJavaType() { - return toBoxedJavaType(); - } - /** * Takes a type name and returns one suitable for use as an identifier. * diff --git a/templates/BoaJava.stg b/templates/BoaJava.stg index 3dce9bbb5..ce73337ee 100644 --- a/templates/BoaJava.stg +++ b/templates/BoaJava.stg @@ -121,19 +121,19 @@ new () } >> -TupleType(name, fields, types, protos) ::= << +TupleType(name, fields, types, types2, protos) ::= << private class { ___}; separator="; ">; ( ___}; separator=", "> ){ - this.___ = ___ this.___ = new (___) }; separator="; ">; } ( tmp){ - this.___ = tmp.___ this.___ = new (tmp.___) From 683c817d8db9867ba712fc2c6cf56d98ad3163fb Mon Sep 17 00:00:00 2001 From: Robert Dyer Date: Thu, 15 Aug 2019 15:54:01 -0400 Subject: [PATCH 13/18] code cleanup --- src/java/boa/graphs/cfg/CFG.java | 8 ++++---- src/java/boa/types/BoaFloat.java | 6 ------ src/java/boa/types/BoaInt.java | 6 ------ 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/java/boa/graphs/cfg/CFG.java b/src/java/boa/graphs/cfg/CFG.java index b18a40179..214498371 100644 --- a/src/java/boa/graphs/cfg/CFG.java +++ b/src/java/boa/graphs/cfg/CFG.java @@ -50,10 +50,10 @@ public class CFG { protected CFGNode entryNode; protected CFGNode exitNode; - private final Set outs = new LinkedHashSet(); - private final Set ins = new LinkedHashSet(); - private final Set breaks = new LinkedHashSet(); - private final Set returns = new LinkedHashSet(); + protected final Set outs = new LinkedHashSet(); + protected final Set ins = new LinkedHashSet(); + protected final Set breaks = new LinkedHashSet(); + protected final Set returns = new LinkedHashSet(); protected boolean isLoopPresent = false; protected boolean isBranchPresent = false; diff --git a/src/java/boa/types/BoaFloat.java b/src/java/boa/types/BoaFloat.java index a2fff3847..aad2a8b13 100644 --- a/src/java/boa/types/BoaFloat.java +++ b/src/java/boa/types/BoaFloat.java @@ -69,12 +69,6 @@ public String toBoxedJavaType() { return "Double"; } - /** {@inheritDoc} */ - @Override - public String toInterfaceJavaType() { - return toBoxedJavaType(); - } - /** {@inheritDoc} */ @Override public String toString() { diff --git a/src/java/boa/types/BoaInt.java b/src/java/boa/types/BoaInt.java index 3c8a1a02b..ac4219322 100644 --- a/src/java/boa/types/BoaInt.java +++ b/src/java/boa/types/BoaInt.java @@ -65,10 +65,4 @@ public String toJavaType() { public String toBoxedJavaType() { return "Long"; } - - /** {@inheritDoc} */ - @Override - public String toInterfaceJavaType() { - return toBoxedJavaType(); - } } From 9961c74ebad13168a38042f4687f1163ac4f8249 Mon Sep 17 00:00:00 2001 From: Robert Dyer Date: Sun, 3 Sep 2023 10:28:33 -0500 Subject: [PATCH 14/18] fix bad merge that lost types2 --- .../visitors/analysis/DataFlowSensitivityAnalysis.java | 1 - .../boa/compiler/visitors/analysis/InformationAnalysis.java | 1 - .../compiler/visitors/analysis/LocalMayAliasAnalysis.java | 1 - .../compiler/visitors/analysis/LoopSensitivityAnalysis.java | 1 - templates/BoaJava.stg | 6 +++--- 5 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/java/boa/compiler/visitors/analysis/DataFlowSensitivityAnalysis.java b/src/java/boa/compiler/visitors/analysis/DataFlowSensitivityAnalysis.java index 8683d7a49..a916b040d 100644 --- a/src/java/boa/compiler/visitors/analysis/DataFlowSensitivityAnalysis.java +++ b/src/java/boa/compiler/visitors/analysis/DataFlowSensitivityAnalysis.java @@ -16,7 +16,6 @@ */ package boa.compiler.visitors.analysis; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; diff --git a/src/java/boa/compiler/visitors/analysis/InformationAnalysis.java b/src/java/boa/compiler/visitors/analysis/InformationAnalysis.java index ffb69dd86..12aadb46e 100644 --- a/src/java/boa/compiler/visitors/analysis/InformationAnalysis.java +++ b/src/java/boa/compiler/visitors/analysis/InformationAnalysis.java @@ -16,7 +16,6 @@ */ package boa.compiler.visitors.analysis; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; diff --git a/src/java/boa/compiler/visitors/analysis/LocalMayAliasAnalysis.java b/src/java/boa/compiler/visitors/analysis/LocalMayAliasAnalysis.java index 24de8dc69..358c6dca2 100644 --- a/src/java/boa/compiler/visitors/analysis/LocalMayAliasAnalysis.java +++ b/src/java/boa/compiler/visitors/analysis/LocalMayAliasAnalysis.java @@ -16,7 +16,6 @@ */ package boa.compiler.visitors.analysis; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; diff --git a/src/java/boa/compiler/visitors/analysis/LoopSensitivityAnalysis.java b/src/java/boa/compiler/visitors/analysis/LoopSensitivityAnalysis.java index 4bdc8567c..9234524cc 100644 --- a/src/java/boa/compiler/visitors/analysis/LoopSensitivityAnalysis.java +++ b/src/java/boa/compiler/visitors/analysis/LoopSensitivityAnalysis.java @@ -16,7 +16,6 @@ */ package boa.compiler.visitors.analysis; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; diff --git a/templates/BoaJava.stg b/templates/BoaJava.stg index 229755043..b3c1316a3 100644 --- a/templates/BoaJava.stg +++ b/templates/BoaJava.stg @@ -121,16 +121,16 @@ new () } >> -TupleType(name, fields, types, aliases) ::= << +TupleType(name, fields, types, types2, aliases) ::= << private class { ___;}; separator="\n"> ( ___}; separator=", ">) { - this.___ = ___;this.___ = new (___);}; separator="\n"> + this.___ = ___;this.___ = new (___);}; separator="\n"> } ( tmp) { - this.___ = tmp.___; this.___ = new (tmp.___);}; separator="\n"> + this.___ = tmp.___; this.___ = new (tmp.___);}; separator="\n"> } public clone() { From b73f2d8859c6067ea71124968871d1eb154757ef Mon Sep 17 00:00:00 2001 From: Robert Dyer Date: Sun, 3 Sep 2023 10:45:02 -0500 Subject: [PATCH 15/18] fix compile error with template --- .../compiler/visitors/CodeGeneratingVisitor.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java index 6d184a306..f9a35ded3 100644 --- a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java +++ b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java @@ -276,12 +276,14 @@ public void visit(final Composite n) { final List fields = new ArrayList(); final List types = new ArrayList(); final List types2 = new ArrayList(); + final List aliases = new ArrayList(); int counter = 0; for (final Expression e : n.getExprs()) { fields.add("f" + counter); types.add(e.type.toInterfaceJavaType()); types2.add(e.type.toBoxedJavaType()); + aliases.add((e.type instanceof BoaProtoTuple) || (e.type instanceof BoaEnum)); counter++; } @@ -289,6 +291,7 @@ public void visit(final Composite n) { st.add("fields", fields); st.add("types", types); st.add("types2", types2); + st.add("aliases", aliases); code.add(st.render()); } @@ -309,27 +312,29 @@ public void visit(final TupleType n) { final BoaTuple tupType = ((BoaTuple) n.type); - final List members = n.getMembers(); final List fields = new ArrayList(); final List types = new ArrayList(); + final List types2 = new ArrayList(); final List aliases = new ArrayList(); int fieldCount = 0; - for (final Component c : members) { + for (final Component c : n.getMembers()) { if (c.hasIdentifier()) { fields.add(c.getIdentifier().getToken()); } else { fields.add("f" + fieldCount); } fieldCount++; - BoaType type = c.getType().type; + final BoaType type = c.getType().type; aliases.add((type instanceof BoaProtoTuple) || (type instanceof BoaEnum)); - types.add(type.toBoxedJavaType()); + types.add(type.toInterfaceJavaType()); + types2.add(type.toBoxedJavaType()); } st.add("name", tupType.toJavaType()); st.add("fields", fields); st.add("types", types); + st.add("types2", types2); st.add("aliases", aliases); code.add(st.render()); From a24017415f9acfe9ea835c9770da655dd35219b9 Mon Sep 17 00:00:00 2001 From: Robert Dyer Date: Sun, 3 Sep 2023 10:47:48 -0500 Subject: [PATCH 16/18] fix boxing issue with arrays --- src/java/boa/functions/BoaIntrinsics.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/java/boa/functions/BoaIntrinsics.java b/src/java/boa/functions/BoaIntrinsics.java index 245cc88a0..e5906f71d 100644 --- a/src/java/boa/functions/BoaIntrinsics.java +++ b/src/java/boa/functions/BoaIntrinsics.java @@ -547,22 +547,22 @@ public static T[] basic_array(final T[] arr) { return arr; } - public static long[] basic_array(final Long[] arr) { - final long[] arr2 = new long[arr.length]; + public static Long[] basic_array(final Long[] arr) { + final Long[] arr2 = new Long[arr.length]; for (int i = 0; i < arr.length; i++) arr2[i] = arr[i]; return arr2; } - public static double[] basic_array(final Double[] arr) { - final double[] arr2 = new double[arr.length]; + public static Double[] basic_array(final Double[] arr) { + final Double[] arr2 = new Double[arr.length]; for (int i = 0; i < arr.length; i++) arr2[i] = arr[i]; return arr2; } - public static boolean[] basic_array(final Boolean[] arr) { - final boolean[] arr2 = new boolean[arr.length]; + public static Boolean[] basic_array(final Boolean[] arr) { + final Boolean[] arr2 = new Boolean[arr.length]; for (int i = 0; i < arr.length; i++) arr2[i] = arr[i]; return arr2; From 6a2ccf94454550437abd0cfeea349413ed4cdd6c Mon Sep 17 00:00:00 2001 From: Robert Dyer Date: Sun, 3 Sep 2023 11:14:57 -0500 Subject: [PATCH 17/18] make sure set aggregator sorts output --- src/java/boa/aggregators/SetAggregator.java | 9 +- .../test/known-good/dupe-types.boa.txt | 86 +++++++++---------- 2 files changed, 50 insertions(+), 45 deletions(-) diff --git a/src/java/boa/aggregators/SetAggregator.java b/src/java/boa/aggregators/SetAggregator.java index 00239847a..2d7681f19 100644 --- a/src/java/boa/aggregators/SetAggregator.java +++ b/src/java/boa/aggregators/SetAggregator.java @@ -17,8 +17,11 @@ package boa.aggregators; import java.io.IOException; -import java.util.Set; +import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; import boa.io.EmitKey; @@ -76,7 +79,9 @@ public void aggregate(final String data, final String metadata) throws IOExcepti /** {@inheritDoc} */ @Override public void finish() throws IOException, InterruptedException { - for (final String s : this.set) + final List list = new ArrayList(this.set); + Collections.sort(list); + for (final String s : list) this.collect(s); } } diff --git a/test/datagen/expected/test/known-good/dupe-types.boa.txt b/test/datagen/expected/test/known-good/dupe-types.boa.txt index 43a439cb1..a01f22b1f 100644 --- a/test/datagen/expected/test/known-good/dupe-types.boa.txt +++ b/test/datagen/expected/test/known-good/dupe-types.boa.txt @@ -4,108 +4,108 @@ types[140492550][Account] = src/JLS8/RADemo/Account.java types[140492550][Accountant] = src/JLS2/GenDemo/v2/GenDemo.java types[140492550][Accountant] = src/JLS3/GenDemo/v2/GenDemo.java types[140492550][Accountant] = src/JLS3/GenDemo/v2/GenDemo2.java +types[140492550][AnnDemo] = src/JLS3/AnnDemo/v1/AnnDemo.java +types[140492550][AnnDemo] = src/JLS3/AnnDemo/v2/AnnDemo.java +types[140492550][AnnDemo] = src/JLS3/AnnDemo/v3/AnnDemo.java types[140492550][AnnDemo] = src/JLS3/AnnDemo/v4/AnnDemo.java types[140492550][AnnDemo] = src/JLS3/AnnDemo/v5/AnnDemo.java types[140492550][AnnDemo] = src/JLS3/AnnProcDemo/AnnDemo.java -types[140492550][AnnDemo] = src/JLS3/AnnDemo/v3/AnnDemo.java -types[140492550][AnnDemo] = src/JLS3/AnnDemo/v1/AnnDemo.java -types[140492550][AnnDemo] = src/JLS3/AnnDemo/v2/AnnDemo.java types[140492550][AnnProcDemo] = src/JLS3/AnnProcDemo/AnnProcDemo.java types[140492550][AssertDemo] = src/JLS2/AssertDemo/v1/AssertDemo.java -types[140492550][AssertDemo] = src/JLS2/AssertDemo/v4/AssertDemo.java types[140492550][AssertDemo] = src/JLS2/AssertDemo/v2/AssertDemo.java types[140492550][AssertDemo] = src/JLS2/AssertDemo/v3/AssertDemo.java +types[140492550][AssertDemo] = src/JLS2/AssertDemo/v4/AssertDemo.java types[140492550][BinLitDemo] = src/JLS4/BinLitDemo/BinLitDemo.java +types[140492550][BoxDemo] = src/JLS3/BoxDemo/v1/BoxDemo.java types[140492550][BoxDemo] = src/JLS3/BoxDemo/v2/BoxDemo.java types[140492550][BoxDemo] = src/JLS4/BoxDemo/BoxDemo.java -types[140492550][BoxDemo] = src/JLS3/BoxDemo/v1/BoxDemo.java types[140492550][Box] = src/JLS4/BoxDemo/Box.java types[140492550][BreakageDemo] = src/JLS4/BreakageDemo/BreakageDemo.java -types[140492550][Car] = src/JLS8/DMDemo/v3/DMDemo.java -types[140492550][Car] = src/JLS8/DMDemo/v2/DMDemo.java types[140492550][Car] = src/JLS8/DMDemo/v1/DMDemo.java -types[140492550][CardboardFactory] = src/JLS3/CovarDemo/v2/CovarDemo.java +types[140492550][Car] = src/JLS8/DMDemo/v2/DMDemo.java +types[140492550][Car] = src/JLS8/DMDemo/v3/DMDemo.java types[140492550][CardboardFactory] = src/JLS3/CovarDemo/v1/CovarDemo.java -types[140492550][Cardboard] = src/JLS3/CovarDemo/v2/CovarDemo.java +types[140492550][CardboardFactory] = src/JLS3/CovarDemo/v2/CovarDemo.java types[140492550][Cardboard] = src/JLS3/CovarDemo/v1/CovarDemo.java +types[140492550][Cardboard] = src/JLS3/CovarDemo/v2/CovarDemo.java types[140492550][Container] = src/JLS2/GenDemo/v1/GenDemo.java types[140492550][Container] = src/JLS3/GenDemo/v1/GenDemo.java types[140492550][Container] = src/JLS3/GenDemo/v1/GenDemo1.java -types[140492550][CopyToDatabaseOrFile] = src/JLS4/CopyToDatabaseOrFile/v2/CopyToDatabaseOrFile.java types[140492550][CopyToDatabaseOrFile] = src/JLS4/CopyToDatabaseOrFile/v1/CopyToDatabaseOrFile.java +types[140492550][CopyToDatabaseOrFile] = src/JLS4/CopyToDatabaseOrFile/v2/CopyToDatabaseOrFile.java types[140492550][Copy] = src/JLS4/Copy/v1/Copy.java types[140492550][Copy] = src/JLS4/Copy/v2/Copy.java -types[140492550][CovarDemo] = src/JLS3/CovarDemo/v2/CovarDemo.java types[140492550][CovarDemo] = src/JLS3/CovarDemo/v1/CovarDemo.java -types[140492550][DMDemo] = src/JLS8/DMDemo/v3/DMDemo.java +types[140492550][CovarDemo] = src/JLS3/CovarDemo/v2/CovarDemo.java +types[140492550][DMDemo] = src/JLS8/DMDemo/v1/DMDemo.java types[140492550][DMDemo] = src/JLS8/DMDemo/v2/DMDemo.java +types[140492550][DMDemo] = src/JLS8/DMDemo/v3/DMDemo.java types[140492550][DMDemo] = src/JLS8/DMDemo/v4/DMDemo.java -types[140492550][DMDemo] = src/JLS8/DMDemo/v1/DMDemo.java types[140492550][Drawable] = src/JLS8/SMDemo/Drawable.java types[140492550][Drivable] = src/JLS8/DMDemo/v1/Drivable.java types[140492550][Drivable] = src/JLS8/DMDemo/v2/Drivable.java types[140492550][Drivable] = src/JLS8/DMDemo/v3/Drivable.java types[140492550][Employee] = src/JLS2/GenDemo/v2/GenDemo.java +types[140492550][Employee] = src/JLS3/EnForLoopDemo/v1/EnForLoopDemo.java types[140492550][Employee] = src/JLS3/GenDemo/v2/GenDemo.java types[140492550][Employee] = src/JLS3/GenDemo/v2/GenDemo2.java -types[140492550][Employee] = src/JLS3/EnForLoopDemo/v1/EnForLoopDemo.java -types[140492550][EnForLoopDemo] = src/JLS3/EnForLoopDemo/v2/EnForLoopDemo.java types[140492550][EnForLoopDemo] = src/JLS3/EnForLoopDemo/v1/EnForLoopDemo.java -types[140492550][Filter] = src/JLS3/GenDemo/v5/GenDemo5.java -types[140492550][Filter] = src/JLS3/GenDemo/v5/GenDemo.java +types[140492550][EnForLoopDemo] = src/JLS3/EnForLoopDemo/v2/EnForLoopDemo.java types[140492550][Filter] = src/JLS2/GenDemo/v5/GenDemo.java -types[140492550][GenDemo.] = src/JLS3/GenDemo/v5/GenDemo5.java -types[140492550][GenDemo.] = src/JLS3/GenDemo/v5/GenDemo.java +types[140492550][Filter] = src/JLS3/GenDemo/v5/GenDemo.java +types[140492550][Filter] = src/JLS3/GenDemo/v5/GenDemo5.java types[140492550][GenDemo.] = src/JLS2/GenDemo/v5/GenDemo.java -types[140492550][GenDemo] = src/JLS2/GenDemo/v2/GenDemo.java +types[140492550][GenDemo.] = src/JLS3/GenDemo/v5/GenDemo.java +types[140492550][GenDemo.] = src/JLS3/GenDemo/v5/GenDemo5.java types[140492550][GenDemo] = src/JLS2/GenDemo/v1/GenDemo.java +types[140492550][GenDemo] = src/JLS2/GenDemo/v2/GenDemo.java +types[140492550][GenDemo] = src/JLS2/GenDemo/v3/GenDemo.java types[140492550][GenDemo] = src/JLS2/GenDemo/v4/GenDemo.java -types[140492550][GenDemo] = src/JLS3/GenDemo/v5/GenDemo5.java types[140492550][GenDemo] = src/JLS2/GenDemo/v5/GenDemo.java +types[140492550][GenDemo] = src/JLS3/GenDemo/v1/GenDemo.java types[140492550][GenDemo] = src/JLS3/GenDemo/v1/GenDemo1.java -types[140492550][GenDemo] = src/JLS3/GenDemo/v3/GenDemo3.java -types[140492550][GenDemo] = src/JLS3/GenDemo/v4/GenDemo.java -types[140492550][GenDemo] = src/JLS3/GenDemo/v3/GenDemo.java types[140492550][GenDemo] = src/JLS3/GenDemo/v2/GenDemo.java -types[140492550][GenDemo] = src/JLS3/GenDemo/v5/GenDemo.java -types[140492550][GenDemo] = src/JLS3/GenDemo/v1/GenDemo.java types[140492550][GenDemo] = src/JLS3/GenDemo/v2/GenDemo2.java +types[140492550][GenDemo] = src/JLS3/GenDemo/v3/GenDemo.java +types[140492550][GenDemo] = src/JLS3/GenDemo/v3/GenDemo3.java +types[140492550][GenDemo] = src/JLS3/GenDemo/v4/GenDemo.java types[140492550][GenDemo] = src/JLS3/GenDemo/v4/GenDemo4.java -types[140492550][GenDemo] = src/JLS2/GenDemo/v3/GenDemo.java +types[140492550][GenDemo] = src/JLS3/GenDemo/v5/GenDemo.java +types[140492550][GenDemo] = src/JLS3/GenDemo/v5/GenDemo5.java types[140492550][HeapPollutionDemo] = src/JLS4/HeapPollutionDemo/HeapPollutionDemo.java -types[140492550][LambdaDemo.] = src/JLS8/LambdaDemo/v7/LambdaDemo.java types[140492550][LambdaDemo.] = src/JLS8/LambdaDemo/v2/LambdaDemo.java types[140492550][LambdaDemo.] = src/JLS8/LambdaDemo/v4/LambdaDemo.java +types[140492550][LambdaDemo.] = src/JLS8/LambdaDemo/v7/LambdaDemo.java types[140492550][LambdaDemo] = src/JLS8/LambdaDemo/v1/LambdaDemo.java -types[140492550][LambdaDemo] = src/JLS8/LambdaDemo/v3/LambdaDemo.java -types[140492550][LambdaDemo] = src/JLS8/LambdaDemo/v6/LambdaDemo.java -types[140492550][LambdaDemo] = src/JLS8/LambdaDemo/v7/LambdaDemo.java types[140492550][LambdaDemo] = src/JLS8/LambdaDemo/v10/LambdaDemo.java types[140492550][LambdaDemo] = src/JLS8/LambdaDemo/v2/LambdaDemo.java -types[140492550][LambdaDemo] = src/JLS8/LambdaDemo/v9/LambdaDemo.java +types[140492550][LambdaDemo] = src/JLS8/LambdaDemo/v3/LambdaDemo.java types[140492550][LambdaDemo] = src/JLS8/LambdaDemo/v4/LambdaDemo.java -types[140492550][LambdaDemo] = src/JLS8/LambdaDemo/v8/LambdaDemo.java types[140492550][LambdaDemo] = src/JLS8/LambdaDemo/v5/LambdaDemo.java +types[140492550][LambdaDemo] = src/JLS8/LambdaDemo/v6/LambdaDemo.java +types[140492550][LambdaDemo] = src/JLS8/LambdaDemo/v7/LambdaDemo.java +types[140492550][LambdaDemo] = src/JLS8/LambdaDemo/v8/LambdaDemo.java +types[140492550][LambdaDemo] = src/JLS8/LambdaDemo/v9/LambdaDemo.java types[140492550][Light] = src/JLS3/StaticImportsDemo/v1/Light.java -types[140492550][MRDemo.] = src/JLS8/MRDemo/v3/MRDemo.java types[140492550][MRDemo.] = src/JLS8/MRDemo/v2/MRDemo.java +types[140492550][MRDemo.] = src/JLS8/MRDemo/v3/MRDemo.java types[140492550][MRDemo] = src/JLS8/MRDemo/v1/MRDemo.java +types[140492550][MRDemo] = src/JLS8/MRDemo/v2/MRDemo.java types[140492550][MRDemo] = src/JLS8/MRDemo/v3/MRDemo.java types[140492550][MRDemo] = src/JLS8/MRDemo/v4/MRDemo.java types[140492550][MRDemo] = src/JLS8/MRDemo/v5/MRDemo.java -types[140492550][MRDemo] = src/JLS8/MRDemo/v2/MRDemo.java types[140492550][MRDemo] = src/JLS8/MRDemo/v6/MRDemo.java types[140492550][Marble] = src/JLS4/BoxDemo/Marble.java -types[140492550][MonitorEngine] = src/JLS4/MonitorEngine/v2/MonitorEngine.java types[140492550][MonitorEngine] = src/JLS4/MonitorEngine/v1/MonitorEngine.java +types[140492550][MonitorEngine] = src/JLS4/MonitorEngine/v2/MonitorEngine.java types[140492550][PNG] = src/JLS2/AssertDemo/v3/AssertDemo.java -types[140492550][PaperFactory] = src/JLS3/CovarDemo/v2/CovarDemo.java types[140492550][PaperFactory] = src/JLS3/CovarDemo/v1/CovarDemo.java -types[140492550][Paper] = src/JLS3/CovarDemo/v2/CovarDemo.java +types[140492550][PaperFactory] = src/JLS3/CovarDemo/v2/CovarDemo.java types[140492550][Paper] = src/JLS3/CovarDemo/v1/CovarDemo.java +types[140492550][Paper] = src/JLS3/CovarDemo/v2/CovarDemo.java types[140492550][Planets] = src/JLS4/Planets/Planets.java -types[140492550][PressureException] = src/JLS4/MonitorEngine/v2/MonitorEngine.java types[140492550][PressureException] = src/JLS4/MonitorEngine/v1/MonitorEngine.java +types[140492550][PressureException] = src/JLS4/MonitorEngine/v2/MonitorEngine.java types[140492550][SortInts.] = src/JLS4/SortInts/v1/SortInts.java types[140492550][SortInts.] = src/JLS4/SortInts/v2/SortInts.java types[140492550][SortInts] = src/JLS4/SortInts/v1/SortInts.java @@ -121,14 +121,14 @@ types[140492550][SuperException] = src/JLS4/BreakageDemo/BreakageDemo.java types[140492550][Switchable] = src/JLS3/StaticImportsDemo/v1/Switchable.java types[140492550][TEDemo] = src/JLS3/TEDemo/v1/TEDemo.java types[140492550][TEDemo] = src/JLS3/TEDemo/v2/TEDemo.java -types[140492550][TemperatureException] = src/JLS4/MonitorEngine/v2/MonitorEngine.java types[140492550][TemperatureException] = src/JLS4/MonitorEngine/v1/MonitorEngine.java +types[140492550][TemperatureException] = src/JLS4/MonitorEngine/v2/MonitorEngine.java +types[140492550][ToDo] = src/JLS3/AnnDemo/v2/ToDo.java +types[140492550][ToDo] = src/JLS3/AnnDemo/v3/ToDo.java types[140492550][ToDo] = src/JLS3/AnnDemo/v4/ToDo.java +types[140492550][ToDo] = src/JLS3/AnnDemo/v5/ToDo.java types[140492550][ToDo] = src/JLS3/AnnProcDemo/ToDo.java types[140492550][ToDo] = src/JLS8/RADemo/ToDo.java -types[140492550][ToDo] = src/JLS3/AnnDemo/v3/ToDo.java -types[140492550][ToDo] = src/JLS3/AnnDemo/v5/ToDo.java -types[140492550][ToDo] = src/JLS3/AnnDemo/v2/ToDo.java types[140492550][TransientDemo.Transient] = src/JLS2/TransientDemo/Transient.java types[140492550][UndLitDemo] = src/JLS4/UndLitDemo/UndLitDemo.java types[140492550][UnsafeVarargsDemo2] = src/JLS4/UnsafeVarargsDemo/UnsafeVarargsDemo2.java From e63b9b3bbf90dd88ad25eb3aebd7287557a5269c Mon Sep 17 00:00:00 2001 From: Robert Dyer Date: Sun, 3 Sep 2023 11:18:31 -0500 Subject: [PATCH 18/18] the set aggregator does not need to be a linked set, since we sort it --- src/java/boa/aggregators/SetAggregator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/java/boa/aggregators/SetAggregator.java b/src/java/boa/aggregators/SetAggregator.java index 2d7681f19..00e865a0d 100644 --- a/src/java/boa/aggregators/SetAggregator.java +++ b/src/java/boa/aggregators/SetAggregator.java @@ -19,7 +19,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedHashSet; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -64,7 +64,7 @@ public void start(final EmitKey key) { super.start(key); // the set of data to be collected - this.set = new LinkedHashSet(); + this.set = new HashSet(); } /** {@inheritDoc} */