-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PCompiler] Correct foreach -> while transformation (#684)
* [PCompiler] Correct foreach -> while transformation to account for continue in loop body * [Tst] Adds more regression tests for foreach with break/continue * [Tst] Minor commments * [Tst] Exclude unsupported tests from PSym regression suite
- Loading branch information
Showing
9 changed files
with
226 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
Tst/RegressionTests/Feature2Stmts/Correct/foreach2/foreach2.p
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/******************** | ||
* This example explains the usage of foreach iterator with continue | ||
* ******************/ | ||
|
||
|
||
machine Main { | ||
var ss: set[int]; | ||
|
||
start state Init { | ||
entry { | ||
var iter: int; | ||
var sum: int; | ||
ss += (100); | ||
ss += (134); | ||
ss += (245); | ||
|
||
foreach(iter in ss) | ||
{ | ||
print format ("Iter = {0}, Sum = {1}", iter, sum); | ||
assert sum <= 345, "Incorrect sum inside loop"; | ||
if (iter == 134) { | ||
continue; | ||
} | ||
sum = sum + iter; | ||
} | ||
|
||
print format ("Final Sum = {0}", sum); | ||
assert sum == 345, "Incorrect sum outside loop"; | ||
} | ||
} | ||
} | ||
|
33 changes: 33 additions & 0 deletions
33
Tst/RegressionTests/Feature2Stmts/Correct/foreach3/foreach3.p
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/******************** | ||
* This example explains the usage of foreach iterator with break | ||
* ******************/ | ||
|
||
|
||
machine Main { | ||
var ss: set[int]; | ||
|
||
start state Init { | ||
entry { | ||
var iter: int; | ||
var sum: int; | ||
ss += (100); | ||
ss += (123); | ||
ss += (134); | ||
ss += (245); | ||
|
||
foreach(iter in ss) | ||
{ | ||
print format ("Iter = {0}, Sum = {1}", iter, sum); | ||
assert sum <= 100, "Incorrect sum inside loop"; | ||
sum = sum + iter; | ||
if (iter == 123) { | ||
break; | ||
} | ||
} | ||
|
||
print format ("Final Sum = {0}", sum); | ||
assert sum == 223, "Incorrect sum outside loop"; | ||
} | ||
} | ||
} | ||
|
36 changes: 36 additions & 0 deletions
36
Tst/RegressionTests/Feature2Stmts/Correct/foreach4/foreach4.p
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/******************** | ||
* This example explains the usage of foreach iterator with break and continue | ||
* ******************/ | ||
|
||
|
||
machine Main { | ||
var ss: set[int]; | ||
|
||
start state Init { | ||
entry { | ||
var iter: int; | ||
var sum: int; | ||
ss += (100); | ||
ss += (134); | ||
ss += (123); | ||
ss += (245); | ||
|
||
foreach(iter in ss) | ||
{ | ||
print format ("Iter = {0}, Sum = {1}", iter, sum); | ||
assert sum <= 100, "Incorrect sum inside loop"; | ||
if (iter == 134) { | ||
continue; | ||
} | ||
sum = sum + iter; | ||
if (iter == 123) { | ||
break; | ||
} | ||
} | ||
|
||
print format ("Final Sum = {0}", sum); | ||
assert sum == 223, "Incorrect sum outside loop"; | ||
} | ||
} | ||
} | ||
|
32 changes: 32 additions & 0 deletions
32
Tst/RegressionTests/Feature2Stmts/DynamicError/foreach2/foreach2.p
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/******************** | ||
* This example explains the usage of foreach iterator with continue | ||
* ******************/ | ||
|
||
|
||
machine Main { | ||
var ss: set[int]; | ||
|
||
start state Init { | ||
entry { | ||
var iter: int; | ||
var sum: int; | ||
ss += (100); | ||
ss += (134); | ||
ss += (245); | ||
|
||
foreach(iter in ss) | ||
{ | ||
print format ("Iter = {0}, Sum = {1}", iter, sum); | ||
assert sum <= 345, "Incorrect sum inside loop"; | ||
if (iter == 134) { | ||
continue; | ||
} | ||
sum = sum + iter; | ||
} | ||
|
||
print format ("Final Sum = {0}", sum); | ||
assert sum != 345, "Should get triggered"; | ||
} | ||
} | ||
} | ||
|
33 changes: 33 additions & 0 deletions
33
Tst/RegressionTests/Feature2Stmts/DynamicError/foreach3/foreach3.p
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/******************** | ||
* This example explains the usage of foreach iterator with break | ||
* ******************/ | ||
|
||
|
||
machine Main { | ||
var ss: set[int]; | ||
|
||
start state Init { | ||
entry { | ||
var iter: int; | ||
var sum: int; | ||
ss += (100); | ||
ss += (123); | ||
ss += (134); | ||
ss += (245); | ||
|
||
foreach(iter in ss) | ||
{ | ||
print format ("Iter = {0}, Sum = {1}", iter, sum); | ||
assert sum <= 100, "Incorrect sum inside loop"; | ||
sum = sum + iter; | ||
if (iter == 123) { | ||
break; | ||
} | ||
} | ||
|
||
print format ("Final Sum = {0}", sum); | ||
assert sum != 223, "Should get triggered"; | ||
} | ||
} | ||
} | ||
|
36 changes: 36 additions & 0 deletions
36
Tst/RegressionTests/Feature2Stmts/DynamicError/foreach4/foreach4.p
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/******************** | ||
* This example explains the usage of foreach iterator with break and continue | ||
* ******************/ | ||
|
||
|
||
machine Main { | ||
var ss: set[int]; | ||
|
||
start state Init { | ||
entry { | ||
var iter: int; | ||
var sum: int; | ||
ss += (100); | ||
ss += (134); | ||
ss += (123); | ||
ss += (245); | ||
|
||
foreach(iter in ss) | ||
{ | ||
print format ("Iter = {0}, Sum = {1}", iter, sum); | ||
assert sum <= 100, "Incorrect sum inside loop"; | ||
if (iter == 134) { | ||
continue; | ||
} | ||
sum = sum + iter; | ||
if (iter == 123) { | ||
break; | ||
} | ||
} | ||
|
||
print format ("Final Sum = {0}", sum); | ||
assert sum != 223, "Should get triggered"; | ||
} | ||
} | ||
} | ||
|