Skip to content

Commit c2e072a

Browse files
committed
Putting function declaration under interface.
Signed-off-by: Cervenka Dusan <cervenka@acrios.com>
1 parent f50951c commit c2e072a

30 files changed

+366
-207
lines changed

erpc_c/infra/erpc_manually_constructed.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class ManuallyConstructed
161161
* @brief Returns information if object is free or is used.
162162
*
163163
* @return true Object is constructed and used.
164-
* @return false Object wasn't constructor or it is destructed and free.
164+
* @return false Object wasn't constructed or it was destructed already.
165165
*/
166166
bool isUsed(void) { return m_isConstructed; }
167167

erpc_c/infra/erpc_transport_arbitrator.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class TransportArbitrator : public Transport
141141
* @return Crc16* Pointer to CRC-16 object containing crc-16 compute function.
142142
*/
143143
virtual Crc16 * getCrc16(void) override;
144+
144145
/*!
145146
* @brief Check if the underlying shared transport has a message
146147
*

erpc_c/infra/erpc_utils.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/*
2+
* Copyright 2023 ACRIOS Systems s.r.o.
3+
* All rights reserved.
4+
*
5+
*
6+
* SPDX-License-Identifier: BSD-3-Clause
7+
*/
8+
19
#include "erpc_utils.hpp"
210

311
bool erpc::findIndexOfFunction(const arrayOfFunctionPtr_t sourceArrayOfFunctionPtr, uint16_t sourceArrayLength,

erpc_c/infra/erpc_utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 NXP
2+
* Copyright 2023 ACRIOS Systems s.r.o.
33
* All rights reserved.
44
*
55
*

erpcgen/src/CGenerator.cpp

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,6 @@ void CGenerator::generateClientCppSourceFile(string fileName)
142142
fileName += "_client.cpp";
143143
m_templateData["clientCppSourceName"] = fileName;
144144

145-
// TODO: temporary workaround for tests
146-
m_templateData["unitTest"] = (fileName.compare("test_unit_test_common_client.cpp") == 0 ? false : true);
147-
148145
generateOutputFile(fileName, "cpp_client_source", m_templateData, kCppClientSource);
149146
}
150147

@@ -161,9 +158,6 @@ void CGenerator::generateServerCppSourceFile(string fileName)
161158
fileName += "_server.cpp";
162159
m_templateData["serverCppSourceName"] = fileName;
163160

164-
// TODO: temporary workaround for tests
165-
m_templateData["unitTest"] = (fileName.compare("test_unit_test_common_server.cpp") == 0 ? false : true);
166-
167161
generateOutputFile(fileName, "cpp_server_source", m_templateData, kCppServerSource);
168162
}
169163

@@ -180,9 +174,6 @@ void CGenerator::generateClientCSourceFile(string fileName)
180174
fileName = "c_" + fileName + "_client.cpp";
181175
m_templateData["clientCSourceName"] = fileName;
182176

183-
// TODO: temporary workaround for tests
184-
m_templateData["unitTest"] = (fileName.compare("c_test_unit_test_common_client.cpp") == 0 ? false : true);
185-
186177
generateOutputFile(fileName, "c_client_source", m_templateData, kCClientSource);
187178
}
188179

@@ -199,9 +190,6 @@ void CGenerator::generateServerCSourceFile(string fileName)
199190
fileName = "c_" + fileName + "_server.cpp";
200191
m_templateData["serverCSourceName"] = fileName;
201192

202-
// TODO: temporary workaround for tests
203-
m_templateData["unitTest"] = (fileName.compare("c_test_unit_test_common_server.cpp") == 0 ? false : true);
204-
205193
generateOutputFile(fileName, "c_server_source", m_templateData, kCServerSource);
206194
}
207195

@@ -524,13 +512,6 @@ void CGenerator::generate()
524512
}
525513

526514
// check if structure/function parameters annotations are valid.
527-
for (Symbol *symbol : getDataTypesFromSymbolScope(m_globals, DataType::kFunctionType))
528-
{
529-
FunctionType *functionType = dynamic_cast<FunctionType *>(symbol);
530-
assert(functionType);
531-
scanStructForAnnotations(&functionType->getParameters(), true);
532-
}
533-
534515
for (Symbol *symbol : getDataTypesFromSymbolScope(m_globals, DataType::kStructType))
535516
{
536517
StructType *structType = dynamic_cast<StructType *>(symbol);
@@ -546,6 +527,11 @@ void CGenerator::generate()
546527
{
547528
scanStructForAnnotations(&function->getParameters(), true);
548529
}
530+
531+
for (FunctionType *functionType : interface->getFunctionTypes())
532+
{
533+
scanStructForAnnotations(&functionType->getParameters(), true);
534+
}
549535
}
550536

