Skip to content

Commit

Permalink
Namespace can be defined by user. Default erpcshim
Browse files Browse the repository at this point in the history
Signed-off-by: Cervenka Dusan <[email protected]>
  • Loading branch information
Hadatko committed May 15, 2023
1 parent 085042c commit f50951c
Show file tree
Hide file tree
Showing 37 changed files with 159 additions and 62 deletions.
6 changes: 4 additions & 2 deletions erpcgen/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ SOURCES += $(OBJS_ROOT)/erpcgen_parser.tab.cpp \
# Prevent make from deleting these temp files.
.SECONDARY: $(OBJS_ROOT)/erpcgen_parser.tab.cpp \
$(OBJS_ROOT)/erpcgen_lexer.cpp \
$(OBJS_ROOT)/erpcgen/src/templates/c_common_header.c \
$(OBJS_ROOT)/erpcgen/src/templates/c_common_standard_header.c \
$(OBJS_ROOT)/erpcgen/src/templates/c_common_erpc_header.c \
$(OBJS_ROOT)/erpcgen/src/templates/cpp_interface_header.c \
$(OBJS_ROOT)/erpcgen/src/templates/cpp_interface_source.c \
$(OBJS_ROOT)/erpcgen/src/templates/cpp_client_header.c \
Expand All @@ -92,7 +93,8 @@ SOURCES += $(OBJS_ROOT)/erpcgen_parser.tab.cpp \
$(OBJS_ROOT)/erpcgen/src/templates/py_coders.c \
$(OBJS_ROOT)/erpcgen/src/templates/py_global_init.c

SOURCES += $(OBJS_ROOT)/erpcgen/src/templates/c_common_header.c \
SOURCES += $(OBJS_ROOT)/erpcgen/src/templates/c_common_standard_header.c \
$(OBJS_ROOT)/erpcgen/src/templates/c_common_erpc_header.c \
$(OBJS_ROOT)/erpcgen/src/templates/cpp_interface_header.c \
$(OBJS_ROOT)/erpcgen/src/templates/cpp_interface_source.c \
$(OBJS_ROOT)/erpcgen/src/templates/cpp_client_header.c \
Expand Down
3 changes: 2 additions & 1 deletion erpcgen/VisualStudio_v14/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ cpp_client_header.cpp
cpp_server_header.cpp
cpp_server_source.cpp
cpp_coders.cpp
c_common_header.cpp
c_common_standard_header.cpp
c_common_erpc_header.cpp
c_client_source.cpp
c_client_header.cpp
c_server_header.cpp
Expand Down
9 changes: 6 additions & 3 deletions erpcgen/VisualStudio_v14/erpcgen.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
</CustomBuildStep>
<PreBuildEvent>
<Command>python.exe ..\bin\txt_to_c.py --output .\cpp_coders.cpp ..\src\templates\cpp_coders.template
python.exe ..\bin\txt_to_c.py --output .\c_common_header.cpp ..\src\templates\c_common_header.template
python.exe ..\bin\txt_to_c.py --output .\c_common_standard_header.cpp ..\src\templates\c_common_standard_header.template
python.exe ..\bin\txt_to_c.py --output .\c_common_erpc_header.cpp ..\src\templates\c_common_erpc_header.template
python.exe ..\bin\txt_to_c.py --output .\cpp_interface_header.cpp ..\src\templates\cpp_interface_header.template
python.exe ..\bin\txt_to_c.py --output .\cpp_interface_source.cpp ..\src\templates\cpp_interface_source.template
python.exe ..\bin\txt_to_c.py --output .\cpp_client_header.cpp ..\src\templates\cpp_client_header.template
Expand Down Expand Up @@ -145,7 +146,8 @@ python.exe ..\bin\txt_to_c.py --output .\py_global_init.cpp ..\src\templates\py_
</Link>
<PreBuildEvent>
<Command>python.exe ..\bin\txt_to_c.py --output .\cpp_coders.cpp ..\src\templates\cpp_coders.template
python.exe ..\bin\txt_to_c.py --output .\c_common_header.cpp ..\src\templates\c_common_header.template
python.exe ..\bin\txt_to_c.py --output .\c_common_standard_header.cpp ..\src\templates\c_common_standard_header.template
python.exe ..\bin\txt_to_c.py --output .\c_common_erpc_header.cpp ..\src\templates\c_common_erpc_header.template
python.exe ..\bin\txt_to_c.py --output .\cpp_interface_header.cpp ..\src\templates\cpp_interface_header.template
python.exe ..\bin\txt_to_c.py --output .\cpp_interface_source.cpp ..\src\templates\cpp_interface_source.template
python.exe ..\bin\txt_to_c.py --output .\cpp_client_header.cpp ..\src\templates\cpp_client_header.template
Expand Down Expand Up @@ -244,7 +246,8 @@ python.exe ..\bin\txt_to_c.py --output .\py_global_init.cpp ..\src\templates\py_
<ClCompile Include="..\src\UniqueIdChecker.cpp" />
<ClCompile Include="..\src\Utils.cpp" />
<ClCompile Include="cpp_coders.cpp" />
<ClCompile Include="c_common_header.cpp" />
<ClCompile Include="c_common_standard_header.cpp" />
<ClCompile Include="c_common_erpc_header.cpp" />
<ClCompile Include="c_crc.cpp" />
<ClCompile Include="cpp_interface_header.cpp" />
<ClCompile Include="cpp_interface_source.cpp" />
Expand Down
5 changes: 4 additions & 1 deletion erpcgen/VisualStudio_v14/erpcgen.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@
<ClCompile Include="cpp_coders.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="c_common_header.cpp">
<ClCompile Include="c_common_standard_header.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="c_common_erpc_header.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="cpp_interface_header.cpp">
Expand Down
24 changes: 17 additions & 7 deletions erpcgen/src/CGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ using namespace std;
static const char *const kIdentifierChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";

