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

Commit 1efe7ca

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Redeclare improvements.
- Improved handling of all types of redeclare. - Implemented propagation of final through the frontend, and added checks for final elements being modified. - Various instantiation improvements. Belonging to [master]: - #2288 - OpenModelica/OpenModelica-testsuite#880
1 parent fc30ae1 commit 1efe7ca

File tree

16 files changed

+1334
-414
lines changed

16 files changed

+1334
-414
lines changed

Compiler/FrontEnd/SCode.mo

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,6 +4113,16 @@ algorithm
41134113
end match;
41144114
end getModifierBinding;
41154115

4116+
function getComponentCondition
4117+
input Element element;
4118+
output Option<Absyn.Exp> condition;
4119+
algorithm
4120+
condition := match element
4121+
case COMPONENT() then element.condition;
4122+
else NONE();
4123+
end match;
4124+
end getComponentCondition;
4125+
41164126
public function removeComponentCondition
41174127
input Element inElement;
41184128
output Element outElement;
@@ -5763,5 +5773,39 @@ algorithm
57635773
end match;
57645774
end isEmptyMod;
57655775

5776+
function getConstrainingMod
5777+
input SCode.Element element;
5778+
output SCode.Mod mod;
5779+
algorithm
5780+
mod := match element
5781+
case Element.CLASS(prefixes = Prefixes.PREFIXES(replaceablePrefix =
5782+
Replaceable.REPLACEABLE(cc = SOME(ConstrainClass.CONSTRAINCLASS(modifier = mod))))) then mod;
5783+
case Element.CLASS(classDef = ClassDef.DERIVED(modifications = mod)) then mod;
5784+
case Element.COMPONENT(prefixes = Prefixes.PREFIXES(replaceablePrefix =
5785+
Replaceable.REPLACEABLE(cc = SOME(ConstrainClass.CONSTRAINCLASS(modifier = mod))))) then mod;
5786+
case Element.COMPONENT(modifications = mod) then mod;
5787+
else Mod.NOMOD();
5788+
end match;
5789+
end getConstrainingMod;
5790+
5791+
function isEmptyClassDef
5792+
input SCode.ClassDef cdef;
5793+
output Boolean isEmpty;
5794+
algorithm
5795+
isEmpty := match cdef
5796+
case PARTS()
5797+
then listEmpty(cdef.elementLst) and
5798+
listEmpty(cdef.normalEquationLst) and
5799+
listEmpty(cdef.initialEquationLst) and
5800+
listEmpty(cdef.normalAlgorithmLst) and
5801+
listEmpty(cdef.initialAlgorithmLst) and
5802+
isNone(cdef.externalDecl);
5803+
5804+
case CLASS_EXTENDS() then isEmptyClassDef(cdef.composition);
5805+
case ENUMERATION() then listEmpty(cdef.enumLst);
5806+
else true;
5807+
end match;
5808+
end isEmptyClassDef;
5809+
57665810
annotation(__OpenModelica_Interface="frontend");
57675811
end SCode;

Compiler/NFFrontEnd/NFClass.mo

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ uniontype Class
7878
record PARTIAL_CLASS
7979
ClassTree elements;
8080
Modifier modifier;
81+
Class.Prefixes prefixes;
8182
end PARTIAL_CLASS;
8283

8384
record EXPANDED_CLASS
@@ -121,12 +122,13 @@ uniontype Class
121122
input list<SCode.Element> elements;
122123
input Boolean isClassExtends;
123124
input InstNode scope;
125+
input Prefixes prefixes;
124126
output Class cls;
125127
protected
126128
ClassTree tree;
127129
algorithm
128130
tree := ClassTree.fromSCode(elements, isClassExtends, scope);
129-
cls := PARTIAL_CLASS(tree, Modifier.NOMOD());
131+
cls := PARTIAL_CLASS(tree, Modifier.NOMOD(), prefixes);
130132
end fromSCode;
131133

132134
function fromEnumeration
@@ -147,8 +149,7 @@ uniontype Class
147149
algorithm
148150
cls := match cls
149151
case PARTIAL_CLASS()
150-
then EXPANDED_CLASS(cls.elements, cls.modifier, DEFAULT_PREFIXES,
151-
Restriction.UNKNOWN());
152+
then EXPANDED_CLASS(cls.elements, cls.modifier, cls.prefixes, Restriction.UNKNOWN());
152153
end match;
153154
end initExpandedClass;
154155

@@ -261,6 +262,39 @@ uniontype Class
261262
end match;
262263
end getModifier;
263264

265+
function setModifier
266+
input Modifier modifier;
267+
input output Class cls;
268+
algorithm
269+
() := match cls
270+
case PARTIAL_CLASS()
271+
algorithm
272+
cls.modifier := modifier;
273+
then
274+
();
275+
case EXPANDED_CLASS()
276+
algorithm
277+
cls.modifier := modifier;
278+
then
279+
();
280+
case DERIVED_CLASS()
281+
algorithm
282+
cls.modifier := modifier;
283+
then
284+
();
285+
case PARTIAL_BUILTIN()
286+
algorithm
287+
cls.modifier := modifier;
288+
then
289+
();
290+
else
291+
algorithm
292+
Error.assertion(false, getInstanceName() + " got non-modifiable class", sourceInfo());
293+
then
294+
fail();
295+
end match;
296+
end setModifier;
297+
264298
function mergeModifier
265299
input Modifier modifier;
266300
input output Class cls;
@@ -422,6 +456,36 @@ uniontype Class
422456
output Boolean isFunction = Restriction.isFunction(restriction(cls));
423457
end isFunction;
424458

459+
function getPrefixes
460+
input Class cls;
461+
output Prefixes prefs;
462+
algorithm
463+
prefs := match cls
464+
case PARTIAL_CLASS() then cls.prefixes;
465+
case EXPANDED_CLASS() then cls.prefixes;
466+
case DERIVED_CLASS() then cls.prefixes;
467+
end match;
468+
end getPrefixes;
469+
470+
function setPrefixes
471+
input Prefixes prefs;
472+
input output Class cls;
473+
algorithm
474+
() := match cls
475+
case EXPANDED_CLASS()
476+
algorithm
477+
cls.prefixes := prefs;
478+
then
479+
();
480+
481+
case DERIVED_CLASS()
482+
algorithm
483+
cls.prefixes := prefs;
484+
then
485+
();
486+
487+
end match;
488+
end setPrefixes;
425489
end Class;
426490

427491
annotation(__OpenModelica_Interface="frontend");

0 commit comments

Comments
 (0)