Skip to content

C++: allow iterating over unique enum values#1806

Merged
pwrobeldev merged 5 commits into
masterfrom
pwrobeldev/provide-way-to-get-all-enumerator-values
May 25, 2026
Merged

C++: allow iterating over unique enum values#1806
pwrobeldev merged 5 commits into
masterfrom
pwrobeldev/provide-way-to-get-all-enumerator-values

Conversation

@pwrobeldev

Copy link
Copy Markdown
Contributor

---------- Motivation ----------
There were a few requests in the past to provide the means for
users of the generated code to iterate over enumeration values.

---------- Solution ----------
Introduced a new cpp-specific attribute in LIME language called 'EnumValues'.
When LIME enumeration is annotated with it, then C++ generator creates additional
helper function that returns the array of unique enumerators. It is achieved via the new
mustache templates. The change implements smoke and functional tests to confirm
that the new functionality works as expected.

For the following input:

@Cpp(EnumValues)
enum EnumWithAccessibleValues {
    FOO,
    BAR,
    BAZ,
    FOO_ALIAS = FOO
}

The additional function is generated:

std::array<EnumWithAccessibleValues, 3>
EnumWithAccessibleValues_enumerators();

This commit implements a new cpp-only attribute
called 'EnumeratorValues'. When enumeration is
annotated with it, then additional function is
generated. It returns std::array with all enumerator
values.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
This commit implements new LIME input that is properly handled.
The committed output of smoke-tests confirm that for the new
attribute the C++ generator creates the additional function.

Note: the returned enumeration values are unique. Aliasing enumerators
are skipped.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
This commit brings new functional tests, which check if
the generated code for the new 'EnumValues' cpp attribute
works correctly and compiles without problems.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
The new attribute can be used for C++ enums to instruct the generator
to create a helper function that returns unique enum values.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
@pwrobeldev

Copy link
Copy Markdown
Contributor Author

The failure for Swift on MacOS seems to be related to environment issues related to the used runner / action to setup JDK. I will investigate it and fix in a separate MR.

In meantime, I executed all functional tests on my local MacOS with the current branch -- there are no problems.

1: Test Suite 'testfunctional.xctest' passed at 2026-05-25 19:12:27.586.
1: 	 Executed 501 tests, with 0 failures (0 unexpected) in 0.063 (0.072) seconds
1: Test Suite 'All tests' passed at 2026-05-25 19:12:27.586.
1: 	 Executed 501 tests, with 0 failures (0 unexpected) in 0.063 (0.076) seconds
1/1 Test #1: XCTest.functional ................   Passed    1.42 sec

@pwrobeldev
pwrobeldev removed the request for review from Hsilgos May 25, 2026 17:21
@pwrobeldev
pwrobeldev merged commit e1875a1 into master May 25, 2026
17 of 19 checks passed
@pwrobeldev
pwrobeldev deleted the pwrobeldev/provide-way-to-get-all-enumerator-values branch May 25, 2026 18:46
@pwrobeldev

Copy link
Copy Markdown
Contributor Author

The changes have been merged. The environment issue for Swift on MacOS job will be investigated and fixed in a separate MR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants