Skip to content

Commit

Permalink
fix code generation for createArray from functions
Browse files Browse the repository at this point in the history
See e.g. Modelica.Media.Examples.R134a.R134a1 -- the treatment of constant array data may make you cringe though.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25868 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
rfranke committed May 1, 2015
1 parent 4cfa5ba commit f14a53f
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -23,11 +23,14 @@ template translateModel(SimCode simCode)
let()= textFile(simulationMainFile(target, simCode , &extraFuncs , &extraFuncsDecl, "", "", "", "", numRealVars, numIntVars, numBoolVars, getPreVarsCount(modelInfo)), 'OMCpp<%fileNamePrefix%>Main.cpp')
let()= textFile(simulationCppFile(simCode, contextOther, stringInt(numRealVars), stringInt(numIntVars), stringInt(numBoolVars), &extraFuncs, &extraFuncsDecl, '<%lastIdentOfPath(modelInfo.name)%>', stateDerVectorName, false), 'OMCpp<%fileNamePrefix%>.cpp')
let()= textFile(simulationHeaderFile(simCode , contextOther,&extraFuncs , &extraFuncsDecl, '<%lastIdentOfPath(modelInfo.name)%>', "", "", "", MemberVariable(modelInfo, false), MemberVariablePreVariables(modelInfo,false), false), 'OMCpp<%fileNamePrefix%>.h')
let()= textFile(simulationFunctionsHeaderFile(simCode , &extraFuncs , &extraFuncsDecl, "",modelInfo.functions,literals,stateDerVectorName,false), 'OMCpp<%fileNamePrefix%>Functions.h')
let()= textFile(simulationFunctionsFile(simCode, &extraFuncs, &extraFuncsDecl, "", modelInfo.functions, literals, externalFunctionIncludes, stateDerVectorName, false), 'OMCpp<%fileNamePrefix%>Functions.cpp')
let()= textFile(simulationTypesHeaderFile(simCode, &extraFuncs, &extraFuncsDecl, "", modelInfo.functions, literals, stateDerVectorName, false), 'OMCpp<%fileNamePrefix%>Types.h')
let()= textFile(simulationMakefile(target,simCode , &extraFuncs , &extraFuncsDecl, "","","","","",false), '<%fileNamePrefix%>.makefile')

let &extraFuncsFun = buffer "" /*BUFD*/
let &extraFuncsDeclFun = buffer "" /*BUFD*/
let()= textFile(simulationFunctionsFile(simCode, &extraFuncsFun, &extraFuncsDeclFun, 'Functions', modelInfo.functions, literals, externalFunctionIncludes, stateDerVectorName, false), 'OMCpp<%fileNamePrefix%>Functions.cpp')
let()= textFile(simulationFunctionsHeaderFile(simCode, &extraFuncsFun, &extraFuncsDeclFun, 'Functions', modelInfo.functions, literals, stateDerVectorName, false), 'OMCpp<%fileNamePrefix%>Functions.h')

let &extraFuncsInit = buffer "" /*BUFD*/
let &extraFuncsDeclInit = buffer "" /*BUFD*/
let()= textFile(simulationInitCppFile(simCode , &extraFuncsInit , &extraFuncsDeclInit, '<%lastIdentOfPath(modelInfo.name)%>Initialize', stateDerVectorName, false),'OMCpp<%fileNamePrefix%>Initialize.cpp')
Expand Down Expand Up @@ -2337,6 +2340,8 @@ case SIMCODE(modelInfo=MODELINFO(__)) then
}

<%functionBodies(functions, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)%>
/*extraFuncs*/
<%extraFuncs%>
>>
end simulationFunctionsFile;

