Skip to content

Commit

Permalink
Handle mapping of record members to external C code types and layout. (
Browse files Browse the repository at this point in the history
…#9399)

* Cleanup external function handling.

  - This is done in preparation for implementing of conversion types and
    function for sending and receiving record types to external C functions
    while making sure that types are interpreted correctly
      modelica_integer (a.k.a long) vs int right now.'

* Handle mapping of recrods to external function arguments.

  - Each Modelica record now gets two struct definitions. The first,
    already existing, version uses OpenModelica types for the record members.

    The new additional type uses types specified in Modelica Standard for
    mapping of external arguments, i.e., uses `double`, `int`, `int`, '
    `const char*`, and `int` for Real, Integer, Boolean, String, and Enumeration
    repsectively, regardless of our internal representations.

  - Each Modelica record also gets two addition functions for converting
    to/from one representation of the record to the other.

  - This is a lot of additional code generation. However, it can be mitigated
    by identifying the only records that need it and avoiding it for the others.

  - Records that contain arrays or other records are not yet supported in
    this mode.

* Add mapping support for record record members.

  - Extend the record conversion functions to handle nested records.
  - We do not support arrays yet.

* typedef external versions for alias records too.

* Add marker for records needing conversion to external versions.

  - This marker is set to false for all record types at the moment. The
    additional code is generated for all records regardless of the value.

    Once we implement the necessary analysis we can change the value for
    records that need it and disable the generation being done for all
    records right now.
  • Loading branch information
mahge committed Sep 20, 2022
1 parent 02c4db5 commit 1cd773f
Show file tree
Hide file tree
Showing 17 changed files with 186 additions and 60 deletions.
5 changes: 3 additions & 2 deletions OMCompiler/Compiler/FrontEnd/DAE.mo
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,8 @@ constant Type T_ANYTYPE_DEFAULT = T_ANYTYPE(NONE());
constant Type T_UNKNOWN_DEFAULT = T_UNKNOWN();
constant Type T_NORETCALL_DEFAULT = T_NORETCALL();
constant Type T_METATYPE_DEFAULT = T_METATYPE(T_UNKNOWN_DEFAULT);
constant Type T_COMPLEX_DEFAULT = T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("")), {}, NONE()) "default complex with unknown CiState";
constant Type T_COMPLEX_DEFAULT_RECORD = T_COMPLEX(ClassInf.RECORD(Absyn.IDENT("")), {}, NONE()) "default complex with record CiState";
constant Type T_COMPLEX_DEFAULT = T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("")), {}, NONE(), false) "default complex with unknown CiState";
constant Type T_COMPLEX_DEFAULT_RECORD = T_COMPLEX(ClassInf.RECORD(Absyn.IDENT("")), {}, NONE(), false) "default complex with record CiState";

constant Type T_SOURCEINFO_DEFAULT_METARECORD = T_METARECORD(Absyn.QUALIFIED("SourceInfo",Absyn.IDENT("SOURCEINFO")), Absyn.IDENT("SourceInfo"), {}, 1, {
TYPES_VAR("fileName", dummyAttrVar, T_STRING_DEFAULT, UNBOUND(), false, NONE()),
Expand Down Expand Up @@ -964,6 +964,7 @@ public uniontype Type "models the different front-end and back-end types"
ClassInf.State complexClassType "The type of a class";
list<Var> varLst "The variables of a complex type";
EqualityConstraint equalityConstraint;
Boolean needsExternalConversion "If the record is passed to an external function at any point, we need to generate conversion functions for it (for instance to convert 'modelica_integer' to 'int')";
end T_COMPLEX;

record T_SUBTYPE_BASIC
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/FrontEnd/Inst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ algorithm
end for;
tvars := listReverse(tvars);

then DAE.T_COMPLEX(inType.complexClassType, tvars, inType.equalityConstraint);
then DAE.T_COMPLEX(inType.complexClassType, tvars, inType.equalityConstraint, inType.needsExternalConversion);
end match;

end markDerivedRecordOutsideBindings;
Expand Down Expand Up @@ -1084,7 +1084,7 @@ algorithm
end for;
tvars := listReverse(tvars);

then DAE.T_COMPLEX(inType.complexClassType, tvars, inType.equalityConstraint);
then DAE.T_COMPLEX(inType.complexClassType, tvars, inType.equalityConstraint, inType.needsExternalConversion);
end match;

end markTypesVarsOutsideBindings;
Expand Down
3 changes: 2 additions & 1 deletion OMCompiler/Compiler/FrontEnd/InstBinding.mo
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public constant DAE.Type distributionType =
false,
NONE())
},
NONE());
NONE(),
false);

