Skip to content

Commit

Permalink
erpcgen/C++: Add namespace and remove same name typedefs
Browse files Browse the repository at this point in the history
- Only typdefs for same name structs and unions are removed
- Constant variable declarations are not namespaced
  • Loading branch information
Häfele, Philipp committed Apr 5, 2024
1 parent f9af0f6 commit fe132ff
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions erpcgen/src/CGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,8 @@ void CGenerator::makeAliasesTemplateData()
DataType *elementDataType = aliasType->getElementType();
setTemplateComments(aliasType, aliasInfo);

aliasInfo["isSameNameTypedef"] = false;

if (elementDataType->getName() != "")
{
string realType;
Expand All @@ -785,6 +787,7 @@ void CGenerator::makeAliasesTemplateData()
if (elementDataType->getName() == aliasType->getName() ||
getOutputName(elementDataType, false) == aliasType->getName())
{
aliasInfo["isSameNameTypedef"] = true;
if (elementDataType->isStruct())
{
realType = "struct " + realType;
Expand Down
9 changes: 8 additions & 1 deletion erpcgen/src/templates/c_common_header.template
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ extern "C"

#if !defined(ERPC_TYPE_DEFINITIONS{$scopeNamePrefix}{$scopeNameC})
#define ERPC_TYPE_DEFINITIONS{$scopeNamePrefix}{$scopeNameC}
{% if not cCommonHeaderFile %}
{$fillNamespaceBegin()}
{% endif -- not cCommonHeaderFile %}
{% if not empty(enums) %}

// Enumerators data types declarations
Expand Down Expand Up @@ -67,7 +70,9 @@ typedef {$alias.unnamedType}
{% endfor -- alias.unnamed.members %}
} {$alias.unnamedName};
{% else -- alias.typenameName %}
{% if (cCommonHeaderFile) || (not alias.isSameNameTypedef) %}
typedef {$alias.typenameName};{$alias.ilComment}
{% endif -- (cCommonHeaderFile) || (not alias.isSameNameTypedef) %}
{% endif -- alias.typenameName %}
{% endfor -- aliases %}
{% endif -- aliases %}
Expand Down Expand Up @@ -95,8 +100,10 @@ union {$us.name}
{% endif -- us.type == "union/struct" %}
{% endif -- !us.isExternal %}
{% endfor -- symbols %}

{% endif -- nonExternalStruct || nonExternalUnion %}
{% if not cCommonHeaderFile %}
{$fillNamespaceEnd()}
{% endif -- not cCommonHeaderFile %}
{% if not empty(consts) %}

// Constant variable declarations
Expand Down
8 changes: 8 additions & 0 deletions test/test_annotations/external.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

#include <stdint.h>

#ifdef __cplusplus
namespace erpcShim {
#endif

// Enumerators data types declarations
typedef enum myEnum
{
Expand All @@ -36,6 +40,10 @@ struct fooStruct
float y;
};

#ifdef __cplusplus
} // namespace erpcShim
#endif

// Constant variable declarations
const int32_t i = 4;

Expand Down

0 comments on commit fe132ff

Please sign in to comment.