Skip to content

Commit

Permalink
Evaluate uriToFilename in the script environment
Browse files Browse the repository at this point in the history
Added a new internal flag that keeps track of if we are translating
a model or not.

Belonging to [master]:
  - OpenModelica/OMCompiler#2125
  - OpenModelica/OpenModelica-testsuite#833
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Jan 29, 2018
1 parent 75770db commit fbbbe20
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 7 additions & 3 deletions Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -1361,9 +1361,11 @@ algorithm
print("The following path is a loaded resource... "+res+"\n");
fail();
end if;
then
(cache,Values.STRING(res));
/* Note: Do not evaluate uriToFilename if it says it fails. We need simulations to be able to report URI not found */
then (cache,Values.STRING(res));
/* Note: Only evaluate uriToFilename during scripting. We need simulations to be able to report URI not found */
case (cache,_,"OpenModelica_uriToFilename",_,_)
guard not Flags.getConfigBool(Flags.BUILDING_MODEL)
then (cache,Values.STRING(""));

case (cache,_,"getAnnotationVersion",{},_)
equation
Expand Down Expand Up @@ -2936,6 +2938,7 @@ protected
algorithm
// add program to the cache so it can be used to lookup modelica://
// URIs in external functions IncludeDirectory/LibraryDirectory
Flags.setConfigBool(Flags.BUILDING_MODEL, true);
try
b := runFrontEndLoadProgram(className);
true := b;
Expand All @@ -2951,6 +2954,7 @@ algorithm
else
// Return odae=NONE(); needed to update cache and symbol table if we fail
end try;
Flags.setConfigBool(Flags.BUILDING_MODEL, false);
end runFrontEnd;

protected function runFrontEndLoadProgram
Expand Down
2 changes: 2 additions & 0 deletions Compiler/SimCode/SimCodeMain.mo
Expand Up @@ -740,6 +740,7 @@ protected
type State = enumeration(frontend, backend, templates, simcode);
State state = State.frontend;
algorithm
Flags.setConfigBool(Flags.BUILDING_MODEL, true);
(success, outBackendDAE, outStringLst, outFileDir) :=
matchcontinue (inEnv, className, inFileNamePrefix, addDummy, inSimSettingsOpt, args)
local
Expand Down Expand Up @@ -891,6 +892,7 @@ algorithm
("timeSimCode", Values.REAL(timeSimCode)),
("timeBackend", Values.REAL(timeBackend)),
("timeFrontend", Values.REAL(timeFrontend))};
Flags.setConfigBool(Flags.BUILDING_MODEL, false);
end translateModel;

protected function serializeNotify<T>
Expand Down
8 changes: 7 additions & 1 deletion Compiler/Util/Flags.mo
Expand Up @@ -1427,6 +1427,11 @@ constant ConfigFlag IGNORE_REPLACEABLE = CONFIG_FLAG(117, "ignoreReplaceable",
constant ConfigFlag BUILDING_FMU = CONFIG_FLAG(122,
"", NONE(), INTERNAL(), BOOL_FLAG(false), NONE(),
Util.gettext("Is true when building an FMU (so the compiler can look for URIs to package as FMI resources)."));

constant ConfigFlag BUILDING_MODEL = CONFIG_FLAG(123,
"", NONE(), INTERNAL(), BOOL_FLAG(false), NONE(),
Util.gettext("Is true when building a model (as opposed to running a Modelica script)."));

protected
// This is a list of all configuration flags. A flag can not be used unless it's
// in this list, and the list is checked at initialization so that all flags are
Expand Down Expand Up @@ -1553,7 +1558,8 @@ constant list<ConfigFlag> allConfigFlags = {
DISABLE_EXTRA_LABELING,
LOAD_MSL_MODEL,
Load_PACKAGE_FILE,
BUILDING_FMU
BUILDING_FMU,
BUILDING_MODEL
};

public function new
Expand Down

0 comments on commit fbbbe20

Please sign in to comment.