Skip to content

Commit

Permalink
- added:
Browse files Browse the repository at this point in the history
  getShortDefinitionBaseClassInformation(path)
  -> returns: 
  {} if no base class or no short definition or not found or
  {path, ""|"flow", ""|"stream", "unspecified"|"discrete"|"parameter"|"constant", "unspecified"|"input"|"output", {dimension}}

- added:
  getExternalFunctionSpecification(path)
  -> returns: 
  {} if no external or does not exists
  {"C"|"Java", "output"|"", "functionName"|"", "x, y, z"|"", "annotation 1", "annotation 2"}


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11949 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed May 29, 2012
1 parent 7302fe4 commit c49b9d2
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -5642,4 +5642,44 @@ algorithm
case ELEMENTITEM(element=_) then ();
end match;
end filterAnnotationItem;

public function getExternalDecl
"@author: adrpo
returns the Absyn.EXTERNAL form parts if there is any.
if there is none, it fails!"
input Class inCls;
output ClassPart outExternal;
algorithm
outExternal := matchcontinue(inCls)
local
ClassPart cp;
list<ClassPart> classParts;

case (CLASS(body = PARTS(classParts = classParts)))
equation
cp = getExternalFromClassParts(classParts);
then
cp;
end matchcontinue;
end getExternalDecl;

public function getExternalFromClassParts
input list<ClassPart> inClassParts;
output ClassPart outExternal;
algorithm
outExternal := matchcontinue(inClassParts)
local
ClassPart cp;
list<ClassPart> rest;

case ((cp as EXTERNAL(externalDecl = _))::rest) then cp;

case (_::rest)
equation
cp = getExternalFromClassParts(rest);
then
cp;
end matchcontinue;
end getExternalFromClassParts;

end Absyn;
103 changes: 103 additions & 0 deletions Compiler/Script/Interactive.mo
Expand Up @@ -1906,6 +1906,22 @@ algorithm
then
(resstr,st);

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

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

case (istmts, st as SYMBOLTABLE(ast = p))
equation
matchApiFunction(istmts, "getClassInformation");
Expand Down Expand Up @@ -8382,6 +8398,93 @@ algorithm
str_scol,",",str_eline,",",str_ecol,"},",dim_str,"}"}) "composing the final returned string" ;
end getClassInformation;

protected function getShortDefinitionBaseClassInformation
"function: getShortDefinitionBaseClassInformation
author: adrpo
Returns all the prefixes of the base class and the base class array dimensions.
{{bool,bool,bool}}"
input Absyn.ComponentRef cr;
input Absyn.Program p;
output String res_1;
algorithm
res_1 := matchcontinue(cr, p)
local
Absyn.Path path, baseClassPath;
String name,file,strFlow,strStream,strVariability,strDirection,str,dim_str,strBaseClassPath;
Boolean flowPrefix,streamPrefix;
Absyn.Variability variability;
Absyn.Direction direction;
Absyn.ArrayDim arrayDim;
Absyn.ClassDef cdef;
Absyn.ElementAttributes attr;
Absyn.Parallelism parallelism;

case (cr, p)
equation
path = Absyn.crefToPath(cr);
Absyn.CLASS(
name = name,
body = cdef as Absyn.DERIVED(typeSpec = Absyn.TPATH(baseClassPath, _),
attributes = attr as Absyn.ATTR(flowPrefix, streamPrefix, parallelism, variability, direction, arrayDim)) )
= getPathedClassInProgram(path, p);
dim_str = getClassDimensions(cdef);
strBaseClassPath = Absyn.pathString(baseClassPath);
strFlow = Util.if_(flowPrefix, "\"flow\"", "\"\"");
strStream = Util.if_(streamPrefix, "\"stream\"", "\"\"");
strVariability = attrVariabilityStr(attr);
strDirection = attrDirectionStr(attr);
str = stringAppendList({"{",strBaseClassPath, ",", strFlow,",", strStream, ",", strVariability, ",", strDirection, ",", dim_str,"}"});
then
str;

case (cr, p) then "{}";

end matchcontinue;
end getShortDefinitionBaseClassInformation;

protected function getExternalFunctionSpecification
"function: getExternalFunctionSpecification
author: adrpo
Returns the external declaration from the function definition"
input Absyn.ComponentRef cr;
input Absyn.Program p;
output String res_1;
algorithm
res_1 := matchcontinue(cr, p)
local
Absyn.Path path;
String name,strLanguage,strFuncName,strOutput,strAnnotation,strArguments,strAnn1,strAnn2,str;
Absyn.Class cls;
Absyn.ClassPart externalDecl;
Option<Absyn.Ident> funcName "The name of the external function" ;
Option<String> lang "Language of the external function" ;
Option<Absyn.ComponentRef> output_ "output parameter as return value" ;
list<Absyn.Exp> args "only positional arguments, i.e. expression list" ;
Option<Absyn.Annotation> ann1, ann2;

case (cr, p)
equation
path = Absyn.crefToPath(cr);
cls = getPathedClassInProgram(path, p);
Absyn.EXTERNAL(Absyn.EXTERNALDECL(funcName, lang, output_, args, ann1), ann2) = Absyn.getExternalDecl(cls);
strLanguage = "\"" +& Util.getOptionOrDefault(lang, "") +& "\"";
strOutput = "\"" +& Absyn.printComponentRefStr(
Util.getOptionOrDefault(
output_,
Absyn.CREF_IDENT("", {}))) +& "\"";
strFuncName = "\"" +& Util.getOptionOrDefault(funcName, "") +& "\"";
strArguments = "\"" +& Dump.printExpLstStr(args) +& "\"";
strAnn1 = "\"" +& Dump.unparseAnnotationOption(0, ann1) +& "\"";
strAnn2 = "\"" +& Dump.unparseAnnotationOption(0, ann2) +& "\"";
str = stringAppendList({strLanguage, ",", strOutput, ",", strFuncName, ",", strArguments, ",", strAnn1, ",", strAnn2, "}"});
then
str;

case (cr, p) then "{}";

end matchcontinue;
end getExternalFunctionSpecification;

protected function getClassDimensions
"return the dimensions of a class
as vector of dimension sizes in a string.
Expand Down

0 comments on commit c49b9d2

Please sign in to comment.