Skip to content

Commit

Permalink
- Moved getPackages() to ModelicaBuiltin.mo
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10192 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 21, 2011
1 parent ea58f12 commit 2675f8c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 53 deletions.
6 changes: 6 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -1600,6 +1600,12 @@ function getClassNames
external "builtin";
end getClassNames;

function getPackages
input TypeName class_ := $TypeName(AllLoadedClasses);
output TypeName classNames[:];
external "builtin";
end getPackages;

end Scripting;

annotation(Documentation(info="<html>OpenModelica internal defintions and scripting functions are defined here.</html>", __Dymola_DocumentationClass = true));
Expand Down
15 changes: 15 additions & 0 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -819,6 +819,21 @@ algorithm
then
(cache,ValuesUtil.makeArray(vals),st);

case (cache,env,"getPackages",{Values.CODE(Absyn.C_TYPENAME(Absyn.IDENT("AllLoadedClasses")))},st as Interactive.SYMBOLTABLE(ast = p),msg)
equation
paths = Interactive.getTopPackages(p);
vals = List.map(paths,ValuesUtil.makeCodeTypeName);
then
(cache,ValuesUtil.makeArray(vals),st);


case (cache,env,"getPackages",{Values.CODE(Absyn.C_TYPENAME(path))},st as Interactive.SYMBOLTABLE(ast = p),msg)
equation
paths = Interactive.getPackagesInPath(path, p);
vals = List.map(paths,ValuesUtil.makeCodeTypeName);
then
(cache,ValuesUtil.makeArray(vals),st);

/* Does not exist in the env...
case (cache,env,"lookupClass",{Values.CODE(Absyn.C_TYPENAME(path))},(st as Interactive.SYMBOLTABLE(ast = p)),msg)
equation
Expand Down
66 changes: 13 additions & 53 deletions Compiler/Script/Interactive.mo
Expand Up @@ -2053,24 +2053,6 @@ algorithm
then
(resstr,st);

case (istmts, st as SYMBOLTABLE(ast = p))
equation
matchApiFunction(istmts, "getPackages");
{Absyn.CREF(componentRef = cr)} = getApiFunctionArgs(istmts);
path_1 = Absyn.crefToPath(cr);
resstr = getPackagesInPath(path_1, p);
then
(resstr,st);

case (istmts, st as SYMBOLTABLE(ast = p))
equation
matchApiFunction(istmts, "getPackages");
{} = getApiFunctionArgs(istmts);
s1 = getTopPackages(p);
resstr = stringAppend(s1, "\n");
then
(resstr,st);

case (istmts, st as SYMBOLTABLE(ast = p))
equation
matchApiFunction(istmts, "getClassNamesRecursive");
Expand Down Expand Up @@ -11787,15 +11769,15 @@ algorithm
end matchcontinue;
end getIconAnnotation;

protected function getPackagesInPath
public function getPackagesInPath
"function: getPackagesInPath
This function takes a Path and a Program and returns a list of the
names of the packages found in the Path."
input Absyn.Path inPath;
input Absyn.Program inProgram;
output String outString;
output list<Absyn.Path> paths;
algorithm
outString := matchcontinue (inPath,inProgram)
paths := matchcontinue (inPath,inProgram)
local
Absyn.Class cdef;
String str,res;
Expand All @@ -11804,35 +11786,19 @@ algorithm
case (modelpath,p)
equation
cdef = getPathedClassInProgram(modelpath, p);
str = getPackagesInClass(modelpath, p, cdef);
res = stringAppendList({"{", str, "}"});
then
res;
case (_,_) then "Error";
then getPackagesInClass(modelpath, p, cdef);
else {};
end matchcontinue;
end getPackagesInPath;

protected function getTopPackages
public function getTopPackages
"function: getTopPackages
This function takes a Path and a Program and returns a list of the
names of the packages found in the Path."
input Absyn.Program inProgram;
output String outString;
input Absyn.Program p;
output list<Absyn.Path> paths;
algorithm
outString := matchcontinue (inProgram)
local
list<String> strlist;
String str,res;
Absyn.Program p;
case (p)
equation
strlist = getTopPackagesInProgram(p);
str = stringDelimitList(strlist, ",");
res = stringAppendList({"{", str, "}"});
then
res;
case (_) then "Error";
end matchcontinue;
paths := List.map(getTopPackagesInProgram(p),Absyn.makeIdentPathFromString);
end getTopPackages;

protected function getTopPackagesInProgram
Expand Down Expand Up @@ -11872,7 +11838,7 @@ protected function getPackagesInClass
input Absyn.Path inPath;
input Absyn.Program inProgram;
input Absyn.Class inClass;
output String outString;
output list<Absyn.Path> outString;
algorithm
outString:=
match (inPath,inProgram,inClass)
Expand All @@ -11887,26 +11853,20 @@ algorithm
case (_,_,Absyn.CLASS(body = Absyn.PARTS(classParts = parts,comment = cmt)))
equation
strlist = getPackagesInParts(parts);
res = stringDelimitList(strlist, ",");
then
res;
then List.map(strlist,Absyn.makeIdentPathFromString);
/* an extended class with parts: model extends M end M; */
case (_,_,Absyn.CLASS(body = Absyn.CLASS_EXTENDS(parts = parts)))
equation
strlist = getPackagesInParts(parts);
res = stringDelimitList(strlist, ",");
then
res;
then List.map(strlist,Absyn.makeIdentPathFromString);
/* a derived class */
case (inmodel,p,Absyn.CLASS(body = Absyn.DERIVED(typeSpec=Absyn.TPATH(path,_))))
equation
/* adrpo: 2009-10-27 we shouldn't look into derived!
(cdef,newpath) = lookupClassdef(path, inmodel, p);
res = getPackagesInClass(newpath, p, cdef);
*/
res = "";
then
res;
then {};
end match;
end getPackagesInClass;

Expand Down

0 comments on commit 2675f8c

Please sign in to comment.