Skip to content

Commit

Permalink
#2889 Fix for r22769 accidentally reverting r22763
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22783 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 17, 2014
1 parent a327ab4 commit 5568f74
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
1 change: 1 addition & 0 deletions Compiler/SimCode/SimCode.mo
Expand Up @@ -341,6 +341,7 @@ uniontype Variable
String name;
list<DAE.Type> tys;
list<Variable> args;
Option<DAE.Exp> defaultValue "default value";
end FUNCTION_PTR;
end Variable;

Expand Down
39 changes: 20 additions & 19 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -783,7 +783,7 @@ algorithm
DAE.FUNCTION_ATTRIBUTES(functionParallelism=DAE.FP_NON_PARALLEL()) = funAttrs;

outVars = List.map(DAEUtil.getOutputVars(daeElts), daeInOutSimVar);
funArgs = List.map(args, typesSimFunctionArg);
funArgs = List.map1(args, typesSimFunctionArg, NONE());
(recordDecls, rt_1) = elaborateRecordDeclarations(daeElts, recordDecls, rt);
vars = List.filter(daeElts, isVarQ);
varDecls = List.map(vars, daeInOutSimVar);
Expand All @@ -803,7 +803,7 @@ algorithm
DAE.FUNCTION_ATTRIBUTES(functionParallelism=DAE.FP_KERNEL_FUNCTION()) = funAttrs;

outVars = List.map(DAEUtil.getOutputVars(daeElts), daeInOutSimVar);
funArgs = List.map(args, typesSimFunctionArg);
funArgs = List.map1(args, typesSimFunctionArg, NONE());
(recordDecls, rt_1) = elaborateRecordDeclarations(daeElts, recordDecls, rt);
vars = List.filter(daeElts, isVarNotInputNotOutput);
varDecls = List.map(vars, daeInOutSimVar);
Expand All @@ -823,7 +823,7 @@ algorithm
DAE.FUNCTION_ATTRIBUTES(functionParallelism=DAE.FP_PARALLEL_FUNCTION()) = funAttrs;

outVars = List.map(DAEUtil.getOutputVars(daeElts), daeInOutSimVar);
funArgs = List.map(args, typesSimFunctionArg);
funArgs = List.map1(args, typesSimFunctionArg, NONE());
(recordDecls, rt_1) = elaborateRecordDeclarations(daeElts, recordDecls, rt);
vars = List.filter(daeElts, isVarQ);
varDecls = List.map(vars, daeInOutSimVar);
Expand All @@ -843,7 +843,7 @@ algorithm
// outvars = DAEUtil.getOutputVars(daeElts);
// invars = DAEUtil.getInputVars(daeElts);
// bivars = DAEUtil.getBidirVars(daeElts);
funArgs = List.map(args, typesSimFunctionArg);
funArgs = List.map1(args, typesSimFunctionArg, NONE());
outVars = List.map(DAEUtil.getOutputVars(daeElts), daeInOutSimVar);
inVars = List.map(DAEUtil.getInputVars(daeElts), daeInOutSimVar);
biVars = List.map(DAEUtil.getBidirVars(daeElts), daeInOutSimVar);
Expand All @@ -868,7 +868,7 @@ algorithm
// Record constructor.
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);
funArgs = List.map1(args, typesSimFunctionArg, NONE());
(recordDecls, rt_1) = elaborateRecordDeclarationsForRecord(restype, recordDecls, rt);
DAE.T_COMPLEX(varLst = varlst) = restype;
varlst = List.filterOnTrue(varlst, Types.isProtectedVar);
Expand All @@ -890,9 +890,10 @@ end elaborateFunction;
protected function typesSimFunctionArg
"Generates code from a function argument."
input DAE.FuncArg inFuncArg;
input Option<DAE.Exp> binding;
output SimCode.Variable outVar;
algorithm
outVar := matchcontinue (inFuncArg)
outVar := matchcontinue (inFuncArg, binding)
local
DAE.Type tty;
String name;
Expand All @@ -905,33 +906,33 @@ algorithm
DAE.VarKind kind;
DAE.VarParallelism prl;