protected function instBinding
"This function investigates a modification and extracts the
Expand Down
13 changes: 8 additions & 5 deletions OMCompiler/Compiler/FrontEnd/InstFunction.mo
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,8 @@ algorithm
list<DAE.FuncArg> fargs;
DAE.EqualityConstraint eqCo;
String name, newName;
Boolean extConvert;


case(_, _, _)
equation
Expand All @@ -821,7 +823,7 @@ algorithm
UnitAbsynBuilder.emptyInstStore(), DAE.NOMOD(), DAE.NOPRE(), recordCl,
{}, true, InstTypes.INNER_CALL(), ConnectionGraph.EMPTY, Connect.emptySet);

DAE.T_COMPLEX(ClassInf.RECORD(path), vars, eqCo) = recType;
DAE.T_COMPLEX(ClassInf.RECORD(path), vars, eqCo, extConvert) = recType;

vars = Types.filterRecordComponents(vars, SCodeUtil.elementInfo(recordCl));
(inputs,locals) = List.extractOnTrue(vars, Types.isModifiableTypesVar);
Expand All @@ -830,7 +832,7 @@ algorithm
vars = listAppend(inputs,locals);

path = AbsynUtil.makeFullyQualified(path);
fixedTy = DAE.T_COMPLEX(ClassInf.RECORD(path), vars, eqCo);
fixedTy = DAE.T_COMPLEX(ClassInf.RECORD(path), vars, eqCo, extConvert);
fargs = Types.makeFargsList(inputs);
funcTy = DAE.T_FUNCTION(fargs, fixedTy, DAE.FUNCTION_ATTRIBUTES_DEFAULT, path);
func = DAE.RECORD_CONSTRUCTOR(path,funcTy,DAE.emptyElementSource);
Expand All @@ -839,7 +841,7 @@ algorithm

// add the instance record constructor too!
path = AbsynUtil.pathSetLastIdent(path, name);
fixedTy = DAE.T_COMPLEX(ClassInf.RECORD(path), vars, eqCo);
fixedTy = DAE.T_COMPLEX(ClassInf.RECORD(path), vars, eqCo, extConvert);
fargs = Types.makeFargsList(inputs);
funcTy = DAE.T_FUNCTION(fargs, fixedTy, DAE.FUNCTION_ATTRIBUTES_DEFAULT, path);
func = DAE.RECORD_CONSTRUCTOR(path,funcTy,DAE.emptyElementSource);
Expand Down Expand Up @@ -878,6 +880,7 @@ algorithm
FCore.Graph recordEnv;
DAE.Function func;
list<DAE.FuncArg> fargs;
Boolean extConvert;

// try to instantiate class
case (cache, _, DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(path)), _)
Expand All @@ -888,7 +891,7 @@ algorithm
cache;

// if previous stuff didn't work, try to use the ty directly
case (cache, _, DAE.T_COMPLEX(ClassInf.RECORD(path), vars, eqCo), _)
case (cache, _, DAE.T_COMPLEX(ClassInf.RECORD(path), vars, eqCo, extConvert), _)
equation
path = AbsynUtil.makeFullyQualified(path);

Expand All @@ -898,7 +901,7 @@ algorithm
locals = List.map(locals,Types.setVarProtected);
vars = listAppend(inputs,locals);

fixedTy = DAE.T_COMPLEX(ClassInf.RECORD(path), vars, eqCo);
fixedTy = DAE.T_COMPLEX(ClassInf.RECORD(path), vars, eqCo, extConvert);
fargs = Types.makeFargsList(inputs);
funcTy = DAE.T_FUNCTION(fargs, fixedTy, DAE.FUNCTION_ATTRIBUTES_DEFAULT, path);
func = DAE.RECORD_CONSTRUCTOR(path,funcTy,DAE.emptyElementSource);
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/FrontEnd/InstSection.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3108,7 +3108,7 @@ algorithm
equation
vars = List.sort(vars, connectorCompGt);
then
DAE.T_COMPLEX(ci_state, vars, ec);
DAE.T_COMPLEX(ci_state, vars, ec, inType.needsExternalConversion);
else inType;
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/FrontEnd/InstUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -5545,7 +5545,7 @@ algorithm
case (_,st,l,NONE(),equalityConstraint,_)
equation
failure(ClassInf.META_UNIONTYPE(_) = st);
then DAE.T_COMPLEX(st,l,equalityConstraint);
then DAE.T_COMPLEX(st,l,equalityConstraint, false);

