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

Commit 047112f

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] stream connector improvements.
- Reenable special handling for inStream/actualStream. - Handle arrays in BuiltinCall.typeActualInStreamCall. - Check that components with flow or stream prefix has Real type. Belonging to [master]: - OpenModelica/OpenModelica#152 - #3062
1 parent 2da4cb3 commit 047112f

File tree

4 files changed

+74
-27
lines changed

4 files changed

+74
-27
lines changed

Compiler/NFFrontEnd/NFBuiltinCall.mo

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,35 +1789,60 @@ protected
17891789
end if;
17901790

17911791
(arg, ty, var) := Typing.typeExp(listHead(args), origin, info);
1792+
arg := ExpandExp.expand(arg);
17921793

1793-
// The argument of actualStream/inStream must be a component reference.
1794-
if not Expression.isCref(arg) then
1795-
Error.addSourceMessage(Error.ARGUMENT_MUST_BE_VARIABLE,
1796-
{"First", ComponentRef.toString(fn_ref), "<REMOVE ME>"}, info);
1797-
fail();
1798-
end if;
1794+
{fn} := Function.typeRefCache(fn_ref);
1795+
callExp := typeActualInStreamCall2(name, fn, arg, var, info);
1796+
end typeActualInStreamCall;
17991797

1800-
arg_ref := Expression.toCref(arg);
1801-
arg_node := ComponentRef.node(arg_ref);
1798+
function typeActualInStreamCall2
1799+
input String name;
1800+
input Function fn;
1801+
input Expression arg;
1802+
input Variability var;
1803+
input SourceInfo info;
1804+
output Expression callExp;
1805+
algorithm
1806+
callExp := match arg
1807+
local
1808+
InstNode arg_node;
18021809

1803-
// The argument of actualStream/inStream must be a stream variable.
1804-
if not InstNode.isComponent(arg_node) or
1805-
not ConnectorType.isStream(Component.connectorType(InstNode.component(arg_node))) then
1806-
Error.addSourceMessageAndFail(Error.NON_STREAM_OPERAND_IN_STREAM_OPERATOR,
1807-
{ComponentRef.toString(arg_ref), name}, info);
1808-
end if;
1810+
case Expression.CREF()
1811+
algorithm
1812+
arg_node := ComponentRef.node(arg.cref);
18091813

1810-
// The argument of actualStream/inStream must have subscripts that can be evaluated.
1811-
for sub in ComponentRef.subscriptsAllFlat(arg_ref) loop
1812-
if Subscript.variability(sub) > Variability.PARAMETER then
1813-
Error.addSourceMessageAndFail(Error.CONNECTOR_NON_PARAMETER_SUBSCRIPT,
1814-
{ComponentRef.toString(arg_ref), Subscript.toString(sub)}, info);
1815-
end if;
1816-
end for;
1814+
// The argument of actualStream/inStream must be a stream variable.
1815+
if not InstNode.isComponent(arg_node) or
1816+
not ConnectorType.isStream(Component.connectorType(InstNode.component(arg_node))) then
1817+
Error.addSourceMessageAndFail(Error.NON_STREAM_OPERAND_IN_STREAM_OPERATOR,
1818+
{ComponentRef.toString(arg.cref), name}, info);
1819+
end if;
18171820

1818-
{fn} := Function.typeRefCache(fn_ref);
1819-
callExp := Expression.CALL(Call.makeTypedCall(fn, {arg}, var, ty));
1820-
end typeActualInStreamCall;
1821+
// The argument of actualStream/inStream must have subscripts that can be evaluated.
1822+
for sub in ComponentRef.subscriptsAllFlat(arg.cref) loop
1823+
if Subscript.variability(sub) > Variability.PARAMETER then
1824+
Error.addSourceMessageAndFail(Error.CONNECTOR_NON_PARAMETER_SUBSCRIPT,
1825+
{ComponentRef.toString(arg.cref), Subscript.toString(sub)}, info);
1826+
end if;
1827+
end for;
1828+
then
1829+
Expression.CALL(Call.makeTypedCall(fn, {arg}, var, arg.ty));
1830+
1831+
case Expression.ARRAY()
1832+
algorithm
1833+
arg.elements := list(typeActualInStreamCall2(name, fn, e, var, info) for e in arg.elements);
1834+
then
1835+
arg;
1836+
1837+
else
1838+
algorithm
1839+
Error.addSourceMessage(Error.NON_STREAM_OPERAND_IN_STREAM_OPERATOR,
1840+
{Expression.toString(arg), name}, info);
1841+
then
1842+
fail();
1843+
1844+
end match;
1845+
end typeActualInStreamCall2;
18211846

