-
Notifications
You must be signed in to change notification settings - Fork 137
[ffigen] Add C++ public inheritance support (single, multiple, diamond) #3542
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
Open
Hassnaa9
wants to merge
6
commits into
dart-lang:main
Choose a base branch
from
Hassnaa9:cpp-inheritance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,960
−9
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a95321d
[ffigen] Add C++ public inheritance support (single, multiple, diamond)
Hassnaa9 4e79ab9
Copy inherited C++ methods in visitor instead of delegating at codegen.
Hassnaa9 71af05a
Merge branch 'main' into cpp-inheritance
liamappelbe 7c3a325
fix analyze issues
Hassnaa9 a600f41
Refactor CppMethod originatingClass reference and signatureKey lookup.
Hassnaa9 06d61f0
Remove static_cast from C++ glue code and use virtual inheritance in …
Hassnaa9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| #include "cpp_inheritance_test.h" | ||
|
|
||
| #ifndef M_PI | ||
| #define M_PI 3.14159265358979323846 | ||
| #endif | ||
|
|
||
| Shape::Shape(double x, double y) : x_(x), y_(y) {} | ||
| Shape::~Shape() {} | ||
| double Shape::getX() const { return x_; } | ||
| double Shape::getY() const { return y_; } | ||
|
|
||
| Drawable::Drawable() : drawCount_(0) {} | ||
| Drawable::~Drawable() {} | ||
| int Drawable::draw() const { return 42; } | ||
|
|
||
| Circle::Circle(double x, double y, double radius) | ||
| : Shape(x, y), radius_(radius) {} | ||
|
|
||
| double Circle::area() const { | ||
| return M_PI * radius_ * radius_; | ||
| } | ||
|
|
||
| ColoredCircle::ColoredCircle(double x, double y, double radius, int color) | ||
| : Circle(x, y, radius), Drawable(), color_(color) {} | ||
|
|
||
| int ColoredCircle::getColor() const { return color_; } | ||
|
|
||
| Square::Square(double x, double y, double side) | ||
| : Shape(x, y), side_(side) {} | ||
|
|
||
| double Square::getX() const { return Shape::getX() + side_; } | ||
|
|
||
| double Square::area() const { return side_ * side_; } | ||
|
|
||
| int AccessBase::value() const { return v_; } | ||
| PublicDerived::PublicDerived() {} | ||
| ProtectedDerived::ProtectedDerived() {} | ||
| PrivateDerived::PrivateDerived() {} | ||
|
|
||
| OverloadBase::OverloadBase() {} | ||
| OverloadBase::~OverloadBase() {} | ||
| int OverloadBase::getValue(int x) { return x * 2; } | ||
| double OverloadBase::getValueDouble(double x) { return x * 3.0; } | ||
|
|
||
| OverloadDerived::OverloadDerived() {} | ||
| int OverloadDerived::getValue(int x) { return x * 10; } | ||
|
|
||
| DiamondBase::DiamondBase() {} | ||
| DiamondBase::~DiamondBase() {} | ||
| int DiamondBase::baseVal() const { return 42; } | ||
| int DiamondBase::virtVal() const { return 100; } | ||
|
|
||
| DiamondLeft::DiamondLeft() {} | ||
| int DiamondLeft::virtVal() const { return 200; } | ||
| DiamondRight::DiamondRight() {} | ||
| DiamondDerived::DiamondDerived() {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 was pretty confused about this name mangling until I realised that you're using
originalNameinstead ofnamewhen generating the Dart method. That means that users won't be able to rename methods, and the name collision resolution logic won't work.You don't need to fix that in this PR, but I filed a bug so we don't forget: #3552