// extending
case (_,st,l,SOME(bc),equalityConstraint,_)
Expand Down Expand Up @@ -5646,7 +5646,7 @@ algorithm

// not extending basic type!
case (_,st,l,NONE(),_)
then DAE.T_COMPLEX(st,l,NONE()); // adrpo: TODO! check equalityConstraint!
then DAE.T_COMPLEX(st,l,NONE(), false); // adrpo: TODO! check equalityConstraint!

case (_,st,l,SOME(bc),_)
then DAE.T_SUBTYPE_BASIC(st,l,bc,NONE());
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/FrontEnd/Lookup.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2198,12 +2198,12 @@ algorithm
// function_name cardinality
case (_,"cardinality")
then {DAE.T_FUNCTION(
{DAE.FUNCARG("x",DAE.T_COMPLEX(ClassInf.CONNECTOR(Absyn.IDENT("$$"),false),{},NONE()),DAE.C_VAR(),DAE.NON_PARALLEL(),NONE())},
{DAE.FUNCARG("x",DAE.T_COMPLEX(ClassInf.CONNECTOR(Absyn.IDENT("$$"),false),{},NONE(), false),DAE.C_VAR(),DAE.NON_PARALLEL(),NONE())},
DAE.T_INTEGER_DEFAULT,
DAE.FUNCTION_ATTRIBUTES_DEFAULT,
Absyn.IDENT("cardinality")),
DAE.T_FUNCTION(
{DAE.FUNCARG("x",DAE.T_COMPLEX(ClassInf.CONNECTOR(Absyn.IDENT("$$"),true),{},NONE()),DAE.C_VAR(),DAE.NON_PARALLEL(),NONE())},
{DAE.FUNCARG("x",DAE.T_COMPLEX(ClassInf.CONNECTOR(Absyn.IDENT("$$"),true),{},NONE(), false),DAE.C_VAR(),DAE.NON_PARALLEL(),NONE())},
DAE.T_INTEGER_DEFAULT,
DAE.FUNCTION_ATTRIBUTES_DEFAULT,
Absyn.IDENT("cardinality"))};
Expand Down
8 changes: 4 additions & 4 deletions OMCompiler/Compiler/FrontEnd/PrefixUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,15 @@ algorithm
case (cache,_,_,DAE.PREFIX(DAE.NOCOMPPRE(),_),SOME(cref)) then (cache,cref);
case (cache,env,_,DAE.PREFIX(DAE.PRE(prefix = i,dimensions=ds,subscripts = s,next = xs,ci_state=ci_state),cp),NONE())
equation
ident_ty = Expression.liftArrayLeftList(DAE.T_COMPLEX(ci_state, {}, NONE()), ds);
ident_ty = Expression.liftArrayLeftList(DAE.T_COMPLEX(ci_state, {}, NONE(), false), ds);
cref_ = ComponentReference.makeCrefIdent(i,ident_ty,s);
(cache,cref_1) = prefixToCref2(cache,env,inIH,DAE.PREFIX(xs,cp), SOME(cref_));
then
(cache,cref_1);
case (cache,env,_,DAE.PREFIX(DAE.PRE(prefix = i,dimensions=ds,subscripts = s,next = xs,ci_state=ci_state),cp),SOME(cref))
equation
(cache,cref) = prefixSubscriptsInCref(cache,env,inIH,inPrefix,cref);
ident_ty = Expression.liftArrayLeftList(DAE.T_COMPLEX(ci_state, {}, NONE()), ds);
ident_ty = Expression.liftArrayLeftList(DAE.T_COMPLEX(ci_state, {}, NONE(), false), ds);
cref_2 = ComponentReference.makeCrefQual(i,ident_ty,s,cref);
(cache,cref_1) = prefixToCref2(cache,env,inIH,DAE.PREFIX(xs,cp), SOME(cref_2));
then
Expand Down Expand Up @@ -456,13 +456,13 @@ algorithm
case (DAE.PREFIX(DAE.NOCOMPPRE(),_),SOME(cref)) then SOME(cref);
case (DAE.PREFIX(DAE.PRE(prefix = i,subscripts = s,next = xs),cp),NONE())
equation
cref_ = ComponentReference.makeCrefIdent(i,DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("")), {}, NONE()),s);
cref_ = ComponentReference.makeCrefIdent(i,DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("")), {}, NONE(), false),s);
cref_1 = prefixToCrefOpt2(DAE.PREFIX(xs,cp), SOME(cref_));
then
cref_1;
case (DAE.PREFIX(DAE.PRE(prefix = i,subscripts = s,next = xs),cp),SOME(cref))
equation
cref_ = ComponentReference.makeCrefQual(i,DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("")), {}, NONE()),s,cref);
cref_ = ComponentReference.makeCrefQual(i,DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("")), {}, NONE(), false),s,cref);
cref_1 = prefixToCrefOpt2(DAE.PREFIX(xs,cp), SOME(cref_));
then
cref_1;
Expand Down
12 changes: 6 additions & 6 deletions OMCompiler/Compiler/FrontEnd/Static.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2146,19 +2146,19 @@ algorithm
then DAE.T_CODE(DAE.C_VARIABLENAME());
case Absyn.C_EQUATIONSECTION()
then DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("EquationSection")),{},NONE());
then DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("EquationSection")),{},NONE(), false);
case Absyn.C_ALGORITHMSECTION()
then DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("AlgorithmSection")),{},NONE());
then DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("AlgorithmSection")),{},NONE(), false);
case Absyn.C_ELEMENT()
then DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("Element")),{},NONE());
then DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("Element")),{},NONE(), false);
case Absyn.C_EXPRESSION()
then DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("Expression")),{},NONE());
then DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("Expression")),{},NONE(), false);
case Absyn.C_MODIFICATION()
then DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("Modification")),{},NONE());
then DAE.T_COMPLEX(ClassInf.UNKNOWN(Absyn.IDENT("Modification")),{},NONE(), false);
end match;
end elabCodeType;
Expand Down Expand Up @@ -9426,7 +9426,7 @@ algorithm
end for;
vars := listReverse(vars);
outType := DAE.T_COMPLEX(complexClassType, vars, NONE());
outType := DAE.T_COMPLEX(complexClassType, vars, NONE(), false);
end complexTypeFromSlots;
protected function slotListArgs
Expand Down
8 changes: 4 additions & 4 deletions OMCompiler/Compiler/FrontEnd/Types.mo
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ algorithm
equation
vars = List.map(vars, convertFromExpToTypesVar);
then
DAE.T_COMPLEX(CIS, vars, ec);
DAE.T_COMPLEX(CIS, vars, ec, inType.needsExternalConversion);

