Skip to content

Commit

Permalink
- Added a flag to OMC, +std, to set the Modelica language version to …
Browse files Browse the repository at this point in the history
…use. API

  calls setLanguageStandard and getLanguageStandard are also implemented for
  this.
- The Modelica language version is now set automatically if a specific version
  of the MSL is loaded, and gives a notification if the version has changed.
- Added new package RTOptsData, which contains data types and some functions
  which can't be in RTOpts since RML doesn't allow mixing external and
  non-external things.
- Turned on error messages for replaceable base classes if Modelica version is
  at least 3.0.
- Turned on balance checking of connectors if Modelica version is at least 3.0.
- Updated test suite, and added a new test case redeclare/ReplaceableBaseClass.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10221 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Oct 26, 2011
1 parent 87267eb commit 3c8db16
Show file tree
Hide file tree
Showing 18 changed files with 381 additions and 13 deletions.
4 changes: 3 additions & 1 deletion Compiler/FrontEnd/ConnectUtil.mo
Expand Up @@ -65,6 +65,7 @@ protected import List;
protected import Lookup;
protected import PrefixUtil;
protected import RTOpts;
protected import RTOptsData;
protected import System;
protected import Types;
protected import Util;
Expand Down Expand Up @@ -2947,7 +2948,8 @@ algorithm
// The connector is balanced.
case (_, _, _, _, _)
equation
true = intEq(inPotentialVars, inFlowVars) or not RTOpts.debugFlag("checkconnect");
true = intEq(inPotentialVars, inFlowVars) or
RTOptsData.languageStandardAtMost(RTOptsData.MODELICA_2_X());
true = Util.if_(intEq(inStreamVars, 0), true, intEq(inFlowVars, 1));
then
();
Expand Down
13 changes: 13 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -1136,6 +1136,19 @@ function getOrderConnections
external "builtin";
end getOrderConnections;

function setLanguageStandard
input String inVersion;
output Boolean success;
annotation(__OpenModelica_EarlyInline = true);
algorithm
success := setCommandLineOptions("+std=" + inVersion);
end setLanguageStandard;

function getLanguageStandard
output String outVersion;
external "builtin";
end getLanguageStandard;

function getAstAsCorbaString "Print the whole AST on the CORBA format for records, e.g.
record Absyn.PROGRAM
classes = ...,
Expand Down
39 changes: 30 additions & 9 deletions Compiler/FrontEnd/SCodeCheck.mo
Expand Up @@ -47,6 +47,7 @@ protected import Error;
protected import List;
protected import Util;
protected import SCodeDump;
protected import RTOptsData;

public function checkDuplicateClasses
input SCode.Program inProgram;
Expand Down Expand Up @@ -170,29 +171,49 @@ algorithm
end isSelfReference;

public function checkExtendsReplaceability
"Checks that a base class in an extends clause is not replaceable. If it is,
this function will print an error and fail, except for some special cases."
input SCodeEnv.Item inBaseClass;
input Absyn.Path inPath;
input SCodeEnv.Env inEnv;
input Absyn.Info inOriginInfo;
algorithm
_ := match(inBaseClass, inPath, inOriginInfo)
_ := matchcontinue(inBaseClass, inPath, inEnv, inOriginInfo)
local
Absyn.Info info;
String err_str;
SCode.ClassDef cdef;

// The base class is not replaceable, ok.
case (SCodeEnv.CLASS(cls = SCode.CLASS(prefixes = SCode.PREFIXES(
replaceablePrefix = SCode.NOT_REPLACEABLE()))), _, _)
replaceablePrefix = SCode.NOT_REPLACEABLE()))), _, _, _)
then ();

case (SCodeEnv.CLASS(cls = SCode.CLASS(prefixes = SCode.PREFIXES(
replaceablePrefix = SCode.REPLACEABLE(cc = _)), info = info)), _, _)
// If the parent class contains no elements it might be a short class
// definition, which is allowed to have a replaceable base class.
case (_, _, SCodeEnv.FRAME(clsAndVars = SCodeEnv.AVLTREENODE(value = NONE(),
left = NONE(), right = NONE())) :: _, _)
then ();

// If we're using Modelica 2.x or earlier we don't care, since replaceable
// baseclasses weren't explicitly forbidden in older versions.
case (_, _, _, _)
equation
// Disabled until it's decided whether this is an error or not.
//err_str = Absyn.pathString(inPath);
//Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inOriginInfo);
//Error.addSourceMessage(Error.REPLACEABLE_BASE_CLASS, {err_str}, info);
true = RTOptsData.languageStandardAtMost(RTOptsData.MODELICA_2_X());
then
();
end match;

