Skip to content

Commit 4e1a8c2

Browse files
authored
Improved energyflaw analysis
1 parent 28fdc1c commit 4e1a8c2

7 files changed

Lines changed: 768 additions & 17 deletions

BasicExpression.java

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19262,6 +19262,17 @@ else if (pars.size() == 1)
1926219262
}
1926319263
}
1926419264

19265+
if ("excludingAt".equals(data) &&
19266+
arrayIndex == null &&
19267+
pars != null)
19268+
{ if (pars.size() == 1)
19269+
{ Expression res =
19270+
Expression.simplifyExcludingAt(objR,
19271+
(Expression) pars.get(0));
19272+
return res;
19273+
}
19274+
}
19275+
1926519276
if ("insertAt".equals(data) &&
1926619277
arrayIndex == null &&
1926719278
pars != null)
@@ -19286,7 +19297,30 @@ else if (pars.size() == 1)
1928619297
}
1928719298
}
1928819299

19289-
// excludingSubrange, setSubrange, + regex ops
19300+
if ("excludingSubrange".equals(data) &&
19301+
arrayIndex == null &&
19302+
pars != null)
19303+
{ if (pars.size() == 2)
19304+
{ Expression res =
19305+
Expression.simplifyExcludingSubrange(objR,
19306+
(Expression) pars.get(0),
19307+
(Expression) pars.get(1));
19308+
return res;
19309+
}
19310+
}
19311+
19312+
if ("setSubrange".equals(data) &&
19313+
arrayIndex == null &&
19314+
pars != null)
19315+
{ if (pars.size() == 3)
19316+
{ Expression res =
19317+
Expression.simplifySetSubrange(objR,
19318+
(Expression) pars.get(0),
19319+
(Expression) pars.get(1),
19320+
(Expression) pars.get(2));
19321+
return res;
19322+
}
19323+
}
1929019324