case DAE.T_SUBTYPE_BASIC(CIS, vars, ty, ec)
equation
Expand Down Expand Up @@ -1159,7 +1159,7 @@ algorithm
case Values.RECORD(record_ = cname,orderd = vl,comp = ids, index = -1)
equation
vars = valuesToVars(vl, ids);
then DAE.T_COMPLEX(ClassInf.RECORD(cname),vars,NONE());
then DAE.T_COMPLEX(ClassInf.RECORD(cname),vars,NONE(), false);

// MetaModelica Uniontype
case Values.RECORD(record_ = cname,orderd = vl,comp = ids, index = index)
Expand Down Expand Up @@ -3871,7 +3871,7 @@ algorithm
true = Config.acceptMetaModelicaGrammar();
varLst = list(simplifyVar(v) for v in varLst);
then
DAE.T_COMPLEX(CIS, varLst, ec);
DAE.T_COMPLEX(CIS, varLst, ec, inType.needsExternalConversion);
// do this for records too, otherwise:
// frame.R = Modelica.Mechanics.MultiBody.Frames.Orientation({const_matrix);
Expand All @@ -3880,7 +3880,7 @@ algorithm
equation
varLst = list(simplifyVar(v) for v in varLst);
then
DAE.T_COMPLEX(CIS, varLst, ec);
DAE.T_COMPLEX(CIS, varLst, ec, inType.needsExternalConversion);
// otherwise just return the same!
case DAE.T_COMPLEX() then inType;
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/FrontEnd/ValuesUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ algorithm
case(Values.RECORD(path,valLst,nameLst,_)) equation
eltTps = List.map(valLst,valueExpType);
varLst = List.threadMap(eltTps,nameLst,valueExpTypeExpVar);
then DAE.T_COMPLEX(ClassInf.RECORD(path),varLst,NONE());
then DAE.T_COMPLEX(ClassInf.RECORD(path),varLst,NONE(), false);