551537
// transform alias data types
@@ -1082,8 +1068,8 @@ data_map CGenerator::getStructDeclarationTemplateData(StructType *structType)
10821068

10831069
DataType *trueDataType = member->getDataType()->getTrueDataType();
10841070
// Check if member is byRef type. Add "*" for type and allocate space for data on server side.
1085-
if (member->isByref() &&
1086-
(trueDataType->isStruct() || trueDataType->isUnion() || trueDataType->isScalar() || trueDataType->isEnum() || trueDataType->isFunction()))
1071+
if (member->isByref() && (trueDataType->isStruct() || trueDataType->isUnion() || trueDataType->isScalar() ||
1072+
trueDataType->isEnum() || trueDataType->isFunction()))
10871073
{
10881074
memberName = "*" + memberName;
10891075
}
@@ -1364,14 +1350,16 @@ void CGenerator::setTemplateComments(Symbol *symbol, data_map &symbolInfo)
13641350
bool CGenerator::isServerNullParam(StructMember *param)
13651351
{
13661352
DataType *paramTrueDataType = param->getDataType()->getTrueDataType();
1367-
return (!paramTrueDataType->isScalar() && !paramTrueDataType->isEnum() && !paramTrueDataType->isArray() && !paramTrueDataType->isFunction());
1353+
return (!paramTrueDataType->isScalar() && !paramTrueDataType->isEnum() && !paramTrueDataType->isArray() &&
1354+
!paramTrueDataType->isFunction());
13681355
}
13691356

13701357
bool CGenerator::isPointerParam(StructMember *param)
13711358
{
13721359
DataType *paramTrueDataType = param->getDataType()->getTrueDataType();
13731360
return (isServerNullParam(param) ||
1374-
((paramTrueDataType->isScalar() || paramTrueDataType->isEnum() || paramTrueDataType->isFunction()) && param->getDirection() != kInDirection));
1361+
((paramTrueDataType->isScalar() || paramTrueDataType->isEnum() || paramTrueDataType->isFunction()) &&
1362+
param->getDirection() != kInDirection));
13751363
}
13761364

13771365
bool CGenerator::isNullableParam(StructMember *param)
@@ -1448,7 +1436,8 @@ data_map CGenerator::getFunctionBaseTemplateData(Group *group, FunctionBase *fn)
14481436
info["needTempVariableClientI32"] = needTempVariableI32;
14491437
returnInfo["resultVariable"] = resultVariable;
14501438
returnInfo["errorReturnValue"] = getErrorReturnValue(fn);
1451-
returnInfo["isNullReturnType"] = (!trueDataType->isScalar() && !trueDataType->isEnum() && !trueDataType->isFunction());
1439+
returnInfo["isNullReturnType"] =
1440+
(!trueDataType->isScalar() && !trueDataType->isEnum() && !trueDataType->isFunction());
14521441
}
14531442
info["returnValue"] = returnInfo;
14541443

@@ -1584,6 +1573,7 @@ data_map CGenerator::getFunctionBaseTemplateData(Group *group, FunctionBase *fn)
15841573
}
15851574
}
15861575

1576+
string ifaceScope = "";
15871577
if (paramTrueType->isFunction())
15881578
{
15891579
FunctionType *funType = dynamic_cast<FunctionType *>(paramTrueType);
@@ -1592,6 +1582,10 @@ data_map CGenerator::getFunctionBaseTemplateData(Group *group, FunctionBase *fn)
15921582
info["needTempVariableServerU16"] = true;
15931583
info["needTempVariableClientU16"] = true;
15941584
}
1585+
if (funType->getInterface() != fn->getInterface())
1586+
{
1587+
ifaceScope = funType->getInterface()->getName();
1588+
}
15951589
}
15961590

15971591
paramInfo["mallocServer"] = firstAllocOnServerWhenIsNeed(name, param);
@@ -1630,7 +1624,6 @@ data_map CGenerator::getFunctionBaseTemplateData(Group *group, FunctionBase *fn)
16301624

