diff --git a/OMCompiler/Compiler/SimCode/SimCodeFunctionUtil.mo b/OMCompiler/Compiler/SimCode/SimCodeFunctionUtil.mo index 64132ef162c..d79a0b19c2e 100644 --- a/OMCompiler/Compiler/SimCode/SimCodeFunctionUtil.mo +++ b/OMCompiler/Compiler/SimCode/SimCodeFunctionUtil.mo @@ -474,14 +474,14 @@ public function elaborateFunctions input list literals; input list includes; output list functions; - output list extraRecordDecls; + output list extraRecordDecls = {}; output list outIncludes; output list includeDirs; output list libs; output list libpaths; protected list fns; - list outRecordTypes, recordNames; + list outRecordTypes = {}, recordNames; HashTableStringToPath.HashTable ht; list>> g; UnorderedMap declMap; @@ -489,7 +489,7 @@ protected algorithm declMap := UnorderedMap.new(stringHashDjb2Mod, stringEq); - (extraRecordDecls, outRecordTypes) := elaborateRecordDeclarationsForMetarecords(literals, {}, {}, declMap); + elaborateRecordDeclarationsForMetarecords(literals, declMap); (functions, outRecordTypes, extraRecordDecls, outIncludes, includeDirs, libs,libpaths) := elaborateFunctions2(program, daeElements, {}, outRecordTypes, extraRecordDecls, includes, {}, {},{}, declMap); extraRecordDecls := List.unique(extraRecordDecls); elaborateRecordDeclarationsFromTypes(metarecordTypes, declMap); @@ -1462,9 +1462,9 @@ algorithm elaborateRecordDeclarationsForRecord(ft, declMap); if Util.isSome(binding) and Config.acceptMetaModelicaGrammar() then (_, expl) = Expression.traverseExpBottomUp(Util.getOption(binding), matchMetarecordCalls, {}); - (accRecDecls, rt_1) = elaborateRecordDeclarationsForMetarecords(expl, accRecDecls, rt, declMap); + elaborateRecordDeclarationsForMetarecords(expl, declMap); end if; - (accRecDecls, rt_2) = elaborateRecordDeclarations(rest, accRecDecls, rt_1, declMap); + (accRecDecls, rt_2) = elaborateRecordDeclarations(rest, accRecDecls, rt, declMap); then (accRecDecls, rt_2); @@ -1472,9 +1472,9 @@ algorithm equation true = Config.acceptMetaModelicaGrammar(); ((_, expl)) = DAEUtil.traverseAlgorithmExps(algorithm_, Expression.traverseSubexpressionsHelper, (matchMetarecordCalls, {})); - (accRecDecls, rt_2) = elaborateRecordDeclarationsForMetarecords(expl, accRecDecls, rt, declMap); + elaborateRecordDeclarationsForMetarecords(expl, declMap); // TODO: ? what about rest ? , can be there something else after the ALGORITHM - (accRecDecls, rt_2) = elaborateRecordDeclarations(rest, accRecDecls, rt_2, declMap); + (accRecDecls, rt_2) = elaborateRecordDeclarations(rest, accRecDecls, rt, declMap); then (accRecDecls, rt_2); @@ -1839,35 +1839,26 @@ end elaborateNestedRecordDeclarations; protected function elaborateRecordDeclarationsForMetarecords input list inExpl; - input list inAccRecordDecls; - input list inReturnTypes; input UnorderedMap declMap; - output list outRecordDecls; - output list outReturnTypes; algorithm - (outRecordDecls, outReturnTypes) := match (inExpl, inAccRecordDecls, inReturnTypes) + () := match (inExpl) local - list rt, rt_1, rt_2, fieldNames; + list fieldNames; list rest; String name; Absyn.Path path; - list accRecDecls; - Boolean b; - case ({}, accRecDecls, rt) then (accRecDecls, rt); - case (DAE.METARECORDCALL(path=path, fieldNames=fieldNames)::rest, accRecDecls, rt) + case {} then (); + case DAE.METARECORDCALL(path=path, fieldNames=fieldNames)::rest equation name = AbsynUtil.pathStringUnquoteReplaceDot(path, "_"); - b = listMember(name, rt); - accRecDecls = List.consOnTrue(not b, SimCodeFunction.RECORD_DECL_DEF(path, fieldNames), accRecDecls); - rt_1 = List.consOnTrue(not b, name, rt); - UnorderedMap.add(name, SimCodeFunction.RECORD_DECL_DEF(path, fieldNames), declMap); - (accRecDecls, rt_2) = elaborateRecordDeclarationsForMetarecords(rest, accRecDecls, rt_1, declMap); - then (accRecDecls, rt_2); - case (_::rest, accRecDecls, rt) + UnorderedMap.tryAdd(name, SimCodeFunction.RECORD_DECL_DEF(path, fieldNames), declMap); + elaborateRecordDeclarationsForMetarecords(rest, declMap); + then (); + case _::rest equation - (accRecDecls, rt_1) = elaborateRecordDeclarationsForMetarecords(rest, accRecDecls, rt, declMap); - then (accRecDecls, rt_1); + elaborateRecordDeclarationsForMetarecords(rest, declMap); + then (); end match; end elaborateRecordDeclarationsForMetarecords;