Skip to content

Commit

Permalink
Make protected functions static in the generated code
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22482 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Sep 29, 2014
1 parent e09b5f7 commit a9813ab
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 94 deletions.
4 changes: 4 additions & 0 deletions Compiler/BackEnd/SimCode.mo
Expand Up @@ -56,6 +56,7 @@ public import Absyn;
public import BackendDAE;
public import DAE;
public import HpcOmSimCode;
public import SCode;

public
type ExtConstructor = tuple<DAE.ComponentRef, String, list<DAE.Exp>>;
Expand Down Expand Up @@ -312,6 +313,7 @@ uniontype Function
list<Variable> functionArguments;
list<Variable> variableDeclarations;
list<Statement> body;
SCode.Visibility visibility;
Absyn.Info info;
end FUNCTION;

Expand Down Expand Up @@ -345,6 +347,7 @@ uniontype Function
list<String> includes "this one is needed so that we know if we should generate the external function prototype or not";
list<String> libs "need this one for C#";
String language "C or Fortran";
SCode.Visibility visibility;
Absyn.Info info;
Boolean dynamicLoad;
end EXTERNAL_FUNCTION;
Expand All @@ -353,6 +356,7 @@ uniontype Function
Absyn.Path name;
list<Variable> funArgs;
list<Variable> locals;
SCode.Visibility visibility;
Absyn.Info info;
DAE.VarKind kind;
end RECORD_CONSTRUCTOR;
Expand Down
57 changes: 10 additions & 47 deletions Compiler/BackEnd/SimCodeUtil.mo
Expand Up @@ -689,11 +689,12 @@ algorithm
DAE.FunctionAttributes funAttrs;
list<DAE.Var> varlst;
DAE.VarKind kind;
SCode.Visibility visibility;