// Templates strings converted from text files by txt_to_c.py.
extern const char *const kCCommonHeader;
extern const char *const kCCommonStandardHeader;
extern const char *const kCCommonErpcHeader;
extern const char *const kCppInterfaceHeader;
extern const char *const kCppInterfaceSource;
extern const char *const kCppClientHeader;
Expand Down Expand Up @@ -78,7 +79,8 @@ CGenerator::CGenerator(InterfaceDefinition *def)

void CGenerator::generateOutputFiles(const string &fileName)
{
generateCommonCHeaderFiles(fileName);
generateCommonStandardCHeaderFiles(fileName);
generateCommonErpcCHeaderFiles(fileName);

generateInterfaceCppHeaderFile(fileName);
generateInterfaceCppSourceFile(fileName);
Expand All @@ -96,12 +98,20 @@ void CGenerator::generateOutputFiles(const string &fileName)
generateServerCSourceFile(fileName);
}

void CGenerator::generateCommonCHeaderFiles(string fileName)
void CGenerator::generateCommonStandardCHeaderFiles(string fileName)
{
fileName += "_common.h";
m_templateData["commonCGuardMacro"] = generateIncludeGuardName(fileName);
m_templateData["commonCHeaderName"] = fileName;
generateOutputFile(fileName, "c_common_header", m_templateData, kCCommonHeader);
fileName += "_common_standard.h";
m_templateData["commonStandardCGuardMacro"] = generateIncludeGuardName(fileName);
m_templateData["commonStandardCHeaderName"] = fileName;
generateOutputFile(fileName, "c_common_standard_header", m_templateData, kCCommonStandardHeader);
}

void CGenerator::generateCommonErpcCHeaderFiles(string fileName)
{
fileName += "_common_erpc.h";
m_templateData["commonErpcCGuardMacro"] = generateIncludeGuardName(fileName);
m_templateData["commonErpcCHeaderName"] = fileName;
generateOutputFile(fileName, "c_common_erpc_header", m_templateData, kCCommonErpcHeader);
}

void CGenerator::generateInterfaceCppHeaderFile(string fileName)
Expand Down
13 changes: 10 additions & 3 deletions erpcgen/src/CGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,18 @@ class CGenerator : public Generator
void generateOutputFiles(const std::string &fileNameExtension) override;

/*!
* @brief This function generate output common header file.
* @brief This function generate header file output with common standard code.
*
* @param[in] fileName Name for output client source file.
* @param[in] fileName Name for common standard header file output.
*/
void generateCommonStandardCHeaderFiles(std::string fileName);

