Skip to content

Commit 9ca15af

Browse files
committed
Adding API call getUsedClassNames, which is a combination of saveTotalModel and getClassNames(recursive=true)
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21488 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent d2fcd6d commit 9ca15af

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

Compiler/FrontEnd/Ceval.mo

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,7 @@ algorithm
11631163
case "listReverse" equation true = Config.acceptMetaModelicaGrammar(); then cevalListReverse;
11641164
case "listHead" equation true = Config.acceptMetaModelicaGrammar(); then cevalListFirst;
11651165
case "listRest" equation true = Config.acceptMetaModelicaGrammar(); then cevalListRest;
1166+
case "listMember" equation true = Config.acceptMetaModelicaGrammar(); then cevalListMember;
11661167
case "anyString" equation true = Config.acceptMetaModelicaGrammar(); then cevalAnyString;
11671168
case "numBits" then cevalNumBits;
11681169
case "integerMax" then cevalIntegerMax;
@@ -2586,6 +2587,40 @@ algorithm
25862587
end match;
25872588
end cevalListRest;
25882589

2590+
protected function cevalListMember
2591+
input Env.Cache inCache;
2592+
input Env.Env inEnv;
2593+
input list<DAE.Exp> inExpExpLst;
2594+
input Boolean inBoolean;
2595+
input Option<GlobalScript.SymbolTable> inST;
2596+
input Absyn.Msg inMsg;
2597+
input Integer numIter;
2598+
output Env.Cache outCache;
2599+
output Values.Value outValue;
2600+
output Option<GlobalScript.SymbolTable> outInteractiveInteractiveSymbolTableOption;
2601+
algorithm
2602+
(outCache,outValue,outInteractiveInteractiveSymbolTableOption):=
2603+
match (inCache,inEnv,inExpExpLst,inBoolean,inST,inMsg,numIter)
2604+
local
2605+
Env.Env env;
2606+
DAE.Exp exp1,exp2;
2607+
Boolean impl;
2608+
Option<GlobalScript.SymbolTable> st;
2609+
Absyn.Msg msg;
2610+
Env.Cache cache;
2611+
list<Values.Value> vals;
2612+
Values.Value val;
2613+
Boolean b;
2614+
case (cache,env,{exp1,exp2},impl,st,msg,_)
2615+
equation
2616+
(cache,val,st) = ceval(cache,env,exp1,impl,st,msg,numIter+1);
2617+
(cache,Values.LIST(vals),st) = ceval(cache,env,exp2,impl,st,msg,numIter+1);
2618+
b = listMember(val,vals);
2619+
then
2620+
(cache,Values.BOOL(b),st);
2621+
end match;
2622+
end cevalListMember;
2623+
25892624
protected function cevalAnyString
25902625
input Env.Cache inCache;
25912626
input Env.Env inEnv;

Compiler/FrontEnd/ModelicaBuiltin.mo

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,6 +2285,13 @@ external "builtin";
22852285
annotation(preferredView="text");
22862286
end getClassNames;
22872287

2288+
function getUsedClassNames "Returns the list of class names used in the total program defined by the class."
2289+
input TypeName className;
2290+
output TypeName classNames[:];
2291+
external "builtin";
2292+
annotation(preferredView="text");
2293+
end getUsedClassNames;
2294+
22882295
function getPackages "Returns the list of packages defined in the class."
22892296
input TypeName class_ := $TypeName(AllLoadedClasses);
22902297
output TypeName classNames[:];

Compiler/FrontEnd/SCode.mo

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,6 +1950,20 @@ algorithm
19501950
end match;
19511951
end getClassComponents;
19521952

1953+
public function getClassElements
1954+
"This function returns the components from a class"
1955+
input Element cl;
1956+
output list<Element> elts;
1957+
algorithm
1958+
elts := match (cl)
1959+
case (CLASS(classDef = PARTS(elementLst = elts)))
1960+
then elts;
1961+
case (CLASS(classDef = CLASS_EXTENDS(composition = PARTS(elementLst = elts))))
1962+
then elts;
1963+
else {};
1964+
end match;
1965+
end getClassElements;
1966+
19531967
public function makeEnumType
19541968
"Creates an EnumType element from an enumeration literal and an optional
19551969
comment."

