Skip to content

Commit cb97458

Browse files
author
Häfele, Philipp
committed
erpcgen/C++: Add namespace and change consts to constexpr
- Forward declrations are needed somehow for same name typedefs - Using constexpr instead of extern const so we can namespace them easily
1 parent f9af0f6 commit cb97458

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

erpcgen/src/CGenerator.cpp

Lines changed: 6 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["forwardDecl"] = "";
769+
768770
if (elementDataType->getName() != "")
769771
{
770772
string realType;
@@ -785,14 +787,18 @@ void CGenerator::makeAliasesTemplateData()
785787
if (elementDataType->getName() == aliasType->getName() ||
786788
getOutputName(elementDataType, false) == aliasType->getName())
787789
{
790+
string forwardDecl;
788791
if (elementDataType->isStruct())
789792
{
790793
realType = "struct " + realType;
794+
forwardDecl = "struct " + getOutputName(aliasType);
791795
}
792796
else
793797
{
794798
realType = "union " + realType;
799+
forwardDecl = "union " + getOutputName(aliasType);
795800
}
801+
aliasInfo["forwardDecl"] = forwardDecl;
796802
}
797803

798804
aliasInfo["typenameName"] = realType;

erpcgen/src/templates/c_common_header.template

Lines changed: 14 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,6 +70,9 @@ typedef {$alias.unnamedType}
6770
{% endfor -- alias.unnamed.members %}
6871
} {$alias.unnamedName};
6972
{% else -- alias.typenameName %}
73+
{% if alias.forwardDecl != "" %}
74+
{$alias.forwardDecl};
75+
{% endif -- alias.forwardDecl %}
7076
typedef {$alias.typenameName};{$alias.ilComment}
7177
{% endif -- alias.typenameName %}
7278
{% endfor -- aliases %}
@@ -95,17 +101,24 @@ union {$us.name}
95101
{% endif -- us.type == "union/struct" %}
96102
{% endif -- !us.isExternal %}
97103
{% endfor -- symbols %}
98-
99104
{% endif -- nonExternalStruct || nonExternalUnion %}
100105
{% if not empty(consts) %}
101106

102107
// Constant variable declarations
103108
{% for c in consts %}
104109
{$> c.mlComment}
110+
{% if cCommonHeaderFile %}
105111
extern const {$c.typeAndName};{$c.ilComment}{$loop.addNewLineIfNotLast}
112+
{% else -- not cCommonHeaderFile %}
113+
constexpr {$c.typeAndName} = {$c.value};{$c.ilComment}{$loop.addNewLineIfNotLast}
114+
{% endif -- cCommonHeaderFile %}
106115
{% endfor -- consts %}
107116
{% endif -- consts %}
117+
{% if not cCommonHeaderFile %}
118+
119+
{$fillNamespaceEnd()}
108120

121+
{% endif -- not cCommonHeaderFile %}
109122
#endif // ERPC_TYPE_DEFINITIONS{$scopeNamePrefix}{$scopeNameC}
110123

111124
{% if cCommonHeaderFile %}

0 commit comments

Comments
 (0)