-
Notifications
You must be signed in to change notification settings - Fork 40
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -376,9 +376,15 @@ public override ValueTask<string> Compile(BebopSchema schema, GeneratorConfig co | |||
builder.AppendLine("#include \"bebop.hpp\""); | ||||
builder.AppendLine(""); | ||||
|
||||
string[] namespaces = {}; | ||||
if (!string.IsNullOrWhiteSpace(Config.Namespace)) | ||||
{ | ||||
builder.AppendLine($"namespace {Config.Namespace} {{"); | ||||
namespaces = Config.Namespace.Split("::"); | ||||
} | ||||
|
||||
foreach (string ns in namespaces) | ||||
{ | ||||
builder.AppendLine($"namespace {ns} {{"); | ||||
builder.AppendLine(""); | ||||
} | ||||
|
||||
|
@@ -510,9 +516,9 @@ public override ValueTask<string> Compile(BebopSchema schema, GeneratorConfig co | |||
} | ||||
} | ||||
|
||||
if (!string.IsNullOrWhiteSpace(Config.Namespace)) | ||||
foreach (string ns in namespaces) | ||||
{ | ||||
builder.AppendLine($"}} // namespace {Config.Namespace}"); | ||||
builder.AppendLine($"}} // namespace {ns}"); | ||||
builder.AppendLine(""); | ||||
} | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
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. |
||||
|
||||
|
There was a problem hiding this comment.
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.