// A replaceable baseclass will produce an error.
case (SCodeEnv.CLASS(cls = SCode.CLASS(prefixes = SCode.PREFIXES(
replaceablePrefix = SCode.REPLACEABLE(cc = _)),
classDef = cdef, info = info)), _, _, _)
equation
err_str = Absyn.pathString(inPath);
Error.addSourceMessage(Error.ERROR_FROM_HERE, {}, inOriginInfo);
Error.addSourceMessage(Error.REPLACEABLE_BASE_CLASS, {err_str}, info);
then
fail();
end matchcontinue;
end checkExtendsReplaceability;

public function checkClassExtendsReplaceability
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/SCodeEnv.mo
Expand Up @@ -862,7 +862,7 @@ algorithm

case (SOME(bc), SOME(item), EXTENDS(obc, rl, info), _, _)
equation
SCodeCheck.checkExtendsReplaceability(item, obc, info);
SCodeCheck.checkExtendsReplaceability(item, obc, inEnv, info);
bc = Absyn.makeFullyQualified(bc);
rl = List.map1(rl, SCodeFlattenRedeclare.qualifyRedeclare, inEnv);
List.map2_0(rl, SCodeCheck.checkRedeclareModifier, bc, inEnv);
Expand Down
1 change: 1 addition & 0 deletions Compiler/GenerateOMCHeader.mos
Expand Up @@ -2,6 +2,7 @@ loadFile("FrontEnd/Absyn.mo");
loadFile("Script/Interactive.mo");
loadFile("FrontEnd/Values.mo");
loadFile("Util/Error.mo");
loadFile("Util/RTOptsData.mo");

if getErrorString() == "" then loadOK := true; end if;
a:=loadOK; // Will cause exit(1) if loadOK is undefined
Expand Down
5 changes: 4 additions & 1 deletion Compiler/Main/Main.mo
Expand Up @@ -77,6 +77,7 @@ protected import TaskGraph;
protected import TaskGraphExt;
protected import TplMain;
protected import Util;
protected import RTOptsData;

protected function serverLoop
"function: serverLoop
Expand Down Expand Up @@ -1076,6 +1077,8 @@ algorithm
print("\t this way multiple omc compilers can be started\n");
print("\t+annotationVersion=1.x what annotation version should be used\n");
print("\t accept 1.x or 2.x (default) or 3.x\n");
print("\t+std=version the language standard that should be used.\n");
print("\t accepts 1.x, 2.x, 3.1, 3.2 or 3.3; default to latest version.\n");
print("\t+noSimplify do not simplify expressions (default is to simplify)\n");
print("\t+preOptModules=module1,.. pre optimisation modules (default is removeFinalParameters,removeEqualFunctionCalls,removeSimpleEquations,expandDerOperator)\n");
print("\t+pastOptModules=module1,.. past optimisation modules (default is lateInline,inlineArrayEqn,removeSimpleEquations)\n");
Expand Down Expand Up @@ -1151,7 +1154,7 @@ algorithm
case args as _::_
equation
args_1 = RTOpts.args(args);

false = System.userIsRoot();
_ = Settings.getInstallationDirectoryPath();

