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

Commit

Permalink
Update the Qt API
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - #2130
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Jan 30, 2018
1 parent e2c5189 commit 782245f
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions Compiler/Template/GenerateAPIFunctionsTpl.tpl
Expand Up @@ -92,10 +92,8 @@ template getCevalScriptInterfaceFunc(String name, list<DAE.FuncArg> args, DAE.Ty
else '<%getOutValue("res", res, &varDecl, &postMatch)%>'
<<
function <%name%>
input SymbolTable st;
<%args |> arg as FUNCARG(__) =>
'input <%getInType(arg.ty)%> <%arg.name%>;' ; separator="\n" %>
output SymbolTable outSymTab;
<%
match res
case T_TUPLE(__) then (types |> ty hasindex i fromindex 1 => 'output <%getInType(ty)%> res<%i%>;' ; separator="\n")
Expand All @@ -109,10 +107,8 @@ template getCevalScriptInterfaceFunc(String name, list<DAE.FuncArg> args, DAE.Ty
>>
%>
algorithm
SymbolTable.update(st);
(_,<%outVals%>) := CevalScript.cevalInteractiveFunctions2(FCore.emptyCache(), FGraph.empty(), "<%name%>", {<%inVals%>}, dummyMsg);
<%postMatch%>
outSymTab := SymbolTable.get();
end <%name%>;<%\n%>
>>
end getCevalScriptInterfaceFunc;
Expand All @@ -128,8 +124,8 @@ template getQtInterface(list<DAE.Type> tys, String classNameWithColons, String c
#include <stdexcept>
#include "OpenModelicaScriptingAPIQt.h"

<%classNameWithColons%><%className%>(threadData_t *td, void *symbolTable)
: threadData(td), st(symbolTable)
<%classNameWithColons%><%className%>(threadData_t *td)
: threadData(td)
{
}
<%funcs%>
Expand All @@ -150,8 +146,7 @@ template getQtInterfaceHeaders(list<DAE.Type> tys, String className)
Q_OBJECT
public:
threadData_t *threadData;
void *st;
<%className%>(threadData_t *td, void *symbolTable);
<%className%>(threadData_t *td);
<%heads%>
signals:
void logCommand(QString command, QTime *commandTime);
Expand Down Expand Up @@ -318,14 +313,14 @@ template getQtOutArg(Text name, Text shortName, DAE.Type ty, Text &varDecl, Text
case T_STRING(__) then
let &varDecl += 'void *<%shortName%>_mm = NULL;<%\n%>'
let &postCall += '<%name%> = QString::fromUtf8(MMC_STRINGDATA(<%shortName%>_mm));<%\n%>'
'&<%shortName%>_mm'
'<%shortName%>_mm'
case T_INTEGER(__)
case T_BOOL(__)
case T_REAL(__) then '&<%name%>'
case T_REAL(__) then '<%name%>'
case aty as T_ARRAY(__) then
let &varDecl += 'void *<%shortName%>_mm = NULL;<%\n%>'
let &postCall += getQtOutArgArray(name, shortName, '<%shortName%>_mm', aty)
'&<%shortName%>_mm'
'<%shortName%>_mm'
else error(sourceInfo(), 'getQtOutArg failed for <%unparseType(ty)%>')
end getQtOutArg;

Expand Down Expand Up @@ -386,17 +381,20 @@ template getQtInterfaceFunc(String name, list<DAE.FuncArg> args, DAE.Type res, S
let inArgs = args |> arg as FUNCARG(__) => ', <%getQtInArg(arg.name, arg.ty, varDecl)%>'
let &commandLog = buffer ""
let &commandLog += args |> arg as FUNCARG(__) => getQtCommandLogText(arg.name, arg.ty, 'commandLog') ; separator='commandLog.append(",");' + "\n"
let &outArg = buffer ""
let outArgs = (match res
case T_NORETCALL(__) then
""
case t as T_TUPLE(__) then
case t as T_TUPLE(types=type1::types2) then
let &varDecl += '<%name%>_res result;<%\n%>'
let &responseLog += '<%getQtResponseLogText('result', res, 'responseLog')%>'
(types |> t hasindex i1 fromindex 1 => ', <%getQtOutArg('result.<%getQtTupleTypeOutputName(res, i1)%>', 'out<%i1%>', t, varDecl, postCall)%>')
let &outArg += '<%getQtOutArg('result.<%getQtTupleTypeOutputName(res, 1)%>', 'out1', type1, varDecl, postCall)%> = '
(types2 |> t hasindex i1 fromindex 2 => ', &<%getQtOutArg('result.<%getQtTupleTypeOutputName(res, i1)%>', 'out<%i1%>', t, varDecl, postCall)%>')
else
let &varDecl += '<%getQtType(res)%> result;<%\n%>'
let &responseLog += '<%getQtResponseLogText('result', res, 'responseLog')%>'
', <%getQtOutArg('result', 'result', res, varDecl, postCall)%>'
let &outArg += '<%getQtOutArg('result', 'result', res, varDecl, postCall)%> = '
""
)
<<
<%getQtInterfaceHeader(name, '<%className%>', args, res, className, false)%>
Expand All @@ -418,7 +416,7 @@ template getQtInterfaceFunc(String name, list<DAE.FuncArg> args, DAE.Type res, S
try {
MMC_TRY_TOP_INTERNAL()
st = omc_OpenModelicaScriptingAPI_<%replaceDotAndUnderscore(name)%>(threadData, st<%inArgs%><%outArgs%>);
<%outArg%>omc_OpenModelicaScriptingAPI_<%replaceDotAndUnderscore(name)%>(threadData<%inArgs%><%outArgs%>);
<%postCall%>
MMC_CATCH_TOP()
Expand All @@ -430,7 +428,7 @@ template getQtInterfaceFunc(String name, list<DAE.FuncArg> args, DAE.Type res, S
<%responseLog%>
emit logResponse(responseLog, &commandTime);

<%if outArgs then "return result;"%>
<%if outArg then "return result;"%>
}
>>
end getQtInterfaceFunc;
Expand Down

0 comments on commit 782245f

Please sign in to comment.