Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit a0c7ddf

Browse files
perostOpenModelica-Hudson
authored andcommitted
Added --ignoreReplaceable flag.
- Added the --ignoreReplaceable flag that disables the check that an element is replaceable before redeclaring. Belonging to [master]: - #2057 - OpenModelica/OpenModelica-testsuite#795
1 parent c73638c commit a0c7ddf

File tree

3 files changed

+110
-105
lines changed

3 files changed

+110
-105
lines changed

Compiler/FrontEnd/Inst.mo

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3820,6 +3820,7 @@ protected
38203820
DAE.Mod redecl_mod, m, old_m;
38213821
String redecl_name, name;
38223822
Boolean found;
3823+
SCode.Replaceable repl;
38233824
Option<SCode.ConstrainClass> cc;
38243825
list<SCode.Element> cc_comps;
38253826
list<Absyn.ComponentRef> crefs;
@@ -3834,8 +3835,7 @@ algorithm
38343835

38353836
(outElement, outMod) := matchcontinue (redecl_el, inElement)
38363837
// Redeclaration of component.
3837-
case (SCode.COMPONENT(),
3838-
SCode.COMPONENT(prefixes = SCode.PREFIXES(replaceablePrefix = SCode.REPLACEABLE(cc = cc))))
3838+
case (SCode.COMPONENT(), SCode.COMPONENT(prefixes = SCode.PREFIXES(replaceablePrefix = repl)))
38393839
algorithm
38403840
true := redecl_name == inElement.name;
38413841

@@ -3848,23 +3848,31 @@ algorithm
38483848
(outCache, old_m) := Mod.elabMod(outCache, outEnv, outIH, inPrefix,
38493849
inElement.modifications, inImpl, Mod.COMPONENT(inElement.name), inElement.info);
38503850

3851-
if isSome(cc) then
3852-
// Constraining type on the component:
3853-
// Extract components belonging to constraining class.
3854-
cc_comps := InstUtil.extractConstrainingComps(cc, inEnv, inPrefix);
3855-
// Keep previous constraining class mods.
3856-
redecl_mod := InstUtil.keepConstrainingTypeModifersOnly(redecl_mod, cc_comps);
3857-
old_m := InstUtil.keepConstrainingTypeModifersOnly(old_m, cc_comps);
3858-
3859-
m := Mod.merge(m, redecl_mod, redecl_name);
3860-
m := Mod.merge(m, old_m, redecl_name);
3861-
m := Mod.merge(m, inCmod, redecl_name);
3862-
else
3863-
// No constraining type on comp, throw away modifiers prior to redeclaration:
3864-
m := Mod.merge(redecl_mod, m, redecl_name);
3865-
m := Mod.merge(m, old_m, redecl_name);
3866-
m := Mod.merge(inCmod, m, redecl_name);
3867-
end if;
3851+
m := match repl
3852+
case SCode.REPLACEABLE(cc = cc as SOME(_))
3853+
algorithm
3854+
// Constraining type on the component:
3855+
// Extract components belonging to constraining class.
3856+
cc_comps := InstUtil.extractConstrainingComps(cc, inEnv, inPrefix);
3857+
// Keep previous constraining class mods.
3858+
redecl_mod := InstUtil.keepConstrainingTypeModifersOnly(redecl_mod, cc_comps);
3859+
old_m := InstUtil.keepConstrainingTypeModifersOnly(old_m, cc_comps);
3860+
3861+
m := Mod.merge(m, redecl_mod, redecl_name);
3862+
m := Mod.merge(m, old_m, redecl_name);
3863+
m := Mod.merge(m, inCmod, redecl_name);
3864+
then
3865+
m;
3866+
3867+
else
3868+
algorithm
3869+
// No constraining type on comp, throw away modifiers prior to redeclaration:
3870+
m := Mod.merge(redecl_mod, m, redecl_name);
3871+
m := Mod.merge(m, old_m, redecl_name);
3872+
m := Mod.merge(inCmod, m, redecl_name);
3873+
then
3874+
m;
3875+
end match;
38683876

38693877
(outCache, outElement) :=
38703878
propagateRedeclCompAttr(outCache, outEnv, inElement, redecl_el);

Compiler/FrontEnd/NFSCodeCheck.mo

