Skip to content

Commit fe132ff

Browse files
author
Häfele, Philipp
committed
erpcgen/C++: Add namespace and remove same name typedefs
- Only typdefs for same name structs and unions are removed - Constant variable declarations are not namespaced
1 parent f9af0f6 commit fe132ff

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

erpcgen/src/CGenerator.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,8 @@ void CGenerator::makeAliasesTemplateData()
765765
DataType *elementDataType = aliasType->getElementType();
766766
setTemplateComments(aliasType, aliasInfo);
767767

768+
aliasInfo["isSameNameTypedef"] = false;
769+
768770
if (elementDataType->getName() != "")
769771
{
770772
string realType;
@@ -785,6 +787,7 @@ void CGenerator::makeAliasesTemplateData()
785787
if (elementDataType->getName() == aliasType->getName() ||
786788
getOutputName(elementDataType, false) == aliasType->getName())
787789
{
790+
aliasInfo["isSameNameTypedef"] = true;
788791
if (elementDataType->isStruct())
789792
{
790793
realType = "struct " + realType;

erpcgen/src/templates/c_common_header.template

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ extern "C"
4040

4141
#if !defined(ERPC_TYPE_DEFINITIONS{$scopeNamePrefix}{$scopeNameC})
4242
#define ERPC_TYPE_DEFINITIONS{$scopeNamePrefix}{$scopeNameC}
43+
{% if not cCommonHeaderFile %}
44+
{$fillNamespaceBegin()}
45+
{% endif -- not cCommonHeaderFile %}
4346
{% if not empty(enums) %}
4447

4548
// Enumerators data types declarations
@@ -67,7 +70,9 @@ typedef {$alias.unnamedType}
6770
{% endfor -- alias.unnamed.members %}
6871
} {$alias.unnamedName};
6972
{% else -- alias.typenameName %}
73+
{% if (cCommonHeaderFile) || (not alias.isSameNameTypedef) %}
7074
typedef {$alias.typenameName};{$alias.ilComment}
75+
{% endif -- (cCommonHeaderFile) || (not alias.isSameNameTypedef) %}
7176
{% endif -- alias.typenameName %}
7277
{% endfor -- aliases %}
7378
{% endif -- aliases %}
@@ -95,8 +100,10 @@ union {$us.name}
95100
{% endif -- us.type == "union/struct" %}
96101
{% endif -- !us.isExternal %}
97102
{% endfor -- symbols %}
98-
99103
{% endif -- nonExternalStruct || nonExternalUnion %}
104+
{% if not cCommonHeaderFile %}
105+
{$fillNamespaceEnd()}
106+
{% endif -- not cCommonHeaderFile %}
100107
{% if not empty(consts) %}
101108

102109
// Constant variable declarations

test/test_annotations/external.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
#include <stdint.h>
1818

19+
#ifdef __cplusplus
20+
namespace erpcShim {
21+
#endif
22+
1923
// Enumerators data types declarations
2024
typedef enum myEnum
2125
{
@@ -36,6 +40,10 @@ struct fooStruct
3640
float y;
3741
};
3842

43+
#ifdef __cplusplus
44+
} // namespace erpcShim
45+
#endif
46+
3947
// Constant variable declarations
4048
const int32_t i = 4;
4149

0 commit comments

Comments
 (0)