Skip to content

Commit 269a2ee

Browse files
j-piaseckimeta-codesync[bot]
authored andcommitted
Fix indexed access in function arguments (facebook#55645)
Summary: Pull Request resolved: facebook#55645 Changelog: [Internal] Updates the C++ api snapshot generator to correctly handle arrays of fixed size. Reviewed By: cipolleschi Differential Revision: D93407605 fbshipit-source-id: b64d30db04696ea54109258d7d4c4fbf43a4cc69
1 parent bf4978e commit 269a2ee

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

scripts/cxx-api/parser/main.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,30 @@ def get_doxygen_params(
230230
resolve_ref_text_name(param.defval).strip() if param.defval else None
231231
)
232232

233+
# Doxygen splits array dimensions into a separate <array> element.
234+
# For complex declarators like "PropNameID (&&propertyNames)[N]",
235+
# doxygen gives type="PropNameID(&&)", name="propertyNames",
236+
# array="[N]". We must reconstruct the full declarator with the
237+
# name embedded inside the grouping parentheses:
238+
# PropNameID(&&propertyNames)[N]
239+
param_array = param.array
240+
if param_array:
241+
# Match type ending with a pointer/reference declarator group:
242+
# e.g. "PropNameID(&&)", "int(&)", "void(*)"
243+
m = re.search(r"\([*&]+\)\s*$", param_type)
244+
if m and param_name:
245+
# Insert name before the closing ')' and append array
246+
insert_pos = m.end() - 1 # position of trailing ')'
247+
param_type = (
248+
param_type[:insert_pos]
249+
+ param_name
250+
+ param_type[insert_pos:]
251+
+ param_array
252+
)
253+
param_name = None
254+
else:
255+
param_type += param_array
256+
233257
qualifiers, core_type = extract_qualifiers(param_type)
234258
arguments.append((qualifiers, core_type, param_name, param_default))
235259

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
struct test::Node {
2+
public void setArray(int(&arr)[10]);
3+
template <size_t N>
4+
public static std::vector< test::PropNameID > names(PropNameID(&&propertyNames)[N]);
5+
}
6+
7+
struct test::PropNameID {
8+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
struct PropNameID {};
13+
14+
struct Node {
15+
template <size_t N>
16+
static std::vector<PropNameID> names(PropNameID (&&propertyNames)[N]);
17+
18+
void setArray(int (&arr)[10]);
19+
};
20+
21+
} // namespace test

0 commit comments

Comments
 (0)