Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
erpcgen/C++: Add namespace and change consts to constexpr
Browse files Browse the repository at this point in the history
- Forward declrations are needed somehow for same name typedefs
- Using constexpr instead of extern const so we can namespace them easily
Häfele, Philipp committed Apr 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent f9af0f6 commit cb97458
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions erpcgen/src/CGenerator.cpp
Original file line number Diff line number Diff line change
@@ -765,6 +765,8 @@ void CGenerator::makeAliasesTemplateData()
DataType *elementDataType = aliasType->getElementType();
setTemplateComments(aliasType, aliasInfo);

aliasInfo["forwardDecl"] = "";

if (elementDataType->getName() != "")
{
string realType;
@@ -785,14 +787,18 @@ void CGenerator::makeAliasesTemplateData()
if (elementDataType->getName() == aliasType->getName() ||
getOutputName(elementDataType, false) == aliasType->getName())
{
string forwardDecl;
if (elementDataType->isStruct())
{
realType = "struct " + realType;
forwardDecl = "struct " + getOutputName(aliasType);
}
else
{
realType = "union " + realType;
forwardDecl = "union " + getOutputName(aliasType);
}
aliasInfo["forwardDecl"] = forwardDecl;
}

aliasInfo["typenameName"] = realType;
15 changes: 14 additions & 1 deletion erpcgen/src/templates/c_common_header.template
Original file line number Diff line number Diff line change
@@ -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
@@ -67,6 +70,9 @@ typedef {$alias.unnamedType}
{% endfor -- alias.unnamed.members %}
} {$alias.unnamedName};
{% else -- alias.typenameName %}
{% if alias.forwardDecl != "" %}
{$alias.forwardDecl};
{% endif -- alias.forwardDecl %}
typedef {$alias.typenameName};{$alias.ilComment}
{% endif -- alias.typenameName %}
{% endfor -- aliases %}
@@ -95,17 +101,24 @@ union {$us.name}
{% endif -- us.type == "union/struct" %}
{% endif -- !us.isExternal %}
{% endfor -- symbols %}

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

// Constant variable declarations
{% for c in consts %}
{$> c.mlComment}
{% if cCommonHeaderFile %}
extern const {$c.typeAndName};{$c.ilComment}{$loop.addNewLineIfNotLast}
{% else -- not cCommonHeaderFile %}
constexpr {$c.typeAndName} = {$c.value};{$c.ilComment}{$loop.addNewLineIfNotLast}
{% endif -- cCommonHeaderFile %}
{% endfor -- consts %}
{% endif -- consts %}
{% if not cCommonHeaderFile %}

{$fillNamespaceEnd()}

{% endif -- not cCommonHeaderFile %}
#endif // ERPC_TYPE_DEFINITIONS{$scopeNamePrefix}{$scopeNameC}

{% if cCommonHeaderFile %}

0 comments on commit cb97458

Please sign in to comment.