Skip to content

Commit

Permalink
[NF] Collect functions in array dimensions.
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - OpenModelica/OMCompiler#2960
  • Loading branch information
perost authored and OpenModelica-Hudson committed Mar 4, 2019
1 parent f0376d4 commit b55fb1b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
33 changes: 33 additions & 0 deletions Compiler/NFFrontEnd/NFDimension.mo
Expand Up @@ -362,5 +362,38 @@ public
end match;
end mapExp;

function foldExp<ArgT>
input Dimension dim;
input FoldFunc func;
input ArgT arg;
output ArgT outArg;

partial function FoldFunc
input Expression dim;
input output ArgT arg;
end FoldFunc;
algorithm
outArg := match dim
case UNTYPED() then Expression.fold(dim.dimension, func, arg);
case EXP() then Expression.fold(dim.exp, func, arg);
else arg;
end match;
end foldExp;

function foldExpList<ArgT>
input list<Dimension> dims;
input FoldFunc func;
input output ArgT arg;

partial function FoldFunc
input Expression dim;
input output ArgT arg;
end FoldFunc;
algorithm
for dim in dims loop
arg := foldExp(dim, func, arg);
end for;
end foldExpList;

annotation(__OpenModelica_Interface="frontend");
end NFDimension;
10 changes: 9 additions & 1 deletion Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -1285,12 +1285,20 @@ end collectBindingFuncs;
function collectTypeFuncs
input Type ty;
input output FunctionTree funcs;
protected
algorithm
() := match Type.arrayElementType(ty)
() := match ty
local
InstNode con, de;
Function fn;

case Type.ARRAY()
algorithm
funcs := Dimension.foldExpList(ty.dimensions, collectExpFuncs_traverse, funcs);
funcs := collectTypeFuncs(ty.elementType, funcs);
then
();

case Type.FUNCTION(fn = fn)
algorithm
funcs := flattenFunction(fn, funcs);
Expand Down

0 comments on commit b55fb1b

Please sign in to comment.