Skip to content

Commit 2777dd5

Browse files
committed
Fix for bug #1044:
- 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
1 parent 6bf2ada commit 2777dd5

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

Compiler/Inst.mo

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,8 +3232,11 @@ algorithm
32323232
// Add components from base classes to be instantiated in 3 as well.
32333233
compelts_1 = Util.listFlatten({extcomps,compelts_1,cdefelts_1});
32343234

3235-
eqs_1 = listAppend(eqs, eqs2);
3236-
initeqs_1 = listAppend(initeqs, initeqs2);
3235+
// Take the union of the equations in the current scope and equations
3236+
// from extends, to filter out identical equations.
3237+
eqs_1 = Util.listUnionComp(eqs, eqs2, SCode.equationEqual);
3238+
initeqs_1 = Util.listUnionComp(initeqs, initeqs2, SCode.equationEqual);
3239+
32373240
alg_1 = listAppend(alg, alg2);
32383241
initalg_1 = listAppend(initalg, initalg2);
32393242

Compiler/InstSection.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ package InstSection
3434
package: InstSection
3535
description: Model instantiation
3636

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

3939
This module is responsible for instantiation of Modelica equation
4040
and algorithm sections (including connect equations)."

Compiler/SCode.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,7 @@ algorithm
18711871
end matchcontinue;
18721872
end algorithmEqual2;
18731873

1874-
protected function equationEqual
1874+
public function equationEqual
18751875
"function equationEqual
18761876
Returns true if two equations are equal."
18771877
input Equation eqn1;

Compiler/Util.mo

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,6 +3405,29 @@ algorithm
34053405
end matchcontinue;
34063406
end listUnionElt;
34073407

3408+
public function listUnionEltComp
3409+
"Works as listUnionElt, but with a compare function."
3410+
input Type_a inElem;
3411+
input list<Type_a> inList;
3412+
input CompareFunc inCompFunc;
3413+
output list<Type_a> outList;
3414+
partial function CompareFunc
3415+
input Type_a inElem1;
3416+
input Type_a inElem2;
3417+
output Boolean res;
3418+
end CompareFunc;
3419+
replaceable type Type_a subtypeof Any;
3420+
algorithm
3421+
outList := matchcontinue(inElem, inList, inCompFunc)
3422+
case (_, _, _)
3423+
equation
3424+
true = listContainsWithCompareFunc(inElem, inList, inCompFunc);
3425+
then
3426+
inList;
3427+
case (_, _, _) then inElem :: inList;
3428+
end matchcontinue;
3429+
end listUnionEltComp;
3430+
34083431
public function listUnion "function listUnion
34093432
Takes two lists and returns the union of the two lists,
34103433
i.e. a list of all elements combined without duplicates.
@@ -3430,6 +3453,36 @@ algorithm
34303453
end matchcontinue;
34313454
end listUnion;
34323455

3456+
public function listUnionComp
3457+
"Works as listUnion, but with a compare function."
3458+
input list<Type_a> inList1;
3459+
input list<Type_a> inList2;
3460+
input CompareFunc inCompFunc;
3461+
output list<Type_a> outList;
3462+
partial function CompareFunc
3463+
input Type_a inElem1;
3464+
input Type_a inElem2;
3465+
output Boolean res;
3466+
end CompareFunc;
3467+
replaceable type Type_a subtypeof Any;
3468+
algorithm
3469+
outList := matchcontinue(inList1, inList2, inCompFunc)
3470+
local
3471+
list<Type_a> res, xs;
3472+
Type_a x;
3473+
case ({}, {}, _)
3474+
then {};
3475+
case ({}, x :: xs, _)
3476+
then listUnionEltComp(x, listUnionComp({}, xs, inCompFunc), inCompFunc);
3477+
case ((x :: xs), _, _)
3478+
equation
3479+
res = listUnionComp(xs, inList2, inCompFunc);
3480+
res = listUnionEltComp(x, res, inCompFunc);
3481+
then
3482+
res;
3483+
end matchcontinue;
3484+
end listUnionComp;
3485+
34333486
public function listListUnion "function: listListUnion
34343487
Takes a list of lists and returns the union of the sublists
34353488
Example: listListUnion({{1},{1,2},{3,4},{5}}) => {1,2,3,4,5}"

0 commit comments

Comments
 (0)