Skip to content

Commit

Permalink
- SearchClassNames API.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13753 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Nov 1, 2012
1 parent cb7dbf9 commit bfb4f38
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2568,6 +2568,21 @@ algorithm
</html>"));
end loadModelica3D;

function searchClassNames "Searches for the class name in the all the loaded classes.
Example command:
searchClassNames(\"ground\");
searchClassNames(\"ground\", true);"
input String searchText;
input Boolean findInText := false;
output TypeName classNames[:];
external "builtin";
annotation(
Documentation(info="<html>
Look for searchText in All Loaded Classes and their code. Returns the list of searched classes.
</html>"),
preferredView="text");
end searchClassNames;

annotation(preferredView="text");
end Scripting;

Expand Down
10 changes: 10 additions & 0 deletions Compiler/FrontEnd/ValuesUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2485,6 +2485,16 @@ algorithm
Values.CODE(code) := val;
end getCode;

public function getPath
input Values.Value val;
output Absyn.Path path;
protected
Absyn.CodeNode code;
algorithm
Values.CODE(code) := val;
Absyn.C_TYPENAME(path) := code;
end getPath;

public function readDataset
input String filename;
input list<String> vars;
Expand Down
55 changes: 55 additions & 0 deletions Compiler/Script/CevalScript.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1993,6 +1993,15 @@ algorithm
case (cache,env,"isExperiment",_,st as Interactive.SYMBOLTABLE(ast=p),_)
then
(cache,Values.BOOL(false),st);

case (cache,env,"searchClassNames",{Values.STRING(str), Values.BOOL(b)},st as Interactive.SYMBOLTABLE(ast=p),_)
equation
(_,paths) = Interactive.getClassNamesRecursive(NONE(),p,false,{});
paths = listReverse(paths);
vals = List.map(paths,ValuesUtil.makeCodeTypeName);
vals = searchClassNames(vals, str, b, p);
then
(cache,ValuesUtil.makeArray(vals),st);

case (cache,env,"getAstAsCorbaString",{Values.STRING("<interactive>")},st as Interactive.SYMBOLTABLE(ast=p),_)
equation
Expand Down Expand Up @@ -6930,4 +6939,50 @@ algorithm
end match;
end cevalWholedimRetCall;

protected function searchClassNames
input list<Values.Value> inVals;
input String inSearchText;
input Boolean inFindInText;
input Absyn.Program inProgram;
output list<Values.Value> outVals;
algorithm
outVals := matchcontinue (inVals, inSearchText, inFindInText, inProgram)
local
list<Values.Value> valsList;
String str, str1;
Boolean b;
Absyn.Program p, p1;
Absyn.Class absynClass;
Integer position;
list<Values.Value> xs;
Values.Value val;
case ((val as Values.CODE(_)) :: xs, str1, true, p)
equation
absynClass = Interactive.getPathedClassInProgram(ValuesUtil.getPath(val), p);
p1 = Absyn.PROGRAM({absynClass},Absyn.TOP(),Absyn.TIMESTAMP(0.0,0.0));
/* Don't consider packages for FindInText search */
false = Interactive.isPackage(ValuesUtil.getPath(val), inProgram);
str = Dump.unparseStr(p1, false);
position = System.stringFind(System.tolower(str), System.tolower(str1));
true = (position > -1);
valsList = searchClassNames(xs, str1, true, p);
then
val::valsList;
case ((val as Values.CODE(_)) :: xs, str1, b, p)
equation
str = ValuesUtil.valString(val);
position = System.stringFind(System.tolower(str), System.tolower(str1));
true = (position > -1);
valsList = searchClassNames(xs, str1, b, p);
then
val::valsList;
case ((_ :: xs), str1, b, p)
equation
valsList = searchClassNames(xs, str1, b, p);
then
valsList;
case ({}, str1, b, p) then {};
end matchcontinue;
end searchClassNames;

end CevalScript;

0 comments on commit bfb4f38

Please sign in to comment.