-
Notifications
You must be signed in to change notification settings - Fork 56
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
constant propagation support #504
constant propagation support #504
Conversation
Codecov Report
@@ Coverage Diff @@
## master #504 +/- ##
==========================================
- Coverage 93.01% 93.01% -0.01%
==========================================
Files 40 40
Lines 14428 14468 +40
==========================================
+ Hits 13420 13457 +37
- Misses 1008 1011 +3
Continue to review full report at Codecov.
|
01f0e53
to
85e7514
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but could you add a correctness test for the switch case as well?
Also one using constants in body would be great
testcases: - constants & const-expressions used as initial values - constants & const-expressions used in case-statement - constants & const-expressions used in array-declaration
done - added correctness tests |
tests/correctness/constants.rs
Outdated
gF : LREAL := cF; | ||
END_VAR | ||
|
||
PROGRAM main : DINT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Programs don't return
tests/correctness/constants.rs
Outdated
let src = r#" | ||
VAR_GLOBAL CONSTANT | ||
cI : DINT := 2 * 5; | ||
cB : BOOL := (CI-5 = 5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
case difference CI != cI
added a test that shows that constants are propagated even in ranged-type's limits, so even if you use (const-)expressions (a+b) to define the limits of a ranged type, the const-expressions will be evaluated during compile time and the result will be used. - as in contrast we would do this calculation all the time at runtime. the behavior was introduced in PR #504 (016328) fixes #350
added a test that shows that constants are propagated even in ranged-type's limits, so even if you use (const-)expressions (a+b) to define the limits of a ranged type, the const-expressions will be evaluated during compile time and the result will be used. - as in contrast we would do this calculation all the time at runtime. the behavior was introduced in PR #504 (016328) fixes #350
added a test that shows that constants are propagated even in ranged-type's limits, so even if you use (const-)expressions (a+b) to define the limits of a ranged type, the const-expressions will be evaluated during compile time and the result will be used. - as in contrast we would do this calculation all the time at runtime. the behavior was introduced in PR #504 (016328) fixes #350
when generating an expression we check if this may refer to a constant
expression and rather generate it's initial value instead of a
reference to the global variable.
fixes #391 and #291