Skip to content

Commit

Permalink
loadFile(".../package.mo") ignores MODELICAPATH
Browse files Browse the repository at this point in the history
Note: If the same directory contains other libraries that are loaded
according to uses-annotations, the full MODELICAPATH is used for these.
This means you might end up loading only one of the packages from the
given directory.

Belonging to [master]:
  - OpenModelica/OMCompiler#2092
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Jan 3, 2018
1 parent 775a336 commit 5aac106
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Compiler/Main/Main.mo
Expand Up @@ -441,7 +441,7 @@ algorithm
path = Absyn.stringPath(inLib);
mp = Settings.getModelicaPath(Config.getRunningTestsuite());
p = GlobalScriptUtil.getSymbolTableAST(inSymTab);
(pnew, true) = CevalScript.loadModel({(path, {"default"})}, mp, p, true, true, true, false);
(pnew, true) = CevalScript.loadModel({(path, {"default"}, false)}, mp, p, true, true, true, false);
newst = GlobalScriptUtil.setSymbolTableAST(inSymTab, pnew);
then
newst;
Expand Down
32 changes: 19 additions & 13 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -323,7 +323,7 @@ algorithm
// see https://trac.openmodelica.org/OpenModelica/ticket/2422
// prio = if_(stringEq(prio,""), "default", prio);
mp = System.realpath(dir + "/../") + System.groupDelimiter() + Settings.getModelicaPath(Config.getRunningTestsuite());
(p1,true) = loadModel((Absyn.IDENT(cname),{prio})::{}, mp, p, true, true, checkUses, true);
(p1,true) = loadModel((Absyn.IDENT(cname),{prio},true)::{}, mp, p, true, true, checkUses, true);
then p1;

case (_, _, _, _)
Expand Down Expand Up @@ -351,7 +351,7 @@ protected type LoadModelFoldArg =
tuple<String /*modelicaPath*/, Boolean /*forceLoad*/, Boolean /*notifyLoad*/, Boolean /*checkUses*/, Boolean /*requireExactVersion*/>;

public function loadModel
input list<tuple<Absyn.Path,list<String>>> imodelsToLoad;
input list<tuple<Absyn.Path,list<String>,Boolean /* Only use the first entry on the MODELICAPATH */>> imodelsToLoad;
input String modelicaPath;
input Absyn.Program ip;
input Boolean forceLoad;
Expand All @@ -367,28 +367,34 @@ algorithm
end loadModel;

protected function loadModel1
input tuple<Absyn.Path,list<String>> modelToLoad;
input tuple<Absyn.Path,list<String>,Boolean> modelToLoad;
input LoadModelFoldArg inArg;
input tuple<Absyn.Program, Boolean> inTpl;
output tuple<Absyn.Program, Boolean> outTpl;
protected
list<tuple<Absyn.Path,list<String>>> modelsToLoad;
Boolean b, b1, success, forceLoad, notifyLoad, checkUses, requireExactVersion;
list<tuple<Absyn.Path,list<String>,Boolean>> modelsToLoad;
Boolean b, b1, success, forceLoad, notifyLoad, checkUses, requireExactVersion, onlyCheckFirstModelicaPath;
Absyn.Path path;
list<String> versionsLst;
String pathStr, versions, className, version, modelicaPath;
String pathStr, versions, className, version, modelicaPath, thisModelicaPath;
Absyn.Program p, pnew;
Error.MessageTokens msgTokens;
algorithm
(path, versionsLst) := modelToLoad;
(path, versionsLst, onlyCheckFirstModelicaPath) := modelToLoad;
(modelicaPath, forceLoad, notifyLoad, checkUses, requireExactVersion) := inArg;
if onlyCheckFirstModelicaPath then
/* Using loadFile() */
thisModelicaPath::_ := System.strtok(modelicaPath, System.groupDelimiter());
else
thisModelicaPath := modelicaPath;
end if;
try
(p, success) := inTpl;
if checkModelLoaded(modelToLoad, p, forceLoad, NONE()) then
pnew := Absyn.PROGRAM({}, Absyn.TOP());
version := "";
else
pnew := ClassLoader.loadClass(path, versionsLst, modelicaPath, NONE(), requireExactVersion);
pnew := ClassLoader.loadClass(path, versionsLst, thisModelicaPath, NONE(), requireExactVersion);
version := getPackageVersion(path, pnew);
b := not notifyLoad or forceLoad;
msgTokens := {Absyn.pathString(path), version};
Expand All @@ -406,7 +412,7 @@ algorithm
(p, _) := inTpl;
pathStr := Absyn.pathString(path);
versions := stringDelimitList(versionsLst, ",");
msgTokens := {pathStr, versions, modelicaPath};
msgTokens := {pathStr, versions, thisModelicaPath};
if forceLoad then
Error.addMessage(Error.LOAD_MODEL, msgTokens);
outTpl := (p, false);
Expand All @@ -418,7 +424,7 @@ algorithm
end loadModel1;