Expand Down
1 change: 1 addition & 0 deletions Compiler/Makefile.common
Expand Up @@ -162,6 +162,7 @@ Pool.mo \
Name.mo \
Scope.mo \
Relation.mo \
RTOptsData.mo \
VarTransform.mo \
# Not used by OpenModelica!
# HashTable4.mo \
Expand Down
112 changes: 112 additions & 0 deletions Compiler/OpenModelicaBootstrappingHeader.h
Expand Up @@ -3,6 +3,118 @@
extern "C" {
#endif
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef RTOptsData_LanguageStandard_MODELICA__1__X__desc_added
#define RTOptsData_LanguageStandard_MODELICA__1__X__desc_added
ADD_METARECORD_DEFINTIONS const char* RTOptsData_LanguageStandard_MODELICA__1__X__desc__fields[1] = {"no fileds"};
ADD_METARECORD_DEFINTIONS struct record_description RTOptsData_LanguageStandard_MODELICA__1__X__desc = {
"RTOptsData_LanguageStandard_MODELICA__1__X",
"RTOptsData.LanguageStandard.MODELICA_1_X",
RTOptsData_LanguageStandard_MODELICA__1__X__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description RTOptsData_LanguageStandard_MODELICA__1__X__desc;
#endif
#define RTOptsData__MODELICA_5f1_5fX_3dBOX0 3
static const MMC_DEFSTRUCTLIT(RTOptsData__MODELICA_5f1_5fX__struct,1,3) {&RTOptsData_LanguageStandard_MODELICA__1__X__desc}};
static void *RTOptsData__MODELICA_5f1_5fX = MMC_REFSTRUCTLIT(RTOptsData__MODELICA_5f1_5fX__struct);
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef RTOptsData_LanguageStandard_MODELICA__2__X__desc_added
#define RTOptsData_LanguageStandard_MODELICA__2__X__desc_added
ADD_METARECORD_DEFINTIONS const char* RTOptsData_LanguageStandard_MODELICA__2__X__desc__fields[1] = {"no fileds"};
ADD_METARECORD_DEFINTIONS struct record_description RTOptsData_LanguageStandard_MODELICA__2__X__desc = {
"RTOptsData_LanguageStandard_MODELICA__2__X",
"RTOptsData.LanguageStandard.MODELICA_2_X",
RTOptsData_LanguageStandard_MODELICA__2__X__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description RTOptsData_LanguageStandard_MODELICA__2__X__desc;
#endif
#define RTOptsData__MODELICA_5f2_5fX_3dBOX0 4
static const MMC_DEFSTRUCTLIT(RTOptsData__MODELICA_5f2_5fX__struct,1,4) {&RTOptsData_LanguageStandard_MODELICA__2__X__desc}};
static void *RTOptsData__MODELICA_5f2_5fX = MMC_REFSTRUCTLIT(RTOptsData__MODELICA_5f2_5fX__struct);
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef RTOptsData_LanguageStandard_MODELICA__3__0__desc_added
#define RTOptsData_LanguageStandard_MODELICA__3__0__desc_added
ADD_METARECORD_DEFINTIONS const char* RTOptsData_LanguageStandard_MODELICA__3__0__desc__fields[1] = {"no fileds"};
ADD_METARECORD_DEFINTIONS struct record_description RTOptsData_LanguageStandard_MODELICA__3__0__desc = {
"RTOptsData_LanguageStandard_MODELICA__3__0",
"RTOptsData.LanguageStandard.MODELICA_3_0",
RTOptsData_LanguageStandard_MODELICA__3__0__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description RTOptsData_LanguageStandard_MODELICA__3__0__desc;
#endif
#define RTOptsData__MODELICA_5f3_5f0_3dBOX0 5
static const MMC_DEFSTRUCTLIT(RTOptsData__MODELICA_5f3_5f0__struct,1,5) {&RTOptsData_LanguageStandard_MODELICA__3__0__desc}};
static void *RTOptsData__MODELICA_5f3_5f0 = MMC_REFSTRUCTLIT(RTOptsData__MODELICA_5f3_5f0__struct);
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef RTOptsData_LanguageStandard_MODELICA__3__1__desc_added
#define RTOptsData_LanguageStandard_MODELICA__3__1__desc_added
ADD_METARECORD_DEFINTIONS const char* RTOptsData_LanguageStandard_MODELICA__3__1__desc__fields[1] = {"no fileds"};
ADD_METARECORD_DEFINTIONS struct record_description RTOptsData_LanguageStandard_MODELICA__3__1__desc = {
"RTOptsData_LanguageStandard_MODELICA__3__1",
"RTOptsData.LanguageStandard.MODELICA_3_1",
RTOptsData_LanguageStandard_MODELICA__3__1__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description RTOptsData_LanguageStandard_MODELICA__3__1__desc;
#endif
#define RTOptsData__MODELICA_5f3_5f1_3dBOX0 6
static const MMC_DEFSTRUCTLIT(RTOptsData__MODELICA_5f3_5f1__struct,1,6) {&RTOptsData_LanguageStandard_MODELICA__3__1__desc}};
static void *RTOptsData__MODELICA_5f3_5f1 = MMC_REFSTRUCTLIT(RTOptsData__MODELICA_5f3_5f1__struct);
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef RTOptsData_LanguageStandard_MODELICA__3__2__desc_added
#define RTOptsData_LanguageStandard_MODELICA__3__2__desc_added
ADD_METARECORD_DEFINTIONS const char* RTOptsData_LanguageStandard_MODELICA__3__2__desc__fields[1] = {"no fileds"};
ADD_METARECORD_DEFINTIONS struct record_description RTOptsData_LanguageStandard_MODELICA__3__2__desc = {
"RTOptsData_LanguageStandard_MODELICA__3__2",
"RTOptsData.LanguageStandard.MODELICA_3_2",
RTOptsData_LanguageStandard_MODELICA__3__2__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description RTOptsData_LanguageStandard_MODELICA__3__2__desc;
#endif
#define RTOptsData__MODELICA_5f3_5f2_3dBOX0 7
static const MMC_DEFSTRUCTLIT(RTOptsData__MODELICA_5f3_5f2__struct,1,7) {&RTOptsData_LanguageStandard_MODELICA__3__2__desc}};
static void *RTOptsData__MODELICA_5f3_5f2 = MMC_REFSTRUCTLIT(RTOptsData__MODELICA_5f3_5f2__struct);
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef RTOptsData_LanguageStandard_MODELICA__3__3__desc_added
#define RTOptsData_LanguageStandard_MODELICA__3__3__desc_added
ADD_METARECORD_DEFINTIONS const char* RTOptsData_LanguageStandard_MODELICA__3__3__desc__fields[1] = {"no fileds"};
ADD_METARECORD_DEFINTIONS struct record_description RTOptsData_LanguageStandard_MODELICA__3__3__desc = {
"RTOptsData_LanguageStandard_MODELICA__3__3",
"RTOptsData.LanguageStandard.MODELICA_3_3",
RTOptsData_LanguageStandard_MODELICA__3__3__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description RTOptsData_LanguageStandard_MODELICA__3__3__desc;
#endif
#define RTOptsData__MODELICA_5f3_5f3_3dBOX0 8
static const MMC_DEFSTRUCTLIT(RTOptsData__MODELICA_5f3_5f3__struct,1,8) {&RTOptsData_LanguageStandard_MODELICA__3__3__desc}};
static void *RTOptsData__MODELICA_5f3_5f3 = MMC_REFSTRUCTLIT(RTOptsData__MODELICA_5f3_5f3__struct);
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef RTOptsData_LanguageStandard_MODELICA__LATEST__desc_added
#define RTOptsData_LanguageStandard_MODELICA__LATEST__desc_added
ADD_METARECORD_DEFINTIONS const char* RTOptsData_LanguageStandard_MODELICA__LATEST__desc__fields[1] = {"no fileds"};
ADD_METARECORD_DEFINTIONS struct record_description RTOptsData_LanguageStandard_MODELICA__LATEST__desc = {
"RTOptsData_LanguageStandard_MODELICA__LATEST",
"RTOptsData.LanguageStandard.MODELICA_LATEST",
RTOptsData_LanguageStandard_MODELICA__LATEST__desc__fields
};
#endif
#else /* Only use the file as a header */
extern struct record_description RTOptsData_LanguageStandard_MODELICA__LATEST__desc;
#endif
#define RTOptsData__MODELICA_5fLATEST_3dBOX0 9
static const MMC_DEFSTRUCTLIT(RTOptsData__MODELICA_5fLATEST__struct,1,9) {&RTOptsData_LanguageStandard_MODELICA__LATEST__desc}};
static void *RTOptsData__MODELICA_5fLATEST = MMC_REFSTRUCTLIT(RTOptsData__MODELICA_5fLATEST__struct);
#ifdef ADD_METARECORD_DEFINTIONS
#ifndef Error_Severity_ERROR__desc_added
#define Error_Severity_ERROR__desc_added
ADD_METARECORD_DEFINTIONS const char* Error_Severity_ERROR__desc__fields[1] = {"no fileds"};
Expand Down
7 changes: 7 additions & 0 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -87,6 +87,7 @@ protected import Parser;
protected import Print;
protected import Refactor;
protected import RTOpts;
protected import RTOptsData;
protected import SCodeDump;
protected import SCodeFlatten;
protected import SimCode;
Expand Down Expand Up @@ -1132,6 +1133,12 @@ algorithm
then
(cache,Values.BOOL(b),st);

