diff --git a/src/java/boa/aggregators/GraphAggregator.java b/src/java/boa/aggregators/GraphAggregator.java index ac2b66d3d..81ddbb52e 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/PreconditionAggregator.java b/src/java/boa/aggregators/PreconditionAggregator.java index 7cf35153a..10156a9f3 100644 --- a/src/java/boa/aggregators/PreconditionAggregator.java +++ b/src/java/boa/aggregators/PreconditionAggregator.java @@ -21,7 +21,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -43,7 +43,7 @@ public class PreconditionAggregator extends Aggregator { private final double sigma; private int args = 0; - private final Set preconds = new HashSet(); + private final Set preconds = new LinkedHashSet(); private final Map> omega = new HashMap>(); // preconditions: set of methods /** @@ -79,7 +79,7 @@ public void aggregate(final String data, final String metadata) throws IOExcepti final Expression precondition = parseexpression(precond); if (!omega.containsKey(precondition)) { - omega.put(precondition, new HashSet()); + omega.put(precondition, new LinkedHashSet()); preconds.add(precondition); } @@ -106,7 +106,7 @@ public void finish() throws IOException, InterruptedException { * @return map of all preconditions which include inferred preconditions */ private void inferNonStrictInequalities() { - final Set added = new HashSet(); + final Set added = new LinkedHashSet(); for (final Expression p : preconds) { if (p.getKind() == ExpressionKind.EQ) { @@ -123,7 +123,7 @@ private void inferNonStrictInequalities() { final Expression t = builder.build(); if (!preconds.contains(t)) { - omega.put(t, new HashSet()); + omega.put(t, new LinkedHashSet()); added.add(t); } @@ -186,7 +186,7 @@ private Map doFiltering() { // generate psi from omega final Map> psi = new HashMap>(); for (final Expression e : preconds) { - psi.put(e, new HashSet()); + psi.put(e, new LinkedHashSet()); for (final String s : omega.get(e)) { psi.get(e).add(s.split(":", 2)[0]); @@ -213,7 +213,7 @@ private Map doFiltering() { private Map calcConfidence(final Map> precondMP) { final Map precondConf = new HashMap(); - final Set totalCalls = new HashSet(); + final Set totalCalls = new LinkedHashSet(); for (final Expression precond : preconds) totalCalls.addAll(precondMP.get(precond)); @@ -267,7 +267,7 @@ private List> doRanking(final Map filt * @return set of all combinations of arguments */ private Set> generateCombinations() { - final Set> comb = new HashSet>(); + final Set> comb = new LinkedHashSet>(); final List argList = new ArrayList(); comb.add(new TreeSet(Collections.singletonList("$RECEIVER$"))); argList.add("$RECEIVER$"); @@ -278,7 +278,7 @@ private Set> generateCombinations() { } 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/aggregators/SetAggregator.java b/src/java/boa/aggregators/SetAggregator.java index 6eeb1a49f..00e865a0d 100644 --- a/src/java/boa/aggregators/SetAggregator.java +++ b/src/java/boa/aggregators/SetAggregator.java @@ -17,7 +17,11 @@ package boa.aggregators; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; +import java.util.List; +import java.util.Set; import boa.io.EmitKey; @@ -28,7 +32,7 @@ */ @AggregatorSpec(name = "set", canCombine = true) public class SetAggregator extends Aggregator { - private HashSet set; + private Set set; private final long max; /** @@ -75,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/src/java/boa/compiler/SymbolTable.java b/src/java/boa/compiler/SymbolTable.java index 42d8817d7..b4723512a 100644 --- a/src/java/boa/compiler/SymbolTable.java +++ b/src/java/boa/compiler/SymbolTable.java @@ -55,6 +55,7 @@ public class SymbolTable { private Operand operand; private Stack operandType = new Stack(); private boolean needsBoxing; + private boolean needsCast; private Stack isVisitor = new Stack(); private Stack lastVisit = new Stack(); private boolean isTraverse = false; @@ -207,7 +208,7 @@ public class SymbolTable { // clone functions globalFunctions.addFunction("clone", new BoaFunction(new BoaMap(new BoaTypeVar("K"), new BoaTypeVar("V")), new BoaType[] {new BoaMap(new BoaTypeVar("K"), new BoaTypeVar("V"))}, "(java.util.HashMap)${0}.clone()")); - 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 @@ -250,7 +251,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})")); @@ -701,6 +702,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/transforms/InheritedAttributeTransformer.java b/src/java/boa/compiler/transforms/InheritedAttributeTransformer.java index 730ddf9a8..037ae55dd 100644 --- a/src/java/boa/compiler/transforms/InheritedAttributeTransformer.java +++ b/src/java/boa/compiler/transforms/InheritedAttributeTransformer.java @@ -20,7 +20,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; @@ -104,7 +104,7 @@ public void visit(final VisitorExpression n) { * mapping from each type T found to a list of all uses in current(T). */ private class FindCurrentInVisitors 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 21c17ffeb..1c8166fae 100644 --- a/src/java/boa/compiler/transforms/VisitorOptimizingTransformer.java +++ b/src/java/boa/compiler/transforms/VisitorOptimizingTransformer.java @@ -17,7 +17,7 @@ */ package boa.compiler.transforms; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import java.util.Stack; @@ -41,8 +41,8 @@ * @author rdyer */ public class VisitorOptimizingTransformer extends AbstractVisitorNoArgNoRet { - protected final static Set> astTypes = new HashSet>(); - protected final static Set> revTypes = new HashSet>(); + protected final static Set> astTypes = new LinkedHashSet>(); + protected final static Set> revTypes = new LinkedHashSet>(); static { astTypes.addAll(new ASTRootProtoTuple().reachableTypes()); @@ -70,7 +70,7 @@ public class VisitorOptimizingTransformer extends AbstractVisitorNoArgNoRet { /** {@inheritDoc} */ @Override protected void initialize() { - types = new HashSet>(); + types = new LinkedHashSet>(); beforeChangedFile = afterChangedFile = null; beforeCodeRepository = afterCodeRepository = null; @@ -90,15 +90,15 @@ public void visit(final VisitorExpression n) { beforeCodeRepositoryStack.push(beforeCodeRepository); afterCodeRepositoryStack.push(afterCodeRepository); - types = new HashSet>(); + types = new LinkedHashSet>(); beforeChangedFile = afterChangedFile = null; n.getBody().accept(this); // if the visitor doesnt use an AST type, we can enforce // a stop at the lowest level visited - final Set> hasAst = new HashSet>(types); - final Set> hasRevision = new HashSet>(types); + final Set> hasAst = new LinkedHashSet>(types); + final Set> hasRevision = new LinkedHashSet>(types); hasAst.retainAll(astTypes); hasRevision.retainAll(revTypes); if (hasRevision.isEmpty()) { diff --git a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java index a2231da06..f9a35ded3 100644 --- a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java +++ b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java @@ -185,7 +185,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); @@ -200,7 +200,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 @@ -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()); @@ -251,7 +251,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 @@ -275,17 +275,23 @@ 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.toBoxedJavaType()); + types.add(e.type.toInterfaceJavaType()); + types2.add(e.type.toBoxedJavaType()); + aliases.add((e.type instanceof BoaProtoTuple) || (e.type instanceof BoaEnum)); counter++; } st.add("name", name); st.add("fields", fields); st.add("types", types); + st.add("types2", types2); + st.add("aliases", aliases); code.add(st.render()); } @@ -306,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()); @@ -427,7 +435,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 @@ -728,15 +736,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()); @@ -784,32 +795,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} */ @@ -860,7 +874,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()); @@ -1494,7 +1508,7 @@ public void visit(final TraverseStatement n) { cfgBuilder.start(n); new CreateNodeId().start(cfgBuilder); - final HashSet aliastSet = new LocalMayAliasAnalysis().start(cfgBuilder, traversalId); + final Set aliastSet = new LocalMayAliasAnalysis().start(cfgBuilder, traversalId); final DataFlowSensitivityAnalysis dataFlowSensitivityAnalysis = new DataFlowSensitivityAnalysis(); dataFlowSensitivityAnalysis.start(cfgBuilder, aliastSet); @@ -1573,7 +1587,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); @@ -1800,7 +1814,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()); @@ -1823,19 +1837,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()); + code.add(n.type.toJavaType()); } /** {@inheritDoc} */ @@ -1860,46 +1862,19 @@ 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()); + code.add(n.type.toJavaType()); } /** {@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} */ @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/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 b121f8a42..a80331a36 100644 --- a/src/java/boa/compiler/visitors/TypeCheckingVisitor.java +++ b/src/java/boa/compiler/visitors/TypeCheckingVisitor.java @@ -54,8 +54,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} */ @@ -99,7 +99,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} */ @@ -141,7 +141,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 9fc5c3361..f5249d1eb 100644 --- a/src/java/boa/compiler/visitors/analysis/CreateNodeId.java +++ b/src/java/boa/compiler/visitors/analysis/CreateNodeId.java @@ -36,7 +36,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 java.util.Set visitedNodes = new java.util.LinkedHashSet(); for (final Node n : cfgBuilder.currentStartNodes) createNodeIds(n, visitedNodes); } diff --git a/src/java/boa/compiler/visitors/analysis/DataFlowSensitivityAnalysis.java b/src/java/boa/compiler/visitors/analysis/DataFlowSensitivityAnalysis.java index a2a063d15..a916b040d 100644 --- a/src/java/boa/compiler/visitors/analysis/DataFlowSensitivityAnalysis.java +++ b/src/java/boa/compiler/visitors/analysis/DataFlowSensitivityAnalysis.java @@ -16,8 +16,9 @@ */ package boa.compiler.visitors.analysis; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import boa.compiler.ast.Call; import boa.compiler.ast.Factor; @@ -33,7 +34,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; @@ -44,8 +45,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 f142e9ad1..12aadb46e 100644 --- a/src/java/boa/compiler/visitors/analysis/InformationAnalysis.java +++ b/src/java/boa/compiler/visitors/analysis/InformationAnalysis.java @@ -16,8 +16,9 @@ */ package boa.compiler.visitors.analysis; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import boa.compiler.ast.Call; import boa.compiler.ast.Factor; @@ -37,21 +38,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 b9a3db12e..358c6dca2 100644 --- a/src/java/boa/compiler/visitors/analysis/LocalMayAliasAnalysis.java +++ b/src/java/boa/compiler/visitors/analysis/LocalMayAliasAnalysis.java @@ -16,8 +16,9 @@ */ package boa.compiler.visitors.analysis; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import boa.compiler.ast.Call; import boa.compiler.ast.Conjunction; @@ -35,15 +36,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 87a2e3fc4..9234524cc 100644 --- a/src/java/boa/compiler/visitors/analysis/LoopSensitivityAnalysis.java +++ b/src/java/boa/compiler/visitors/analysis/LoopSensitivityAnalysis.java @@ -16,8 +16,9 @@ */ package boa.compiler.visitors.analysis; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import boa.compiler.ast.Call; import boa.compiler.ast.Factor; @@ -36,15 +37,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; @@ -52,16 +53,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/BoaGraphIntrinsics.java b/src/java/boa/functions/BoaGraphIntrinsics.java index 4978bfad3..e62ac70d3 100644 --- a/src/java/boa/functions/BoaGraphIntrinsics.java +++ b/src/java/boa/functions/BoaGraphIntrinsics.java @@ -143,8 +143,8 @@ public static PDGSlicer getpdgslice(final Method method, Long id, boolean normal } //@FunctionSpec(name = "get_nodes_with_definition", returnType = "set of string", formalParameters = { "Node" }) - public static HashSet getNodesWithDefinition(final Node node) { - final HashSet vardef = new HashSet(); + public static Set getNodesWithDefinition(final Node 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())); @@ -154,8 +154,8 @@ public static HashSet getNodesWithDefinition(final Node node) { } //@FunctionSpec(name = "get_variable_killed", returnType = "set of string", formalParameters = {"CFG", "Node" }) - public static HashSet getVariableKilled(final boa.types.Control.Graph cfg, final Node node) { - final HashSet varkilled = new HashSet(); + public static Set getVariableKilled(final boa.types.Control.Graph cfg, final Node node) { + final Set varkilled = new LinkedHashSet(); String vardef = ""; if (node.getExpression() != null) { @@ -189,8 +189,8 @@ else if (tnode.getExpression().getKind() == ExpressionKind.ASSIGN) { } //@FunctionSpec(name = "get_variable_def", returnType = "set of string", formalParameters = { "Node" }) - public static HashSet getVariableDef(final Node node) { - final HashSet vardef = new HashSet(); + public static Set getVariableDef(final Node node) { + final Set vardef = new LinkedHashSet(); if (node.getExpression() != null) { if (node.getExpression().getKind() == ExpressionKind.VARDECL) { vardef.add(node.getExpression().getVariableDeclsList().get(0).getName()); @@ -203,15 +203,15 @@ else if (node.getExpression().getKind() == ExpressionKind.ASSIGN) { } //@FunctionSpec(name = "get_variable_used", returnType = "set of string", formalParameters = { "Node" }) - public static HashSet getVariableUsed(final Node node) { - final HashSet varused = new HashSet(); + public static Set getVariableUsed(final Node node) { + final Set 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 Set varused, final Expression expr) { if (expr.getVariable() != null) { varused.add(expr.getVariable()); } @@ -226,7 +226,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 Set 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 aef0c4d35..e5906f71d 100644 --- a/src/java/boa/functions/BoaIntrinsics.java +++ b/src/java/boa/functions/BoaIntrinsics.java @@ -21,7 +21,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; @@ -75,7 +75,7 @@ public static int getRevisionIndex(final CodeRepository cr, final long headId, f final PriorityQueue pq = new PriorityQueue(1 + revCount / 4); pq.offer((int)headId); - final Set seenIds = new HashSet(); + final Set seenIds = new LinkedHashSet(); int idx = -1; long lasttime = Long.MIN_VALUE; @@ -161,10 +161,10 @@ public static ChangedFile[] getSnapshotByIndex(final CodeRepository cr, final lo if (commitOffset < 0) return new ChangedFile[0]; final List snapshot = new LinkedList(); - final Set adds = new HashSet(); - final Set dels = new HashSet(); + final Set adds = new LinkedHashSet(); + final Set dels = new LinkedHashSet(); final PriorityQueue pq = new PriorityQueue(100, snapshotComparator); - final Set queuedCommitIds = new HashSet(); + final Set queuedCommitIds = new LinkedHashSet(); pq.offer((int) commitOffset); queuedCommitIds.add((int) commitOffset); while (!pq.isEmpty()) { @@ -280,10 +280,10 @@ 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) { final List snapshot = new LinkedList(); - final Set adds = new HashSet(); - final Set dels = new HashSet(); + final Set adds = new LinkedHashSet(); + final Set dels = new LinkedHashSet(); final PriorityQueue pq = new PriorityQueue(100, snapshotComparator); - final Set queuedCommitIds = new HashSet(); + final Set queuedCommitIds = new LinkedHashSet(); update(snapshot, commit, adds, dels, pq, queuedCommitIds, kinds); while (!pq.isEmpty()) { final int offset = pq.poll(); @@ -329,7 +329,7 @@ public static ChangedFile[] getPreviousVersion(final CodeRepository cr, final Ch fb.setName(cf.getPreviousNames(i)); final ChangedFile key = fb.build(); int revisionIndex = cf.getPreviousVersions(i); - final Set queuedRevisionIds = new HashSet(); + final Set queuedRevisionIds = new LinkedHashSet(); final PriorityQueue pq = new PriorityQueue(100, snapshotComparator); pq.offer(revisionIndex); queuedRevisionIds.add(revisionIndex); @@ -487,7 +487,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()) @@ -497,7 +497,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()) @@ -507,7 +507,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()) @@ -521,21 +521,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; @@ -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; @@ -583,73 +583,73 @@ 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; } 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.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.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.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.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.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.HashSet 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/functions/BoaNormalFormIntrinsics.java b/src/java/boa/functions/BoaNormalFormIntrinsics.java index b38e37191..fa00d25f3 100644 --- a/src/java/boa/functions/BoaNormalFormIntrinsics.java +++ b/src/java/boa/functions/BoaNormalFormIntrinsics.java @@ -2429,7 +2429,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: @@ -2928,7 +2928,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/functions/BoaSpecialIntrinsics.java b/src/java/boa/functions/BoaSpecialIntrinsics.java index 76b78ba06..8bac764b1 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/graphs/Node.java b/src/java/boa/graphs/Node.java index cdb6c7023..d4e878bac 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 4664cfa2f..0cdf038d5 100644 --- a/src/java/boa/graphs/cdg/CDG.java +++ b/src/java/boa/graphs/cdg/CDG.java @@ -18,8 +18,8 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -43,7 +43,7 @@ public class CDG { private Method md; private CDGNode entryNode; private CFG cfg; - 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 7cac1fb73..119a75f6f 100644 --- a/src/java/boa/graphs/cdg/CDGNode.java +++ b/src/java/boa/graphs/cdg/CDGNode.java @@ -16,7 +16,7 @@ */ package boa.graphs.cdg; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import boa.graphs.cfg.CFGNode; @@ -57,7 +57,7 @@ public CDGNode(final TreeNode node) { public CDGNode(int id) { this.cfgnode = null; this.id = id; - this.useVariables = new HashSet(); + this.useVariables = new LinkedHashSet(); } public CFGNode getCfgNode() { @@ -76,7 +76,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/cfg/CFG.java b/src/java/boa/graphs/cfg/CFG.java index e34dd2384..1c8ece201 100644 --- a/src/java/boa/graphs/cfg/CFG.java +++ b/src/java/boa/graphs/cfg/CFG.java @@ -19,8 +19,9 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Map; +import java.util.Set; import boa.functions.BoaAstIntrinsics; import boa.types.Ast.Expression; @@ -44,14 +45,14 @@ public class CFG { protected Method md; protected String class_name; - protected final HashSet nodes = new HashSet(); + protected final Set nodes = new LinkedHashSet(); protected CFGNode entryNode; protected CFGNode exitNode; - protected final HashSet outs = new HashSet(); - protected final HashSet ins = new HashSet(); - protected final HashSet breaks = new HashSet(); - protected final HashSet returns = new HashSet(); + 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; @@ -91,15 +92,15 @@ public String getClass_name() { return class_name; } - public HashSet getNodes() { + public Set getNodes() { return nodes; } - public HashSet getOuts() { + public Set getOuts() { return outs; } - public HashSet getIns() { + public Set getIns() { return ins; } @@ -208,7 +209,7 @@ protected void mergeSeq(final CFGNode branch) { outs.add(branch); } - protected void mergeBranches(final CFG target, final HashSet saveOuts) { + protected void mergeBranches(final CFG target, final Set saveOuts) { if (target.getNodes().size() == 0) return; diff --git a/src/java/boa/graphs/cfg/CFGNode.java b/src/java/boa/graphs/cfg/CFGNode.java index 50c9cc3ab..484aa25f1 100644 --- a/src/java/boa/graphs/cfg/CFGNode.java +++ b/src/java/boa/graphs/cfg/CFGNode.java @@ -18,7 +18,8 @@ package boa.graphs.cfg; import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Set; import boa.graphs.Node; import boa.types.Ast.Expression.ExpressionKind; @@ -35,12 +36,12 @@ public class CFGNode extends Node { private int objectNameId; private int classNameId; private int numOfParameters = 0; - private HashSet parameters; + private Set parameters; private static final HashMap idOfLabel = new HashMap(); private static final HashMap labelOfID = new HashMap(); - private HashSet useVariables; + private Set useVariables; private String defVariables; public CFGNode() { @@ -55,7 +56,7 @@ public CFGNode(final String methodName, final NodeType kind, final String classN } public CFGNode(final String methodName, final NodeType kind, final String className, - final String objectName, final int numOfParameters, final HashSet datas) { + final String objectName, final int numOfParameters, final Set datas) { super(kind); this.methodId = convertLabel(methodName); if (className == null) { @@ -64,7 +65,7 @@ public CFGNode(final String methodName, final NodeType kind, final String classN this.classNameId = convertLabel(className); } this.objectNameId = convertLabel(objectName); - this.parameters = new HashSet(datas); + this.parameters = new LinkedHashSet(datas); this.numOfParameters = numOfParameters; } @@ -91,11 +92,11 @@ public int getNumOfParameters() { return this.numOfParameters; } - public void setParameters(final HashSet parameters) { + public void setParameters(final Set parameters) { this.parameters = parameters; } - public HashSet getParameters() { + public Set getParameters() { return this.parameters; } @@ -115,7 +116,7 @@ public String getClassName() { return labelOfID.get(this.classNameId); } - public HashSet getUseVariables() { + public Set getUseVariables() { if (this.useVariables == null) processUse(); return this.useVariables; @@ -184,7 +185,7 @@ private static String processDef(final boa.types.Ast.Expression expr) { } private void processUse() { - final HashSet useVar = new HashSet(); + final Set useVar = new LinkedHashSet(); if (this.expr != null) { if (this.expr.getKind() == ExpressionKind.ASSIGN) { processUse(useVar, this.expr.getExpressions(1)); @@ -195,7 +196,7 @@ private void processUse() { this.useVariables = useVar; } - private static void processUse(final HashSet useVar, final boa.types.Ast.Expression expr) { + private static void processUse(final Set useVar, final boa.types.Ast.Expression expr) { if (expr.getKind() == ExpressionKind.ASSIGN) { processUse(useVar, expr.getExpressions(1)); return; @@ -219,7 +220,7 @@ private static void processUse(final HashSet useVar, final boa.types.Ast } } - private static void processUse(final HashSet useVar, final boa.types.Ast.Variable vardecls) { + private static void processUse(final Set useVar, final boa.types.Ast.Variable vardecls) { if (vardecls.hasInitializer()) { processUse(useVar, vardecls.getInitializer()); } diff --git a/src/java/boa/graphs/ddg/DDG.java b/src/java/boa/graphs/ddg/DDG.java index d189c58ae..8c30e0c8d 100644 --- a/src/java/boa/graphs/ddg/DDG.java +++ b/src/java/boa/graphs/ddg/DDG.java @@ -32,7 +32,7 @@ public class DDG { private Method md; private DDGNode entryNode; private CFG cfg; - 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 @@ -99,7 +99,7 @@ public CFG getCfg() { * * @return the set of all the nodes in the graph */ - public HashSet getNodes() { return nodes; } + public Set getNodes() { return nodes; } public DDGNode[] sortNodes() { try { @@ -130,7 +130,7 @@ public HashMap> getDefUseChain() { * @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); @@ -260,7 +260,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); diff --git a/src/java/boa/graphs/ddg/DDGNode.java b/src/java/boa/graphs/ddg/DDGNode.java index 97f7f5cb8..9d5d9225b 100644 --- a/src/java/boa/graphs/ddg/DDGNode.java +++ b/src/java/boa/graphs/ddg/DDGNode.java @@ -16,7 +16,7 @@ */ package boa.graphs.ddg; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import boa.graphs.Node; @@ -30,7 +30,7 @@ */ public class DDGNode extends Node { protected String defVariable; - protected HashSet useVariables = new HashSet(); + protected Set useVariables = new LinkedHashSet(); /** * Constructs a DDG node. @@ -59,7 +59,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/pdg/PDG.java b/src/java/boa/graphs/pdg/PDG.java index aeeb17557..1a76a7d7f 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 34bad2c9e..192e0c1cf 100644 --- a/src/java/boa/graphs/pdg/PDGNode.java +++ b/src/java/boa/graphs/pdg/PDGNode.java @@ -17,7 +17,7 @@ package boa.graphs.pdg; import java.util.ArrayList; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -32,7 +32,7 @@ */ public class PDGNode extends Node { private String defVariable; - private Set useVariables = new HashSet(); + private Set useVariables = new LinkedHashSet(); /** * Constructs a PDG node. @@ -52,7 +52,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 d6d4d792f..0bec9c183 100644 --- a/src/java/boa/graphs/slicers/CFGSlicer.java +++ b/src/java/boa/graphs/slicers/CFGSlicer.java @@ -20,7 +20,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -107,14 +107,14 @@ 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); 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) @@ -123,7 +123,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) @@ -133,14 +133,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); @@ -156,7 +156,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)); } @@ -167,7 +167,7 @@ public void traverse(final CFGNode node, boolean flag) throws Exception { @Override @SuppressWarnings({"unchecked"}) public boolean invoke(final Object current, final Object previous) throws Exception { - return boa.functions.BoaIntrinsics.set_symdiff((HashSet) current, (HashSet) previous).size() == 0; + return boa.functions.BoaIntrinsics.set_symdiff((LinkedHashSet) current, (LinkedHashSet) previous).size() == 0; } }; @@ -205,7 +205,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 4e0cb89d5..47ce8f40f 100644 --- a/src/java/boa/graphs/slicers/PDGSlicer.java +++ b/src/java/boa/graphs/slicers/PDGSlicer.java @@ -24,7 +24,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -45,7 +45,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; @@ -178,7 +178,7 @@ public ArrayList getEntrynodesList() { * * @return all the nodes in the slice */ - public HashSet getSlice() { + public Set getSlice() { return slice; } @@ -256,7 +256,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)) { @@ -308,8 +308,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 0eacc7440..b926f8172 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; } @@ -163,14 +163,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>(); @@ -178,7 +178,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; @@ -193,7 +193,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 341a7d5b2..73799fb22 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/graphs/trees/TreeNode.java b/src/java/boa/graphs/trees/TreeNode.java index beb61132e..357b2b941 100644 --- a/src/java/boa/graphs/trees/TreeNode.java +++ b/src/java/boa/graphs/trees/TreeNode.java @@ -17,7 +17,7 @@ package boa.graphs.trees; 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 TreeNode extends Node { private TreeNode parent; private String defVariable; - private HashSet useVariables; + private Set useVariables; private final ArrayList children = new ArrayList(); private final CFGNode cfgnode; @@ -61,7 +61,7 @@ public TreeNode(final CFGNode node) { public TreeNode(final int id) { this.cfgnode = null; this.id = id; - this.useVariables = new HashSet(); + this.useVariables = new LinkedHashSet(); } public TreeNode getParent() { @@ -88,7 +88,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/runtime/BoaAbstractTraversal.java b/src/java/boa/runtime/BoaAbstractTraversal.java index 5298f8bef..b45030258 100644 --- a/src/java/boa/runtime/BoaAbstractTraversal.java +++ b/src/java/boa/runtime/BoaAbstractTraversal.java @@ -412,7 +412,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; - final java.util.HashSet nl = cfg.getNodes(); + final java.util.Set nl = cfg.getNodes(); for (final CFGNode node : nl) { boolean curFlag = outputMapObj.containsKey(node.getId()); if (curFlag) { @@ -433,7 +433,7 @@ public final void traverse(final boa.graphs.cfg.CFG cfg, final Traversal.Travers break; case HYBRID: prevOutputMapObj = new java.util.HashMap(); - final java.util.Set visitedNodes = new java.util.HashSet(); + final java.util.Set visitedNodes = new java.util.LinkedHashSet(); final CFGNode[] nl = cfg.sortNodes(); if (nl.length != 0) { if (this.isFlowSensitive) { @@ -521,7 +521,7 @@ public final void traverseWithFixp(final CFG cfg, final Traversal.TraversalDirec outputMapObj = new java.util.HashMap(); } if (cfg.getNodes().size() != 0) { - final java.util.Set visitedNodes = new java.util.HashSet(); + final java.util.Set visitedNodes = new java.util.LinkedHashSet(); switch (kind) { case WORKLIST_POSTORDER: Queue queue = new LinkedList(); @@ -565,7 +565,7 @@ public final void traverse(final boa.graphs.cfg.CFG cfg, final Traversal.Travers outputMapObj = new java.util.HashMap(); } if (cfg.getNodes().size() != 0) { - final java.util.Set visitedNodes = new java.util.HashSet(); + final java.util.Set visitedNodes = new java.util.LinkedHashSet(); final CFGNode[] nl = cfg.sortNodes(); switch (kind) { case DFS: @@ -661,7 +661,7 @@ public final void traverse(final boa.graphs.cdg.CDG cdg, final Traversal.Travers outputMapObj = new java.util.HashMap(); } if (cdg.getNodes().size() != 0) { - final java.util.Set visitedNodes = new java.util.HashSet(); + final java.util.Set visitedNodes = new java.util.LinkedHashSet(); //final CDGNode[] nl = cdg.sortNodes(); switch (kind) { case DFS: @@ -759,7 +759,7 @@ public final void traverse(final boa.graphs.ddg.DDG ddg, final Traversal.Travers outputMapObj = new java.util.HashMap(); } if (ddg.getNodes().size() != 0) { - final java.util.Set visitedNodes = new java.util.HashSet(); + final java.util.Set visitedNodes = new java.util.LinkedHashSet(); //final CDGNode[] nl = cdg.sortNodes(); switch (kind) { case DFS: @@ -857,7 +857,7 @@ public final void traverse(final boa.graphs.pdg.PDG pdg, final Traversal.Travers outputMapObj = new java.util.HashMap(); } if (pdg.getNodes().size() != 0) { - final java.util.Set visitedNodes = new java.util.HashSet(); + final java.util.Set visitedNodes = new java.util.LinkedHashSet(); //final CDGNode[] nl = cdg.sortNodes(); switch (kind) { case DFS: @@ -955,7 +955,7 @@ public final void traverse(final boa.graphs.slicers.PDGSlicer pdgslicer, final T outputMapObj = new java.util.HashMap(); } if (pdgslicer.getSlice().size() != 0) { - final java.util.Set visitedNodes = new java.util.HashSet(); + final java.util.Set visitedNodes = new java.util.LinkedHashSet(); //final CDGNode[] nl = cdg.sortNodes(); switch (kind) { case DFS: @@ -1050,7 +1050,7 @@ public final void traverse(final boa.graphs.trees.PDTree tree, final Traversal.T outputMapObj = new java.util.HashMap(); } if (tree.getNodes().size() != 0) { - final java.util.Set visitedNodes = new java.util.HashSet(); + final java.util.Set visitedNodes = new java.util.LinkedHashSet(); //final CDGNode[] nl = cdg.sortNodes(); switch (kind) { case DFS: diff --git a/src/java/boa/types/BoaArray.java b/src/java/boa/types/BoaArray.java index b4cc56749..b54b3d64b 100644 --- a/src/java/boa/types/BoaArray.java +++ b/src/java/boa/types/BoaArray.java @@ -189,6 +189,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/BoaMap.java b/src/java/boa/types/BoaMap.java index a4e7db21f..79fb2c162 100644 --- a/src/java/boa/types/BoaMap.java +++ b/src/java/boa/types/BoaMap.java @@ -165,7 +165,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.toInterfaceJavaType() + ", " + this.valueType.toInterfaceJavaType() + ">"; + } + + /** {@inheritDoc} */ + @Override + public String toInterfaceJavaType() { + return "java.util.Map<" + this.indexType.toInterfaceJavaType() + ", " + this.valueType.toInterfaceJavaType() + ">"; } /** {@inheritDoc} */ diff --git a/src/java/boa/types/BoaProtoList.java b/src/java/boa/types/BoaProtoList.java index 169acc1a0..11e874ce4 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; import boa.compiler.ast.types.AbstractType; @@ -195,6 +195,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/BoaProtoMap.java b/src/java/boa/types/BoaProtoMap.java index fdfc38691..96824bec9 100644 --- a/src/java/boa/types/BoaProtoMap.java +++ b/src/java/boa/types/BoaProtoMap.java @@ -75,6 +75,12 @@ public String toJavaType() { return getEnumClass().getName().replace('$', '.'); } + /** {@inheritDoc} */ + @Override + public String toInterfaceJavaType() { + return toJavaType(); + } + /** {@inheritDoc} */ @Override public String toString() { diff --git a/src/java/boa/types/BoaProtoTuple.java b/src/java/boa/types/BoaProtoTuple.java index ae0c4a61e..d779324fb 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; @@ -98,7 +98,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) { diff --git a/src/java/boa/types/BoaQueue.java b/src/java/boa/types/BoaQueue.java index 3b3834cd6..de9fc2d9d 100644 --- a/src/java/boa/types/BoaQueue.java +++ b/src/java/boa/types/BoaQueue.java @@ -139,7 +139,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 5694a9a15..b5d63d0fd 100644 --- a/src/java/boa/types/BoaSet.java +++ b/src/java/boa/types/BoaSet.java @@ -140,7 +140,13 @@ public String toString() { /** {@inheritDoc} */ @Override public String toJavaType() { - return "java.util.HashSet<" + this.type.toBoxedJavaType() + ">"; + return "java.util.LinkedHashSet<" + this.type.toInterfaceJavaType() + ">"; + } + + /** {@inheritDoc} */ + @Override + public String toInterfaceJavaType() { + 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 f93490e0f..c76392a62 100644 --- a/src/java/boa/types/BoaStack.java +++ b/src/java/boa/types/BoaStack.java @@ -139,7 +139,7 @@ public String toString() { /** {@inheritDoc} */ @Override public String toJavaType() { - return "java.util.Stack<" + this.type.toBoxedJavaType() + ">"; + 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 6dee6bef9..0103830a7 100644 --- a/src/java/boa/types/BoaType.java +++ b/src/java/boa/types/BoaType.java @@ -118,6 +118,17 @@ 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(); + } + /** * Takes a type name and returns one suitable for use as an identifier. * diff --git a/templates/BoaJava.stg b/templates/BoaJava.stg index 4f44a5d04..b3c1316a3 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.HashSet\<>" Block(statements) ::= << { }>} @@ -125,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() { 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