Lines changed: 78 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function checkRedeclaredElementPrefix
204204
input SCode.Element inReplacement;
205205
input SourceInfo inInfo;
206206
algorithm
207-
_ := match(inItem, inReplacement, inInfo)
207+
_ := match(inItem, inReplacement)
208208
local
209209
SCode.Replaceable repl;
210210
SCode.Final fin;
@@ -214,58 +214,54 @@ algorithm
214214
SCode.Restriction res;
215215
SCode.Visibility vis1, vis2;
216216
String ty;
217-
Integer err_count;
218217
Absyn.TypeSpec ty1, ty2;
218+
Boolean ok;
219219

220220
case (NFSCodeEnv.VAR(var =
221221
SCode.COMPONENT(name = name, prefixes = SCode.PREFIXES(
222222
finalPrefix = fin, replaceablePrefix = repl),
223223
attributes = SCode.ATTR(variability = var), typeSpec = ty1, info = info)),
224-
SCode.COMPONENT(prefixes = SCode.PREFIXES(), typeSpec = ty2), _)
225-
equation
226-
err_count = Error.getNumErrorMessages();
227-
ty = "component";
228-
checkCompRedeclarationReplaceable(name, repl, ty1, ty2, inInfo, info);
229-
checkRedeclarationFinal(name, ty, fin, inInfo, info);
230-
checkRedeclarationVariability(name, ty, var, inInfo, info);
224+
SCode.COMPONENT(prefixes = SCode.PREFIXES(), typeSpec = ty2))
225+
algorithm
226+
ty := "component";
227+
ok := checkCompRedeclarationReplaceable(name, repl, ty1, ty2, inInfo, info);
228+
ok := checkRedeclarationFinal(name, ty, fin, inInfo, info) and ok;
229+
ok := checkRedeclarationVariability(name, ty, var, inInfo, info) and ok;
231230
//checkRedeclarationVisibility(name, ty, vis1, vis2, inInfo, info);
232-
true = intEq(err_count, Error.getNumErrorMessages());
231+
true := ok;
233232
then
234233
();
235234

236235
case (NFSCodeEnv.CLASS(cls =
237236
SCode.CLASS(name = name, prefixes = SCode.PREFIXES(
238237
finalPrefix = fin, replaceablePrefix = repl),
239238
restriction = res, info = info)),
240-
SCode.CLASS(prefixes = SCode.PREFIXES()), _)
241-
equation
242-
err_count = Error.getNumErrorMessages();
243-
ty = SCodeDump.restrictionStringPP(res);
244-
checkClassRedeclarationReplaceable(name, ty, repl, inInfo, info);
245-
checkRedeclarationFinal(name, ty, fin, inInfo, info);
239+
SCode.CLASS(prefixes = SCode.PREFIXES()))
240+
algorithm
241+
ty := SCodeDump.restrictionStringPP(res);
242+
ok := checkClassRedeclarationReplaceable(name, ty, repl, inInfo, info);
243+
ok := checkRedeclarationFinal(name, ty, fin, inInfo, info) and ok;
246244
//checkRedeclarationVisibility(name, ty, vis1, vis2, inInfo, info);
247-
true = intEq(err_count, Error.getNumErrorMessages());
245+
true := ok;
248246
then
249247
();
250248

251249
case (NFSCodeEnv.VAR(var = SCode.COMPONENT(name = name, info = info)),
252-
SCode.CLASS(restriction = res), _)
253-
equation
254-
ty = SCodeDump.restrictionStringPP(res);
255-
ty = "a " + ty;
256-
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inInfo);
257-
Error.addSourceMessage(Error.INVALID_REDECLARE_AS,
258-
{"component", name, ty}, info);
250+
SCode.CLASS(restriction = res))
251+
algorithm
252+
ty := SCodeDump.restrictionStringPP(res);
253+
ty := "a " + ty;
254+
Error.addMultiSourceMessage(Error.INVALID_REDECLARE_AS,
255+
{"component", name, ty}, {inInfo, info});
259256
then
260257
fail();
261258

