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

Commit

Permalink
[NF] Add component prefix checks for records.
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - #3034
  • Loading branch information
perost authored and OpenModelica-Hudson committed Apr 3, 2019
1 parent 450104a commit 0839b2f
Showing 1 changed file with 53 additions and 11 deletions.
64 changes: 53 additions & 11 deletions Compiler/NFFrontEnd/NFInst.mo
Expand Up @@ -1682,31 +1682,73 @@ algorithm
case Restriction.CONNECTOR()
algorithm
// Components of a connector may not have prefixes 'inner' or 'outer'.
if attr.innerOuter <> InnerOuter.NOT_INNER_OUTER then
Error.addSourceMessageAndFail(Error.INVALID_COMPONENT_PREFIX,
{Prefixes.innerOuterString(attr.innerOuter), InstNode.name(component)},
InstNode.info(component));
end if;
assertNotInnerOuter(attr.innerOuter, component, parentRestriction);

if parentRestriction.isExpandable then
// Components of an expandable connector may not have the prefix 'flow'.

if ConnectorType.isFlowOrStream(attr.connectorType) then
Error.addSourceMessageAndFail(Error.INVALID_COMPONENT_PREFIX,
{ConnectorType.toString(attr.connectorType), InstNode.name(component), Restriction.toString(parentRestriction)},
InstNode.info(component));
end if;
assertNotFlowStream(attr.connectorType, component, parentRestriction);

// Mark components in expandable connectors as potentially present.
attr.connectorType := intBitOr(attr.connectorType, ConnectorType.POTENTIALLY_PRESENT);
end if;
then
();

case Restriction.RECORD()
algorithm
// Elements of a record may not have prefixes 'input', 'output', 'inner', 'outer', 'stream', or 'flow'.
assertNotInputOutput(attr.direction, component, parentRestriction);
assertNotInnerOuter(attr.innerOuter, component, parentRestriction);
assertNotFlowStream(attr.connectorType, component, parentRestriction);
then
();

else ();
end match;
end checkDeclaredComponentAttributes;

function invalidComponentPrefixError
input String prefix;
input InstNode node;
input Restriction restriction;
algorithm
Error.addSourceMessage(Error.INVALID_COMPONENT_PREFIX,
{prefix, InstNode.name(node), Restriction.toString(restriction)}, InstNode.info(node));
end invalidComponentPrefixError;

function assertNotInputOutput
input Direction dir;
input InstNode node;
input Restriction restriction;
algorithm
if dir <> Direction.NONE then
invalidComponentPrefixError(Prefixes.directionString(dir), node, restriction);
fail();
end if;
end assertNotInputOutput;

function assertNotInnerOuter
input InnerOuter io;
input InstNode node;
input Restriction restriction;
algorithm
if io <> InnerOuter.NOT_INNER_OUTER then
invalidComponentPrefixError(Prefixes.innerOuterString(io), node, restriction);
fail();
end if;
end assertNotInnerOuter;

function assertNotFlowStream
input ConnectorType.Type cty;
input InstNode node;
input Restriction restriction;
algorithm
if ConnectorType.isFlowOrStream(cty) then
invalidComponentPrefixError(ConnectorType.toString(cty), node, restriction);
fail();
end if;
end assertNotFlowStream;

function mergeDerivedAttributes
input Component.Attributes outerAttr;
input Component.Attributes innerAttr;
Expand Down

0 comments on commit 0839b2f

Please sign in to comment.