18221847
annotation(__OpenModelica_Interface="frontend");
18231848
end NFBuiltinCall;

Compiler/NFFrontEnd/NFFunction.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ uniontype Function
13801380
special := match Absyn.pathFirstIdent(path)
13811381
// Can have variable number of arguments.
13821382
case "array" then true;
1383-
//case "actualStream" then true;
1383+
case "actualStream" then true;
13841384
case "branch" then true;
13851385
case "cardinality" then true;
13861386
case "cat" then true;
@@ -1396,7 +1396,7 @@ uniontype Function
13961396
case "getInstanceName" then true;
13971397
// Always discrete.
13981398
case "initial" then true;
1399-
//case "inStream" then true;
1399+
case "inStream" then true;
14001400
case "isRoot" then true;
14011401
// Arguments can be scalar, vector, matrix, 3d array .... basically anything
14021402
// We need to make sure size(Arg,i) = 1 for 2 < i <= ndims(Arg).

Compiler/NFFrontEnd/NFTyping.mo

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@ algorithm
415415
ty := Type.liftArrayLeftList(ty, arrayList(c.dimensions));
416416
InstNode.updateComponent(Component.setType(ty, c), node);
417417

418+
// Check that flow/stream variables are Real.
419+
checkComponentStreamAttribute(c.attributes.connectorType, ty, component);
420+
418421
// Type the component's children.
419422
typeComponents(c.classInst, origin);
420423
then
@@ -435,6 +438,23 @@ algorithm
435438
end match;
436439
end typeComponent;
437440

441+
function checkComponentStreamAttribute
442+
input ConnectorType.Type cty;
443+
input Type ty;
444+
input InstNode component;
445+
protected
446+
Type ety;
447+
algorithm
448+
if ConnectorType.isFlowOrStream(cty) then
449+
ety := Type.arrayElementType(ty);
450+
451+
if not (Type.isReal(ety) or Type.isComplex(ety)) then
452+
Error.addSourceMessageAndFail(Error.NON_REAL_FLOW_OR_STREAM,
453+
{ConnectorType.toString(cty), InstNode.name(component)}, InstNode.info(component));
454+
end if;
455+
end if;
456+
end checkComponentStreamAttribute;
457+
438458
function checkConnectorType
439459
input InstNode node;
440460
output Boolean isConnector;

Compiler/Util/Error.mo

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public constant Message TUPLE_ASSIGN_CREFS_ONLY = MESSAGE(147, TRANSLATION(), ER
425425
public constant Message LOOKUP_FUNCTION_GOT_CLASS = MESSAGE(148, TRANSLATION(), ERROR(),
426426
Util.gettext("Looking for a function %s but found a %s."));
427427
public constant Message NON_STREAM_OPERAND_IN_STREAM_OPERATOR = MESSAGE(149, TRANSLATION(), ERROR(),
428-
Util.gettext("Operand %s to operator %s is not a stream variable."));
428+
Util.gettext("Operand ‘%s‘ to operator ‘%s‘ is not a stream variable."));
429429
public constant Message UNBALANCED_CONNECTOR = MESSAGE(150, TRANSLATION(), WARNING(),
430430
Util.gettext("Connector %s is not balanced: %s"));
431431
public constant Message RESTRICTION_VIOLATION = MESSAGE(151, TRANSLATION(), ERROR(),
@@ -829,6 +829,8 @@ public constant Message WHEN_IF_VARIABLE_MISMATCH = MESSAGE(350, TRANSLATION(),
829829
Util.gettext("The branches of an if-equation inside a when-equation must have the same set of component references on the left-hand side."));
830830
public constant Message DIMENSION_DEDUCTION_FROM_BINDING_FAILURE = MESSAGE(351, TRANSLATION(), ERROR(),
831831
Util.gettext("Dimension %s of ‘%s‘ could not be deduced from the component's binding equation ‘%s‘."));
832+
public constant Message NON_REAL_FLOW_OR_STREAM = MESSAGE(351, TRANSLATION(), ERROR(),
833+
Util.gettext("Invalid prefix ‘%s‘ on non-Real component ‘%s‘."));
832834
public constant Message INITIALIZATION_NOT_FULLY_SPECIFIED = MESSAGE(496, TRANSLATION(), WARNING(),
833835
Util.gettext("The initial conditions are not fully specified. %s."));
834836
public constant Message INITIALIZATION_OVER_SPECIFIED = MESSAGE(497, TRANSLATION(), WARNING(),

0 commit comments

Comments
 (0)