Skip to content

Commit

Permalink
remove unspecific metatype from Cpp function closures
Browse files Browse the repository at this point in the history
see #3419
  • Loading branch information
rfranke committed Aug 28, 2015
1 parent e9cd523 commit cd36c55
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
25 changes: 12 additions & 13 deletions Compiler/Template/CodegenCppCommon.tpl
Expand Up @@ -3136,17 +3136,16 @@ template daeExpPartEvalFunction(Exp exp, Context context, Text &preExp, Text &va
let closureName = '_Closure<%System.tmpTickIndex(2/*auxFunction*/)%>_<%funcName%>'
let functionsObject = match context case FUNCTION_CONTEXT(__) then 'this' else '_functions'
let createClosure = (expList |> e => ', <%daeExp(e, context, &preExp, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)%>')
let closureArgsDecl = (setDifference(t_orig.funcArg, t.funcArg) |> a as FUNCARG(__) hasindex i1 fromindex 1 => ', <%partEvalBoxedType(listGet(expList, i1))%> &<%a.name%>')
let callArgsDecl = (t.funcArg |> a as FUNCARG(__) hasindex i1 fromindex 1 => '<%expTypeShort(a.ty)%> <%a.name%>, ')
let closureArgsDecl = (setDifference(t_orig.funcArg, t.funcArg) |> a as FUNCARG(__) hasindex i1 fromindex 1 => ', <%partEvalUnboxedType(a.ty)%> &<%a.name%>')
let callArgsDecl = (t.funcArg |> a as FUNCARG(__) hasindex i1 fromindex 1 => '<%partEvalUnboxedType(a.ty)%> <%a.name%>, ')
let callArgsOrig = (t_orig.funcArg |> a as FUNCARG(__) hasindex i1 fromindex 1 => '<%a.name%>, ')
let &extraFuncsDecl +=
<<

template <typename metatype> // TODO: remove metatype if actual types known
class <%closureName%>
{
Functions *_functions;
<%setDifference(t_orig.funcArg, t.funcArg) |> a as FUNCARG(__) hasindex i1 fromindex 1 => '<%partEvalBoxedType(listGet(expList, i1))%> &<%a.name%>;<%\n%>'%>
<%setDifference(t_orig.funcArg, t.funcArg) |> a as FUNCARG(__) hasindex i1 fromindex 1 => '<%partEvalUnboxedType(a.ty)%> &<%a.name%>;<%\n%>'%>
public:
<%closureName%>(Functions *functions<%closureArgsDecl%>)
: _functions(functions)
Expand All @@ -3157,22 +3156,22 @@ template daeExpPartEvalFunction(Exp exp, Context context, Text &preExp, Text &va
}
};<%\n%>
>>
'<%closureName%><double>(<%functionsObject%><%createClosure%>)'
'<%closureName%>(<%functionsObject%><%createClosure%>)'
case PARTEVALFUNCTION(__) then
error(sourceInfo(), 'PARTEVALFUNCTION: <%ExpressionDump.printExpStr(exp)%>, ty=<%unparseType(ty)%>, origType=<%unparseType(origType)%>')
end daeExpPartEvalFunction;

template partEvalBoxedType(Exp exp)
"Returns the type of a boxed expression"
template partEvalUnboxedType(Type boxedType)
"Returns the actual type in the box"
::=
match exp
case exp as BOX(__) then
let elty = expTypeFromExpShort(exp.exp)
let ty = if isArrayType(typeof(exp.exp)) then 'BaseArray< <%elty%> >' else '<%elty%>'
match boxedType
case T_METABOXED(__) then
let elty = expTypeShort(Types.unboxedType(boxedType))
let ty = if isArrayType(Types.unboxedType(boxedType)) then 'BaseArray< <%elty%> >' else '<%elty%>'
'<%ty%>'
else
'<%expTypeFromExpShort(exp)%>'
end partEvalBoxedType;
error(sourceInfo(), 'Wrong input of type <%unparseType(boxedType)%> to partEvalUnboxedType')
end partEvalUnboxedType;

template daeExpBox(Exp exp, Context context, Text &preExp, Text &varDecls, SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace, Text stateDerVectorName /*=__zDot*/, Boolean useFlatArrayNotation)
"Not needed; just returns exp"
Expand Down
4 changes: 4 additions & 0 deletions Compiler/Template/SimCodeTV.mo
Expand Up @@ -3305,6 +3305,10 @@ package Types
input DAE.Type ty;
output list<DAE.Var> fields;
end getMetaRecordFields;
function unboxedType
input DAE.Type boxedType;
output DAE.Type ty;
end unboxedType;
end Types;

package HashTableCrIListArray
Expand Down

0 comments on commit cd36c55

Please sign in to comment.