262259
case (NFSCodeEnv.CLASS(cls = SCode.CLASS(restriction = res, info = info)),
263-
SCode.COMPONENT(name = name), _)
264-
equation
265-
ty = SCodeDump.restrictionStringPP(res);
266-
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inInfo);
267-
Error.addSourceMessage(Error.INVALID_REDECLARE_AS,
268-
{ty, name, "a component"}, info);
260+
SCode.COMPONENT(name = name))
261+
algorithm
262+
ty := SCodeDump.restrictionStringPP(res);
263+
Error.addMultiSourceMessage(Error.INVALID_REDECLARE_AS,
264+
{ty, name, "a component"}, {inInfo, info});
269265
then
270266
fail();
271267

@@ -279,17 +275,18 @@ protected function checkClassRedeclarationReplaceable
279275
input SCode.Replaceable inReplaceable;
280276
input SourceInfo inOriginInfo;
281277
input SourceInfo inInfo;
278+
output Boolean isValid;
282279
algorithm
283-
_ := match(inName, inType, inReplaceable, inOriginInfo, inInfo)
284-
case (_, _, SCode.REPLACEABLE(), _, _) then ();
285-
286-
case (_, _, SCode.NOT_REPLACEABLE(), _, _)
287-
equation
288-
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inOriginInfo);
289-
Error.addSourceMessage(Error.REDECLARE_NON_REPLACEABLE,
290-
{inType, inName}, inInfo);
280+
isValid := match inReplaceable
281+
case SCode.NOT_REPLACEABLE() guard not Flags.getConfigBool(Flags.IGNORE_REPLACEABLE)
282+
algorithm
283+
Error.addMultiSourceMessage(Error.REDECLARE_NON_REPLACEABLE,
284+
{inType, inName}, {inOriginInfo, inInfo});
291285
then
292-
();
286+
false;
287+
288+
else true;
289+
293290
end match;
294291
end checkClassRedeclarationReplaceable;
295292

@@ -300,27 +297,24 @@ protected function checkCompRedeclarationReplaceable
300297
input Absyn.TypeSpec inType2;
301298
input SourceInfo inOriginInfo;
302299
input SourceInfo inInfo;
300+
output Boolean isValid;
303301
algorithm
304-
_ := match(inName, inReplaceable, inType1, inType2, inOriginInfo, inInfo)
305-
local
306-
SCode.Element var;
307-
Absyn.TypeSpec ty1, ty2;
308-
309-
case (_, SCode.REPLACEABLE(), _, _, _, _) then ();
310-
311-
case (_, SCode.NOT_REPLACEABLE(), _, _, _, _)
302+
isValid := match inReplaceable
303+
case SCode.NOT_REPLACEABLE()
312304
guard Absyn.pathEqual(Absyn.typeSpecPath(inType1),
313305
Absyn.typeSpecPath(inType2))
314306
then
315-
();
307+
true;
316308

317-
case (_, SCode.NOT_REPLACEABLE(), _, _, _, _)
318-
equation
319-
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inOriginInfo);
320-
Error.addSourceMessage(Error.REDECLARE_NON_REPLACEABLE,
321-
{"component", inName}, inInfo);
309+
case SCode.NOT_REPLACEABLE() guard not Flags.getConfigBool(Flags.IGNORE_REPLACEABLE)
310+
algorithm
311+
Error.addMultiSourceMessage(Error.REDECLARE_NON_REPLACEABLE,
312+
{"component", inName}, {inOriginInfo, inInfo});
322313
then
323-
();
314+
fail();
315+
316+
else true;
317+
324318
end match;
325319
end checkCompRedeclarationReplaceable;
326320

@@ -330,17 +324,18 @@ protected function checkRedeclarationFinal
330324
input SCode.Final inFinal;
331325
input SourceInfo inOriginInfo;
332326
input SourceInfo inInfo;
327+
output Boolean isValid;
333328
algorithm
334-
_ := match(inName, inType, inFinal, inOriginInfo, inInfo)
335-
case (_, _, SCode.NOT_FINAL(), _, _) then ();
329+
isValid := match inFinal
330+
case SCode.NOT_FINAL() then true;
336331

337-
case (_, _, SCode.FINAL(), _, _)
338-
equation
339-
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inOriginInfo);
340-
Error.addSourceMessage(Error.INVALID_REDECLARE,
341-
{"final", inType, inName}, inInfo);
332+
case SCode.FINAL()
333+
algorithm
334+
Error.addMultiSourceMessage(Error.INVALID_REDECLARE,
335+
{"final", inType, inName}, {inOriginInfo, inInfo});
342336
then
343-
();
337+
false;
338+
344339
end match;
345340
end checkRedeclarationFinal;
346341

