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

Commit 83ffab2

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Fix some variability issues.
- Changed pre and change to be discrete and ndims to be parameter, as per the specification. - Derive the variability of components with no explicit variability by using their types. - Hacked the variability of relations to be at most discrete to avoid breaking implicitly discrete variables, needs to be fixed properly for e.g. noEvent. Belonging to [master]: - #2060 - OpenModelica/OpenModelica-testsuite#798
1 parent 12d1ede commit 83ffab2

File tree

7 files changed

+55
-4
lines changed

7 files changed

+55
-4
lines changed

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,7 @@ protected
948948
argtycall := typeNormalCall(call, info);
949949
(call , ty, variability) := matchTypedNormalCall(argtycall, info);
950950
call := unboxArgs(call);
951+
variability := Variability.PARAMETER;
951952
end typeNdimsCall;
952953

953954
function typeSampleCall
@@ -991,7 +992,7 @@ protected
991992
end if;
992993

993994
call := unboxArgs(call);
994-
995+
variability := Variability.DISCRETE;
995996
end typePreCall;
996997

997998
function typeChangeCall
@@ -1020,6 +1021,7 @@ protected
10201021
fail();
10211022
end if;
10221023

1024+
variability := Variability.DISCRETE;
10231025
end typeChangeCall;
10241026

10251027
function typeReinitCall

Compiler/NFFrontEnd/NFComponent.mo

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,17 +403,35 @@ uniontype Component
403403
end isOutput;
404404

405405
function variability
406+
"Returns a component's variability, using the component's type to infer the
407+
variability if no variability has been given explicitly."
406408
input Component component;
407409
output Variability variability;
408410
algorithm
409411
variability := match component
410412
case TYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(variability = variability)) then variability;
413+
case TYPED_COMPONENT() guard Type.isDiscrete(component.ty) then Variability.DISCRETE;
411414
case UNTYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(variability = variability)) then variability;
412415
case ITERATOR() then Variability.CONSTANT;
416+
case ENUM_LITERAL() then Variability.CONSTANT;
413417
else Variability.CONTINUOUS;
414418
end match;
415419
end variability;
416420

421+
function variabilityExplicit
422+
"Returns a component's explicitly given variability, or CONTINUOUS."
423+
input Component component;
424+
output Variability variability;
425+
algorithm
426+
variability := match component
427+
case TYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(variability = variability)) then variability;
428+
case UNTYPED_COMPONENT(attributes = Attributes.ATTRIBUTES(variability = variability)) then variability;
429+
case ITERATOR() then Variability.CONSTANT;
430+
case ENUM_LITERAL() then Variability.CONSTANT;
431+
else Variability.CONTINUOUS;
432+
end match;
433+
end variabilityExplicit;
434+
417435
function isConst
418436
input Component component;
419437
output Boolean isConst = variability(component) == Variability.CONSTANT;

Compiler/NFFrontEnd/NFFlatten.mo

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import Face = NFConnector.Face;
7474
import System;
7575
import ComplexType = NFComplexType;
7676
import NFInstNode.CachedData;
77+
import NFPrefixes.Variability;
7778

7879
public
7980
type FunctionTree = FunctionTreeImpl.Tree;
@@ -228,7 +229,8 @@ algorithm
228229
new_pre := ComponentRef.prefixCref(comp_node, ty, {}, prefix);
229230
binding := flattenBinding(c.binding, prefix, comp_node);
230231

231-
if Type.isArray(ty) and Binding.isBound(binding) and Component.isVar(c) then
232+
if Type.isArray(ty) and Binding.isBound(binding) and
233+
Component.variability(c) >= Variability.DISCRETE then
232234
comps := (new_pre, Binding.UNBOUND()) :: comps;
233235
sections := Sections.prependEquation(
234236
Equation.ARRAY_EQUALITY(Expression.CREF(ty, new_pre), Binding.getTypedExp(binding), ty, c.info),

Compiler/NFFrontEnd/NFFunction.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ uniontype Function
410410

411411
// Add the type if the parameter has been typed.
412412
if printTypes and Component.isTyped(c) then
413-
var_s := if Component.variability(c) < Variability.CONTINUOUS then Prefixes.variabilityString(Component.variability(c)) + " " else "";
413+
var_s := Prefixes.unparseVariability(Component.variabilityExplicit(c));
414414
input_str := var_s + Type.toString(Component.getType(c)) + " " + input_str;
415415
end if;
416416

Compiler/NFFrontEnd/NFPrefixes.mo

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,18 @@ algorithm
205205
end match;
206206
end variabilityString;
207207

208+
function unparseVariability
209+
input Variability var;
210+
output String str;
211+
algorithm
212+
str := match var
213+
case Variability.CONSTANT then "constant ";
214+
case Variability.PARAMETER then "parameter ";
215+
case Variability.DISCRETE then "discrete ";
216+
else "";
217+
end match;
218+
end unparseVariability;
219+
208220
function variabilityMax
209221
input Variability var1;
210222
input Variability var2;

Compiler/NFFrontEnd/NFType.mo

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,5 +519,20 @@ public
519519
end match;
520520
end isEqual;
521521

522+
function isDiscrete
523+
input Type ty;
524+
output Boolean isDiscrete;
525+
algorithm
526+
isDiscrete := match ty
527+
case INTEGER() then true;
528+
case STRING() then true;
529+
case BOOLEAN() then true;
530+
case ENUMERATION() then true;
531+
case ARRAY() then isDiscrete(ty.elementType);
532+
case FUNCTION() then isDiscrete(ty.resultType);
533+
else false;
534+
end match;
535+
end isDiscrete;
536+
522537
annotation(__OpenModelica_Interface="frontend");
523538
end NFType;

Compiler/NFFrontEnd/NFTyping.mo

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,8 +1008,10 @@ algorithm
10081008
(e1, ty1, var1) := typeExp(exp.exp1, info, next_origin);
10091009
(e2, ty2, var2) := typeExp(exp.exp2, info, next_origin);
10101010
(exp, ty) := TypeCheck.checkRelationOperation(e1, ty1, exp.operator, e2, ty2);
1011+
// TODO: Implement this properly according to 3.8.3 in the spec.
1012+
variability := Prefixes.variabilityMin(Prefixes.variabilityMax(var1, var2), Variability.DISCRETE);
10111013
then
1012-
(exp, ty, Prefixes.variabilityMax(var1, var2));
1014+
(exp, ty, variability);
10131015

10141016
case Expression.IF()
10151017
algorithm

0 commit comments

Comments
 (0)