Skip to content

Commit

Permalink
Fix for bug #1044:
Browse files Browse the repository at this point in the history
- Added Util.listUnionComp, list union with a compare function.
- Made SCode.equationEqual public.
- Use list union in Inst.instClassdef2 to filter out identical equations.
- Added test case mofiles/IdenticalEquations.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6245 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Sep 28, 2010
1 parent 6bf2ada commit 2777dd5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
7 changes: 5 additions & 2 deletions Compiler/Inst.mo
Expand Up @@ -3232,8 +3232,11 @@ algorithm
// Add components from base classes to be instantiated in 3 as well.
compelts_1 = Util.listFlatten({extcomps,compelts_1,cdefelts_1});

eqs_1 = listAppend(eqs, eqs2);
initeqs_1 = listAppend(initeqs, initeqs2);
// Take the union of the equations in the current scope and equations
// from extends, to filter out identical equations.
eqs_1 = Util.listUnionComp(eqs, eqs2, SCode.equationEqual);
initeqs_1 = Util.listUnionComp(initeqs, initeqs2, SCode.equationEqual);

alg_1 = listAppend(alg, alg2);
initalg_1 = listAppend(initalg, initalg2);

Expand Down
2 changes: 1 addition & 1 deletion Compiler/InstSection.mo
Expand Up @@ -34,7 +34,7 @@ package InstSection
package: InstSection
description: Model instantiation

RCS: $Id: Inst.mo 6158 2010-09-21 10:13:14Z sjoelund.se $
RCS: $Id: InstSection.mo 6158 2010-09-21 10:13:14Z sjoelund.se $

This module is responsible for instantiation of Modelica equation
and algorithm sections (including connect equations)."
Expand Down
2 changes: 1 addition & 1 deletion Compiler/SCode.mo
Expand Up @@ -1871,7 +1871,7 @@ algorithm
end matchcontinue;
end algorithmEqual2;

protected function equationEqual
public function equationEqual
"function equationEqual
Returns true if two equations are equal."
input Equation eqn1;
Expand Down
53 changes: 53 additions & 0 deletions Compiler/Util.mo
Expand Up @@ -3405,6 +3405,29 @@ algorithm
end matchcontinue;
end listUnionElt;

public function listUnionEltComp
"Works as listUnionElt, but with a compare function."
input Type_a inElem;
input list<Type_a> inList;
input CompareFunc inCompFunc;
output list<Type_a> outList;
partial function CompareFunc
input Type_a inElem1;
input Type_a inElem2;
output Boolean res;
end CompareFunc;
replaceable type Type_a subtypeof Any;
algorithm
outList := matchcontinue(inElem, inList, inCompFunc)
case (_, _, _)
equation
true = listContainsWithCompareFunc(inElem, inList, inCompFunc);
then
inList;
case (_, _, _) then inElem :: inList;
end matchcontinue;
end listUnionEltComp;

public function listUnion "function listUnion
Takes two lists and returns the union of the two lists,
i.e. a list of all elements combined without duplicates.
Expand All @@ -3430,6 +3453,36 @@ algorithm
end matchcontinue;
end listUnion;

public function listUnionComp
"Works as listUnion, but with a compare function."
input list<Type_a> inList1;
input list<Type_a> inList2;
input CompareFunc inCompFunc;
output list<Type_a> outList;
partial function CompareFunc
input Type_a inElem1;
input Type_a inElem2;
output Boolean res;
end CompareFunc;
replaceable type Type_a subtypeof Any;
algorithm
outList := matchcontinue(inList1, inList2, inCompFunc)
local
list<Type_a> res, xs;
Type_a x;
case ({}, {}, _)
then {};
case ({}, x :: xs, _)
then listUnionEltComp(x, listUnionComp({}, xs, inCompFunc), inCompFunc);
case ((x :: xs), _, _)
equation
res = listUnionComp(xs, inList2, inCompFunc);
res = listUnionEltComp(x, res, inCompFunc);
then
res;
end matchcontinue;
end listUnionComp;

public function listListUnion "function: listListUnion
Takes a list of lists and returns the union of the sublists
Example: listListUnion({{1},{1,2},{3,4},{5}}) => {1,2,3,4,5}"
Expand Down

0 comments on commit 2777dd5

Please sign in to comment.