Skip to content

Commit 5b5e235

Browse files
perostOpenModelica-Hudson
authored andcommitted
Implemented handling of duplicates in nfinst.
- Changed BaseAvlTree.ConflictFunc to also take the key as argument, to make it more useful for e.g. BaseAvlTree.join and to facilitate reuse of conflict handlers. - Implemented basic handling of duplicate elements. - Implemented basic handling of element redeclares. - Improved name lookup for e.g. base class names. - Added check for transitively non-replaceable base classes.
1 parent db08647 commit 5b5e235

File tree

15 files changed

+1182
-353
lines changed

15 files changed

+1182
-353
lines changed

Compiler/FFrontEnd/FNode.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,15 @@ end addChildRef;
349349
protected function printElementConflictError
350350
input Ref newRef;
351351
input Ref oldRef;
352+
input RefTree.Key name;
352353
output Ref dummy;
353354
protected
354355
SourceInfo info1, info2;
355-
String name;
356356
algorithm
357357
if Config.acceptMetaModelicaGrammar() then
358358
dummy := newRef;
359359
else
360-
(name, info1) := SCode.elementNameInfo(FNode.getElementFromRef(newRef));
360+
info1 := SCode.elementInfo(FNode.getElementFromRef(newRef));
361361
info2 := SCode.elementInfo(FNode.getElementFromRef(oldRef));
362362
Error.addMultiSourceMessage(Error.DOUBLE_DECLARATION_OF_ELEMENTS, {name}, {info2, info1});
363363
fail();

Compiler/FrontEnd/NFSCodeEnv.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ end extendEnvWithItem;
787787
function extendEnvWithItemConflict
788788
input Item newItem;
789789
input Item oldItem;
790+
input String name;
790791
output Item item;
791792
algorithm
792793
item := linkItemUsage(oldItem, newItem);

Compiler/NFFrontEnd/NFBinding.mo

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,27 @@ public
205205
end match;
206206
end toString;
207207

208+
function isEqual
209+
input Binding binding1;
210+
input Binding binding2;
211+
output Boolean equal;
212+
algorithm
213+
equal := match (binding1, binding2)
214+
case (UNBOUND(), UNBOUND()) then true;
215+
216+
// TODO: Handle propagated dims.
217+
case (RAW_BINDING(), RAW_BINDING())
218+
then Absyn.expEqual(binding1.bindingExp, binding2.bindingExp);
219+
220+
case (UNTYPED_BINDING(), UNTYPED_BINDING())
221+
then Expression.isEqual(binding1.bindingExp, binding2.bindingExp);
222+
223+
case (TYPED_BINDING(), TYPED_BINDING())
224+
then Expression.isEqual(binding1.bindingExp, binding2.bindingExp);
225+
226+
else false;
227+
end match;
228+
end isEqual;
229+
208230
annotation(__OpenModelica_Interface="frontend");
209231
end NFBinding;

Compiler/NFFrontEnd/NFClass.mo

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ uniontype Class
5454
end PREFIXES;
5555

5656
record DEFAULT end DEFAULT;
57+
58+
function isEqual
59+
input Prefixes prefs1;
60+
input Prefixes prefs2;
61+
output Boolean isEqual = valueEq(prefs1, prefs2);
62+
end isEqual;
5763
end Prefixes;
5864

5965
record NOT_INSTANTIATED end NOT_INSTANTIATED;
@@ -238,6 +244,28 @@ uniontype Class
238244
fail();
239245
end match;
240246
end mergeModifier;
247+
248+
function isIdentical
249+
input Class cls1;
250+
input Class cls2;
251+
output Boolean identical = false;
252+
algorithm
253+
identical := match (cls1, cls2)
254+
case (EXPANDED_CLASS(), EXPANDED_CLASS())
255+
then Prefixes.isEqual(cls1.prefixes, cls2.prefixes) and
256+
ClassTree.isIdentical(cls1.elements, cls2.elements);
257+
258+
case (INSTANCED_BUILTIN(), INSTANCED_BUILTIN())
259+
algorithm
260+
if not Type.isEqual(cls1.ty, cls2.ty) then
261+
return;
262+
end if;
263+
then
264+
true;
265+
266+
else true;
267+
end match;
268+
end isIdentical;
241269
end Class;
242270

243271
annotation(__OpenModelica_Interface="frontend");

0 commit comments

Comments
 (0)