Skip to content

Commit

Permalink
allow top level outer on an non standard flag (#11041)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrpo committed Aug 11, 2023
1 parent 9ca1bf6 commit 8355a5d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFInst.mo
Expand Up @@ -3532,7 +3532,7 @@ algorithm
node := Lookup.lookupSimpleName(name, scope, context);

if InstNode.isInner(node) then
is_error := not InstContext.inRelaxed(context);
is_error := not (InstContext.inRelaxed(context) or Flags.isConfigFlagSet(Flags.ALLOW_NON_STANDARD_MODELICA, "nonStdTopLevelOuter"));

if is_error then
Error.addSourceMessageAsError(Error.TOP_LEVEL_OUTER, {name}, InstNode.info(node));
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/Compiler/Util/Flags.mo
Expand Up @@ -1388,6 +1388,7 @@ constant ConfigFlag ALLOW_NON_STANDARD_MODELICA = CONFIG_FLAG(146, "allowNonStan
("nonStdEnumerationAsIntegers", Gettext.gettext("Allow enumeration as integer without casting via Integer(Enum).\nSee: https://specification.modelica.org/maint/3.5/class-predefined-types-and-declarations.html#type-conversion-of-enumeration-values-to-string-or-integer")),
("nonStdIntegersAsEnumeration", Gettext.gettext("Allow integer as enumeration without casting via Enum(Integer).\nSee: https://specification.modelica.org/maint/3.5/class-predefined-types-and-declarations.html#type-conversion-of-integer-to-enumeration-values")),
("nonStdDifferentCaseFileVsClassName", Gettext.gettext("Allow directory or file with different case in the name than the contained class name.\nSee: https://specification.modelica.org/maint/3.5/packages.html#mapping-package-class-structures-to-a-hierarchical-file-system")),
("nonStdTopLevelOuter", Gettext.gettext("Allow top level outer.\nSee: https://specification.modelica.org/maint/3.6/scoping-name-lookup-and-flattening.html#S4.p1")),
("protectedAccess", Gettext.gettext("Allow access of protected elements")),
("reinitInAlgorithms", Gettext.gettext("Allow reinit in algorithm sections"))
})),
Expand Down
1 change: 1 addition & 0 deletions testsuite/flattening/modelica/others/Makefile
Expand Up @@ -98,6 +98,7 @@ VectorizeExtendedType.mo \
WillowForest.mo \
Homotopy.mos \
TestEnumAsInteger.mos \
TestTopLevelOuter.mos \


# test that currently fail. Move up when fixed.
Expand Down
12 changes: 12 additions & 0 deletions testsuite/flattening/modelica/others/TestTopLevelOuter.mo
@@ -0,0 +1,12 @@
package TestNonStandardExtensions

model InnerDefinition
parameter Real x = 1;
end InnerDefinition;

model TestTopLevelOuter
outer InnerDefinition o;
parameter Real y = 2;
end TestTopLevelOuter;

end TestNonStandardExtensions;
30 changes: 30 additions & 0 deletions testsuite/flattening/modelica/others/TestTopLevelOuter.mos
@@ -0,0 +1,30 @@
// name: TestTopLevelOuter.mos
// keywords: non-standard Modelica extensions
// status: correct
//
// Test non-standard Modelica flags that allow usage of integer as enums and enums as integers
//
//

loadFile("TestTopLevelOuter.mo"); getErrorString();
instantiateModel(TestNonStandardExtensions.TestTopLevelOuter); getErrorString();
setCommandLineOptions("--allowNonStandardModelica=nonStdTopLevelOuter"); getErrorString();
instantiateModel(TestNonStandardExtensions.TestTopLevelOuter); getErrorString();

// Result:
// true
// ""
// ""
// "[flattening/modelica/others/TestTopLevelOuter.mo:8:3-8:26:writable] Error: The model can't be instantiated due to top-level outer element 'o', it may only be used as part of a simulation model.
// "
// true
// ""
// "class TestNonStandardExtensions.TestTopLevelOuter
// parameter Real y = 2.0;
// parameter Real o.x = 1.0;
// end TestNonStandardExtensions.TestTopLevelOuter;
// "
// "[flattening/modelica/others/TestTopLevelOuter.mo:8:3-8:26:writable] Warning: The model can't be instantiated due to top-level outer element 'o', it may only be used as part of a simulation model.
// [flattening/modelica/others/TestTopLevelOuter.mo:8:3-8:26:writable] Warning: An inner declaration for outer component o could not be found and was automatically generated.
// "
// endResult

0 comments on commit 8355a5d

Please sign in to comment.