Skip to content

Commit 31f262e

Browse files
j-piaseckimeta-codesync[bot]
authored andcommitted
Fix function pointer param args being qualified to outer class (#56217)
Summary: Pull Request resolved: #56217 Changelog: [Internal] Doxygen may incorrectly cross-reference parameter names inside function pointer types to member variables of the enclosing class. For example, `void (*cb)(const void* data)` inside a class that has a `data` member would produce `const void* Class::data` instead of `const void* data` in the snapshot. This diff addresses two issues: 1. In `get_doxygen_params`, re-parse function pointer type strings through `parse_type_with_argstrings` which delegates to `_parse_single_argument` that already strips "::" from parameter names. 2. In `parse_type_with_argstrings`, recognize complex declarator groups starting with `*` or `&` (e.g. `*(*fp)(int)`) as non-argument-list parenthesized sections, preventing incorrect name extraction from nested function pointer declarators. Reviewed By: cipolleschi Differential Revision: D98118629 fbshipit-source-id: a8532e2adaec1dd2b50be8a20eae1068ac49d548
1 parent cc9d06b commit 31f262e

4 files changed

Lines changed: 46 additions & 1 deletion

File tree

scripts/cxx-api/parser/builders.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@
4141
resolve_linked_text_name,
4242
split_specialization,
4343
)
44-
from .utils.argument_parsing import _find_matching_angle, _split_arguments
44+
from .utils.argument_parsing import (
45+
_find_matching_angle,
46+
_split_arguments,
47+
format_parsed_type,
48+
parse_type_with_argstrings,
49+
)
4550

4651

4752
@dataclass
@@ -307,6 +312,16 @@ def get_doxygen_params(
307312
if param.get_type()
308313
else ""
309314
)
315+
316+
# Doxygen may incorrectly cross-reference parameter names inside
317+
# inline function pointer types to member variables of the enclosing
318+
# class, producing qualified paths like "const void*
319+
# ns::Class::data" instead of "const void* data". Re-parse the
320+
# type through parse_type_with_argstrings which delegates to
321+
# _parse_single_argument — that already strips "::" from names.
322+
segments = parse_type_with_argstrings(param_type)
323+
if len(segments) > 1:
324+
param_type = format_parsed_type(segments)
310325
param_name = param.declname or param.defname or None
311326
param_default = (
312327
resolve_linked_text_name(param.defval)[0].strip() if param.defval else None

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,14 @@ def parse_type_with_argstrings(
530530
i = close + 1
531531
continue
532532

533+
# Complex declarator starting with * or &, e.g. *(*fp)(int)
534+
# in "int(*(*fp)(int))(double)". Argument lists never start
535+
# with pointer/reference characters.
536+
if stripped and stripped[0] in ("*", "&"):
537+
current_text.append(type_str[i : close + 1])
538+
i = close + 1
539+
continue
540+
533541
# Try to parse as a function argument list
534542
args: list[Argument] = []
535543
if stripped:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class test::Runtime {
2+
public int data;
3+
public virtual void getStringData(void* ctx, void(*)(void* ctx, bool ascii, const void* data, size_t num) cb);
4+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 Runtime {
13+
public:
14+
int data;
15+
virtual void getStringData(void *ctx, void (*cb)(void *ctx, bool ascii, const void *data, size_t num));
16+
};
17+
18+
} // namespace test

0 commit comments

Comments
 (0)