-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C++] Simplify forward declaration detection #11490
[C++] Simplify forward declaration detection #11490
Conversation
The PR template said I should @ mention the language technical commitee but the link to more information was dead ... and I could not find out how to mention the cpp technical commitee. If anyone knows the name to mention reads this, please add it :) |
Maybe CC @wing328 |
@@ -418,13 +418,10 @@ private void addForwardDeclarations(CodegenModel parentModel, Map<String, Object | |||
if( !childPropertyType.equals(childModel.classname) || childPropertyType.equals(parentModel.classname) || !childModel.hasVars ){ |
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.
What is the !childModel.hasVars
check good for?
To me it looks like we might want to get rid of that too
Found the commitee info: @ravinikam (2017/07) @stkrwork (2017/07) @etherealjoy (2018/02) @MartinDelille (2018/03) @muttleyxd (2019/08) |
@@ -31,6 +31,8 @@ namespace openapitools { | |||
namespace client { | |||
namespace model { | |||
|
|||
class Category; | |||
class Tag; |
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.
@dschmidt thanks for the PR. Are these changes expected?
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.
Thanks for coming back to me!
Well, yes. In this specific case they are not strictly neccessary obviously, but they help in the general case. It's what this PR is all about: make it possible to create template which don't need model includes and avoid circular inclusion problems that way.
I think having forward declarations that are not strictly needed for everyone and every template is still much better than trying to be supersmart and to add complicated logic to determine whether they are needed or better than adding an option for it
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.
... and actually that should be the case for cpp-restsdk already as it uses shared_ptr for storing data members.
I. e. in theory we should be able to move model includes to the cpp files already
Can I do anything to make this happen? |
I remember looking at this few days ago, but forgot to press approve. This looks fine to me, from C++ side, I didn't work much with cpp-restsdk though. |
Yeah, this should not change anything for cpp-restsdk (except for fixing circular include issues). |
btw here's what we're doing with that now: https://github.com/owncloud/libre-graph-api/tree/main/templates/cpp-qt-client We have pimpl'ed the model classes and made it compile despite the circular deps in our spec file. We could have gone for shared pointers in the main class as well but while at it .... 馃榿 No idea if that would be interesting for upstream, as it's most likely a breaking change if anyone relies on the internal implementation of the model classes. edit: P.S.: Thanks for reviewing and approving |
Sure, will take care |
2998e3e
to
6f3a5a0
Compare
This makes sure all model classes are added to the forward declarations which makes it possible to create templates without any model includes which helps to resolve circular inclusion issues.
6f3a5a0
to
91beb7b
Compare
After my rebase the CI started failing, but I don't see how this change would be able to introduce any runtime issue... is this an issue in master? |
Tested locally and the result is good. |
This makes sure all model classes are added to the forward declarations which makes it possible to create templates without any model includes.
This helps to resolve circular inclusion issues.
This adds more forward declarations of which a lot are not strictly needed by the current templates, but they don't harm either. Trying to detect in which case declarations are needed or not or making it configurable does not seem to be worth the effort and would add a lot of complexity.
If you have a spec like this:
(excerpt from https://github.com/owncloud/libre-graph-api/blob/main/api/openapi-spec/v0.0.yaml)
You get issues with circular
#include
s:Drive
requiresDriveItem
requiresUser
requiresDrive
馃挜To solve this issue a template may only use forward declarations and must use pointers to model objects or a pimple implementation.
I'm working on templates based on the
cpp-qt-client
, but with the current implementation (without this PR) required forward declarations are missing: e.g.,Drive
only has aUser
forward declaration, theDriveItem
forward declaration is missing. With this PR all models used in the header are added to the forward declarations.I found the old code hard to reason about so i'm not 100% sure this does not remove any forward declarations in some edge case, but it works for me for the original spec that my excerpt is from and it's not completely trivial.
Attention: This change alone is not enough to make the generator produce compilable code for the spec above, but it's all that's needed to create working templates. Templates are still work in progress because I've still got runtime issues to resolve.
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
(5.3.0),6.0.x