dewolf
dewolf copied to clipboard
[For-Loop] Properties of Condition
Proposal
Currently, we transform a while-loop into a for-loop independent of the condition. However, for-loops where the condition is a comparison like a == 10
or a != 10
are rather rare (except for pointers).
In the following example (test1_c
in test_goto.zip), we have the condition var_0 == 15
in a for-loop with is rather unusual.
int test1_c() {
int var_0;
var_0 = 10;
do {
for (var_0; var_0 == 15; var_0 += 2) {
printf("We go to the loop head.", var_0);
}
printf("value of a: %d\n", var_0);
var_0++;
}
while (var_0 <= 19);
return 0;
}
Here, a while loop would look more natural, i.e.,
int test1_c() {
int var_0;
var_0 = 10;
do {
while (var_0 == 15) {
printf("We go to the loop head.", var_0);
var_0 += 2;
}
printf("value of a: %d\n", var_0);
var_0++;
}
while (var_0 <= 19);
return 0;
}
Approach
Add a configuration option for the condition of for-loops.
- [ ] which comparisons are allowed
- [ ] how long/complex can the condition be