Skip to content

Commit

Permalink
Putting function declaration under interface.
Browse files Browse the repository at this point in the history
Signed-off-by: Cervenka Dusan <[email protected]>
  • Loading branch information
Hadatko committed Jun 1, 2023
1 parent f50951c commit c2e072a
Show file tree
Hide file tree
Showing 30 changed files with 366 additions and 207 deletions.
2 changes: 1 addition & 1 deletion erpc_c/infra/erpc_manually_constructed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class ManuallyConstructed
* @brief Returns information if object is free or is used.
*
* @return true Object is constructed and used.
* @return false Object wasn't constructor or it is destructed and free.
* @return false Object wasn't constructed or it was destructed already.
*/
bool isUsed(void) { return m_isConstructed; }

Expand Down
1 change: 1 addition & 0 deletions erpc_c/infra/erpc_transport_arbitrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class TransportArbitrator : public Transport
* @return Crc16* Pointer to CRC-16 object containing crc-16 compute function.
*/
virtual Crc16 * getCrc16(void) override;

/*!
* @brief Check if the underlying shared transport has a message
*
Expand Down
8 changes: 8 additions & 0 deletions erpc_c/infra/erpc_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* Copyright 2023 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include "erpc_utils.hpp"

bool erpc::findIndexOfFunction(const arrayOfFunctionPtr_t sourceArrayOfFunctionPtr, uint16_t sourceArrayLength,
Expand Down
2 changes: 1 addition & 1 deletion erpc_c/infra/erpc_utils.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 NXP
* Copyright 2023 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
Expand Down
64 changes: 31 additions & 33 deletions erpcgen/src/CGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ void CGenerator::generateClientCppSourceFile(string fileName)
fileName += "_client.cpp";
m_templateData["clientCppSourceName"] = fileName;

// TODO: temporary workaround for tests
m_templateData["unitTest"] = (fileName.compare("test_unit_test_common_client.cpp") == 0 ? false : true);

generateOutputFile(fileName, "cpp_client_source", m_templateData, kCppClientSource);
}

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

// TODO: temporary workaround for tests
m_templateData["unitTest"] = (fileName.compare("test_unit_test_common_server.cpp") == 0 ? false : true);

generateOutputFile(fileName, "cpp_server_source", m_templateData, kCppServerSource);
}

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

// TODO: temporary workaround for tests
m_templateData["unitTest"] = (fileName.compare("c_test_unit_test_common_client.cpp") == 0 ? false : true);

generateOutputFile(fileName, "c_client_source", m_templateData, kCClientSource);
}

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

// TODO: temporary workaround for tests
m_templateData["unitTest"] = (fileName.compare("c_test_unit_test_common_server.cpp") == 0 ? false : true);

generateOutputFile(fileName, "c_server_source", m_templateData, kCServerSource);
}

Expand Down Expand Up @@ -524,13 +512,6 @@ void CGenerator::generate()
}

// check if structure/function parameters annotations are valid.
for (Symbol *symbol : getDataTypesFromSymbolScope(m_globals, DataType::kFunctionType))
{
FunctionType *functionType = dynamic_cast<FunctionType *>(symbol);
assert(functionType);
scanStructForAnnotations(&functionType->getParameters(), true);
}

for (Symbol *symbol : getDataTypesFromSymbolScope(m_globals, DataType::kStructType))
{
StructType *structType = dynamic_cast<StructType *>(symbol);
Expand All @@ -546,6 +527,11 @@ void CGenerator::generate()
{
scanStructForAnnotations(&function->getParameters(), true);
}

for (FunctionType *functionType : interface->getFunctionTypes())
{
scanStructForAnnotations(&functionType->getParameters(), true);
}
}

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

DataType *trueDataType = member->getDataType()->getTrueDataType();
// Check if member is byRef type. Add "*" for type and allocate space for data on server side.
if (member->isByref() &&
(trueDataType->isStruct() || trueDataType->isUnion() || trueDataType->isScalar() || trueDataType->isEnum() || trueDataType->isFunction()))
if (member->isByref() && (trueDataType->isStruct() || trueDataType->isUnion() || trueDataType->isScalar() ||
trueDataType->isEnum() || trueDataType->isFunction()))
{
memberName = "*" + memberName;
}
Expand Down Expand Up @@ -1364,14 +1350,16 @@ void CGenerator::setTemplateComments(Symbol *symbol, data_map &symbolInfo)
bool CGenerator::isServerNullParam(StructMember *param)
{
DataType *paramTrueDataType = param->getDataType()->getTrueDataType();
return (!paramTrueDataType->isScalar() && !paramTrueDataType->isEnum() && !paramTrueDataType->isArray() && !paramTrueDataType->isFunction());
return (!paramTrueDataType->isScalar() && !paramTrueDataType->isEnum() && !paramTrueDataType->isArray() &&
!paramTrueDataType->isFunction());
}

bool CGenerator::isPointerParam(StructMember *param)
{
DataType *paramTrueDataType = param->getDataType()->getTrueDataType();
return (isServerNullParam(param) ||
((paramTrueDataType->isScalar() || paramTrueDataType->isEnum() || paramTrueDataType->isFunction()) && param->getDirection() != kInDirection));
((paramTrueDataType->isScalar() || paramTrueDataType->isEnum() || paramTrueDataType->isFunction()) &&
param->getDirection() != kInDirection));
}

bool CGenerator::isNullableParam(StructMember *param)
Expand Down Expand Up @@ -1448,7 +1436,8 @@ data_map CGenerator::getFunctionBaseTemplateData(Group *group, FunctionBase *fn)
info["needTempVariableClientI32"] = needTempVariableI32;
returnInfo["resultVariable"] = resultVariable;
returnInfo["errorReturnValue"] = getErrorReturnValue(fn);
returnInfo["isNullReturnType"] = (!trueDataType->isScalar() && !trueDataType->isEnum() && !trueDataType->isFunction());
returnInfo["isNullReturnType"] =
(!trueDataType->isScalar() && !trueDataType->isEnum() && !trueDataType->isFunction());
}
info["returnValue"] = returnInfo;

Expand Down Expand Up @@ -1584,6 +1573,7 @@ data_map CGenerator::getFunctionBaseTemplateData(Group *group, FunctionBase *fn)
}
}

string ifaceScope = "";
if (paramTrueType->isFunction())
{
FunctionType *funType = dynamic_cast<FunctionType *>(paramTrueType);
Expand All @@ -1592,6 +1582,10 @@ data_map CGenerator::getFunctionBaseTemplateData(Group *group, FunctionBase *fn)
info["needTempVariableServerU16"] = true;
info["needTempVariableClientU16"] = true;
}
if (funType->getInterface() != fn->getInterface())
{
ifaceScope = funType->getInterface()->getName();
}
}

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

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

/* Builtin types and function types. */
if (((trueDataType->isScalar()) || trueDataType->isEnum() || trueDataType->isFunction()) && it->getDirection() != kInDirection &&
findAnnotation(it, NULLABLE_ANNOTATION))
if (((trueDataType->isScalar()) || trueDataType->isEnum() || trueDataType->isFunction()) &&
it->getDirection() != kInDirection && findAnnotation(it, NULLABLE_ANNOTATION))
{
// On server side is created new variable for handle null : "_" + name
proto += "_";
}
else if ((it->getDirection() != kInDirection) && (((trueDataType->isScalar()) || trueDataType->isEnum() || trueDataType->isFunction()) ||
(findAnnotation(it, SHARED_ANNOTATION))))
else if ((it->getDirection() != kInDirection) &&
(((trueDataType->isScalar()) || trueDataType->isEnum() || trueDataType->isFunction()) ||
(findAnnotation(it, SHARED_ANNOTATION))))

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

