Skip to content

Commit

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

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

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 @@ -804,6 +804,21 @@ algorithm
then
(cache,Values.BOOL(b),st);

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


case (cache,env,"getClassNames",{Values.CODE(Absyn.C_TYPENAME(path))},st as Interactive.SYMBOLTABLE(ast = p),msg)
equation
paths = Interactive.getClassnamesInPath(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
74 changes: 15 additions & 59 deletions Compiler/Script/Interactive.mo
Expand Up @@ -1682,7 +1682,7 @@ algorithm
{Absyn.STRING(value = name)} = getApiFunctionArgs(istmts);
p1 = ClassLoader.loadFile(name) "System.regularFileExists(name) => 0 & Parser.parse(name) => p1 &" ;
newp = updateProgram(p1, p);
top_names_str = getTopClassnames(p1);
top_names_str = "{" +& stringDelimitList(List.map(getTopClassnames(p1),Absyn.pathString),",") +& "}";
st = setSymbolTableAST(st, newp);
then
(top_names_str,st);
Expand All @@ -1703,6 +1703,7 @@ algorithm
then
("error",st);

// Not moving this yet as it could break things...
case (istmts, st as SYMBOLTABLE(ast = p))
equation
matchApiFunction(istmts, "deleteClass");
Expand Down Expand Up @@ -2070,15 +2071,6 @@ algorithm
then
(resstr,st);

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

case (istmts, st as SYMBOLTABLE(ast = p))
equation
matchApiFunction(istmts, "getClassNamesRecursive");
Expand Down Expand Up @@ -2140,19 +2132,6 @@ algorithm
then
(resstr, st);

case (istmts, st as SYMBOLTABLE(ast = p))
equation
matchApiFunction(istmts, "getClassNames");
{} = getApiFunctionArgs(istmts);
resstr = getTopClassnames(p);
then
(resstr,st);

case (istmts, st)
equation
matchApiFunction(istmts, "getClassNames");
then ("{}",st);

case (istmts, st as SYMBOLTABLE(ast = p))
equation
matchApiFunction(istmts, "getClassInformation");
Expand Down Expand Up @@ -11985,14 +11964,14 @@ algorithm
end matchcontinue;
end getPackagesInElts;

protected function getClassnamesInPath
public function getClassnamesInPath
"function: getClassnamesInPath
Return a comma separated list of classes in a given Path."
input Absyn.Path inPath;
input Absyn.Program inProgram;
output String outString;
output list<Absyn.Path> paths;
algorithm
outString:=
paths :=
matchcontinue (inPath,inProgram)
local
Absyn.Class cdef;
Expand All @@ -12002,36 +11981,19 @@ algorithm
case (modelpath,p)
equation
cdef = getPathedClassInProgram(modelpath, p);
str = getClassnamesInClass(modelpath, p, cdef);
res = stringAppendList({"{", str, "}"});
then
res;
case (_,_) then "Error";
then getClassnamesInClass(modelpath, p, cdef);
else {};
end matchcontinue;
end getClassnamesInPath;

public function getTopClassnames
"function: getTopClassnames
This function takes a Path and a Program and returns a list of
the names of the packages found at the top scope."
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 = getTopClassnamesInProgram(p);
str = stringDelimitList(strlist, ",");
res = stringAppendList({"{", str, "}"});
then
res;
case (_) then "Error";
end matchcontinue;
paths := List.map(getTopClassnamesInProgram(p),Absyn.makeIdentPathFromString);
end getTopClassnames;

public function getTopClassnamesInProgram
Expand Down Expand Up @@ -12103,9 +12065,9 @@ protected function getClassnamesInClass
input Absyn.Path inPath;
input Absyn.Program inProgram;
input Absyn.Class inClass;
output String outString;
output list<Absyn.Path> paths;
algorithm
outString := match (inPath,inProgram,inClass)
paths := match (inPath,inProgram,inClass)
local
list<String> strlist;
String res;
Expand All @@ -12116,26 +12078,20 @@ algorithm
case (_,_,Absyn.CLASS(body = Absyn.PARTS(classParts = parts)))
equation
strlist = getClassnamesInParts(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 = getClassnamesInParts(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 sholdn't dive into derived classes!
(cdef,newpath) = lookupClassdef(path, inmodel, p);
res = getClassnamesInClass(newpath, p, cdef);
*/
res = "";
then
res;
then {};
end match;
end getClassnamesInClass;

Expand Down

0 comments on commit ea58f12

Please sign in to comment.