Skip to content

Commit

Permalink
- Generate struct field names based on function output names.
Browse files Browse the repository at this point in the history
- Converted few more API calls in OMEdit to use scripting API.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24460 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Feb 6, 2015
1 parent 2900bde commit 33d3e2d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Compiler/Template/GenerateAPIFunctionsTpl.tpl
Expand Up @@ -165,6 +165,20 @@ template getQtType(DAE.Type ty)
else error(sourceInfo(), 'getQtType failed for <%unparseType(ty)%>')
end getQtType;

template getQtTupleTypeOutputNameHelper(Option<list<String>> names, Integer index)
::=
match names
case SOME(lst) then listGet(lst, index)
else 'res<%index%>'
end getQtTupleTypeOutputNameHelper;

template getQtTupleTypeOutputName(DAE.Type ty, Integer index)
::=
match ty
case T_TUPLE(__) then getQtTupleTypeOutputNameHelper(names, index)
else 'res<%index%>'
end getQtTupleTypeOutputName;

template getQtInterfaceHeader(String name, String prefix, list<DAE.FuncArg> args, DAE.Type res, String className, Boolean addStructs)
::=
let inTypes = args |> arg as FUNCARG(__) => '<%getQtType(arg.ty)%> <%arg.name%>' ; separator=", "
Expand All @@ -173,7 +187,7 @@ template getQtInterfaceHeader(String name, String prefix, list<DAE.FuncArg> args
if addStructs then
<<
typedef struct {
<%types |> ty hasindex i fromindex 1 => '<%getQtType(ty)%> res<%i%>;' ; separator="\n" %>
<%types |> ty hasindex i fromindex 1 => '<%getQtType(ty)%> <%getQtTupleTypeOutputName(res, i)%>;' ; separator="\n" %>
} <%name%>_res;
<%name%>_res
>>
Expand Down Expand Up @@ -275,7 +289,7 @@ template getQtInterfaceFunc(String name, list<DAE.FuncArg> args, DAE.Type res, S
case T_NORETCALL(__) then ""
case t as T_TUPLE(__) then
let &varDecl += '<%name%>_res result;<%\n%>'
(types |> t hasindex i1 fromindex 1 => ', <%getQtOutArg('result.res<%i1%>', 'out<%i1%>', t, varDecl, postCall)%>')
(types |> t hasindex i1 fromindex 1 => ', <%getQtOutArg('result.<%getQtTupleTypeOutputName(res, i1)%>', 'out<%i1%>', t, varDecl, postCall)%>')
else
let &varDecl += '<%getQtType(res)%> result;<%\n%>'
', <%getQtOutArg('result', 'result', res, varDecl, postCall)%>'
Expand Down
1 change: 1 addition & 0 deletions Compiler/Template/SimCodeTV.mo
Expand Up @@ -1740,6 +1740,7 @@ package DAE

record T_TUPLE
list<Type> types "For functions returning multiple values.";
Option<list<String>> names "For tuples elements that have names (function outputs)";
TypeSource source;
end T_TUPLE;

Expand Down

0 comments on commit 33d3e2d

Please sign in to comment.