case (cache,env,"getLanguageStandard",{},st,msg)
equation
res = RTOptsData.languageStandardString(RTOpts.getLanguageStandard());
then
(cache,Values.STRING(res),st);

case (cache,env,"buildModel",vals,st,msg)
equation
(cache,compileDir,executable,method_str,outputFormat_str,st,initfilename,_) = buildModel(cache,env, vals, st, msg);
Expand Down
11 changes: 11 additions & 0 deletions Compiler/Util/RTOpts.mo
Expand Up @@ -41,6 +41,7 @@ encapsulated package RTOpts

This module is used pretty much everywhere where debug calls are made."

public import RTOptsData;

public function args
input list<String> inStringLst;
Expand Down Expand Up @@ -278,5 +279,15 @@ public function simCodeTarget "Default is set by +simCodeTarget=C"
external "C" target=RTOpts_simCodeTarget() annotation(Library = "omcruntime");
end simCodeTarget;

public function getLanguageStandard
output RTOptsData.LanguageStandard outStandard;
external "C" outStandard = RTOpts_getLanguageStandard();
end getLanguageStandard;

public function setLanguageStandard
input RTOptsData.LanguageStandard inStandard;
external "C" RTOpts_setLanguageStandard(inStandard);
end setLanguageStandard;

end RTOpts;

0 comments on commit 3c8db16

Please sign in to comment.