Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fixes #330 #374

Open
wants to merge 3 commits into
base: 2024-06
Choose a base branch
from
Open

Fixes #330 #374

wants to merge 3 commits into from

Conversation

AlexisDrogoul
Copy link
Member

Separates the int and float bounded definitions. Makes a loop where "from" > "to" at least execute once with the value of "from". Should fix #330.

Separates the int and float bounded definitions. Makes a loop where "from" > "to" at least execute once with the value of "from".
Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: FAILED

Change in average Code Health of affected files: +0.36 (7.01 -> 7.38)

  • Declining Code Health: 3 findings(s) 🚩
  • Improving Code Health: 4 findings(s) ✅

View detailed results in CodeScene

Comment on lines +605 to +607
final Double f = constantFrom == null ? value(scope, from) : constantFrom;
final Double t = constantTo == null ? value(scope, to) : constantTo;
Double s = constantStep == null ? value(scope, step) : constantStep;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Complex Method
LoopStatement.FloatBounded.runIn has a cyclomatic complexity of 16, threshold = 9

Suppress

Comment on lines +524 to +551
public Object runIn(final IScope scope) throws GamaRuntimeException {
final Object[] result = new Object[1];
final Integer f = constantFrom == null ? value(scope, from) : constantFrom;
final Integer t = constantTo == null ? value(scope, to) : constantTo;
Integer s = constantStep == null ? value(scope, step) : constantStep;
boolean shouldBreak = false;
if (f.equals(t)) {
loopBody(scope, f, result);
} else if (f > t) {
if (s > 0) {
if (stepDefined) {
loopBody(scope, f, result);
return result[0];
}
s = -s;
}
for (int i = f, n = t; i >= n && !shouldBreak; i += s) {
FlowStatus status = loopBody(scope, i, result);
switch (status) {
case CONTINUE:
continue;
case BREAK, RETURN, DIE, DISPOSE:
shouldBreak = true;
break;
default:
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Complex Method
LoopStatement.IntBounded.runIn has a cyclomatic complexity of 16, threshold = 9

Suppress

Comment on lines +416 to +421
IExpression from = getFacet(IKeyword.FROM);
IExpression to = getFacet(IKeyword.TO);
IExpression step = getFacet(IKeyword.STEP);
final boolean isBounded = from != null && to != null;
boolean isInt = isBounded && from.getGamlType() == Types.INT && to.getGamlType() == Types.INT
&& (step == null || step.getGamlType() == Types.INT);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Complex Method
LoopStatement has a cyclomatic complexity of 10, threshold = 9

Suppress

Comment on lines -551 to -553
final Number f = constantFrom == null ? getFromExp(scope, from) : constantFrom;
final Number t = constantTo == null ? getFromExp(scope, to) : constantTo;
Number s = constantStep == null ? getFromExp(scope, step) : constantStep;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No longer an issue: Bumpy Road Ahead
LoopStatement.Bounded.runIn is no longer above the threshold for logical blocks with deeply nested code

Comment on lines +524 to +551
public Object runIn(final IScope scope) throws GamaRuntimeException {
final Object[] result = new Object[1];
final Integer f = constantFrom == null ? value(scope, from) : constantFrom;
final Integer t = constantTo == null ? value(scope, to) : constantTo;
Integer s = constantStep == null ? value(scope, step) : constantStep;
boolean shouldBreak = false;
if (f.equals(t)) {
loopBody(scope, f, result);
} else if (f > t) {
if (s > 0) {
if (stepDefined) {
loopBody(scope, f, result);
return result[0];
}
s = -s;
}
for (int i = f, n = t; i >= n && !shouldBreak; i += s) {
FlowStatus status = loopBody(scope, i, result);
switch (status) {
case CONTINUE:
continue;
case BREAK, RETURN, DIE, DISPOSE:
shouldBreak = true;
break;
default:
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ New issue: Bumpy Road Ahead
LoopStatement.IntBounded.runIn has 3 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function

Comment on lines +605 to +607
final Double f = constantFrom == null ? value(scope, from) : constantFrom;
final Double t = constantTo == null ? value(scope, to) : constantTo;
Double s = constantStep == null ? value(scope, step) : constantStep;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ New issue: Bumpy Road Ahead
LoopStatement.FloatBounded.runIn has 3 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function

@@ -1,7 +1,6 @@
/*******************************************************************************************************
*
* LoopStatement.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform
* (v.2.0.0).
* LoopStatement.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform (v.2.0.0).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Getting better: Overall Code Complexity
The mean cyclomatic complexity decreases from 5.44 to 5.24, threshold = 4

@lesquoyb
Copy link
Contributor

while testing this PR I noticed that a from/to loop with from<to but a negative step ends up in an infinite loop.
It was happening before so I don't know if I should create a new issue or this can be solved here, what do you think ?

@AlexisDrogoul
Copy link
Member Author

while testing this PR I noticed that a from/to loop with from<to but a negative step ends up in an infinite loop. It was happening before so I don't know if I should create a new issue or this can be solved here, what do you think ?

Seems to me like a normal behavior 🤔

@lesquoyb
Copy link
Contributor

while testing this PR I noticed that a from/to loop with from<to but a negative step ends up in an infinite loop. It was happening before so I don't know if I should create a new issue or this can be solved here, what do you think ?

Seems to me like a normal behavior 🤔

then we have another problem because in the other direction we just iterate once and exit the loop.

I'm making a unit test model for loops because it seems like there are a lot of inconsistencies here

- some models are not passing the tests right now do to bugs/inconsistencies in the loop statement
Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: FAILED

Change in average Code Health of affected files: -0.07 (7.01 -> 6.94)

  • Declining Code Health: 4 findings(s) 🚩
  • Improving Code Health: 4 findings(s) ✅

View detailed results in CodeScene

Comment on lines +605 to +607
final Double f = constantFrom == null ? value(scope, from) : constantFrom;
final Double t = constantTo == null ? value(scope, to) : constantTo;
Double s = constantStep == null ? value(scope, step) : constantStep;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Code Duplication
The module contains 4 functions with similar structure: LoopStatement.FloatBounded.FloatBounded,LoopStatement.FloatBounded.runIn,LoopStatement.IntBounded.IntBounded,LoopStatement.IntBounded.runIn

Suppress

The problem came from the choice of the operator + at compilation times, because step was not used to compute the type of i ...
Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: FAILED

Change in average Code Health of affected files: +0.06 (7.29 -> 7.35)

  • Declining Code Health: 4 findings(s) 🚩
  • Improving Code Health: 7 findings(s) ✅

View detailed results in CodeScene

@@ -333,8 +332,7 @@ protected IExpression createVarWithTypes(final String tag) {
}
}
} else if (hasFacet(FROM) && hasFacet(TO)) {
final IExpression expr = getFacetExpr(FROM);
if (expr != null) { t = expr.getGamlType(); }
t = GamaType.findCommonType(getFacetExpr(FROM), getFacetExpr(TO), getFacetExpr(STEP));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Getting better: Complex Method
createVarWithTypes decreases in cyclomatic complexity from 17 to 16, threshold = 9

@@ -333,8 +332,7 @@ protected IExpression createVarWithTypes(final String tag) {
}
}
} else if (hasFacet(FROM) && hasFacet(TO)) {
final IExpression expr = getFacetExpr(FROM);
if (expr != null) { t = expr.getGamlType(); }
t = GamaType.findCommonType(getFacetExpr(FROM), getFacetExpr(TO), getFacetExpr(STEP));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Getting better: Bumpy Road Ahead
createVarWithTypes decreases from 4 to 3 logical blocks with deeply nested code, threshold is one single block per function

@@ -1,7 +1,6 @@
/*******************************************************************************************************
*
* StatementDescription.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform
* .
* StatementDescription.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform .

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No longer an issue: Overall Code Complexity
The mean cyclomatic complexity in this module is no longer above the threshold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loop from/to has inconsistent behaviour
2 participants