1929119325
BasicExpression res = (BasicExpression) clone();
1929219326
res.objectRef = objR;
@@ -19417,6 +19451,7 @@ public java.util.Map collectionOperatorUses(int level,
1941719451
data.equals("insertInto") ||
1941819452
data.equals("subrange") ||
1941919453
data.equals("setAt") ||
19454+
data.equals("excludingAt") ||
1942019455
data.equals("excludingSubrange") ||
1942119456
data.equals("setSubrange"))
1942219457
{ Vector opers = (Vector) res.get(level);
@@ -19483,6 +19518,14 @@ public java.util.Map collectionOperatorUses(int level,
1948319518
Map uses, Vector messages)
1948419519
{ // level |-> [x.setAt(i,y), etc]
1948519520

19521+
if (parameters != null)
19522+
{ for (int i = 0; i < parameters.size(); i++)
19523+
{ Expression par = (Expression) parameters.get(i);
19524+
par.collectionOperatorUses(level, res, vars,
19525+
uses, messages);
19526+
}
19527+
}
19528+
1948619529
/* JOptionPane.showInputDialog("Collection uses of " + this + " " + level + " " + objectRef + " " + parameters); */
1948719530

1948819531
if (objectRef != null || parameters != null ||
@@ -19491,11 +19534,7 @@ public java.util.Map collectionOperatorUses(int level,
1949119534
Vector vuses = variablesUsedIn(vars);
1949219535
int syncom = syntacticComplexity();
1949319536

19494-
/* JOptionPane.showInputDialog("Complexity of " + this +
19495-
" = " + syncom + " uses = " + vuses +
19496-
" level: " + level + " sideeffect: " + sideeffect); */
19497-
19498-
if (syncom >= TestParameters.energyCloneSizeLimit &&
19537+
if (syncom > TestParameters.energyCloneSizeLimit &&
1949919538
level > 1 && vuses.size() == 0 && !sideeffect)
1950019539
{ messages.add("!!! Warning (LCE): The expression " + this + " may be independent of the iterator variables " + vars + "\n" +
1950119540
"!!! Use Extract local variable to optimise.");
@@ -19506,12 +19545,24 @@ public java.util.Map collectionOperatorUses(int level,
1950619545
int oescount = (int) uses.get("LCE");
1950719546
uses.set("LCE", oescount+1);
1950819547
}
19548+
else if (syncom > 1 &&
19549+
level > 1 && vuses.size() == 0 && !sideeffect)
19550+
{ messages.add("! Warning (OEW): The expression " + this + " may be independent of the iterator variables " + vars + "\n" +
19551+
"! Use Extract local variable to optimise.");
19552+
refactorELV = true;
19553+
int yScore = (int) uses.get("yellow");
19554+
uses.set("yellow", yScore+1);
19555+
messages.add("");
19556+
int oewcount = (int) uses.get("OEW");
19557+
uses.set("OEW", oewcount+1);
19558+
}
1950919559
} // Any non-trivial basic expression
1951019560

1951119561
if (data.equals("insertAt") ||
1951219562
data.equals("insertInto") ||
1951319563
data.equals("subrange") ||
1951419564
data.equals("setAt") ||
19565+
data.equals("excludingAt") ||
1951519566
data.equals("excludingSubrange") ||
1951619567
data.equals("setSubrange"))
1951719568
{ Vector opers = (Vector) res.get(level);

BehaviouralFeature.java

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5043,8 +5043,64 @@ public void collectionOperatorUses(int level,
50435043
}
50445044

50455045
if (activity != null)
5046-
{ activity.collectionOperatorUses(level, res, vars,
5047-
flaws, messages);
5046+
{ java.util.Map localres = new java.util.HashMap();
5047+
5048+
activity.collectionOperatorUses(level, localres, vars,
5049+
flaws, messages);
5050+
5051+
java.util.Set keys = localres.keySet();
5052+
for (Object k : keys)
5053+
{ java.util.Set linearOpCollections =
5054+
new java.util.HashSet();
5055+
5056+
Vector opers = (Vector) localres.get(k);
5057+
for (int i = 0; i < opers.size(); i++)
5058+
{ Expression oper = (Expression) opers.get(i);
5059+
5060+
if (oper instanceof UnaryExpression)
5061+
{ UnaryExpression ue = (UnaryExpression) oper;
5062+
Expression arg = ue.getArgument();
5063+
if (arg instanceof BasicExpression &&
5064+
Expression.linearOperators.contains(
5065+
ue.getOperator()))
5066+
{ arg.setBrackets(false);
5067+
if (linearOpCollections.contains("" + arg))
5068+
{ messages.add("! (OEW): multiple linear iterations over collection " +
5069+
arg + " in " + this +
5070+
": Can be optimised using a single iteration.\n");
5071+
int rScore = (int) flaws.get("yellow");
5072+
flaws.set("yellow", rScore+1);
5073+
int lcecount = (int) flaws.get("OEW");
5074+
flaws.set("OEW", lcecount+1);
5075+
}
5076+
5077+
linearOpCollections.add("" + arg);
5078+
}
5079+
}
5080+
5081+
if (oper instanceof BinaryExpression)
5082+
{ BinaryExpression be = (BinaryExpression) oper;
5083+
Expression arg = be.getLeft();
5084+
if (arg instanceof BasicExpression &&
5085+
Expression.linearOperators.contains(
5086+
be.getOperator()))
5087+
{ arg.setBrackets(false);
5088+
if (linearOpCollections.contains("" + arg))
5089+
{ messages.add("! (OEW): multiple linear iterations over collection " + arg + " in " + this +
5090+
": Can be optimised using a single iteration.\n");
5091+
int rScore = (int) flaws.get("yellow");
5092+
flaws.set("yellow", rScore+1);
5093+
int lcecount = (int) flaws.get("OEW");
5094+
flaws.set("OEW", lcecount+1);
5095+
}
5096+
5097+
linearOpCollections.add("" + arg);
5098+
}
5099+
}
5100+
}
5101+
}
5102+
5103+
res.putAll(localres);
50485104
}
50495105

50505106
} // and activity

BinaryExpression.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22515,6 +22515,11 @@ public Expression simplifyOCL()
2251522515
return Expression.simplifyIntersection(lexpr,rexpr);
2251622516
}
2251722517

22518+
if ("->excludingAt".equals(operator))
22519+
{ // merge the literal sets/sequences/maps
22520+
return Expression.simplifyExcludingAt(lexpr,rexpr);
22521+
}
22522+
2251822523
int synLeft = lexpr.syntacticComplexity();
2251922524
int synRight = rexpr.syntacticComplexity();
2252022525

@@ -24038,21 +24043,37 @@ public java.util.Map collectionOperatorUses(int level,
2403824043
Vector messages)
2403924044
{ // level |-> [x.setAt(i,y), etc]
2404024045

24046+
int syncomp = syntacticComplexity();
2404124047
boolean sideeffect = isSideEffecting();
2404224048
Vector vuses = variablesUsedIn(vars);
2404324049

24044-
if (level > 1 && vuses.size() == 0 && !sideeffect)
24050+
if (level > 1 &&
24051+
syncomp > TestParameters.energyCloneSizeLimit &&
24052+
vuses.size() == 0 && !sideeffect)
2404524053
{ messages.add("!!! (LCE) flaw: The expression " + this + " may be independent of the iterator variables " + vars + "\n" +
2404624054
"!!! Use Extract local variable to optimise.");
2404724055
messages.add("");
24048-
System.err.println();
24056+
// System.err.println();
2404924057
refactorELV = true;
2405024058
int rScore = (int) uses.get("red");
2405124059
uses.set("red", rScore+1);
2405224060
int lcecount = (int) uses.get("LCE");
2405324061
uses.set("LCE", lcecount+1);
2405424062
return res;
2405524063
}
24064+
else if (level > 1 &&
24065+
syncomp > 1 &&
24066+
vuses.size() == 0 && !sideeffect)
24067+
{ messages.add("! (OEW) warning: The expression " + this + " may be independent of the iterator variables " + vars + "\n" +
24068+
"! Use Extract local variable to optimise.");
24069+
messages.add("");
24070+
// System.err.println();
24071+
refactorELV = true;
24072+
int rScore = (int) uses.get("yellow");
24073+
uses.set("yellow", rScore+1);
24074+
int lcecount = (int) uses.get("OEW");
24075+
uses.set("OEW", lcecount+1);
24076+
}
2405624077

2405724078
if (operator.equals("->including") ||
2405824079
operator.equals("->prepend") ||

0 commit comments

Comments
 (0)