protected function checkModelLoaded
input tuple<Absyn.Path,list<String>> tpl;
input tuple<Absyn.Path,list<String>,Boolean> tpl;
input Absyn.Program p;
input Boolean forceLoad;
input Option<String> failNonLoad;
Expand All @@ -432,14 +438,14 @@ algorithm
Absyn.Path path;

case (_,_,true,_) then false;
case ((path,str1::_),_,false,_)
case ((path,str1::_,_),_,false,_)
equation
cdef = Interactive.getPathedClassInProgram(path,p);
ostr2 = Absyn.getNamedAnnotationInClass(cdef,Absyn.IDENT("version"),Interactive.getAnnotationStringValueOrFail);
checkValidVersion(path,str1,ostr2);
then true;
case (_,_,_,NONE()) then false;
case ((path,_),_,_,SOME(str2))
case ((path,_,_),_,_,SOME(str2))
equation
str1 = Absyn.pathString(path);
Error.addMessage(Error.INST_NON_LOADED, {str1,str2});
Expand Down Expand Up @@ -1353,7 +1359,7 @@ algorithm
if b1 then
Config.setLanguageStandard(Config.versionStringToStd(str));
end if;
(p,b) = loadModel({(path,strings)},mp,p,true,b,true,requireExactVersion);
(p,b) = loadModel({(path,strings,false)},mp,p,true,b,true,requireExactVersion);
if b1 then
Config.setLanguageStandard(oldLanguageStd);
end if;
Expand Down
24 changes: 12 additions & 12 deletions Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -735,7 +735,7 @@ algorithm
GlobalScript.SimulationOptions defaulSimOpt;
SimCode.SimulationSettings simSettings;
Boolean dumpExtractionSteps, requireExactVersion;
list<tuple<Absyn.Path,list<String>>> uses;
list<tuple<Absyn.Path,list<String>,Boolean>> uses;
Config.LanguageStandard oldLanguageStd;
SCode.Element cl;
list<SCode.Element> cls, elts;
Expand Down Expand Up @@ -1418,24 +1418,24 @@ algorithm

case (cache,env,"buildLabel",vals,st,_)
equation
Flags.setConfigBool(Flags.GENERATE_LABELED_SIMCODE, true);
//Flags.set(Flags.WRITE_TO_BUFFER,true);
List.map_0(ClockIndexes.buildModelClocks,System.realtimeClear);
Flags.setConfigBool(Flags.GENERATE_LABELED_SIMCODE, true);
//Flags.set(Flags.WRITE_TO_BUFFER,true);
List.map_0(ClockIndexes.buildModelClocks,System.realtimeClear);
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMULATE_TOTAL);
(cache,st,compileDir,executable,_,_,initfilename,_,_) = buildModel(cache,env, vals, st, msg);
(cache,st,compileDir,executable,_,_,initfilename,_,_) = buildModel(cache,env, vals, st, msg);
then
(cache,ValuesUtil.makeArray({Values.STRING(executable),Values.STRING(initfilename)}),st);

case (cache,env,"reduceTerms",vals,st,_)
equation
Flags.setConfigBool(Flags.REDUCE_TERMS, true);
// Flags.setConfigBool(Flags.DISABLE_EXTRA_LABELING, true);
Flags.setConfigBool(Flags.GENERATE_LABELED_SIMCODE, false);
_=Flags.disableDebug(Flags.WRITE_TO_BUFFER);
List.map_0(ClockIndexes.buildModelClocks,System.realtimeClear);
Flags.setConfigBool(Flags.GENERATE_LABELED_SIMCODE, false);
_=Flags.disableDebug(Flags.WRITE_TO_BUFFER);
List.map_0(ClockIndexes.buildModelClocks,System.realtimeClear);
System.realtimeTick(ClockIndexes.RT_CLOCK_SIMULATE_TOTAL);

(cache,st,compileDir,executable,_,_,initfilename,_,_) = buildLabeledModel(cache,env, vals, st, msg);
(cache,st,compileDir,executable,_,_,initfilename,_,_) = buildLabeledModel(cache,env, vals, st, msg);
then
(cache,ValuesUtil.makeArray({Values.STRING(executable),Values.STRING(initfilename)}),st);
case(cache,env,"buildOpenTURNSInterface",vals,st,_)
Expand Down Expand Up @@ -2960,7 +2960,7 @@ algorithm
case (_, GlobalScript.SYMBOLTABLE(p,fp,ic,iv,cf,lf))
equation
str = Absyn.pathFirstIdent(className);
(p,b) = CevalScript.loadModel({(Absyn.IDENT(str),{"default"})},Settings.getModelicaPath(Config.getRunningTestsuite()),p,true,true,true,false);
(p,b) = CevalScript.loadModel({(Absyn.IDENT(str),{"default"},false)},Settings.getModelicaPath(Config.getRunningTestsuite()),p,true,true,true,false);
Error.assertionOrAddSourceMessage(not b,Error.NOTIFY_NOT_LOADED,{str,"default"},Absyn.dummyInfo);
// print(stringDelimitList(list(Absyn.pathString(path) for path in Interactive.getTopClassnames(p)), ",") + "\n");
then GlobalScript.SYMBOLTABLE(p,fp,ic,iv,cf,lf);
Expand Down Expand Up @@ -7082,14 +7082,14 @@ algorithm
end searchClassNames;

