From 7b001b072f08af7a65db72051b4b1df6baca1a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=96stlund?= Date: Tue, 16 Jul 2019 11:06:18 +0200 Subject: [PATCH] Handle fully qualified reduction expressions. --- OMCompiler/Compiler/FrontEnd/Static.mo | 10 ++++++---- testsuite/flattening/modelica/operators/Reductions.mo | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/OMCompiler/Compiler/FrontEnd/Static.mo b/OMCompiler/Compiler/FrontEnd/Static.mo index cdd416ba341..dacec230da5 100644 --- a/OMCompiler/Compiler/FrontEnd/Static.mo +++ b/OMCompiler/Compiler/FrontEnd/Static.mo @@ -1713,7 +1713,7 @@ protected function makeReductionFoldExp protected String func_name; algorithm - (outEnv, afoldExp) := match path + (outEnv, afoldExp) := match AbsynUtil.makeNotFullyQualified(path) local Absyn.Exp exp; Absyn.ComponentRef cr, cr1, cr2; @@ -1761,7 +1761,7 @@ end makeReductionFoldExp; protected function reductionType input FCore.Cache inCache; input FCore.Graph inEnv; - input Absyn.Path fn; + input Absyn.Path inFn; input DAE.Exp inExp; input DAE.Type inType; input DAE.Type unboxedType; @@ -1774,6 +1774,8 @@ protected function reductionType output DAE.Type resultType; output Option defaultValue; output Absyn.Path outPath; +protected + Absyn.Path fn = AbsynUtil.makeNotFullyQualified(inFn); algorithm (outExp, outType, resultType, defaultValue, outPath) := match(fn, unboxedType) local @@ -1951,8 +1953,8 @@ algorithm else algorithm - (outCache, fnTypes) := Lookup.lookupFunctionsInEnv(inCache, inEnv, fn, info); - (typeA,typeB,resType,defaultBinding,path) := checkReductionType1(inEnv, fn,fnTypes,info); + (outCache, fnTypes) := Lookup.lookupFunctionsInEnv(inCache, inEnv, inFn, info); + (typeA,typeB,resType,defaultBinding,path) := checkReductionType1(inEnv,inFn,fnTypes,info); ty2 := if isSome(defaultBinding) then typeB else inType; (exp,typeA,bindings) := Types.matchTypePolymorphicWithError(inExp, inType,typeA,SOME(path),{},info); (_,typeB,bindings) := Types.matchTypePolymorphicWithError(DAE.CREF(DAE.CREF_IDENT("$result",DAE.T_ANYTYPE_DEFAULT,{}),DAE.T_ANYTYPE_DEFAULT),ty2,typeB,SOME(path),bindings,info); diff --git a/testsuite/flattening/modelica/operators/Reductions.mo b/testsuite/flattening/modelica/operators/Reductions.mo index fdf3b8dd1ec..b0f4978a64c 100644 --- a/testsuite/flattening/modelica/operators/Reductions.mo +++ b/testsuite/flattening/modelica/operators/Reductions.mo @@ -15,6 +15,7 @@ model Reductions Real f; Real g[n,n]; Real h; + Real k; equation c = sum(A[i]^2 + B[i]^2 for i in 1:n); d = product(A[i]^2 + B[i]^2 for i in 1:n); @@ -22,6 +23,7 @@ equation f = min(A[i]^2 + B[i]^2 for i in 1:n); g = {(1/(i+j-1)) for i in 1:n, j in 1:n}; h = sum((1/(i+j-1)) for i in 1:n, j in 1:n); + k = .sum(i for i in 1:n); end Reductions; // Result: @@ -67,6 +69,7 @@ end Reductions; // Real g[5,4]; // Real g[5,5]; // Real h; +// Real k; // equation // c = A[1] ^ 2.0 + B[1] ^ 2.0 + A[2] ^ 2.0 + B[2] ^ 2.0 + A[3] ^ 2.0 + B[3] ^ 2.0 + A[4] ^ 2.0 + B[4] ^ 2.0 + A[5] ^ 2.0 + B[5] ^ 2.0; // d = (A[1] ^ 2.0 + B[1] ^ 2.0) * (A[2] ^ 2.0 + B[2] ^ 2.0) * (A[3] ^ 2.0 + B[3] ^ 2.0) * (A[4] ^ 2.0 + B[4] ^ 2.0) * (A[5] ^ 2.0 + B[5] ^ 2.0); @@ -97,6 +100,7 @@ end Reductions; // g[5,3] = 0.1428571428571428; // g[5,4] = 0.125; // g[5,5] = 0.1111111111111111; -// h = 6.456349206349207; +// h = 6.456349206349206; +// k = 15.0; // end Reductions; // endResult