Skip to content

Commit

Permalink
Fixes ticket:6133 Made loadFile and loadModel behave same (#6784)
Browse files Browse the repository at this point in the history
Enable notifications for all except loadModel
OMEdit has notifications enabled on all by default
Update NFFrontEnd/NFModelicaBuiltin.mo accordingly
  • Loading branch information
adeas31 committed Oct 9, 2020
1 parent 3ce8f83 commit d4ecd07
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 25 deletions.
11 changes: 11 additions & 0 deletions OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo
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.";
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
11 changes: 11 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo
Expand Up @@ -1344,6 +1344,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.";
output Boolean success;
external "builtin";
annotation(Documentation(info="<html>
Expand All @@ -1360,6 +1362,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 @@ -1379,6 +1384,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 @@ -1435,6 +1443,9 @@ end parseFile;
function loadFileInteractiveQualified
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
28 changes: 16 additions & 12 deletions OMCompiler/Compiler/Script/CevalScript.mo
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
Expand Up @@ -176,9 +176,11 @@ int LoadFile(data* omcData, const char* fileName)
modelica_boolean result;
std::string encoding = "UTF-8";
modelica_boolean uses = true; //Uses-annotations
modelica_boolean notify = false;
modelica_boolean requireExactVersion = false;

MMC_TRY_TOP_SET(omcData->threadData)
result = omc_OpenModelicaScriptingAPI_loadFile(threadData, mmc_mk_scon(fileName), mmc_mk_scon(encoding.c_str()), uses);
result = omc_OpenModelicaScriptingAPI_loadFile(threadData, mmc_mk_scon(fileName), mmc_mk_scon(encoding.c_str()), uses, notify, requireExactVersion);
CP_TD();
MMC_CATCH_TOP(return -1)

Expand Down
8 changes: 4 additions & 4 deletions OMEdit/OMEditLIB/OMC/OMCProxy.cpp
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
7 changes: 3 additions & 4 deletions OMEdit/OMEditLIB/OMC/OMCProxy.h
Expand Up @@ -154,9 +154,8 @@ class OMCProxy : public QObject
QList<QString> getDocumentationAnnotationInClass(LibraryTreeItem *pLibraryTreeItem);
QString getClassComment(QString className);
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 loadModel(QString className, QString priorityVersion = QString("default"), bool notify = true, QString languageStandard = QString(""), bool requireExactVersion = false);
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 +267,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
Expand Up @@ -28,14 +28,14 @@ checkModel(FourBar.TestPlanarLoops); getErrorString();

// Result:
// true
// ""
// "Check of Aufgabe1_1 completed successfully.
// Class Aufgabe1_1 has 52 equation(s) and 52 variable(s).
// 39 of these are trivial equation(s)."
// "Notification: Automatically loaded package Modelica 3.2.1 due to uses annotation.
// Notification: Automatically loaded package Complex 3.2.1 due to uses annotation.
// Notification: Automatically loaded package ModelicaServices 3.2.1 due to uses annotation.
// "
// "Check of Aufgabe1_1 completed successfully.
// Class Aufgabe1_1 has 52 equation(s) and 52 variable(s).
// 39 of these are trivial equation(s)."
// ""
// "Check of Aufgabe1_2 completed successfully.
// Class Aufgabe1_2 has 89 equation(s) and 89 variable(s).
// 61 of these are trivial equation(s)."
Expand Down

0 comments on commit d4ecd07

Please sign in to comment.