Expand Down Expand Up @@ -2417,6 +2422,8 @@ case SIMCODE(modelInfo=MODELINFO(__)) then
bool& _initial;
double* __z;
double* __zDot;
/*extraFuncs*/
<%extraFuncsDecl%>
};
>>
end simulationFunctionsHeaderFile;
Expand Down Expand Up @@ -7607,11 +7614,10 @@ template crefStr(ComponentRef cr)
match cr
case CREF_IDENT(ident = "xloc") then '__xd<%subscriptsStr(subscriptLst)%>'
case CREF_IDENT(ident = "time") then "_simTime"
//filter key words for variable names
case CREF_IDENT(ident = "unsigned") then
'unsigned_'
case CREF_IDENT(ident = "string") then
'string_'
//filter key words for variable names
case CREF_IDENT(ident = "unsigned") then 'unsigned_'
case CREF_IDENT(ident = "string") then 'string_'
case CREF_IDENT(ident = "int") then 'int_'
case CREF_IDENT(__) then '<%ident%><%subscriptsStr(subscriptLst)%>'
// Are these even needed? Function context should only have CREF_IDENT :)
case CREF_QUAL(ident = "$DER") then 'der(<%crefStr(componentRef)%>)'
Expand Down Expand Up @@ -10933,19 +10939,16 @@ case ARRAY(array=_::_, ty = arraytype) then
<<
void <%extraFuncsNamespace%>::createArray_<%arrayVar%>(<%ArrayType%>& <%arrayVar%>)
{
<%arrayVar%>.setDims(<%allocateDimensions(arraytype,context)%>);
<%funcCalls%>


}
<%arrayVar%>.setDims(<%allocateDimensions(arraytype,context)%>);
<%funcCalls%>
}<%\n%>
>>
<<
<%ArrayType%> <%arrayVar%>;
createArray_<%arrayVar%>(<%arrayVar%>);<%\n%>
>>


let &preExp += '<%arrayassign%>'
let &preExp += '<%arrayassign%>'
arrayVar
case ARRAY(__) then
let arrayTypeStr = expTypeArray(ty)
Expand Down Expand Up @@ -10994,23 +10997,23 @@ template daeExpSubArray2(list<Exp> array, Integer idx, Integer multiplicator, St
"Generates code for an array expression."
::=
let func = 'void createArray_<%arrayVar%>_<%idx%>(<%ArrayType%>& <%arrayVar%>);'
let &extraFuncsDecl+= '<%func%><%\n%>'
let funcCall = 'createArray_<%arrayVar%>_<%idx%>(<%arrayVar%>);<%\n%>'
let &extraFuncsDecl += '<%func%><%\n%>'
let funcCall = 'createArray_<%arrayVar%>_<%idx%>(<%arrayVar%>);'
let &funcVarDecls = buffer ""
let &preExpSubArrays = buffer ""
let funcs = (array |> e hasindex i0 fromindex intAdd(intMul(idx, multiplicator),1) =>
let subArraycall = daeExp(e, context, &preExpSubArrays, &funcVarDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
<<
<%arrayVar%>.append(<%i0%>, <%subArraycall%>);
>> ;separator="\n")
let & extraFuncs +=
let &extraFuncs +=
<<
void <%extraFuncsNamespace%>::createArray_<%arrayVar%>_<%idx%>(<%ArrayType%>& <%arrayVar%>)
{
<%funcVarDecls%>
<%preExpSubArrays%>
<%funcs%>
}
}<%\n%>
>>
funcCall
end daeExpSubArray2;
Expand Down Expand Up @@ -12305,12 +12308,10 @@ template cref1(ComponentRef cr, SimCode simCode ,Text& extraFuncs,Text& extraFun
else
"_simTime"
end match
//filter key words for variable names
case CREF_IDENT(ident = "unsigned") then
'unsigned_'
case CREF_IDENT(ident = "string") then
'string_'

//filter key words for variable names
case CREF_IDENT(ident = "unsigned") then 'unsigned_'
case CREF_IDENT(ident = "string") then 'string_'
case CREF_IDENT(ident = "int") then 'int_'
else '<%representationCref(cr, simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace,context, varDecls, stateDerVectorName, useFlatArrayNotation) %>'
end cref1;

Expand Down

0 comments on commit f14a53f

Please sign in to comment.