Skip to content

Commit 7d80d6e

Browse files
j-piaseckimeta-codesync[bot]
authored andcommitted
Use the derived class name in inherited constructors in the API snapshot (facebook#56031)
Summary: Pull Request resolved: facebook#56031 Changelog: [Internal] Doxygen uses base class name for inherited constructors. This diff adds a guard to replace them with the derived class name in the final API snapshot. Reviewed By: cipolleschi Differential Revision: D95939080 fbshipit-source-id: 918135b8c5c603423e3a13537d9723e54ed4f035
1 parent 2be2770 commit 7d80d6e

5 files changed

Lines changed: 97 additions & 2 deletions

File tree

scripts/cxx-api/parser/builders.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,37 @@
4141
)
4242

4343

44+
######################
45+
# Inherited constructor fixup
46+
######################
47+
48+
49+
def _fix_inherited_constructor_name(
50+
func_member: FunctionMember,
51+
compound_name: str,
52+
) -> None:
53+
"""
54+
Fix inherited constructor names reported by Doxygen.
55+
56+
When a class inherits constructors via ``using Base::Base;``, Doxygen
57+
reports them with the base class name instead of the derived class name.
58+
This function detects such constructors and renames them.
59+
"""
60+
if (
61+
func_member.type != ""
62+
or func_member.name.startswith("~")
63+
or func_member.name.startswith("operator")
64+
):
65+
return
66+
67+
class_unqualified_name = parse_qualified_path(compound_name)[-1]
68+
# Strip template args for comparison
69+
class_base_name = class_unqualified_name.split("<")[0]
70+
71+
if func_member.name != class_base_name:
72+
func_member.name = class_unqualified_name
73+
74+
4475
######################
4576
# Member extraction
4677
######################
@@ -601,9 +632,13 @@ def create_class_scope(
601632
)
602633
elif member_type == "func":
603634
for function_def in section_def.memberdef:
604-
class_scope.add_member(
605-
get_function_member(function_def, visibility, is_static)
635+
func_member = get_function_member(
636+
function_def, visibility, is_static
637+
)
638+
_fix_inherited_constructor_name(
639+
func_member, compound_object.compoundname
606640
)
641+
class_scope.add_member(func_member)
607642
elif member_type == "type":
608643
for member_def in section_def.memberdef:
609644
if member_def.kind == "enum":
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class test::Base {
2+
public Base() = default;
3+
public Base(const test::Base& other);
4+
public Base(int test);
5+
}
6+
7+
class test::Derived : public test::Base {
8+
public Derived() = default;
9+
public Derived(const test::Base& other);
10+
public Derived(int test);
11+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
namespace test {
11+
12+
class Base {
13+
public:
14+
Base() = default;
15+
Base(int test);
16+
Base(const Base &other);
17+
};
18+
19+
class Derived : public Base {
20+
public:
21+
using Base::Base;
22+
};
23+
24+
} // namespace test
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class test::Clss {
2+
public operator Other() const;
3+
}
4+
5+
class test::Other {
6+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
namespace test {
11+
12+
class Other {};
13+
14+
class Clss {
15+
public:
16+
operator Other() const;
17+
};
18+
19+
} // namespace test

0 commit comments

Comments
 (0)