/*!
* @brief This function generate header file output with common eRPC code.
*
* @param[in] fileName Name for common eRPC header file output.
*/
void generateCommonCHeaderFiles(std::string fileName);
void generateCommonErpcCHeaderFiles(std::string fileName);

/*!
* @brief This function generate output interface header file.
Expand Down
9 changes: 9 additions & 0 deletions erpcgen/src/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ Generator::Generator(InterfaceDefinition *def, generator_type_t generatorType)
{
scopeName = getAnnStringValue(program, SCOPE_NAME_ANNOTATION);
}

if (findAnnotation(m_def->getProgramSymbol(), NAMESPACE_ANNOTATION) != nullptr)
{
m_templateData["namespace"] = getAnnStringValue(m_def->getProgramSymbol(), NAMESPACE_ANNOTATION);
}
else
{
m_templateData["namespace"] = "erpcshim";
}
}

m_templateData["scopeName"] = scopeName;
Expand Down
3 changes: 3 additions & 0 deletions erpcgen/src/annotations.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
//! Specify the symbol name.
#define NAME_ANNOTATION "name"

//! Specify the namespace of program code.
#define NAMESPACE_ANNOTATION "namespace"

//! Turn off error checking code for allocations in generated output
#define NO_ALLOC_ERRORS_ANNOTATION "no_alloc_errors"

Expand Down
3 changes: 2 additions & 1 deletion erpcgen/src/templates/c_client_header.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#if !defined({$clientCGuardMacro})
#define {$clientCGuardMacro}

#include "{$commonCHeaderName}"
#include "{$commonStandardCHeaderName}"
#include "{$commonErpcCHeaderName}"
#include "erpc_client_manager.h"
{% for iface in group.interfaces %}
{% for fn in iface.functions %}
Expand Down
1 change: 1 addition & 0 deletions erpcgen/src/templates/c_client_source.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using namespace erpc;
using namespace std;
{$usingNamespace() >}
{% for iface in group.interfaces %}
{% if count(iface.callbacksAll) > 0 %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,20 @@
{% endif %}
{$commonHeader()}

#if !defined({$commonCGuardMacro})
#define {$commonCGuardMacro}
#if !defined({$commonErpcCGuardMacro})
#define {$commonErpcCGuardMacro}
{% if usedUnionType %}

#if defined(__CC_ARM) || defined(__ARMCC_VERSION)
#pragma anon_unions
#endif
{% endif -- usedUnionType %}
#ifdef __cplusplus

{% for inc in includes %}
#include "{$inc}"
{% endfor -- includes %}

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "erpc_version.h"
{% if empty(crc16) == false %}
#include "{$crcHeaderName}"
{% endif -- empty(crc16) == false %}

{$checkVersion()}
{$>checkCrc()}

Expand Down Expand Up @@ -107,4 +95,4 @@ extern const {$c.typeAndName};{$c.ilComment}{$loop.addNewLineIfNotLast}
}
#endif // __cplusplus

#endif // {$commonCGuardMacro}
#endif // {$commonErpcCGuardMacro}
35 changes: 35 additions & 0 deletions erpcgen/src/templates/c_common_standard_header.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{% if mlComment != ""%}
{$mlComment}

{% endif %}
{$commonHeader()}

#if !defined({$commonStandardCGuardMacro})
#define {$commonStandardCGuardMacro}

#ifdef __cplusplus

{% for inc in includes %}
#include "{$inc}"
{% endfor -- includes %}

extern "C"
{
#endif

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "erpc_version.h"
{% if empty(crc16) == false %}
#include "{$crcHeaderName}"
{% endif -- empty(crc16) == false %}

{$checkVersion()}
{$>checkCrc()}

#ifdef __cplusplus
}
#endif

#endif // {$commonStandardCGuardMacro}
3 changes: 2 additions & 1 deletion erpcgen/src/templates/c_server_header.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#if !defined({$serverCGuardMacro})
#define {$serverCGuardMacro}

#include "{$commonCHeaderName}"
#include "{$commonStandardCHeaderName}"
#include "{$commonErpcCHeaderName}"
{% for iface in group.interfaces %}
{% for fn in iface.functions %}
{% for externalInterface in fn.externalInterfaces %}
Expand Down
1 change: 1 addition & 0 deletions erpcgen/src/templates/c_server_source.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using namespace erpc;
using namespace std;
{$usingNamespace() >}
{% for iface in group.interfaces %}

ERPC_MANUALLY_CONSTRUCTED_STATIC({$iface.serviceClassName}, s_{$iface.serviceClassName});
Expand Down
12 changes: 5 additions & 7 deletions erpcgen/src/templates/cpp_client_header.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
#include "{$interfaceCppHeaderName}"

#include "erpc_client_manager.h"
{$fillNamespaceBegin()>}

namespace erpc {
{% for iface in group.interfaces %}

class {$iface.clientClassName}: public {$iface.interfaceClassName}
{
public:
{$iface.clientClassName}(ClientManager *manager);
{$iface.clientClassName}(erpc::ClientManager *manager);
{% for fn in iface.functions if fn.isNonExternalFunction == true %}

{% if fn.mlComment %}
Expand All @@ -27,10 +26,9 @@ class {$iface.clientClassName}: public {$iface.interfaceClassName}
{% endfor -- fn %}

protected:
ClientManager *m_clientManager;
erpc::ClientManager *m_clientManager;
};
{% endfor -- iface %}

} // namespace erpc

{% endfor -- iface %}
{$fillNamespaceEnd()}
#endif // {$clientCppGuardMacro}
3 changes: 2 additions & 1 deletion erpcgen/src/templates/cpp_client_source.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern "C"
{% if groupNames %}
// import callbacks declaration from other groups
{% for name in groupNames if name != group.name %}
#include "{$outputFilename}_{$name}_common.h"
#include "{$outputFilename}_{$name}_common_erpc.h"
{% endfor %}
{% endif %}
}
Expand All @@ -25,6 +25,7 @@ extern "C"
{$>checkCrc()}
using namespace erpc;
using namespace std;
{$usingNamespace() >}
{$generateCrcVariable()}
{$> setSharedMemAddresses()}
{$> constantsDefinitions(consts)}
Expand Down
22 changes: 22 additions & 0 deletions erpcgen/src/templates/cpp_common_functions.template
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ extern const uint32_t erpc_generated_crc = {$crc16};
{% endif -- empty(crc16) == false %}
{% enddef --checkCrc %}

{# ---------------- namespace ---------------- #}
{% def fillNamespaceBegin() %}
{% if empty(namespace) == false %}

namespace {$namespace}
{
{% endif -- empty(crc16) == false %}
{% enddef --checkCrc %}

{% def fillNamespaceEnd() %}
{% if empty(namespace) == false %}
} // {$namespace}

{% endif -- empty(crc16) == false %}
{% enddef --checkCrc %}

{% def usingNamespace() %}
{% if empty(namespace) == false %}
using namespace {$namespace};
{% endif -- empty(crc16) == false %}
{% enddef --checkCrc %}

{# ---------------- constantsDefinitions ---------------- #}
{% def constantsDefinitions(consts) %}
{% if not empty(consts) %}
Expand Down
11 changes: 4 additions & 7 deletions erpcgen/src/templates/cpp_interface_header.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
#if !defined({$interfaceCppGuardMacro})
#define {$interfaceCppGuardMacro}

#include "{$commonCHeaderName}"

#include "{$commonStandardCHeaderName}"
{% for iface in group.interfaces %}
{% for fn in iface.functions %}
{% for externalInterface in fn.externalInterfaces %}
Expand All @@ -20,8 +19,8 @@
{% endfor -- externalInterface %}
{% endfor -- fn %}
{% endfor -- iface %}

namespace erpc {
{$fillNamespaceBegin()}
#include "{$commonErpcCHeaderName}"
{% for iface in group.interfaces %}

// Abstract base class for {$iface.name}
Expand Down Expand Up @@ -56,7 +55,5 @@ private:
{% endfor %}
};
{% endfor -- iface %}

} // namespace erpc

{$fillNamespaceEnd()}
#endif // {$interfaceCppGuardMacro}
2 changes: 1 addition & 1 deletion erpcgen/src/templates/cpp_interface_source.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
{$checkVersion()}
{$>checkCrc()}

using namespace erpc;
using namespace std;
{$usingNamespace() >}

{% for iface in group.interfaces -- service subclass method impl %}
{% for cb in iface.callbacksInt %}
Expand Down
Loading

0 comments on commit f50951c

Please sign in to comment.