Skip to content

Commit 41a1941

Browse files
j-piaseckimeta-codesync[bot]
authored andcommitted
Remove incorrect qualification from function parameters (#55971)
Summary: Pull Request resolved: #55971 Changelog: [Internal] Doxygen incorrectly transforms parameter names to references if they match a member. This diff strips the resulting invalid qualification from the type. Reviewed By: cipolleschi Differential Revision: D95548542 fbshipit-source-id: c1e475f10e07af6a4076336cab0d3cbe0da342e5
1 parent 6d19a27 commit 41a1941

4 files changed

Lines changed: 58 additions & 0 deletions

File tree

scripts/cxx-api/parser/utils/argument_parsing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,13 @@ def _parse_single_argument(arg: str) -> Argument:
297297
)
298298
):
299299
return (qualifiers, base_arg, None, default_value)
300+
# C++ parameter names cannot contain "::". Doxygen may
301+
# incorrectly cross-reference a parameter name to a member
302+
# variable, producing a qualified path (e.g. "bool
303+
# ns::Class::isActive" instead of "bool isActive"). Strip
304+
# the namespace prefix to recover the original name.
305+
if "::" in potential_name:
306+
potential_name = potential_name.rsplit("::", 1)[-1]
300307
return (qualifiers, prefix, potential_name, default_value)
301308
else:
302309
return (qualifiers, base_arg, None, default_value)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class test::Tracer {
2+
public bool isActive;
3+
public uint32_t subscribe(test::Tracer::StateCallback callback);
4+
public using StateCallback = void(*)(bool isActive);
5+
}
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 Tracer {
13+
public:
14+
bool isActive;
15+
using StateCallback = void (*)(bool isActive);
16+
uint32_t subscribe(StateCallback callback);
17+
};
18+
19+
} // namespace test

scripts/cxx-api/tests/test_parse_arg_string.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,33 @@ def test_full_complex_signature(self):
374374
self.assertTrue(mods.is_noexcept)
375375
self.assertTrue(mods.is_override)
376376

377+
# =========================================================================
378+
# Qualified parameter names (Doxygen cross-reference cleanup)
379+
# =========================================================================
380+
381+
def test_qualified_parameter_name_stripped(self):
382+
"""Parameter names containing '::' should be stripped to base name.
383+
384+
Doxygen may incorrectly cross-reference parameter names to member
385+
variables, producing qualified paths like 'ns::Class::paramName'.
386+
C++ parameter names cannot contain '::', so the qualification must
387+
be stripped to just the base name.
388+
"""
389+
args, mods = parse_arg_string(
390+
"(bool facebook::react::PerformanceTracer::isTracing)"
391+
)
392+
self.assertEqual(args, [(None, "bool", "isTracing", None)])
393+
394+
def test_qualified_parameter_name_simple(self):
395+
"""Simple qualified parameter name: test::Foo::value"""
396+
args, mods = parse_arg_string("(int test::Foo::value)")
397+
self.assertEqual(args, [(None, "int", "value", None)])
398+
399+
def test_unqualified_parameter_name_unchanged(self):
400+
"""Regular parameter names without '::' should not be affected."""
401+
args, mods = parse_arg_string("(bool isActive)")
402+
self.assertEqual(args, [(None, "bool", "isActive", None)])
403+
377404

378405
if __name__ == "__main__":
379406
unittest.main()

0 commit comments

Comments
 (0)