// Modelica functions.
case (_, DAE.FUNCTION(path = fpath, source = source,
case (_, DAE.FUNCTION(path = fpath, source = source, visibility = visibility,
functions = DAE.FUNCTION_DEF(body = daeElts)::_, // might be followed by derivative maps
type_ = DAE.T_FUNCTION(funcArg=args, funcResultType=_, functionAttributes=funAttrs),
type_ = DAE.T_FUNCTION(funcArg=args, functionAttributes=funAttrs),
partialPrefix=false), rt, recordDecls, includes, includeDirs, libs)
equation

Expand All @@ -708,12 +709,12 @@ algorithm
bodyStmts = List.map(algs, elaborateStatement);
info = DAEUtil.getElementSourceFileInfo(source);
then
(SimCode.FUNCTION(fpath, outVars, funArgs, varDecls, bodyStmts, info), rt_1, recordDecls, includes, includeDirs, libs);
(SimCode.FUNCTION(fpath, outVars, funArgs, varDecls, bodyStmts, visibility, info), rt_1, recordDecls, includes, includeDirs, libs);


case (_, DAE.FUNCTION(path = fpath, source = source,
functions = DAE.FUNCTION_DEF(body = daeElts)::_, // might be followed by derivative maps
type_ = DAE.T_FUNCTION(funcArg=args, funcResultType=_, functionAttributes=funAttrs),
type_ = DAE.T_FUNCTION(funcArg=args, functionAttributes=funAttrs),
partialPrefix=false), rt, recordDecls, includes, includeDirs, libs)
equation

Expand Down Expand Up @@ -750,48 +751,10 @@ algorithm
then
(SimCode.PARALLEL_FUNCTION(fpath, outVars, funArgs, varDecls, bodyStmts, info), rt_1, recordDecls, includes, includeDirs, libs);

/*
// mahge930: kernel functions
case (DAE.FUNCTION(path = fpath, source = source,
functions = DAE.FUNCTION_DEF(body = daeElts)::_, // might be followed by derivative maps
type_ = tp as DAE.T_FUNCTION(funcArg=args, funcResultType=restype, functionAttributes = funAttrs),
partialPrefix=false), rt, recordDecls, includes, includeDirs, libs)
equation

DAE.FUNCTION_ATTRIBUTES(_, _, _, DAE.FP_KERNEL_FUNCTION()) = funAttrs;

outVars = List.map(DAEUtil.getOutputVars(daeElts), daeInOutSimVar);
funArgs = List.map(args, typesSimFunctionArg);
(recordDecls, rt_1) = elaborateRecordDeclarations(daeElts, recordDecls, rt);
vars = List.filter(daeElts, isVarQ);
varDecls = List.map(vars, daeInOutSimVar);
algs = List.filter(daeElts, DAEUtil.isAlgorithm);
bodyStmts = List.map(algs, elaborateStatement);
info = DAEUtil.getElementSourceFileInfo(source);


outVars = Util.listMap(DAEUtil.getOutputVars(daeElts), daeInOutSimVarKernelInterface);
// outVars = Util.listMap(DAEUtil.getOutputVars(daeElts), daeInOutSimVar);

funArgs = Util.listMap(args, typesSimFunctionArgKernelInterface);
// funArgs = Util.listMap(args, typesSimFunctionArg);

(recordDecls, rt_1) = elaborateRecordDeclarations(daeElts, recordDecls, rt);

// kernel function "vardecls" shouldn't include output vars.
vars = Util.listFilter(daeElts, isVarNotInputNotOutput);
varDecls = Util.listMap(vars, daeInOutSimVar);
algs = Util.listFilter(daeElts, DAEUtil.isAlgorithm);
bodyStmts = Util.listMap(algs, elaborateStatement);

then
(KERNEL_FUNCTION(fpath, outVars, funArgs, varDecls, bodyStmts, info), rt_1, recordDecls, includes, includeDirs, libs);
*/

// External functions.
case (_, DAE.FUNCTION(path = fpath, source = source,
case (_, DAE.FUNCTION(path = fpath, source = source, visibility = visibility,
functions = DAE.FUNCTION_EXT(body = daeElts, externalDecl = extdecl)::_, // might be followed by derivative maps
type_ = (DAE.T_FUNCTION(funcArg = args, funcResultType = _))), rt, recordDecls, includes, includeDirs, libs)
type_ = (DAE.T_FUNCTION(funcArg = args))), rt, recordDecls, includes, includeDirs, libs)
equation
DAE.EXTERNALDECL(name=extfnname, args=extargs,
returnArg=extretarg, language=lang, ann=ann) = extdecl;
Expand All @@ -817,11 +780,11 @@ algorithm
lang = System.toupper(lang);
then
(SimCode.EXTERNAL_FUNCTION(fpath, extfnname, funArgs, simextargs, extReturn,
inVars, outVars, biVars, fn_includes, fn_libs, lang, info, dynamicLoad),
inVars, outVars, biVars, fn_includes, fn_libs, lang, visibility, info, dynamicLoad),
rt_1, recordDecls, includes, includeDirs, libs);

// Record constructor.
case (_, DAE.RECORD_CONSTRUCTOR(path = _, source = source, type_ = DAE.T_FUNCTION(funcArg = args, funcResultType = restype as DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(name))),kind=kind), rt, recordDecls, includes, includeDirs, libs)
case (_, DAE.RECORD_CONSTRUCTOR(source = source, type_ = DAE.T_FUNCTION(funcArg = args, funcResultType = restype as DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(name))),kind=kind), rt, recordDecls, includes, includeDirs, libs)
equation
funArgs = List.map(args, typesSimFunctionArg);
(recordDecls, rt_1) = elaborateRecordDeclarationsForRecord(restype, recordDecls, rt);
Expand All @@ -830,7 +793,7 @@ algorithm
varDecls = List.map(varlst, typesVar);
info = DAEUtil.getElementSourceFileInfo(source);
then
(SimCode.RECORD_CONSTRUCTOR(name, funArgs, varDecls, info, kind), rt_1, recordDecls, includes, includeDirs, libs);
(SimCode.RECORD_CONSTRUCTOR(name, funArgs, varDecls, SCode.PUBLIC(), info, kind), rt_1, recordDecls, includes, includeDirs, libs);

// failure
case (_, fn, _, _, _, _, _)
Expand Down

0 comments on commit a9813ab

Please sign in to comment.