Skip to content

Commit 40ae66b

Browse files
committed
Refactored code
Signed-off-by: Cervenka Dusan <cervenka@acrios.com>
1 parent c2e072a commit 40ae66b

File tree

50 files changed

+830
-1000
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+830
-1000
lines changed

erpcgen/src/CGenerator.cpp

Lines changed: 23 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ void CGenerator::generate()
490490
m_templateData["structs"] = empty;
491491
m_templateData["unions"] = empty;
492492
m_templateData["consts"] = empty;
493-
m_templateData["functions"] = empty;
494493

495494
m_templateData["nonExternalStructUnion"] = false;
496495

@@ -573,7 +572,6 @@ void CGenerator::generate()
573572
groupTemplate["includes"] = makeGroupIncludesTemplateData(group);
574573
groupTemplate["symbolsMap"] = makeGroupSymbolsTemplateData(group);
575574
groupTemplate["interfaces"] = makeGroupInterfacesTemplateData(group);
576-
groupTemplate["callbacks"] = makeGroupCallbacksTemplateData(group);
577575
group->setTemplate(groupTemplate);
578576

579577
generateGroupOutputFiles(group);
@@ -1002,43 +1000,6 @@ data_map CGenerator::makeGroupSymbolsTemplateData(Group *group)
10021000
return symbolsTemplate;
10031001
}
10041002

1005-
data_list CGenerator::makeGroupCallbacksTemplateData(Group *group)
1006-
{
1007-
data_list functionTypes;
1008-
std::map<FunctionType *, int> functionTypeMap;
1009-
1010-
// need go trough functions instead of group symbols.
1011-
for (Interface *interface : group->getInterfaces())
1012-
{
1013-
for (Function *function : interface->getFunctions())
1014-
{
1015-
FunctionType *functionType = function->getFunctionType();
1016-
if (functionType)
1017-
{
1018-
bool isPresent = (functionTypeMap.find(functionType) != functionTypeMap.end());
1019-
if (isPresent)
1020-
{
1021-
++functionTypeMap[functionType];
1022-
}
1023-
else
1024-
{
1025-
functionTypeMap[functionType] = 1;
1026-
}
1027-
}
1028-
}
1029-
}
1030-
1031-
for (std::map<FunctionType *, int>::iterator it = functionTypeMap.begin(); it != functionTypeMap.end(); ++it)
1032-
{
1033-
if (it->second > 1)
1034-
{
1035-
functionTypes.push_back(getFunctionTypeTemplateData(group, it->first));
1036-
}
1037-
}
1038-
1039-
return functionTypes;
1040-
}
1041-
10421003
data_map CGenerator::getStructDeclarationTemplateData(StructType *structType)
10431004
{
10441005
data_map info;
@@ -1681,7 +1642,7 @@ data_map CGenerator::getFunctionBaseTemplateData(Group *group, FunctionBase *fn)
16811642
return info;
16821643
}
16831644

1684-
data_map CGenerator::getFunctionTemplateData(Group *group, Function *fn, Interface *interface)
1645+
data_map CGenerator::getFunctionTemplateData(Group *group, Function *fn)
16851646
{
16861647
data_map info;
16871648

@@ -1724,22 +1685,18 @@ data_map CGenerator::getFunctionTemplateData(Group *group, Function *fn, Interfa
17241685
else
17251686
{
17261687
info["isCallback"] = false;
1727-
string serverProto = getFunctionServerCall(fn, nullptr, "m_handler->");
1728-
info["serverPrototype"] = serverProto;
1688+
info["serverPrototype"] = getFunctionServerCall(fn);
17291689
info["serviceId"] = "";
17301690
}
1731-
string serverProtoC = getFunctionServerCall(fn);
1691+
string serverProtoC = getFunctionServerCall(fn, true);
17321692
info["serverPrototypeC"] = serverProtoC;
17331693

17341694
string proto = getFunctionPrototype(group, fn);
17351695
info["prototype"] = proto;
1736-
if (interface != nullptr)
1737-
{
1738-
string protoCpp = getFunctionPrototype(group, fn, interface->getName() + "_client", "", true);
1739-
info["prototypeCpp"] = protoCpp;
1740-
string protoInterface = getFunctionPrototype(group, fn, "", "", true);
1741-
info["prototypeInterface"] = protoInterface;
1742-
}
1696+
string protoCpp = getFunctionPrototype(group, fn, fn->getInterface()->getName() + "_client", "", true);
1697+
info["prototypeCpp"] = protoCpp;
1698+
string protoInterface = getFunctionPrototype(group, fn, "", "", true);
1699+
info["prototypeInterface"] = protoInterface;
17431700

17441701
data_list callbackParameters;
17451702
for (auto parameter : fn->getParameters().getMembers())
@@ -1794,7 +1751,7 @@ data_map CGenerator::getFunctionTypeTemplateData(Group *group, FunctionType *fn)
17941751
{
17951752
data_map functionInfo = getFunctionTemplateData(group, function);
17961753
// set serverPrototype function with parameters of common function.
1797-
string serverProto = getFunctionServerCall(function, fn);
1754+
string serverProto = getFunctionServerCall(function, true);
17981755
functionInfo["serverPrototype"] = serverProto;
17991756
functionInfos.push_back(functionInfo);
18001757
}
@@ -1971,18 +1928,23 @@ string CGenerator::getErrorReturnValue(FunctionBase *fn)
19711928
}
19721929
}
19731930

