From 0839b2fe1786d629df2f1d49fad49e4b0115f4ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=96stlund?= Date: Wed, 3 Apr 2019 15:00:36 +0200 Subject: [PATCH] [NF] Add component prefix checks for records. Belonging to [master]: - OpenModelica/OMCompiler#3034 --- Compiler/NFFrontEnd/NFInst.mo | 64 +++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/Compiler/NFFrontEnd/NFInst.mo b/Compiler/NFFrontEnd/NFInst.mo index 8a8e35730cd..45784cf5041 100644 --- a/Compiler/NFFrontEnd/NFInst.mo +++ b/Compiler/NFFrontEnd/NFInst.mo @@ -1682,20 +1682,11 @@ 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); @@ -1703,10 +1694,61 @@ algorithm 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;