if (interfaceClass)
{
string ifaceScope = it->getIfaceScope();
if (ifaceScope != "")
if (trueDataType->isFunction())
{
proto += ifaceScope + "_interface::";
FunctionType *funcType = dynamic_cast<FunctionType *>(trueDataType);
if (fn->getInterface() != funcType->getInterface())
{
proto += funcType->getInterface()->getName() + "_interface::";
}
}
}

Expand Down Expand Up @@ -2958,7 +2955,8 @@ data_map CGenerator::firstAllocOnServerWhenIsNeed(const string &name, StructMemb
}
else if (structMember->getDirection() == kOutDirection)
{
if (!trueDataType->isBuiltin() && !trueDataType->isEnum() && !trueDataType->isArray() && !trueDataType->isFunction())
if (!trueDataType->isBuiltin() && !trueDataType->isEnum() && !trueDataType->isArray() &&
!trueDataType->isFunction())
{
return allocateCall(name, structMember);
}
Expand Down
26 changes: 8 additions & 18 deletions erpcgen/src/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,11 @@ void Generator::getCallbacksTemplateData(const Interface *iface, data_list &call
DataType *datatype = param->getDataType()->getTrueDataType();
if (datatype->isFunction())
{
if (param->getIfaceScope() != "")
FunctionType *funType = dynamic_cast<FunctionType *>(datatype);
if (funType->getInterface() != iface)
{
interfacesNames.push_back(param->getIfaceScope());
interfacesNames.push_back(funType->getInterface()->getName());
}
FunctionType *funType = dynamic_cast<FunctionType *>(datatype);
if ((std::find(callbackTypesNames.begin(), callbackTypesNames.end(), funType->getName()) ==
callbackTypesNames.end()))
{
Expand All @@ -699,23 +699,13 @@ void Generator::getCallbacksTemplateData(const Interface *iface, data_list &call
}
}
}

for (Symbol *functionTypeSymbol : getDataTypesFromSymbolScope(m_globals, DataType::kFunctionType))
for (auto functionType : iface->getFunctionTypes())
{
FunctionType *functionType = dynamic_cast<FunctionType *>(functionTypeSymbol);
assert(functionType);

for (auto fun : functionType->getCallbackFuns())
if ((std::find(callbackTypesNames.begin(), callbackTypesNames.end(), functionType->getName()) ==
callbackTypesNames.end()))
{
if (fun->getInterface() == iface)
{
if ((std::find(callbackTypesNames.begin(), callbackTypesNames.end(), functionType->getName()) ==
callbackTypesNames.end()))
{
callbackTypes.push_back(functionType);
callbackTypesNames.push_back(functionType->getName());
}
}
callbackTypes.push_back(functionType);
callbackTypesNames.push_back(functionType->getName());
}
}

Expand Down
Loading

0 comments on commit c2e072a

Please sign in to comment.