@@ -350,17 +345,17 @@ protected function checkRedeclarationVariability
350345
input SCode.Variability inVariability;
351346
input SourceInfo inOriginInfo;
352347
input SourceInfo inInfo;
348+
output Boolean isValid;
353349
algorithm
354-
_ := match(inName, inType, inVariability, inOriginInfo, inInfo)
355-
case (_, _, SCode.CONST(), _, _)
356-
equation
357-
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inOriginInfo);
358-
Error.addSourceMessage(Error.INVALID_REDECLARE,
359-
{"constant", inType, inName}, inInfo);
350+
isValid := match inVariability
351+
case SCode.CONST()
352+
algorithm
353+
Error.addMultiSourceMessage(Error.INVALID_REDECLARE,
354+
{"constant", inType, inName}, {inOriginInfo, inInfo});
360355
then
361-
();
356+
false;
362357

363-
else ();
358+
else true;
364359
end match;
365360
end checkRedeclarationVariability;
366361

@@ -371,26 +366,24 @@ protected function checkRedeclarationVisibility
371366
input SCode.Visibility inNewVisibility;
372367
input SourceInfo inOriginInfo;
373368
input SourceInfo inNewInfo;
369+
output Boolean isValid;
374370
algorithm
375-
_ := match(inName, inType, inOriginalVisibility, inNewVisibility,
376-
inOriginInfo, inNewInfo)
377-
case (_, _, SCode.PUBLIC(), SCode.PROTECTED(), _, _)
378-
equation
379-
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inNewInfo);
380-
Error.addSourceMessage(Error.INVALID_REDECLARE_AS,
381-
{"public element", inName, "protected"}, inOriginInfo);
371+
isValid := match (inOriginalVisibility, inNewVisibility)
372+
case (SCode.PUBLIC(), SCode.PROTECTED())
373+
algorithm
374+
Error.addMultiSourceMessage(Error.INVALID_REDECLARE_AS,
375+
{"public element", inName, "protected"}, {inNewInfo, inOriginInfo});
382376
then
383-
fail();
377+
false;
384378

385-
case (_, _, SCode.PROTECTED(), SCode.PUBLIC(), _, _)
386-
equation
387-
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inNewInfo);
388-
Error.addSourceMessage(Error.INVALID_REDECLARE_AS,
389-
{"protected element", inName, "public"}, inOriginInfo);
379+
case (SCode.PROTECTED(), SCode.PUBLIC())
380+
algorithm
381+
Error.addMultiSourceMessage(Error.INVALID_REDECLARE_AS,
382+
{"protected element", inName, "public"}, {inNewInfo, inOriginInfo});
390383
then
391-
fail();
384+
false;
392385

393-
else ();
386+
else true;
394387
end match;
395388
end checkRedeclarationVisibility;
396389

Compiler/Util/Flags.mo

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,9 @@ constant ConfigFlag HOMOTOPY_APPROACH = CONFIG_FLAG(116, "homotopyApproach",
14011401
("adaptiveGlobal", Util.gettext("Global homotopy approach with adaptive lambda steps. The homotopy parameter effects the entire initialization system."))
14021402
})),
14031403
Util.gettext("Sets the homotopy approach."));
1404+
constant ConfigFlag IGNORE_REPLACEABLE = CONFIG_FLAG(117, "ignoreReplaceable",
1405+
NONE(), EXTERNAL(), BOOL_FLAG(false), NONE(),
1406+
Util.gettext("Sets whether to ignore replaceability or not when redeclaring."));
14041407

14051408
protected
14061409
// This is a list of all configuration flags. A flag can not be used unless it's
@@ -1522,7 +1525,8 @@ constant list<ConfigFlag> allConfigFlags = {
15221525
TEARING_STRICTNESS,
15231526
INTERACTIVE,
15241527
ZEROMQ_FILE_SUFFIX,
1525-
HOMOTOPY_APPROACH
1528+
HOMOTOPY_APPROACH,
1529+
IGNORE_REPLACEABLE
15261530
};
15271531

15281532
public function new

0 commit comments

Comments
 (0)