16311625
paramInfo["variable"] = getTypenameName(paramType, name);
16321626
paramInfo["name"] = name;
1633-
string ifaceScope = param->getIfaceScope();
16341627
if (ifaceScope != "")
16351628
{
16361629
externalInterfacesList.push_back(ifaceScope);
@@ -2000,14 +1993,15 @@ string CGenerator::getFunctionServerCall(Function *fn, FunctionType *functionTyp
20001993
DataType *trueDataType = it->getDataType()->getTrueDataType();
20011994

20021995
/* Builtin types and function types. */
2003-
if (((trueDataType->isScalar()) || trueDataType->isEnum() || trueDataType->isFunction()) && it->getDirection() != kInDirection &&
2004-
findAnnotation(it, NULLABLE_ANNOTATION))
1996+
if (((trueDataType->isScalar()) || trueDataType->isEnum() || trueDataType->isFunction()) &&
1997+
it->getDirection() != kInDirection && findAnnotation(it, NULLABLE_ANNOTATION))
20051998
{
20061999
// On server side is created new variable for handle null : "_" + name
20072000
proto += "_";
20082001
}
2009-
else if ((it->getDirection() != kInDirection) && (((trueDataType->isScalar()) || trueDataType->isEnum() || trueDataType->isFunction()) ||
2010-
(findAnnotation(it, SHARED_ANNOTATION))))
2002+
else if ((it->getDirection() != kInDirection) &&
2003+
(((trueDataType->isScalar()) || trueDataType->isEnum() || trueDataType->isFunction()) ||
2004+
(findAnnotation(it, SHARED_ANNOTATION))))
20112005

20122006
{
20132007
if (prefix != "")
@@ -2165,10 +2159,13 @@ string CGenerator::getFunctionPrototype(Group *group, FunctionBase *fn, const st
21652159

21662160
if (interfaceClass)
21672161
{
2168-
string ifaceScope = it->getIfaceScope();
2169-
if (ifaceScope != "")
2162+
if (trueDataType->isFunction())
21702163
{
2171-
proto += ifaceScope + "_interface::";
2164+
FunctionType *funcType = dynamic_cast<FunctionType *>(trueDataType);
2165+
if (fn->getInterface() != funcType->getInterface())
2166+
{
2167+
proto += funcType->getInterface()->getName() + "_interface::";
2168+
}
21722169
}
21732170
}
21742171

@@ -2958,7 +2955,8 @@ data_map CGenerator::firstAllocOnServerWhenIsNeed(const string &name, StructMemb
29582955
}
29592956
else if (structMember->getDirection() == kOutDirection)
29602957
{
2961-
if (!trueDataType->isBuiltin() && !trueDataType->isEnum() && !trueDataType->isArray() && !trueDataType->isFunction())
2958+
if (!trueDataType->isBuiltin() && !trueDataType->isEnum() && !trueDataType->isArray() &&
2959+
!trueDataType->isFunction())
29622960
{
29632961
return allocateCall(name, structMember);
29642962
}

erpcgen/src/Generator.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -685,11 +685,11 @@ void Generator::getCallbacksTemplateData(const Interface *iface, data_list &call
685685
DataType *datatype = param->getDataType()->getTrueDataType();
686686
if (datatype->isFunction())
687687
{
688-
if (param->getIfaceScope() != "")
688+
FunctionType *funType = dynamic_cast<FunctionType *>(datatype);
689+
if (funType->getInterface() != iface)
689690
{
690-
interfacesNames.push_back(param->getIfaceScope());
691+
interfacesNames.push_back(funType->getInterface()->getName());
691692
}
692-
FunctionType *funType = dynamic_cast<FunctionType *>(datatype);
693693
if ((std::find(callbackTypesNames.begin(), callbackTypesNames.end(), funType->getName()) ==
694694
callbackTypesNames.end()))
695695
{
@@ -699,23 +699,13 @@ void Generator::getCallbacksTemplateData(const Interface *iface, data_list &call
699699
}
700700
}
701701
}
702-
703-
for (Symbol *functionTypeSymbol : getDataTypesFromSymbolScope(m_globals, DataType::kFunctionType))
702+
for (auto functionType : iface->getFunctionTypes())
704703
{
705-
FunctionType *functionType = dynamic_cast<FunctionType *>(functionTypeSymbol);
706-
assert(functionType);
707-
708-
for (auto fun : functionType->getCallbackFuns())
704+
if ((std::find(callbackTypesNames.begin(), callbackTypesNames.end(), functionType->getName()) ==
705+
callbackTypesNames.end()))
709706
{
710-
if (fun->getInterface() == iface)
711-
{
712-
if ((std::find(callbackTypesNames.begin(), callbackTypesNames.end(), functionType->getName()) ==
713-
callbackTypesNames.end()))
714-
{
715-
callbackTypes.push_back(functionType);
716-
callbackTypesNames.push_back(functionType->getName());
717-
}
718-
}
707+
callbackTypes.push_back(functionType);
708+
callbackTypesNames.push_back(functionType->getName());
719709
}
720710
}
721711

0 commit comments

Comments
 (0)