case DAE.FUNCARG(name=name, ty=DAE.T_FUNCTION(funcArg = args, funcResultType = DAE.T_TUPLE(tupleType = tys)))
case (DAE.FUNCARG(name=name, ty=DAE.T_FUNCTION(funcArg = args, funcResultType = DAE.T_TUPLE(tupleType = tys))), _)
equation
var_args = List.map(args, typesSimFunctionArg);
var_args = List.map1(args, typesSimFunctionArg, NONE());
tys = List.map(tys, Types.simplifyType);
then
SimCode.FUNCTION_PTR(name, tys, var_args);
SimCode.FUNCTION_PTR(name, tys, var_args, binding);

case DAE.FUNCARG(name=name, ty=DAE.T_FUNCTION(funcArg = args, funcResultType = DAE.T_NORETCALL(source = _)))
case (DAE.FUNCARG(name=name, ty=DAE.T_FUNCTION(funcArg = args, funcResultType = DAE.T_NORETCALL(source = _))), _)
equation
var_args = List.map(args, typesSimFunctionArg);
var_args = List.map1(args, typesSimFunctionArg, NONE());
then
SimCode.FUNCTION_PTR(name, {}, var_args);
SimCode.FUNCTION_PTR(name, {}, var_args, binding);

case DAE.FUNCARG(name=name, ty=DAE.T_FUNCTION(funcArg = args, funcResultType = res_ty))
case (DAE.FUNCARG(name=name, ty=DAE.T_FUNCTION(funcArg = args, funcResultType = res_ty)), _)
equation
res_ty = Types.simplifyType(res_ty);
var_args = List.map(args, typesSimFunctionArg);
var_args = List.map1(args, typesSimFunctionArg, NONE());
then
SimCode.FUNCTION_PTR(name, {res_ty}, var_args);
SimCode.FUNCTION_PTR(name, {res_ty}, var_args, binding);

case DAE.FUNCARG(name=name, ty=tty, par=prl, const=const)
case (DAE.FUNCARG(name=name, ty=tty, par=prl, const=const), _)
equation
tty = Types.simplifyType(tty);
cref_ = ComponentReference.makeCrefIdent(name, tty, {});
kind = DAEUtil.const2VarKind(const);
then
SimCode.VARIABLE(cref_, tty, NONE(), {}, prl, kind);
SimCode.VARIABLE(cref_, tty, binding, {}, prl, kind);
end matchcontinue;
end typesSimFunctionArg;

Expand All @@ -950,9 +951,9 @@ algorithm
list<DAE.Exp> inst_dims_exp;
Option<DAE.Exp> binding;
SimCode.Variable var;
case (DAE.VAR(componentRef = DAE.CREF_IDENT(ident=name), ty = daeType as DAE.T_FUNCTION(funcArg=_), parallelism = prl))
case (DAE.VAR(componentRef = DAE.CREF_IDENT(ident=name), ty = daeType as DAE.T_FUNCTION(funcArg=_), parallelism = prl, binding = binding))
equation
var = typesSimFunctionArg(DAE.FUNCARG(name, daeType, DAE.C_VAR(), prl, NONE()));
var = typesSimFunctionArg(DAE.FUNCARG(name, daeType, DAE.C_VAR(), prl, NONE()), binding);
then var;

case (DAE.VAR(componentRef = id,
Expand Down
5 changes: 5 additions & 0 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -6311,6 +6311,11 @@ case var as VARIABLE(__) then

case var as FUNCTION_PTR(__) then
let &varDecls += 'modelica_fnptr _<%name%>;<%\n%>'
let varInitText = (match defaultValue
case SOME(exp) then
let v = daeExp(exp, contextFunction, &varInits, &varDecls, &auxFunction)
'_<%name%> = <%v%>;<%\n%>')
let &varInits += varInitText
""
else error(sourceInfo(), 'Unknown local variable type')
end varInit;
Expand Down
1 change: 1 addition & 0 deletions Compiler/Template/SimCodeTV.mo
Expand Up @@ -369,6 +369,7 @@ package SimCode
String name;
list<DAE.Type> tys;
list<Variable> args;
Option<DAE.Exp> defaultValue;
end FUNCTION_PTR;
end Variable;

Expand Down

0 comments on commit 5568f74

Please sign in to comment.