Skip to content

Commit

Permalink
- Integrated the uses annotation with the loadModel command
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9106 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed May 25, 2011
1 parent 2d3378a commit 732a652
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 130 deletions.
33 changes: 0 additions & 33 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -109,38 +109,6 @@ uniontype Program
Within within_ "Within clause" ;
TimeStamp globalBuildTimes "";
end PROGRAM;

/*
adrpo: 2008-11-30 !THESE SEEMS NOT TO BE USED ANYMORE!
ModExtension: The following 3 nodes are not standard Modelica
Nodes such as BEGIN_DEFINITION and END_DEFINITION
can be used for representing packages and classes that are entered piecewise,
e.g., first entering the package head (as BEGIN_DEFINITION),
then the contained definitions, then an end package repesented as END_DEFINITION.
record BEGIN_DEFINITION
Path path "path for split definitions" ;
Restriction restriction "Class restriction" ;
Boolean partialPrefix "true if partial" ;
Boolean encapsulatedPrefix "true if encapsulated" ;
end BEGIN_DEFINITION;
record END_DEFINITION
Ident name "name for split definitions" ;
end END_DEFINITION;
record COMP_DEFINITION
ElementSpec element "element for split definitions" ;
Option<Path> insertInto "insert into, Default: NONE" ;
end COMP_DEFINITION;
record IMPORT_DEFINITION
ElementSpec importElementFor "For split definitions" ;
Option<Path> insertInto "Insert into, Default: NONE" ;
end IMPORT_DEFINITION;
*/

end Program;

public
Expand All @@ -150,7 +118,6 @@ uniontype Within "Within Clauses"
end WITHIN;

record TOP end TOP;

end Within;

public
Expand Down
85 changes: 82 additions & 3 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -579,6 +579,86 @@ algorithm
end matchcontinue;
end simOptionsAsString;

protected function loadModel
input list<tuple<Absyn.Path,list<String>>> modelsToLoad;
input String modelicaPath;
input Absyn.Program p;
input Boolean forceLoad;
output Absyn.Program pnew;
output Boolean success;
algorithm
(pnew,success) := matchcontinue (modelsToLoad,modelicaPath,p,forceLoad)
local
Absyn.Path path;
String pathStr,versions;
list<String> strings;
Boolean b,b1,b2;
case ({},_,p,_) then (p,true);
case ((path,strings)::modelsToLoad,modelicaPath,p,forceLoad)
equation
b = checkModelLoaded(path,strings,p,forceLoad);
pnew = Debug.bcallret3(not b, ClassLoader.loadClass, path, strings, modelicaPath, Absyn.PROGRAM({},Absyn.TOP(),Absyn.dummyTimeStamp));
p = Interactive.updateProgram(pnew, p);
(p,b1) = loadModel(Interactive.getUsesAnnotation(pnew),modelicaPath,p,false);
(p,b2) = loadModel(modelsToLoad,modelicaPath,p,forceLoad);
then (p,b1 and b2);
case ((path,strings)::_,modelicaPath,p,_)
equation
pathStr = Absyn.pathString(path);
versions = Util.stringDelimitList(strings,",");
Error.addMessage(Error.LOAD_MODEL,{pathStr,versions,modelicaPath});
then (p,false);
end matchcontinue;
end loadModel;

protected function checkModelLoaded
input Absyn.Path path;
input list<String> validVersions;
input Absyn.Program p;
input Boolean forceLoad;
output Boolean loaded;
algorithm
loaded := matchcontinue (path,validVersions,p,forceLoad)
local
Absyn.Class cdef;
String str1,str2;
Option<String> ostr2;
case (_,_,_,true) then false;
case (path,{str1},p,false)
equation
cdef = Interactive.getPathedClassInProgram(path,p);
ostr2 = Interactive.getNamedAnnotationInClass(cdef,"version",Interactive.getAnnotationStringValueOrFail);
checkValidVersion(path,str1,ostr2);
then true;
else false;
end matchcontinue;
end checkModelLoaded;

protected function checkValidVersion
input Absyn.Path path;
input String version;
input Option<String> actualVersion;
algorithm
_ := matchcontinue (path,version,actualVersion)
local
String pathStr,str1,str2;
case (_,str1,SOME(str2))
equation
true = stringEq(str1,str2);
then ();
case (path,str1,SOME(str2))
equation
pathStr = Absyn.pathString(path);
Error.addMessage(Error.LOAD_MODEL_DIFFERENT_VERSIONS,{pathStr,str1,str2});
then ();
case (path,str1,NONE())
equation
pathStr = Absyn.pathString(path);
Error.addMessage(Error.LOAD_MODEL_DIFFERENT_VERSIONS,{pathStr,str1,"unknown"});
then ();
end matchcontinue;
end checkValidVersion;

public function cevalInteractiveFunctions
"function cevalInteractiveFunctions
This function evaluates the functions
Expand Down Expand Up @@ -1290,12 +1370,11 @@ algorithm
equation
mp = Settings.getModelicaPath();
strings = Util.listMap(cvars, ValuesUtil.extractValueString);
pnew = ClassLoader.loadClass(path, strings, mp);
p = Interactive.updateProgram(pnew, p);
(p,b) = loadModel({(path,strings)},mp,p,true);
str = Print.getString();
newst = Interactive.SYMBOLTABLE(p,aDep,NONE(),{},iv,cf,lf);
then
(Env.emptyCache(),Values.BOOL(true),newst);
(Env.emptyCache(),Values.BOOL(b),newst);

case (cache,env,"loadModel",Values.CODE(Absyn.C_TYPENAME(path))::_,st,msg)
equation
Expand Down

0 comments on commit 732a652

Please sign in to comment.