Skip to content

Commit

Permalink
Improve library loading for conversion (#8735)
Browse files Browse the repository at this point in the history
- Only load the library to convert to if it isn't already loaded.
- Try to set the language standard to the version needed to load the
  library to convert to, in case another version was already loaded with
  a different language standard.
  • Loading branch information
perost committed Mar 21, 2022
1 parent 480e8f6 commit ba24aff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
25 changes: 19 additions & 6 deletions OMCompiler/Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -8717,6 +8717,7 @@ protected
SemanticVersion.Version lib_version, lib_version_used;
list<tuple<String, Option<String>, Option<String>>> conversions;
list<String> scripts;
String lib_name;
algorithm
try
// Get the Absyn for the class and check which version of the library it's using.
Expand All @@ -8732,12 +8733,24 @@ algorithm
fail();
end if;

// Load the library that we want to convert the class to.
(lib_program, true) := CevalScript.loadModel(
{(libPath, AbsynUtil.pathFirstIdent(libPath), {libVersion}, false)},
Settings.getModelicaPath(Testsuite.isRunning()),
p, true, true, false, true);
SymbolTable.setAbsyn(lib_program);
lib_name := AbsynUtil.pathFirstIdent(libPath);
lib_version := SemanticVersion.parse(CevalScript.getPackageVersion(libPath, p));

// Check if the wanted version of the library is already loaded, otherwise
// we need to load it.
if SemanticVersion.compare(lib_version, SemanticVersion.parse(libVersion)) <> 0 then
// Try to set the language standard to the version needed to load the wanted library.
if lib_name == "Modelica" then
Config.setLanguageStandardFromMSL("Modelica " + libVersion, force = true);
end if;

// Load the library that we want to convert the class to.
(lib_program, true) := CevalScript.loadModel({(libPath, lib_name, {libVersion}, false)},
Settings.getModelicaPath(Testsuite.isRunning()), p, true, true, false, true);
SymbolTable.setAbsyn(lib_program);
else
lib_program := p;
end if;

// Get the version of the library.
lib_version := SemanticVersion.parse(CevalScript.getPackageVersion(libPath, lib_program));
Expand Down
3 changes: 2 additions & 1 deletion OMCompiler/Compiler/Util/Config.mo
Expand Up @@ -490,11 +490,12 @@ end languageStandardString;

public function setLanguageStandardFromMSL
input String inLibraryName;
input Boolean force = false "Set the standard even if it was already set";
protected
LanguageStandard current_std;
algorithm
current_std := getLanguageStandard();
if current_std <> LanguageStandard.latest then
if not force and current_std <> LanguageStandard.latest then
// If we selected an MSL version manually, we respect that choice.
return;
end if;
Expand Down

0 comments on commit ba24aff

Please sign in to comment.