case _
equation
Expand Down Expand Up @@ -885,7 +885,7 @@ algorithm
expl = List.map(vallist,function valueExp(originalExp=NONE()));
tpl = List.map(expl,Expression.typeof);
varlst = List.threadMap(namelst,tpl,Expression.makeVar);
t = DAE.T_COMPLEX(ClassInf.RECORD(path),varlst,NONE());
t = DAE.T_COMPLEX(ClassInf.RECORD(path),varlst,NONE(), false);
then DAE.RECORD(path,expl,namelst,t);

case(Values.ENUM_LITERAL(name = path, index = ix))
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/NFFrontEnd/NFInstNode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,7 @@ uniontype InstNode
algorithm
state := Restriction.toDAE(Class.restriction(cls), fullPath(clsNode));
then
DAE.Type.T_COMPLEX(state, {}, NONE());
DAE.Type.T_COMPLEX(state, {}, NONE(), false);

end match;
end match;
Expand Down Expand Up @@ -1712,7 +1712,7 @@ uniontype InstNode
algorithm
state := Restriction.toDAE(Class.restriction(cls), fullPath(clsNode));
vars := ConvertDAE.makeTypeVars(clsNode);
outType := DAE.Type.T_COMPLEX(state, vars, NONE());
outType := DAE.Type.T_COMPLEX(state, vars, NONE(), false);
Pointer.update(clsNode.cls, Class.DAE_TYPE(outType));
then
outType;
Expand Down
6 changes: 3 additions & 3 deletions OMCompiler/Compiler/Script/CevalScriptBackend.mo
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected constant DAE.Type simulationResultType_rtest = DAE.T_COMPLEX(ClassInf.
DAE.TYPES_VAR("resultFile",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE()),
DAE.TYPES_VAR("simulationOptions",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE()),
DAE.TYPES_VAR("messages",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE())
},NONE());
},NONE(), false);

protected constant DAE.Type simulationResultType_full = DAE.T_COMPLEX(ClassInf.RECORD(Absyn.IDENT("SimulationResult")),{
DAE.TYPES_VAR("resultFile",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE()),
Expand All @@ -159,13 +159,13 @@ protected constant DAE.Type simulationResultType_full = DAE.T_COMPLEX(ClassInf.R
DAE.TYPES_VAR("timeCompile",DAE.dummyAttrVar,DAE.T_REAL_DEFAULT,DAE.UNBOUND(),false,NONE()),
DAE.TYPES_VAR("timeSimulation",DAE.dummyAttrVar,DAE.T_REAL_DEFAULT,DAE.UNBOUND(),false,NONE()),
DAE.TYPES_VAR("timeTotal",DAE.dummyAttrVar,DAE.T_REAL_DEFAULT,DAE.UNBOUND(),false,NONE())
},NONE());
},NONE(), false);

protected constant DAE.Type simulationResultType_drModelica = DAE.T_COMPLEX(ClassInf.RECORD(Absyn.IDENT("SimulationResult")),{
DAE.TYPES_VAR("messages",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE()),
DAE.TYPES_VAR("flatteningTime",DAE.dummyAttrVar,DAE.T_REAL_DEFAULT,DAE.UNBOUND(),false,NONE()),
DAE.TYPES_VAR("simulationTime",DAE.dummyAttrVar,DAE.T_REAL_DEFAULT,DAE.UNBOUND(),false,NONE())
},NONE());
},NONE(), false);