Compiler/Script/CevalScript.mo

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,19 @@ algorithm
10001000
then
10011001
(cache,ValuesUtil.makeArray(vals),st);
10021002

1003+
case (cache,env,"getUsedClassNames",{Values.CODE(Absyn.C_TYPENAME(path))},st as GlobalScript.SYMBOLTABLE(ast = p),_)
1004+
equation
1005+
(sp, st) = Interactive.symbolTableToSCode(st);
1006+
(sp, _) = NFSCodeFlatten.flattenClassInProgram(path, sp);
1007+
sp = SCode.removeBuiltinsFromTopScope(sp);
1008+
paths = Interactive.getSCodeClassNamesRecursive(sp);
1009+
// paths = Debug.bcallret2(sort, List.sort, paths, Absyn.pathGe, paths);
1010+
vals = List.map(paths,ValuesUtil.makeCodeTypeName);
1011+
then (cache,ValuesUtil.makeArray(vals),st);
1012+
1013+
case (cache,env,"getUsedClassNames",_,st as GlobalScript.SYMBOLTABLE(ast = p),_)
1014+
then (cache,ValuesUtil.makeArray({}),st);
1015+
10031016
case (cache,_,"getClassComment",{Values.CODE(Absyn.C_TYPENAME(path))},st as GlobalScript.SYMBOLTABLE(ast = p),_)
10041017
equation
10051018
Absyn.CLASS(_,_,_,_,_,cdef,_) = Interactive.getPathedClassInProgram(path, p);

Compiler/Script/Interactive.mo

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18568,6 +18568,45 @@ algorithm
1856818568
end matchcontinue;
1856918569
end getClassNamesRecursive;
1857018570

18571+
public function getSCodeClassNamesRecursive
18572+
"Returns a string with all the classes for a given path."
18573+
input SCode.Program inProgram;
18574+
output list<Absyn.Path> paths;
18575+
algorithm
18576+
paths := List.fold1(inProgram,getSCodeClassNamesRecursiveWork,NONE(),{});
18577+
end getSCodeClassNamesRecursive;
18578+
18579+
protected function getSCodeClassNamesRecursiveWork
18580+
"Returns a string with all the classes for a given path."
18581+
input SCode.Element inElement;
18582+
input Option<Absyn.Path> inPath;
18583+
input list<Absyn.Path> inAcc;
18584+
output list<Absyn.Path> paths;
18585+
algorithm
18586+
paths := match (inElement,inPath,inAcc)
18587+
local
18588+
list<SCode.Element> classes;
18589+
list<Absyn.Path> acc;
18590+
Absyn.Path path;
18591+
String name;
18592+
case (SCode.CLASS(name=name),NONE(),acc)
18593+
equation
18594+
path = Absyn.IDENT(name);
18595+
acc = path::acc;
18596+
classes = SCode.getClassElements(inElement);
18597+
acc = List.fold1(classes,getSCodeClassNamesRecursiveWork,SOME(path),acc);
18598+
then acc;
18599+
case (SCode.CLASS(name=name),SOME(path),acc)
18600+
equation
18601+
path = Absyn.suffixPath(path,name);
18602+
acc = path::acc;
18603+
classes = SCode.getClassElements(inElement);
18604+
acc = List.fold1(classes,getSCodeClassNamesRecursiveWork,SOME(path),acc);
18605+
then acc;
18606+
else inAcc;
18607+
end match;
18608+
end getSCodeClassNamesRecursiveWork;
18609+
1857118610
public function getPathedComponentElementInProgram "Returns a component given a path and a program. See also getPathedClassInProgram"
1857218611
input Absyn.Path path;
1857318612
input Absyn.Program prg;

0 commit comments

Comments
 (0)