Skip to content

Commit

Permalink
- New API call to check if the nested class is protected or not,
Browse files Browse the repository at this point in the history
  + isProtectedClass

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12373 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Jul 30, 2012
1 parent 0353c9f commit 1d6b0ee
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -2352,6 +2352,18 @@ annotation(
preferredView="text");
end isOperatorFunction;

function isProtectedClass
input TypeName cl;
input String c2;
output Boolean b;
external "builtin";
annotation(
Documentation(info="<html>
Returns true if the given class c1 has class c2 as one of its protected class.
</html>"),
preferredView="text");
end isProtectedClass;

function setInitXmlStartValue
input String fileName;
input String variableName;
Expand Down
6 changes: 6 additions & 0 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -1814,6 +1814,12 @@ algorithm
b = Interactive.isOperatorFunction(classpath, p);
then
(cache,Values.BOOL(b),st);

case (cache,env,"isProtectedClass",{Values.CODE(Absyn.C_TYPENAME(classpath)), Values.STRING(name)},st as Interactive.SYMBOLTABLE(ast=p),msg)
equation
b = Interactive.isProtectedClass(classpath, name, p);
then
(cache,Values.BOOL(b),st);

case (cache,env,"getAstAsCorbaString",{Values.STRING("<interactive>")},st as Interactive.SYMBOLTABLE(ast=p),msg)
equation
Expand Down
73 changes: 72 additions & 1 deletion Compiler/Script/Interactive.mo
Expand Up @@ -9053,7 +9053,7 @@ algorithm
local
Absyn.Path modelpath;
Boolean res, public_res, protected_res;
String element_name,str;
String str;
list<Absyn.ClassPart> parts;
list<Absyn.ElementItem> public_elementitem_list, protected_elementitem_list;
Absyn.ComponentRef model_;
Expand Down Expand Up @@ -9137,6 +9137,77 @@ algorithm
end matchcontinue;
end isReplaceableInElements;

public function isProtectedClass
"function: isProtectedClass
Returns true if the class referenced by inString within path is protected.
Only look to Element Items of inComponentRef1 for components use getComponents."
input Absyn.Path path;
input String inString;
input Absyn.Program inProgram;
output Boolean outBoolean;
algorithm
outBoolean := matchcontinue (path,inString,inProgram)
local
Boolean res, protected_res;
String str;
list<Absyn.ClassPart> parts;
list<Absyn.ElementItem> protected_elementitem_list;
Absyn.Program p;
/* a class with parts - protected elements */
case (path,str,p)
equation
Absyn.CLASS(_,_,_,_,_,Absyn.PARTS(classParts=parts),_) = getPathedClassInProgram(path, p);
protected_elementitem_list = getProtectedList(parts);
protected_res = isProtectedClassInElements(protected_elementitem_list, str);
res = Util.if_(protected_res, true, false);
then
res;
/* an extended class with parts: model extends M end M; protected elements */
case (path,str,p)
equation
Absyn.CLASS(_,_,_,_,_,Absyn.CLASS_EXTENDS(_,_,_,parts),_) = getPathedClassInProgram(path, p);
protected_elementitem_list = getProtectedList(parts);
protected_res = isProtectedClassInElements(protected_elementitem_list, str);
res = Util.if_(protected_res, true, false);
then
res;
case (_,_,_) then false;
end matchcontinue;
end isProtectedClass;

protected function isProtectedClassInElements
"function: isProtectedClassInElements
Helper function to isProtectedClass."
input list<Absyn.ElementItem> inAbsynElementItemLst;
input String inString;
output Boolean outBoolean;
algorithm
outBoolean := matchcontinue (inAbsynElementItemLst, inString)
local
String str, id;
Boolean res;
Absyn.ElementItem current;
list<Absyn.ElementItem> rest;
case ({}, _) then false;
case ((Absyn.ELEMENTITEM(element = Absyn.ELEMENT(specification = Absyn.CLASSDEF(class_ = Absyn.CLASS(name = id)))) :: rest), str) /* ok, first see if is a classdef if is not a classdef, just follow the normal stuff */
equation
true = stringEq(id,str);
then
true;
case ((Absyn.ELEMENTITEM(element = Absyn.ELEMENT(name = id)) :: rest), str)
equation
true = stringEq(id,str);
then
true;
case ((_ :: rest), str)
equation
res = isProtectedClassInElements(rest, str);
then
res;
case (_,_) then false;
end matchcontinue;
end isProtectedClassInElements;

protected function getEnumLiterals
"function: getEnumLiterals
Returns the enum literals as a list of string."
Expand Down

0 comments on commit 1d6b0ee

Please sign in to comment.