1974-
string CGenerator::getFunctionServerCall(Function *fn, FunctionType *functionType, const std::string prefix)
1931+
string CGenerator::getFunctionServerCall(Function *fn, bool isCCall)
19751932
{
19761933
string proto = "";
1977-
if (!fn->getReturnType()->isVoid() && prefix.length() > 0)
1934+
if (!isCCall)
19781935
{
1979-
proto += "result = ";
1936+
if (!fn->getReturnType()->isVoid())
1937+
{
1938+
proto += "result = ";
1939+
}
1940+
proto += "m_handler->";
19801941
}
1981-
proto += prefix;
19821942
proto += getOutputName(fn);
19831943
proto += "(";
19841944

1985-
auto params = (functionType) ? functionType->getParameters().getMembers() : fn->getParameters().getMembers();
1945+
FunctionType *funcType = fn->getFunctionType();
1946+
1947+
auto params = (funcType) ? funcType->getParameters().getMembers() : fn->getParameters().getMembers();
19861948

19871949
if (params.size())
19881950
{
@@ -2004,7 +1966,7 @@ string CGenerator::getFunctionServerCall(Function *fn, FunctionType *functionTyp
20041966
(findAnnotation(it, SHARED_ANNOTATION))))
20051967

20061968
{
2007-
if (prefix != "")
1969+
if (!isCCall)
20081970
{
20091971
proto += "&";
20101972
}
@@ -2022,7 +1984,7 @@ string CGenerator::getFunctionServerCall(Function *fn, FunctionType *functionTyp
20221984
}
20231985

20241986
string CGenerator::getFunctionPrototype(Group *group, FunctionBase *fn, const std::string &interfaceName,
2025-
const std::string &name, bool interfaceClass)
1987+
const string &name, bool insideInterfaceCall)
20261988
{
20271989
DataType *dataTypeReturn = fn->getReturnType();
20281990
string proto = getExtraPointerInReturn(dataTypeReturn);
@@ -2037,12 +1999,11 @@ string CGenerator::getFunctionPrototype(Group *group, FunctionBase *fn, const st
20371999
ifaceVar += "::";
20382000
}
20392001

2040-
Symbol *symbol = dynamic_cast<Symbol *>(fn);
2041-
assert(symbol);
2042-
20432002
FunctionType *funType = dynamic_cast<FunctionType *>(fn);
20442003
if (name.empty())
20452004
{
2005+
Symbol *symbol = dynamic_cast<Symbol *>(fn);
2006+
assert(symbol);
20462007
string functionName = getOutputName(symbol);
20472008
if (funType) /* Need add '(*name)' for function type definition. */
20482009
{
@@ -2157,7 +2118,7 @@ string CGenerator::getFunctionPrototype(Group *group, FunctionBase *fn, const st
21572118
}
21582119
}
21592120

2160-
if (interfaceClass)
2121+
if (insideInterfaceCall)
21612122
{
21622123
if (trueDataType->isFunction())
21632124
{

erpcgen/src/CGenerator.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class CGenerator : public Generator
239239
*
240240
* @return Contains interface function data.
241241
*/
242-
cpptempl::data_map getFunctionTemplateData(Group *group, Function *fn, Interface *interface = nullptr) override;
242+
cpptempl::data_map getFunctionTemplateData(Group *group, Function *fn) override;
243243

244244
/*!
245245
* @brief This function returns function type (callbacks type) template data.
@@ -469,23 +469,24 @@ class CGenerator : public Generator
469469
*
470470
* @param[in] group Group to which function belongs.
471471
* @param[in] fn Function for prototyping.
472-
* @param[in] name Name used for FunctionType.
473-
* @param[in] interfaceClass interfaceClass specific.
472+
* @param[in] interfaceName Interface name used for function declaration.
473+
* @param[in] name Name used for shared code in case of function type.
474+
* @param[in] insideInterfaceCall interfaceClass specific.
474475
*
475476
* @return String prototype representation for given function.
476477
*/
477478
std::string getFunctionPrototype(Group *group, FunctionBase *fn, const std::string &interfaceName = "",
478-
const std::string &name = "", bool interfaceClass = false);
479+
const std::string &name = "", bool insideInterfaceCall = false);
479480

480481
/*!
481482
* @brief This function return interface function representation called by server side.
482483
*
483484
* @param[in] fn Function for interface function representation.
484-
* @param[in] functionType Inside FunctionType common shim code server call need use FunctionType parameters names.
485+
* @param[in] isCCall C and C++ code is similar, but not same.
485486
*
486487
* @return String representation for given function.
487488
*/
488-
std::string getFunctionServerCall(Function *fn, FunctionType *functionType = nullptr, const std::string = "");
489+
std::string getFunctionServerCall(Function *fn, bool isCCall = false);
489490

490491
/*!
491492
* @brief This function return name with guard.

erpcgen/src/Generator.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,8 @@ data_list Generator::makeGroupInterfacesTemplateData(Group *group)
452452
data_list callbacksInt;
453453
data_list callbacksExt;
454454
data_list callbacksAll;
455-
getCallbacksTemplateData(iface, callbacksInt, callbacksExt, callbacksAll);
455+
getCallbacksTemplateData(group, iface, callbacksInt, callbacksExt, callbacksAll);
456456
ifaceInfo["callbacksInt"] = callbacksInt;
457-
ifaceInfo["callbacksExt"] = callbacksExt;
458457
ifaceInfo["callbacksAll"] = callbacksAll;
459458
ifaceInfo["isNonExternalInterface"] = false;
460459
for (unsigned int i = 0; i < functions.size(); ++i)
@@ -647,7 +646,7 @@ data_list Generator::getFunctionsTemplateData(Group *group, Interface *iface)
647646
int j = 0;
648647
for (auto fit : iface->getFunctions())
649648
{
650-
data_map function = getFunctionTemplateData(group, fit, iface);
649+
data_map function = getFunctionTemplateData(group, fit);
651650
fns.push_back(function);
652651

653652
Log::info(" %d: (%d) %s\n", j, fit->getUniqueId(), function["prototype"]->getvalue().c_str());
@@ -671,7 +670,7 @@ Generator::datatype_vector_t Generator::getDataTypesFromSymbolScope(SymbolScope
671670
return vector;
672671
}
673672

674-
void Generator::getCallbacksTemplateData(const Interface *iface, data_list &callbackTypesInt,
673+
void Generator::getCallbacksTemplateData(Group *group, const Interface *iface, data_list &callbackTypesInt,
675674
data_list &callbackTypesExt, data_list &callbackTypesAll)
676675
{
677676
list<FunctionType *> callbackTypes;
@@ -736,14 +735,12 @@ void Generator::getCallbacksTemplateData(const Interface *iface, data_list &call
736735
{
737736
data_map callbackType;
738737
callbackType["name"] = functionType->getName();
739-
AliasType aliasTypeInterface(getFunctionPrototype(nullptr, functionType, iface->getName() + "_interface"),
740-
functionType);
741-
AliasType aliasType(getFunctionPrototype(nullptr, functionType), functionType);
742-
callbackType["typenameName"] = getOutputName(&aliasType);
743-
callbackType["interfaceTypenameName"] = getOutputName(&aliasTypeInterface);
738+
callbackType["typenameName"] = getFunctionPrototype(nullptr, functionType);
739+
callbackType["interfaceTypenameName"] = getFunctionPrototype(nullptr, functionType, iface->getName() + "_interface");
744740
if (!functionsInt.empty())
745741
{
746742
callbackType["callbacks"] = functionsInt;
743+
callbackType["callbacksData"] = getFunctionTypeTemplateData(group, functionType);
747744
callbackTypesInt.push_back(callbackType);
748745
}
749746
if (!functionsExt.empty())

erpcgen/src/Generator.hpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,24 @@ class Generator
201201
*
202202
* @param[in] group Pointer to a group.
203203
* @param[in] fn From this are set interface function template data.
204-
* @param[in] fnIndex Function index.
205204
*
206205
* @return Contains interface function data.
207206
*/
208-
virtual cpptempl::data_map getFunctionTemplateData(Group *group, Function *fn, Interface *interface = nullptr) = 0;
207+
virtual cpptempl::data_map getFunctionTemplateData(Group *group, Function *fn) = 0;
208+
209+
/*!
210+
* @brief This function returns function type (callbacks type) template data.
211+
*
212+
* This function returns function type (callbacks type) template data with all data, which
213+
* are necessary for generating output code for output files. Shim code is generating
214+
* common function for serialization/deserialization of data.
215+
*
216+
* @param[in] group Group to which function belongs.
217+
* @param[in] fn From this are set function type template data.
218+
*
219+
* @return Contains interface function data.
220+
*/
221+
virtual cpptempl::data_map getFunctionTypeTemplateData(Group *group, FunctionType *fn) = 0;
209222

210223
/*!
211224
* @brief This function will get symbol comments and convert to language specific ones
@@ -250,7 +263,6 @@ class Generator
250263
* @brief This function generates output files for defined interfaces.
251264
*
252265
* @param[in] group Pointer to a group.
253-
* @param[out] commonFilesFilename Common filename part of group generated files.
254266
*/
255267
void generateGroupOutputFiles(Group *group);
256268

@@ -361,13 +373,14 @@ class Generator
361373
*
362374
* @param[in] group Group to which function belongs.
363375
* @param[in] fn Function for prototyping.
364-
* @param[in] name Name used for FunctionType.
365-
* @param[in] interfaceClass interfaceClass specific.
376+
* @param[in] interfaceName Interface name used for function declaration.
377+
* @param[in] name Name used for shared code in case of function type.
378+
* @param[in] insideInterfaceCall interfaceClass specific.
366379
*
367380
* @return String prototype representation for given function.
368381
*/
369382
virtual std::string getFunctionPrototype(Group *group, FunctionBase *fn, const std::string &interfaceName = "",
370-
const std::string &name = "", bool interfaceClass = false) = 0;
383+
const std::string &name = "", bool insideInterfaceCall = false) = 0;
371384

372385
private:
373386
/*!
@@ -382,7 +395,16 @@ class Generator
382395
*/
383396
cpptempl::data_list getFunctionsTemplateData(Group *group, Interface *iface);
384397

385-
void getCallbacksTemplateData(const Interface *iface, cpptempl::data_list &callbackTypesInt,
398+
/*!
399+
* @brief Get the Callbacks template data and dived them to the interface scope list.
400+
*
401+
* @param[in] group Group to which callbacks belongs.
402+
* @param[in] iface Use callbacks belongs to this interface.
403+
* @param[out] callbackTypesInt Template data for current interface scope callbacks
404+
* @param[out] callbackTypesExt Template data for others interface scope callbacks
405+
* @param[out] callbackTypesAll Template data of all callbacks.
406+
*/
407+
void getCallbacksTemplateData(Group *group, const Interface *iface, cpptempl::data_list &callbackTypesInt,
386408
cpptempl::data_list &callbackTypesExt, cpptempl::data_list &callbackTypesAll);
387409
};
388410

erpcgen/src/PythonGenerator.cpp

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@ void PythonGenerator::generate()
146146

147147
makeEnumsTemplateData();
148148

149-
makeFunctionsTemplateData();
150-
151149
for (Group *group : m_groups)
152150
{
153151
data_map groupTemplate;
@@ -169,7 +167,7 @@ void PythonGenerator::setTemplateComments(Symbol *symbol, data_map &symbolInfo)
169167
symbolInfo["ilComment"] = convertComment(symbol->getIlComment(), kInlineComment);
170168
}
171169

172-
data_map PythonGenerator::getFunctionTemplateData(Group *group, Function *fn, Interface *interface)
170+
data_map PythonGenerator::getFunctionTemplateData(Group *group, Function *fn)
173171
{
174172
(void)group;
175173
data_map info;
@@ -267,7 +265,7 @@ data_map PythonGenerator::getFunctionTemplateData(Group *group, Function *fn, In
267265
}
268266

269267
string PythonGenerator::getFunctionPrototype(Group *group, FunctionBase *fn, const string &interfaceName,
270-
const string &name, bool interfaceClass)
268+
const string &name, bool insideInterfaceCall)
271269
{
272270
FunctionType *functionType = dynamic_cast<FunctionType *>(fn);
273271
if (functionType)
@@ -582,32 +580,6 @@ void PythonGenerator::setOneStructMemberTemplateData(StructMember *member, data_
582580
setTemplateComments(member, member_info);
583581
}
584582

585-
void PythonGenerator::makeFunctionsTemplateData()
586-
{
587-
/* type definitions of functions and table of functions */
588-
Log::info("Functions:\n");
589-
data_list functions;
590-
for (Symbol *functionTypeSymbol : getDataTypesFromSymbolScope(m_globals, DataType::kFunctionType))
591-
{
592-
FunctionType *functionType = dynamic_cast<FunctionType *>(functionTypeSymbol);
593-
data_map functionInfo;
594-
595-
/* Table template data. */
596-
data_list callbacks;
597-
for (Function *fun : functionType->getCallbackFuns())
598-
{
599-
data_map callbacksInfo;
600-
callbacksInfo["name"] = fun->getName();
601-
callbacks.push_back(callbacksInfo);
602-
}
603-
functionInfo["callbacks"] = callbacks;
604-
/* Function type name. */
605-
functionInfo["name"] = functionType->getName();
606-
functions.push_back(functionInfo);
607-
}
608-
m_templateData["functions"] = functions;
609-
}
610-
611583
data_map PythonGenerator::getTypeInfo(DataType *t)
612584
{
613585
data_map info;

0 commit comments

Comments
 (0)