Skip to content

Commit f906121

Browse files
j-piaseckimeta-codesync[bot]
authored andcommitted
Handle constexpr functions (#55801)
Summary: Pull Request resolved: #55801 Changelog: [Internal] Handle `constexpr` functions in the C++ API snapshot Reviewed By: javache Differential Revision: D94658128 fbshipit-source-id: 9e380de951e46dff72ba40c8726e46c01340a9a8
1 parent cc44e96 commit f906121

6 files changed

Lines changed: 44 additions & 0 deletions

File tree

scripts/cxx-api/parser/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ def get_function_member(
316316
function_arg_string = function_def.get_argsstring()
317317
is_pure_virtual = function_def.get_virt() == "pure-virtual"
318318
function_virtual = function_def.get_virt() == "virtual" or is_pure_virtual
319+
is_constexpr = function_def.constexpr == "yes"
319320

320321
# Doxygen incorrectly merges "=0" into the return type for pure-virtual
321322
# functions using trailing return types (e.g. "auto f() -> T = 0").
@@ -333,6 +334,7 @@ def get_function_member(
333334
is_pure_virtual,
334335
is_static,
335336
doxygen_params,
337+
is_constexpr,
336338
)
337339

338340
function.add_template(get_template_params(function_def))

scripts/cxx-api/parser/member.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,13 @@ def __init__(
206206
is_pure_virtual: bool,
207207
is_static: bool,
208208
doxygen_params: list[Argument] | None = None,
209+
is_constexpr: bool = False,
209210
) -> None:
210211
super().__init__(name, visibility)
211212
self.type: str = type
212213
self.is_virtual: bool = is_virtual
213214
self.is_static: bool = is_static
215+
self.is_constexpr: bool = is_constexpr
214216
parsed_arguments, self.modifiers = parse_arg_string(arg_string)
215217
self.arguments = (
216218
doxygen_params if doxygen_params is not None else parsed_arguments
@@ -258,6 +260,9 @@ def to_string(
258260
if self.is_static:
259261
result += "static "
260262

263+
if self.is_constexpr:
264+
result += "constexpr "
265+
261266
if self.type:
262267
result += f"{self.type} "
263268

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
constexpr int test::makeValue();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
constexpr int makeValue();
13+
14+
} // namespace test
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class test::Clss {
2+
public constexpr int getValue() const;
3+
public static constexpr int getDefault();
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 Clss {
13+
public:
14+
constexpr int getValue() const;
15+
static constexpr int getDefault();
16+
};
17+
18+
} // namespace test

0 commit comments

Comments
 (0)