Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 5e4878f

Browse files
rfrankeOpenModelica-Hudson
authored andcommitted
Initialize external objects with parameters in Cpp runtime
1 parent 8899379 commit 5e4878f

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

Compiler/Template/CodegenCpp.tpl

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4373,16 +4373,16 @@ template extType2(Type type, Boolean isInput, Boolean isArray)
43734373
"Generates type for external function argument or return value."
43744374
::=
43754375
let s = match type
4376-
case T_INTEGER(__) then "int"
4376+
case T_INTEGER(__) then "int"
43774377
case T_REAL(__) then "double"
43784378
case T_STRING(__) then "const char*"
43794379
case T_BOOL(__) then "int"
43804380
case T_ENUMERATION(__) then "int"
43814381
case T_ARRAY(__) then extType2(ty,isInput,true)
43824382
case T_COMPLEX(complexClassType=EXTERNAL_OBJ(__))
4383-
then "void *"
4383+
then "void*"
43844384
case T_COMPLEX(complexClassType=RECORD(path=rname))
4385-
then 'struct <%underscorePath(rname)%>'
4385+
then 'struct <%underscorePath(rname)%>'
43864386
case T_METATYPE(__) case T_METABOXED(__) then "modelica_metatype"
43874387
else error(sourceInfo(), 'Unknown external C type <%unparseType(type)%>')
43884388
match type case T_ARRAY(__) then s else if isInput then (if isArray then '<%match s case "const char*" then "" else "const "%><%s%>*' else s) else '<%s%>*'
@@ -5815,10 +5815,6 @@ case SIMCODE(modelInfo = MODELINFO(__),makefileParams = MAKEFILE_PARAMS(__)) th
58155815
initializeDerVars();
58165816
>>
58175817
%>
5818-
/*external objects*/
5819-
if (_constructedExternalObjects)
5820-
destructExternalObjects();
5821-
_constructedExternalObjects = false;
58225818

58235819
#if defined(__TRICORE__) || defined(__vxworks)
58245820
//init inputs
@@ -5837,11 +5833,13 @@ case SIMCODE(modelInfo = MODELINFO(__),makefileParams = MAKEFILE_PARAMS(__)) th
58375833
//variable decls
58385834
<%varDecls%>
58395835

5836+
//destruct external objects if already constructed in a previous call
5837+
if (_constructedExternalObjects)
5838+
destructExternalObjects();
5839+
58405840
initParameterEquations();
58415841

5842-
//construct external objects once
5843-
if (!_constructedExternalObjects)
5844-
constructExternalObjects();
5842+
//mark external objects constructed during initParameterEquations
58455843
_constructedExternalObjects = true;
58465844

58475845
//bound start values
@@ -11318,22 +11316,24 @@ case SES_SIMPLE_ASSIGN(__) then
1131811316
_discrete_events->pre(<%cref(componentRef, useFlatArrayNotation)%>)=<%expPart%>;
1131911317
>>
1132011318
else
11321-
match exp
11319+
match exp
1132211320
case CREF(ty = t as T_ARRAY(__)) then
11323-
<<
11324-
//Array assign
11325-
<%cref1(cref, simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace,context,varDecls, stateDerVectorName, useFlatArrayNotation)%> = <%expPart%>;
11326-
>>
11321+
<<
11322+
//Array assign
11323+
<%cref1(cref, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace,context,varDecls, stateDerVectorName, useFlatArrayNotation)%> = <%expPart%>;
11324+
>>
1132711325
else
11328-
let &assignExp = buffer if(assignToStartValues) then 'SystemDefaultImplementation::set<%crefStartValueType(cref)%>StartValue(' else ''
11329-
let &assignExp += cref1(cref, simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace, context, varDecls, stateDerVectorName, useFlatArrayNotation)
11330-
let &assignExp += if(assignToStartValues) then ',<%expPart%>,<%overwriteOldStartValue%>);' else ' = <%expPart%>;'
11331-
<<
11332-
<%if not assignToStartValues then '<%startFixedExp%>'%>
11333-
<%preExp%>
11334-
<%assignExp%>
11335-
>>
11336-
end match
11326+
let startValueType = crefStartValueType(cref)
11327+
let lvalue = cref1(cref, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, context, varDecls, stateDerVectorName, useFlatArrayNotation)
11328+
let assignExp = if boolAnd(assignToStartValues, boolNot(stringEq(startValueType, "ExternalObject"))) then
11329+
'SystemDefaultImplementation::set<%startValueType%>StartValue(<%lvalue%>, <%expPart%>, <%overwriteOldStartValue%>);' else
11330+
'<%lvalue%> = <%expPart%>;'
11331+
<<
11332+
<%if not assignToStartValues then '<%startFixedExp%>'%>
11333+
<%preExp%>
11334+
<%assignExp%>
11335+
>>
11336+
end match
1133711337
end match
1133811338
end equationSimpleAssign;
1133911339

Compiler/Template/CodegenCppCommon.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ template crefStartValueType(ComponentRef cr)
602602
else if stringEq(typeShort, "int") then "Int"
603603
else if stringEq(typeShort, "bool") then "Bool"
604604
else if stringEq(typeShort, "string") then "String"
605+
else if stringEq(typeShort, "void*") then "ExternalObject"
605606
else 'ERROR:crefStartValueType <%typeShort%> '
606607
'<%typeString%>'
607608
case CREF_QUAL(__) then

0 commit comments

Comments
 (0)