Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve typing of function calls (#7387)
- Type default arguments for each call with the input arguments taken into account, instead of typing them only once for the function. - Improve the insertion of input arguments into the default arguments such that it handles subscripts and complex component references. - Fixes #7384 and #7385.
- Loading branch information
Showing
8 changed files
with
175 additions
and
33 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
26 changes: 26 additions & 0 deletions
26
testsuite/flattening/modelica/scodeinst/FuncDefaultArg3.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,26 @@ | ||
// name: FuncDefaultArg3 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
function f | ||
input Real x[:]; | ||
input Real y = x[1]; | ||
output Real z[size(x, 1)] = y * x; | ||
end f; | ||
|
||
model FuncDefaultArg3 | ||
Real x[:] = f({2, 3, 4}); | ||
end FuncDefaultArg3; | ||
|
||
// Result: | ||
// class FuncDefaultArg3 | ||
// Real x[1]; | ||
// Real x[2]; | ||
// Real x[3]; | ||
// equation | ||
// x = {4.0, 6.0, 8.0}; | ||
// end FuncDefaultArg3; | ||
// endResult |
26 changes: 26 additions & 0 deletions
26
testsuite/flattening/modelica/scodeinst/FuncDefaultArg4.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,26 @@ | ||
// name: FuncDefaultArg4 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
record R | ||
Real x; | ||
end R; | ||
|
||
function f | ||
input R r; | ||
input Real x = r.x; | ||
output Real y = r.x * x; | ||
end f; | ||
|
||
model FuncDefaultArg4 | ||
Real x = f(R(2)); | ||
end FuncDefaultArg4; | ||
|
||
// Result: | ||
// class FuncDefaultArg4 | ||
// Real x = 4.0; | ||
// end FuncDefaultArg4; | ||
// endResult |
27 changes: 27 additions & 0 deletions
27
testsuite/flattening/modelica/scodeinst/FuncDefaultArg5.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,27 @@ | ||
// name: FuncDefaultArg5 | ||
// keywords: | ||
// status: correct | ||
// cflags: -d=newInst | ||
// | ||
// | ||
|
||
function f | ||
input Integer dim; | ||
input Real x = f2(dim); | ||
output Integer n = dim; | ||
end f; | ||
|
||
function f2 | ||
input Integer dim; | ||
output Integer n = dim; | ||
end f2; | ||
|
||
model FuncDefaultArg5 | ||
parameter Real x = f(3); | ||
end FuncDefaultArg5; | ||
|
||
// Result: | ||
// class FuncDefaultArg5 | ||
// parameter Real x = 3.0; | ||
// end FuncDefaultArg5; | ||
// 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