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

Commit f79568b

Browse files
adeas31OpenModelica-Hudson
authored andcommitted
Fixed arrays for OMEdit logs.
1 parent 94c1c9b commit f79568b

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

Compiler/Template/GenerateAPIFunctionsTpl.tpl

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,29 @@ template getQtInArgBoxed(Text name, DAE.Type ty)
283283
else error(sourceInfo(), 'getQtInArgBoxed failed for <%unparseType(ty)%>')
284284
end getQtInArgBoxed;
285285

286-
template getQtCommandLogText(Text name, DAE.Type ty)
286+
template getQtCommandLogText(Text name, DAE.Type ty, Text commandLog)
287287
::=
288288
match ty
289-
case T_CODE(ty=C_TYPENAME(__)) then '<%name%>'
290-
case T_STRING(__) then 'QString("\""+<%name%>+"\"")'
289+
case T_CODE(ty=C_TYPENAME(__)) then '<%commandLog%>.append(<%name%>);' + "\n"
290+
case T_STRING(__) then '<%commandLog%>.append("\"" + <%name%> + "\"");' + "\n"
291291
case T_INTEGER(__)
292-
case T_REAL(__) then 'QString::number(<%name%>)'
293-
case T_BOOL(__) then 'QString(<%name%> ? "true" : "false")'
294-
case aty as T_ARRAY(__) then 'QString("### Handle array arguments ###")'
292+
case T_REAL(__) then '<%commandLog%>.append(QString::number(<%name%>));' + "\n"
293+
case T_BOOL(__) then '<%commandLog%>.append(<%name%> ? "true" : "false");' + "\n"
294+
case aty as T_ARRAY(__) then
295+
let elt = '<%name%>_elt'
296+
let counter = '<%name%>_i'
297+
<<
298+
<%commandLog%>.append("{");
299+
int <%counter%> = 0;
300+
foreach(<%getQtType(aty.ty)%> <%elt%>, <%name%>) {
301+
if (<%counter%>) {
302+
<%commandLog%>.append(",");
303+
}
304+
<%getQtCommandLogText(elt, aty.ty, commandLog)%>
305+
<%counter%>++;
306+
}
307+
<%commandLog%>.append("}");
308+
>>
295309
else error(sourceInfo(), 'getQtCommandLogText failed for <%unparseType(ty)%>')
296310
end getQtCommandLogText;
297311

@@ -352,7 +366,7 @@ template getQtResponseLogText(Text name, DAE.Type ty, Text responseLog)
352366
int <%counter%> = 0;
353367
foreach(<%getQtType(aty.ty)%> <%elt%>, <%name%>) {
354368
if (<%counter%>) {
355-
responseLog.append(",");
369+
<%responseLog%>.append(",");
356370
}
357371
<%getQtResponseLogText(elt, aty.ty, responseLog)%>
358372
<%counter%>++;
@@ -368,7 +382,8 @@ template getQtInterfaceFunc(String name, list<DAE.FuncArg> args, DAE.Type res, S
368382
let &responseLog = buffer ""
369383
let &postCall = buffer ""
370384
let inArgs = args |> arg as FUNCARG(__) => ', <%getQtInArg(arg.name, arg.ty, varDecl)%>'
371-
let commandArgs = args |> arg as FUNCARG(__) => getQtCommandLogText(arg.name, arg.ty) ; separator='+"," +'
385+
let &commandLog = buffer ""
386+
let &commandLog += args |> arg as FUNCARG(__) => getQtCommandLogText(arg.name, arg.ty, 'commandLog') ; separator='commandLog.append(",");' + "\n"
372387
let outArgs = (match res
373388
case T_NORETCALL(__) then
374389
""
@@ -386,7 +401,15 @@ template getQtInterfaceFunc(String name, list<DAE.FuncArg> args, DAE.Type res, S
386401
{
387402
QTime commandTime;
388403
commandTime.start();
389-
emit logCommand("<%replaceDotAndUnderscore(name)%>("+<%if intGt(listLength(args), 0) then commandArgs else 'QString("")'%>+")", &commandTime);
404+
<%if intGt(listLength(args), 0) then
405+
<<
406+
QString commandLog;
407+
<%commandLog%>
408+
emit logCommand("<%replaceDotAndUnderscore(name)%>("+commandLog+")", &commandTime);
409+
>> else
410+
<<
411+
emit logCommand("<%replaceDotAndUnderscore(name)%>()", &commandTime);
412+
>>%>
390413
391414
<%varDecl%>
392415

0 commit comments

Comments
 (0)