Skip to content

Commit

Permalink
Some minor cleanup and renaming.
Browse files Browse the repository at this point in the history
  • Loading branch information
mahge committed Sep 25, 2022
1 parent 5901d9d commit 7c7fc89
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions OMCompiler/Compiler/SimCode/SimCodeFunctionUtil.mo
Expand Up @@ -474,36 +474,31 @@ public function elaborateFunctions
input list<DAE.Exp> literals;
input list<String> includes;
output list<SimCodeFunction.Function> functions;
output list<SimCodeFunction.RecordDeclaration> extraRecordDecls = {};
output list<SimCodeFunction.RecordDeclaration> recordDecls;
output list<String> outIncludes;
output list<String> includeDirs;
output list<String> libs;
output list<String> libpaths;
protected
list<SimCodeFunction.Function> fns;
list<String> recordNames;
HashTableStringToPath.HashTable ht;
list<tuple<SimCodeFunction.RecordDeclaration,list<SimCodeFunction.RecordDeclaration>>> g;
UnorderedMap<String, SimCodeFunction.RecordDeclaration> declMap;

algorithm
declMap := UnorderedMap.new<SimCodeFunction.RecordDeclaration>(stringHashDjb2Mod, stringEq);
(functions, outIncludes, includeDirs, libs, libpaths) := elaborateFunctions2(program, daeElements, {}, includes, {}, {}, {}, declMap);

collectRecDeclsFromMetaRecCallExps(literals, declMap);
(functions, outIncludes, includeDirs, libs,libpaths) := elaborateFunctions2(program, daeElements, {}, includes, {}, {}, {}, declMap);

collectRecDeclsFromTypes(metarecordTypes, declMap);

extraRecordDecls := UnorderedMap.valueList(declMap);

extraRecordDecls := List.sort(extraRecordDecls, orderRecordDecls);
recordNames := UnorderedMap.keyList(declMap);
recordDecls := UnorderedMap.valueList(declMap);
recordDecls := List.sort(recordDecls, orderRecordDecls);

ht := HashTableStringToPath.emptyHashTableSized(BaseHashTable.lowBucketSize);
(extraRecordDecls,_) := List.mapFold(extraRecordDecls, aliasRecordDeclarations, ht);
(recordDecls,_) := List.mapFold(recordDecls, aliasRecordDeclarations, ht);
// Topological sort since we have no guarantees in the order of generated records
g := Graph.buildGraph(extraRecordDecls, getRecordDependencies, extraRecordDecls);
(extraRecordDecls, {}) := Graph.topologicalSort(g, isRecordDeclEqual);
g := Graph.buildGraph(recordDecls, getRecordDependencies, recordDecls);
(recordDecls, {}) := Graph.topologicalSort(g, isRecordDeclEqual);
end elaborateFunctions;

protected function getRecordDependencies
Expand All @@ -518,9 +513,9 @@ algorithm
list<DAE.Type> tys;
list<list<DAE.Type>> tyss;
case (SimCodeFunction.RECORD_DECL_FULL(aliasName=SOME(name)),_)
then List.select1(allDecls, isRecordDecl, name);
then List.select1(allDecls, recordDeclHasName, name);
case (SimCodeFunction.RECORD_DECL_ADD_CONSTRCTOR(name=name),_)
then List.select1(allDecls, isRecordDecl, name);
then List.select1(allDecls, recordDeclHasName, name);
case (SimCodeFunction.RECORD_DECL_FULL(variables=vars),_)
equation
tys = list(getVarType(v) for v in vars);
Expand Down Expand Up @@ -552,33 +547,28 @@ protected
algorithm
DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(path)) := ty;
name := AbsynUtil.pathStringUnquoteReplaceDot(path, "_");
decl := List.find1(allDecls, isRecordDecl, name);
decl := List.find1(allDecls, recordDeclHasName, name);
end getRecordDependenciesFromType;

protected function isRecordDecl
protected function recordDeclHasName
input SimCodeFunction.RecordDeclaration decl;
input String name;
output Boolean b;
algorithm
b := match (decl,name)
local
String name1;
case (SimCodeFunction.RECORD_DECL_FULL(name=name1),_) then stringEq(name,name1);
b := match decl
case SimCodeFunction.RECORD_DECL_FULL() then stringEq(name, decl.name);
else false;
end match;
end isRecordDecl;
end recordDeclHasName;

protected function isRecordDeclEqual
input SimCodeFunction.RecordDeclaration decl1;
input SimCodeFunction.RecordDeclaration decl2;
output Boolean b;
algorithm
b := match (decl1,decl2)
local
String name1,name2;
Absyn.Path path1,path2;
case (SimCodeFunction.RECORD_DECL_FULL(name=name1),SimCodeFunction.RECORD_DECL_FULL(name=name2)) then stringEq(name1,name2);
case (SimCodeFunction.RECORD_DECL_DEF(path=path1),SimCodeFunction.RECORD_DECL_DEF(path=path2)) then AbsynUtil.pathEqual(path1,path2);
case (SimCodeFunction.RECORD_DECL_FULL(),SimCodeFunction.RECORD_DECL_FULL()) then stringEq(decl1.name, decl2.name);
case (SimCodeFunction.RECORD_DECL_DEF(),SimCodeFunction.RECORD_DECL_DEF()) then AbsynUtil.pathEqual(decl1.path, decl2.path);
else false;
end match;
end isRecordDeclEqual;
Expand Down Expand Up @@ -1761,8 +1751,6 @@ end collectRecDeclsFromTypesVars;
protected function collectRecDeclsFromMetaRecCallExps
input list<DAE.Exp> inExpl;
input UnorderedMap<String, SimCodeFunction.RecordDeclaration> declMap;
protected
String name;
algorithm
for exp in inExpl loop
collectRecDeclsFromMetaRecCallExp(exp, declMap);
Expand Down

0 comments on commit 7c7fc89

Please sign in to comment.