Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit a581f29

Browse files
perostOpenModelica-Hudson
authored andcommitted
Improve parsing of function partial applications.
- Change the parser to only accept named arguments for function partial applications, as defined by the grammar in the Modelica specification. Belonging to [master]: - #2791 - OpenModelica/OpenModelica-testsuite#1077
1 parent 74a1cd4 commit a581f29

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

Compiler/BackEnd/HpcOmMemory.mo

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,10 @@ import Util;
359359
//Get not optimized variables (e.g. paramters that are not part of the task graph)
360360
//--------------------------------------------------------------------------------
361361
notOptimizedVars = getNotOptimizedVarsByCacheLineMapping(scVarCLMapping, allVarsMapping, simCodeVarTypes);
362-
notOptimizedVarsFloatOpt = List.map(Util.tuple41(notOptimizedVars), function arrayGet(allVarsMapping));
363-
notOptimizedVarsIntOpt = List.map(Util.tuple42(notOptimizedVars), function arrayGet(allVarsMapping));
364-
notOptimizedVarsBoolOpt = List.map(Util.tuple43(notOptimizedVars), function arrayGet(allVarsMapping));
365-
notOptimizedVarsStringOpt = List.map(Util.tuple44(notOptimizedVars), function arrayGet(allVarsMapping));
362+
notOptimizedVarsFloatOpt = List.map(Util.tuple41(notOptimizedVars), function arrayGet(arr = allVarsMapping));
363+
notOptimizedVarsIntOpt = List.map(Util.tuple42(notOptimizedVars), function arrayGet(arr = allVarsMapping));
364+
notOptimizedVarsBoolOpt = List.map(Util.tuple43(notOptimizedVars), function arrayGet(arr = allVarsMapping));
365+
notOptimizedVarsStringOpt = List.map(Util.tuple44(notOptimizedVars), function arrayGet(arr = allVarsMapping));
366366

367367
notOptimizedVarsFloat = List.map(notOptimizedVarsFloatOpt, Util.getOption);
368368
notOptimizedVarsInt = List.map(notOptimizedVarsIntOpt, Util.getOption);

Compiler/NFFrontEnd/NFInst.mo

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,6 +2154,9 @@ algorithm
21542154
case Absyn.Exp.CALL()
21552155
then Call.instantiate(absynExp.function_, absynExp.functionArgs, scope, info);
21562156

2157+
case Absyn.Exp.PARTEVALFUNCTION()
2158+
then instPartEvalFunction(absynExp.function_, absynExp.functionArgs, scope, info);
2159+
21572160
case Absyn.Exp.END() then Expression.END();
21582161

21592162
else
@@ -2343,6 +2346,32 @@ algorithm
23432346
end match;
23442347
end instSubscript;
23452348

2349+
function instPartEvalFunction
2350+
input Absyn.ComponentRef func;
2351+
input Absyn.FunctionArgs args;
2352+
input InstNode scope;
2353+
input SourceInfo info;
2354+
output Expression outExp;
2355+
algorithm
2356+
outExp := match args
2357+
case Absyn.FUNCTIONARGS(args = {}, argNames = {})
2358+
then instCref(func, scope, info);
2359+
2360+
case Absyn.FUNCTIONARGS()
2361+
algorithm
2362+
2363+
then
2364+
fail();
2365+
2366+
case Absyn.FOR_ITER_FARG()
2367+
algorithm
2368+
print("Invalid argument to function partial application\n");
2369+
then
2370+
fail();
2371+
2372+
end match;
2373+
end instPartEvalFunction;
2374+
23462375
function instSections
23472376
input InstNode node;
23482377
input InstNode scope;

Parser/Modelica.g

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,8 +1129,11 @@ expression[int allowPartEvalFunc] returns [void* ast] :
11291129
;
11301130

11311131
part_eval_function_expression returns [void* ast]
1132-
@init { cr.ast = 0; fc = 0; } :
1133-
FUNCTION cr=component_reference fc=function_call { ast = Absyn__PARTEVALFUNCTION(cr.ast, fc); }
1132+
@init { cr.ast = 0; args = 0; } :
1133+
FUNCTION cr=component_reference LPAR (args=named_arguments)? RPAR
1134+
{
1135+
ast = Absyn__PARTEVALFUNCTION(cr.ast, Absyn__FUNCTIONARGS(mmc_mk_nil(), or_nil(args)));
1136+
}
11341137
;
11351138

11361139
if_expression returns [void* ast]

0 commit comments

Comments
 (0)