Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi-level namespace support in C++ generator #347

Closed
wants to merge 5 commits into from

Conversation

SirusDoma
Copy link
Contributor

This allows C++ generator to generate multi-level namespaces in generated header file. Additionally, it add supports of using Namespace1::Namespace2 format in namespace configuration.

I avoid using Namespace1::Namespace2 directly in generated header because it requires C++17.

{
builder.AppendLine($"}} // namespace {Config.Namespace}");
builder.AppendLine($"}} // namespace {ns}");
builder.AppendLine("");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally fine with this, but it would be better to handle your desired behavior behind an option, that way those who are targeting C++17 and above can get a single level namespace you can see an example of that here:

if (Version.TryParse(config.GetOptionRawValue("langVersion"), out var langVersion))

I'll leave it to you to determine what an appropriate option name would be. For a refresher options are passed either via the bebop.json config or on the command line inside the generator string. ( "cpp:./GeneratedTestCode/test.g.hpp,namespace=Bebop::Codegen".

You'll need to test it works through both these means.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I was busy with other things and only had free time during this holiday to revisit this. I think this should be using C++17 instead since bebop already relying on std::variant; which is only available on C++17 and newer

Core/Meta/Extensions/StringExtensions.cs Show resolved Hide resolved
@@ -376,9 +376,15 @@ public override ValueTask<string> Compile(BebopSchema schema, GeneratorConfig co
builder.AppendLine("#include \"bebop.hpp\"");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see a test workflow implemented to verify C++ changes here. We already have some basic testing setup in the lab: https://github.com/betwixt-labs/bebop/tree/master/Laboratory/C%2B%2B

So if you can setup a new test-cpp.yml in the workflows folder (https://github.com/betwixt-labs/bebop/tree/master/.github/workflows) and validate these changes there, I'll be happy to merge.

@SirusDoma SirusDoma requested a review from andrewmd5 December 28, 2024 04:25
@SirusDoma
Copy link
Contributor Author

I will close this PR for now because my master branch on my local are already polluted and I wish to push the changes on my fork. I will probably raise another PR in different branch for this if you still interested to see this merged into upstream

@SirusDoma SirusDoma closed this Jan 2, 2025
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