Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes ticket:6133 Made loadFile and loadModel behave same #6784

Merged
merged 6 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,8 @@ function loadFile "load file (*.mo) and merge it with the loaded AST."
input String fileName;
input String encoding = "UTF-8";
input Boolean uses = true;
input Boolean notify = true "Give a notification of the libraries and versions that were loaded";
input Boolean requireExactVersion = false "If the version is required to be exact, if there is a uses Modelica(version=\"3.2\"), Modelica 3.2.1 will not match it.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does requireExactVersion mean for loadFile and friends? Don't you already point to the version you wanted to load?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its for the version of the uses annotation library.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you are changing how loadModel works since that was always true. And your commit comment has nothing about this change in behaviour (only notify).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is even how loadModel is working. Try the test model in ticket:6133 with loadModel. By default it loads the PowerSystems library version 1.0.0 and if you specify requireExactVersion to true then it skips loading it since the version specified in uses annotation is uses(PowerSystems(version = "0.9.0")).

So this PR is not changing anything with loadModel.

output Boolean success;
external "builtin";
annotation(Documentation(info="<html>
Expand All @@ -1142,6 +1144,9 @@ function loadFiles "load files (*.mo) and merges them with the loaded AST."
input String[:] fileNames;
input String encoding = "UTF-8";
input Integer numThreads = OpenModelica.Scripting.numProcessors();
input Boolean uses = true;
input Boolean notify = true "Give a notification of the libraries and versions that were loaded";
input Boolean requireExactVersion = false "If the version is required to be exact, if there is a uses Modelica(version=\"3.2\"), Modelica 3.2.1 will not match it.";
output Boolean success;
external "builtin";
annotation(preferredView="text");
Expand All @@ -1161,6 +1166,9 @@ function loadEncryptedPackage
input String fileName;
input String workdir = "<default>" "The output directory for imported encrypted files. <default> will put the files to current working directory.";
input Boolean skipUnzip = false "Skips the unzip of .mol if true. In that case we expect the files are already extracted e.g., because of parseEncryptedPackage() call.";
input Boolean uses = true;
input Boolean notify = true "Give a notification of the libraries and versions that were loaded";
input Boolean requireExactVersion = false "If the version is required to be exact, if there is a uses Modelica(version=\"3.2\"), Modelica 3.2.1 will not match it.";
output Boolean success;
external "builtin";
annotation(Documentation(info="<html>
Expand Down Expand Up @@ -1225,6 +1233,9 @@ end loadFileInteractiveQualified;
function loadFileInteractive
input String filename;
input String encoding = "UTF-8";
input Boolean uses = true;
input Boolean notify = true "Give a notification of the libraries and versions that were loaded";
input Boolean requireExactVersion = false "If the version is required to be exact, if there is a uses Modelica(version=\"3.2\"), Modelica 3.2.1 will not match it.";
output TypeName names[:];
external "builtin";
annotation(preferredView="text");
Expand Down Expand Up @@ -2084,7 +2095,7 @@ end generateCode;
function loadModel "Loads the Modelica Standard Library."
input TypeName className;
input String[:] priorityVersion = {"default"};
input Boolean notify = false "Give a notification of the libraries and versions that were loaded";
input Boolean notify = true "Give a notification of the libraries and versions that were loaded";
input String languageStandard = "" "Override the set language standard. Parse with the given setting, but do not change it permanently.";
input Boolean requireExactVersion = false "If the version is required to be exact, if there is a uses Modelica(version=\"3.2\"), Modelica 3.2.1 will not match it.";
output Boolean success;
Expand Down
28 changes: 16 additions & 12 deletions OMCompiler/Compiler/Script/CevalScript.mo
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ protected function loadFile "load the file or the directory structure if the fil
input String encoding;
input Absyn.Program p;
input Boolean checkUses;
input Boolean notifyLoad;
input Boolean requireExactVersion;
output Absyn.Program outProgram;
protected
String dir,filename,cname,prio,mp;
Expand All @@ -321,25 +323,27 @@ algorithm
// see https://trac.openmodelica.org/OpenModelica/ticket/2422
// prio = if_(stringEq(prio,""), "default", prio);
mp := System.realpath(dir + "/../") + Autoconf.groupDelimiter + Settings.getModelicaPath(Testsuite.isRunning());
(outProgram,true) := loadModel((Absyn.IDENT(cname),"loadFile automatically converted to loadModel",{prio},true)::{}, mp, p, true, true, checkUses, true, filename == "package.moc");
(outProgram,true) := loadModel((Absyn.IDENT(cname),"loadFile automatically converted to loadModel",{prio},true)::{}, mp, p, true, notifyLoad, checkUses, requireExactVersion, filename == "package.moc");
return;
end if;
outProgram := Parser.parse(name,encoding);
ClassLoader.checkOnLoadMessage(outProgram);
outProgram := checkUsesAndUpdateProgram(outProgram, p, checkUses, Settings.getModelicaPath(Testsuite.isRunning()));
outProgram := checkUsesAndUpdateProgram(outProgram, p, checkUses, Settings.getModelicaPath(Testsuite.isRunning()), notifyLoad, requireExactVersion);
end loadFile;

protected function checkUsesAndUpdateProgram
input Absyn.Program newp;
input output Absyn.Program p;
input Boolean checkUses;
input String modelicaPath;
input Boolean notifyLoad;
input Boolean requireExactVersion;
protected
list<tuple<Absyn.Path,String,list<String>,Boolean>> modelsToLoad;
algorithm
modelsToLoad := if checkUses then Interactive.getUsesAnnotationOrDefault(newp, requireExactVersion=true) else {};
modelsToLoad := if checkUses then Interactive.getUsesAnnotationOrDefault(newp, requireExactVersion) else {};
p := Interactive.updateProgram(newp, p);
(p, _) := loadModel(modelsToLoad, modelicaPath, p, false, true, true, true, false);
(p, _) := loadModel(modelsToLoad, modelicaPath, p, false, notifyLoad, checkUses, requireExactVersion, false);
end checkUsesAndUpdateProgram;

protected type LoadModelFoldArg =
Expand Down Expand Up @@ -653,9 +657,9 @@ algorithm
vals = List.map(paths,ValuesUtil.makeCodeTypeName);
then (cache,ValuesUtil.makeArray(vals));

case (cache,_,"loadFileInteractive",{Values.STRING(str1),Values.STRING(encoding)},_)
case (cache,_,"loadFileInteractive",{Values.STRING(str1),Values.STRING(encoding),Values.BOOL(b),Values.BOOL(b1),Values.BOOL(requireExactVersion)},_)
equation
pnew = loadFile(str1, encoding, SymbolTable.getAbsyn(), false) "System.regularFileExists(name) => 0 & Parser.parse(name) => p1 &" ;
pnew = loadFile(str1, encoding, SymbolTable.getAbsyn(), b, b1, requireExactVersion) "System.regularFileExists(name) => 0 & Parser.parse(name) => p1 &" ;
vals = List.map(Interactive.getTopClassnames(pnew),ValuesUtil.makeCodeTypeName);
SymbolTable.setAbsyn(pnew);
then (cache,ValuesUtil.makeArray(vals));
Expand Down Expand Up @@ -1464,11 +1468,11 @@ algorithm
then
(cache,Values.BOOL(false));

case (_,_,"loadFile",Values.STRING(name)::Values.STRING(encoding)::Values.BOOL(b)::_,_)
case (_,_,"loadFile",Values.STRING(name)::Values.STRING(encoding)::Values.BOOL(b)::Values.BOOL(b1)::Values.BOOL(requireExactVersion)::_,_)
equation
execStatReset();
name = Testsuite.friendlyPath(name);
newp = loadFile(name, encoding, SymbolTable.getAbsyn(), b);
newp = loadFile(name, encoding, SymbolTable.getAbsyn(), b, b1, requireExactVersion);
execStat("loadFile("+name+")");
SymbolTable.setAbsyn(newp);
then
Expand All @@ -1477,11 +1481,11 @@ algorithm
case (cache,_,"loadFile",_,_)
then (cache,Values.BOOL(false));

case (_,_,"loadFiles",Values.ARRAY(valueLst=vals)::Values.STRING(encoding)::Values.INTEGER(i)::_,_)
case (_,_,"loadFiles",Values.ARRAY(valueLst=vals)::Values.STRING(encoding)::Values.INTEGER(i)::Values.BOOL(b)::Values.BOOL(b1)::Values.BOOL(requireExactVersion)::_,_)
equation
strs = List.mapMap(vals,ValuesUtil.extractValueString,Testsuite.friendlyPath);
newps = Parser.parallelParseFilesToProgramList(strs,encoding,numThreads=i);
newp = List.fold(newps, function checkUsesAndUpdateProgram(checkUses=false, modelicaPath=Settings.getModelicaPath(Testsuite.isRunning())), SymbolTable.getAbsyn());
newp = List.fold(newps, function checkUsesAndUpdateProgram(checkUses=b, modelicaPath=Settings.getModelicaPath(Testsuite.isRunning()), notifyLoad=b1, requireExactVersion=requireExactVersion), SymbolTable.getAbsyn());
SymbolTable.setAbsyn(newp);
then
(FCore.emptyCache(),Values.BOOL(true));
Expand All @@ -1505,14 +1509,14 @@ algorithm
end if;
then (cache,ValuesUtil.makeArray(vals));

case (_,_,"loadEncryptedPackage",Values.STRING(filename)::Values.STRING(workdir)::Values.BOOL(bval)::_,_)
case (_,_,"loadEncryptedPackage",Values.STRING(filename)::Values.STRING(workdir)::Values.BOOL(bval)::Values.BOOL(b)::Values.BOOL(b1)::Values.BOOL(requireExactVersion)::_,_)
equation
(b, filename_1) = unZipEncryptedPackageAndCheckFile(workdir, filename, bval);
if (b) then
execStatReset();
filename_1 = Testsuite.friendlyPath(filename_1);
p = SymbolTable.getAbsyn();
newp = loadFile(filename_1, "UTF-8", p, true);
newp = loadFile(filename_1, "UTF-8", p, b, b1, requireExactVersion);
execStat("loadFile("+filename_1+")");
SymbolTable.setAbsyn(newp);
end if;
Expand Down
8 changes: 4 additions & 4 deletions OMEdit/OMEditLIB/OMC/OMCProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1579,11 +1579,11 @@ bool OMCProxy::loadModel(QString className, QString priorityVersion, bool notify
\param fileName - the file to load.
\return true on success
*/
bool OMCProxy::loadFile(QString fileName, QString encoding, bool uses)
bool OMCProxy::loadFile(QString fileName, QString encoding, bool uses, bool notify, bool requireExactVersion)
{
bool result = false;
fileName = fileName.replace('\\', '/');
result = mpOMCInterface->loadFile(fileName, encoding, uses);
result = mpOMCInterface->loadFile(fileName, encoding, uses, notify, requireExactVersion);
printMessagesStringInternal();
return result;
}
Expand Down Expand Up @@ -3273,9 +3273,9 @@ QList<QString> OMCProxy::parseEncryptedPackage(QString fileName, QString working
* \param workingDirectory
* \return
*/
bool OMCProxy::loadEncryptedPackage(QString fileName, QString workingDirectory, bool skipUnzip)
bool OMCProxy::loadEncryptedPackage(QString fileName, QString workingDirectory, bool skipUnzip, bool uses, bool notify, bool requireExactVersion)
{
bool result = mpOMCInterface->loadEncryptedPackage(fileName, workingDirectory, skipUnzip);
bool result = mpOMCInterface->loadEncryptedPackage(fileName, workingDirectory, skipUnzip, uses, notify, requireExactVersion);
printMessagesStringInternal();
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditLIB/OMC/OMCProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class OMCProxy : public QObject
QString changeDirectory(QString directory = QString(""));
bool loadModel(QString className, QString priorityVersion = QString("default"), bool notify = false, QString languageStandard = QString(""),
bool requireExactVersion = false);
bool loadFile(QString fileName, QString encoding = Helper::utf8, bool uses = true);
bool loadFile(QString fileName, QString encoding = Helper::utf8, bool uses = true, bool notify = true, bool requireExactVersion = false);
bool loadString(QString value, QString fileName, QString encoding = Helper::utf8, bool merge = false, bool checkError = true);
QList<QString> parseFile(QString fileName, QString encoding = Helper::utf8);
QList<QString> parseString(QString value, QString fileName, bool printErrors = true);
Expand Down Expand Up @@ -268,7 +268,7 @@ class OMCProxy : public QObject
QList<QList<QString > > getUses(QString className);
bool buildEncryptedPackage(QString className, bool encrypt = true);
QList<QString> parseEncryptedPackage(QString fileName, QString workingDirectory);
bool loadEncryptedPackage(QString fileName, QString workingDirectory, bool skipUnzip);
bool loadEncryptedPackage(QString fileName, QString workingDirectory, bool skipUnzip, bool uses = true, bool notify = true, bool requireExactVersion = false);
signals:
void commandFinished();
public slots:
Expand Down