Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for subscripted general expressions (#11448)
- Add subscripted general expressions to the parser. - Add parentheses to the output for subscripted expressions in `NFExpression.toString`, and fix the placement of the parentheses in `NFExpression.toFlatString`.
- Loading branch information
Showing
9 changed files
with
175 additions
and
19 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
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
15 changes: 15 additions & 0 deletions
15
testsuite/flattening/modelica/scodeinst/SubscriptedExp1.mo
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,15 @@ | ||
// name: SubscriptedExp1 | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
model SubscriptedExp1 | ||
Real y = ({1, 2, 3})[2]; | ||
end SubscriptedExp1; | ||
|
||
// Result: | ||
// class SubscriptedExp1 | ||
// Real y = 2.0; | ||
// end SubscriptedExp1; | ||
// endResult |
22 changes: 22 additions & 0 deletions
22
testsuite/flattening/modelica/scodeinst/SubscriptedExp2.mo
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,22 @@ | ||
// name: SubscriptedExp2 | ||
// status: incorrect | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
model SubscriptedExp2 | ||
Real y = (1, 2, 3)[2]; | ||
end SubscriptedExp2; | ||
|
||
// Result: | ||
// Error processing file: SubscriptedExp2.mo | ||
// Failed to parse file: SubscriptedExp2.mo! | ||
// | ||
// [flattening/modelica/scodeinst/SubscriptedExp2.mo:8:12-8:23:writable] Error: Tuple expression can not be subscripted. | ||
// | ||
// # Error encountered! Exiting... | ||
// # Please check the error message and the flags. | ||
// Failed to parse file: SubscriptedExp2.mo! | ||
// | ||
// Execution failed! | ||
// endResult |
19 changes: 19 additions & 0 deletions
19
testsuite/flattening/modelica/scodeinst/SubscriptedExp3.mo
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,19 @@ | ||
// name: SubscriptedExp3 | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
model SubscriptedExp3 | ||
Real y; | ||
equation | ||
({1, 2, 3})[3] = y; | ||
end SubscriptedExp3; | ||
|
||
// Result: | ||
// class SubscriptedExp3 | ||
// Real y; | ||
// equation | ||
// 3.0 = y; | ||
// end SubscriptedExp3; | ||
// endResult |
25 changes: 25 additions & 0 deletions
25
testsuite/flattening/modelica/scodeinst/SubscriptedExp4.mo
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,25 @@ | ||
// name: SubscriptedExp4 | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
model SubscriptedExp4 | ||
Real x[:] = {1, 2, 3}; | ||
Integer n; | ||
Real y = ({1, 2 ,3})[n]; | ||
Real z = (x)[n]; | ||
end SubscriptedExp4; | ||
|
||
// Result: | ||
// class SubscriptedExp4 | ||
// Real x[1]; | ||
// Real x[2]; | ||
// Real x[3]; | ||
// Integer n; | ||
// Real y = {1.0, 2.0, 3.0}[n]; | ||
// Real z = x[n]; | ||
// equation | ||
// x = {1.0, 2.0, 3.0}; | ||
// end SubscriptedExp4; | ||
// endResult |
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