protected function makeUsesArray
input tuple<Absyn.Path,list<String>> inTpl;
input tuple<Absyn.Path,list<String>,Boolean> inTpl;
output Values.Value v;
algorithm
v := match inTpl
local
Absyn.Path p;
String pstr,ver;
case ((p,{ver}))
case ((p,{ver},_))
equation
pstr = Absyn.pathString(p);
then ValuesUtil.makeArray({Values.STRING(pstr),Values.STRING(ver)});
Expand Down
26 changes: 13 additions & 13 deletions Compiler/Script/Interactive.mo
Expand Up @@ -8916,9 +8916,9 @@ algorithm
/*update case*/(boolNot(intEq(l1_1, l2)) and isSome(item)) and success) then
parts2 = replacePublicList(parts, publst2);
else
protlst = getProtectedList(parts);
protlst2 = deleteOrUpdateComponentFromElementitems(name, protlst, item);
parts2 = replaceProtectedList(parts, protlst2);
protlst = getProtectedList(parts);
protlst2 = deleteOrUpdateComponentFromElementitems(name, protlst, item);
parts2 = replaceProtectedList(parts, protlst2);
end if;
then
Absyn.CLASS(i,p,f,e,r,Absyn.CLASS_EXTENDS(bcpath,mod,cmt,parts2,ann),file_info);
Expand Down Expand Up @@ -11516,7 +11516,7 @@ public function getUsesAnnotation
string of values for the Documentation annotation for the class named by the
first argument."
input Absyn.Program p;
output list<tuple<Absyn.Path,list<String>>> usesStr;
output list<tuple<Absyn.Path,list<String>,Boolean>> usesStr;
algorithm
usesStr := matchcontinue (p)
local
Expand All @@ -11538,23 +11538,23 @@ public function getUsesAnnotationOrDefault
first argument."
input Absyn.Program p;
input Boolean requireExactVersion;
output list<tuple<Absyn.Path,list<String>>> usesStr;
output list<tuple<Absyn.Path,list<String>,Boolean>> usesStr;
protected
list<Absyn.Path> paths;
list<list<String>> strs;
algorithm
usesStr := getUsesAnnotation(p);
paths := List.map(usesStr,Util.tuple21);
strs := List.map(usesStr,Util.tuple22);
paths := List.map(usesStr,Util.tuple31);
strs := List.map(usesStr,Util.tuple32);
if not requireExactVersion then
strs := List.map1(strs,listAppend,{"default"});
end if;
usesStr := List.threadTuple(paths,strs);
usesStr := list((p,s,false) threaded for p in paths, s in strs);
end getUsesAnnotationOrDefault;

protected function getUsesAnnotationString
input Option<Absyn.Modification> mod;
output list<tuple<Absyn.Path,list<String>>> usesStr;
output list<tuple<Absyn.Path,list<String>,Boolean>> usesStr;
algorithm
usesStr := match (mod)
local
Expand All @@ -11568,13 +11568,13 @@ end getUsesAnnotationString;

protected function getUsesAnnotationString2
input list<Absyn.ElementArg> eltArgs;
output list<tuple<Absyn.Path,list<String>>> strs;
output list<tuple<Absyn.Path,list<String>,Boolean>> strs;
algorithm
strs := match eltArgs
local
list<Absyn.ElementArg> xs;
String name, version;
list<tuple<Absyn.Path,list<String>>> ss;
list<tuple<Absyn.Path,list<String>,Boolean>> ss;
Absyn.Info info;

case ({}) then {};
Expand All @@ -11585,13 +11585,13 @@ algorithm
})))::xs)
equation
ss = getUsesAnnotationString2(xs);
then (Absyn.IDENT(name),{version})::ss;
then (Absyn.IDENT(name),{version},false)::ss;

case (Absyn.MODIFICATION(info = info, path = Absyn.IDENT(name = name))::xs)
equation
Error.addSourceMessage(Error.USES_MISSING_VERSION, {name}, info);
ss = getUsesAnnotationString2(xs);
then (Absyn.IDENT(name),{"default"})::ss;
then (Absyn.IDENT(name),{"default"},false)::ss;

case (_::xs)
equation
Expand Down

0 comments on commit 5aac106

Please sign in to comment.