//these are in reversed order than above
protected constant list<tuple<String,Values.Value>> zeroAdditionalSimulationResultValues =
Expand Down
6 changes: 3 additions & 3 deletions OMCompiler/Compiler/Script/StaticScript.mo
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ algorithm
DAE.T_COMPLEX(ClassInf.RECORD(Absyn.IDENT("SimulationObject")),
{DAE.TYPES_VAR("flatClass",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE()),
DAE.TYPES_VAR("exeFile",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE())},
NONE());
NONE(), false);
then
(cache,Expression.makePureBuiltinCall("translateModelCPP",
{DAE.CODE(Absyn.C_TYPENAME(className),DAE.T_UNKNOWN_DEFAULT),filenameprefix},DAE.T_STRING_DEFAULT),DAE.PROP(recordtype,DAE.C_VAR()));
Expand All @@ -392,7 +392,7 @@ algorithm
DAE.T_COMPLEX(ClassInf.RECORD(Absyn.IDENT("SimulationObject")),
{DAE.TYPES_VAR("flatClass",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE()),
DAE.TYPES_VAR("exeFile",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE())},
NONE());
NONE(), false);
then
(cache,Expression.makePureBuiltinCall("translateModelXML",
{DAE.CODE(Absyn.C_TYPENAME(className),DAE.T_UNKNOWN_DEFAULT),filenameprefix},DAE.T_STRING_DEFAULT),DAE.PROP(recordtype,DAE.C_VAR()));
Expand All @@ -407,7 +407,7 @@ algorithm
DAE.T_COMPLEX(ClassInf.RECORD(Absyn.IDENT("SimulationObject")),
{DAE.TYPES_VAR("flatClass",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE()),
DAE.TYPES_VAR("exeFile",DAE.dummyAttrVar,DAE.T_STRING_DEFAULT,DAE.UNBOUND(),false,NONE())},
NONE());
NONE(), false);
then
(cache,Expression.makePureBuiltinCall("exportDAEtoMatlab",
{DAE.CODE(Absyn.C_TYPENAME(className),DAE.T_UNKNOWN_DEFAULT),filenameprefix},DAE.T_STRING_DEFAULT),DAE.PROP(recordtype,DAE.C_VAR()));
Expand Down
1 change: 1 addition & 0 deletions OMCompiler/Compiler/SimCode/SimCodeFunction.mo
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ uniontype RecordDeclaration
Option<String> aliasName "alias of struct (record) name ? encoded. Code generators can generate an aliasing typedef using this, and avoid problems when casting a record from one type to another (*(othertype*)(&var)), which only works if you have a lhs value.";
Absyn.Path defPath "definition path";
list<Variable> variables "only name and type";
Boolean needsExternalConversion "If the record is passed to an external function at any point, we need to generate conversion functions for it (for instance to convert 'modelica_integer' to 'int')";
end RECORD_DECL_FULL;

record RECORD_DECL_ADD_CONSTRCTOR
Expand Down
7 changes: 4 additions & 3 deletions OMCompiler/Compiler/SimCode/SimCodeFunctionUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,7 @@ algorithm
(accRecDecls, rt_1) := elaborateNestedRecordDeclarations(varlst, accRecDecls, rt_1);

vars := List.map(varlst, typesVar);
recDecl := SimCodeFunction.RECORD_DECL_FULL(sname, NONE(), path, vars);
recDecl := SimCodeFunction.RECORD_DECL_FULL(sname, NONE(), path, vars, false);
else
vars := List.map(varlst, typesVar);
recDecl := SimCodeFunction.RECORD_DECL_ADD_CONSTRCTOR(sname, name, vars);
Expand Down Expand Up @@ -2590,11 +2590,12 @@ algorithm
Absyn.Path name;
String str,sname;
Option<String> alias;
case (SimCodeFunction.RECORD_DECL_FULL(sname, _, name, vars),_)
Boolean extConvert;
case (SimCodeFunction.RECORD_DECL_FULL(sname, _, name, vars, extConvert),_)
equation
str = stringDelimitList(List.map(vars, variableString), "\n");
(alias,ht) = aliasRecordDeclarations2(str, name, inHt);
then (SimCodeFunction.RECORD_DECL_FULL(sname, alias, name, vars),ht);
then (SimCodeFunction.RECORD_DECL_FULL(sname, alias, name, vars, extConvert),ht);
else (inDecl,inHt);
end match;
end aliasRecordDeclarations;
Expand Down
Loading

0 comments on commit 1cd773f

Please sign in to comment.