Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions scripts/cxx-api/parser/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ def main():
type=str,
help="Directory containing committed snapshots for comparison (used with --check)",
)
parser.add_argument(
"--view",
type=str,
help="Name of the API view to generate",
)
parser.add_argument(
"--test",
action="store_true",
Expand Down Expand Up @@ -250,6 +255,9 @@ def main():
def build_snapshots(output_dir: str, verbose: bool) -> None:
if not args.test:
for config in snapshot_configs:
if args.view and config.snapshot_name != args.view:
continue

build_snapshot_for_view(
api_view=config.snapshot_name,
react_native_dir=react_native_package_dir,
Expand Down
21 changes: 20 additions & 1 deletion scripts/cxx-api/parser/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def get_variable_member(
if initializer_type == InitializerType.BRACE:
is_brace_initializer = True

return VariableMember(
member = VariableMember(
variable_name,
variable_type,
visibility,
Expand All @@ -263,6 +263,10 @@ def get_variable_member(
is_brace_initializer,
)

member.add_template(get_template_params(member_def))

return member


def get_doxygen_params(
function_def: compound.MemberdefType,
Expand Down Expand Up @@ -313,6 +317,21 @@ def get_doxygen_params(
else:
param_type += param_array

# Handle pointer-to-member-function types where the name must be
# embedded inside the declarator group. Doxygen gives:
# type = "void(ns::*)() const", name = "asFoo"
# We need to produce:
# "void(ns::*asFoo)() const"
if param_name:
m = re.search(r"\([^)]*::\*\)", param_type)
if m:
# Insert name before the closing ')' of the ptr-to-member group
insert_pos = m.end() - 1
param_type = (
param_type[:insert_pos] + param_name + param_type[insert_pos:]
)
param_name = None

qualifiers, core_type = extract_qualifiers(param_type)
arguments.append((qualifiers, core_type, param_name, param_default))

Expand Down
3 changes: 3 additions & 0 deletions scripts/cxx-api/parser/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ def to_string(

result = " " * indent

if self.template_list is not None:
result += self.template_list.to_string() + "\n" + " " * indent

if not hide_visibility:
result += self.visibility + " "

Expand Down
7 changes: 6 additions & 1 deletion scripts/cxx-api/parser/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,13 @@ def qualify_name(self, name: str | None) -> str | None:
elif any(
m.name == base_name and not isinstance(m, FriendMember)
for m in current_scope._members
) or any(
any(m.name == base_name for m in inner._members)
for inner in current_scope.inner_scopes.values()
if isinstance(inner.kind, EnumScopeKind)
):
# Found as a member, assume following segments exist in the scope
# Found as a member (or as an unscoped enum value accessible
# from the parent scope), assume following segments exist
prefix = "::".join(matched_segments)
suffix = "::".join(path[i:])
anchor_prefix = anchor_scope.get_qualified_name()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
struct folly::dynamic {
}


template <typename R, typename... T>
R test::jsArg(const folly::dynamic& arg, R(folly::dynamic::*asFoo)() const, const T &... desc);
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

namespace folly {

struct dynamic {};

} // namespace folly

namespace test {

template <typename R, typename... T>
R jsArg(const folly::dynamic &arg, R (folly::dynamic::*asFoo)() const, const T &...desc);

} // namespace test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
template <typename T>
const test::Strct<T> test::Strct<T>::VALUE;

template <typename T>
struct test::Strct {
public static const test::Strct<T> VALUE;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

namespace test {

template <typename T>
struct Strct {
static const Strct<T> VALUE;
};

template <typename T>
const Strct<T> Strct<T>::VALUE = {};

} // namespace test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
struct test::Event {
}

enum test::Event::Type {
NodeAllocation,
NodeDeallocation,
}

template <test::Event::Type E>
struct test::Event::TypedData {
}

struct test::Event::TypedData<test::Event::NodeAllocation> {
public int config;
}

struct test::Event::TypedData<test::Event::NodeDeallocation> {
public int config;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

namespace test {

struct Event {
enum Type {
NodeAllocation,
NodeDeallocation,
};

template <Type E>
struct TypedData {};
};

template <>
struct Event::TypedData<Event::NodeAllocation> {
int config;
};

template <>
struct Event::TypedData<Event::NodeDeallocation> {
int config;
};

} // namespace test
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
constexpr T test::default_value;
constexpr test::MyType test::default_value<test::MyType>;
template <typename T>
constexpr T test::default_value;
template <typename T>
T* test::null_ptr;
test::MyType* test::null_ptr<test::MyType>;

Expand Down
Loading