Skip to content

Commit f0b51fc

Browse files
coadometa-codesync[bot]
authored andcommitted
Add ParsedSectionKind dataclass not to rely on strings directly (#56088)
Summary: Pull Request resolved: #56088 Changelog: [Internal] Adds `ParsedSectionKind` which encapsulates logic related to parsing the section kind string. Reviewed By: cipolleschi Differential Revision: D96455765 fbshipit-source-id: 6d4866112511f24f5781e014eb720b96c3cfaf0d
1 parent 20cf9bc commit f0b51fc

1 file changed

Lines changed: 31 additions & 12 deletions

File tree

scripts/cxx-api/parser/builders.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from __future__ import annotations
1515

1616
import re
17+
from dataclasses import dataclass
1718

1819
from doxmlparser import compound
1920

@@ -43,6 +44,24 @@
4344
from .utils.argument_parsing import _find_matching_angle, _split_arguments
4445

4546

47+
@dataclass
48+
class ParsedSectionKind:
49+
"""Parsed representation of a Doxygen section kind string (e.g. 'public-static-func')."""
50+
51+
visibility: str
52+
is_static: bool
53+
member_type: str
54+
55+
@classmethod
56+
def parse(cls, kind: str) -> ParsedSectionKind:
57+
parts = kind.split("-")
58+
return cls(
59+
visibility=parts[0],
60+
is_static="static" in parts,
61+
member_type=parts[-1],
62+
)
63+
64+
4665
######################
4766
# Base class fixups
4867
######################
@@ -536,11 +555,10 @@ def _process_objc_sections(
536555
members into the base interface XML output.
537556
"""
538557
for section_def in section_defs:
539-
kind = section_def.kind
540-
parts = kind.split("-")
541-
visibility = parts[0]
542-
is_static = "static" in parts
543-
member_type = parts[-1]
558+
section = ParsedSectionKind.parse(section_def.kind)
559+
visibility = section.visibility
560+
is_static = section.is_static
561+
member_type = section.member_type
544562

545563
if visibility == "private":
546564
if member_type == "type":
@@ -577,7 +595,9 @@ def _process_objc_sections(
577595
f"Unknown section member kind: {member_def.kind} in {location_file}"
578596
)
579597
else:
580-
print(f"Unknown {scope_type} section kind: {kind} in {location_file}")
598+
print(
599+
f"Unknown {scope_type} section kind: {section_def.kind} in {location_file}"
600+
)
581601
elif visibility == "property":
582602
for member_def in section_def.memberdef:
583603
if member_def.kind == "property":
@@ -693,11 +713,10 @@ def create_class_scope(
693713
class_scope.location = compound_object.location.file
694714

695715
for section_def in compound_object.sectiondef:
696-
kind = section_def.kind
697-
parts = kind.split("-")
698-
visibility = parts[0]
699-
is_static = "static" in parts
700-
member_type = parts[-1]
716+
section = ParsedSectionKind.parse(section_def.kind)
717+
visibility = section.visibility
718+
is_static = section.is_static
719+
member_type = section.member_type
701720

702721
if visibility == "private":
703722
if member_type == "type":
@@ -746,7 +765,7 @@ def create_class_scope(
746765
)
747766
else:
748767
print(
749-
f"Unknown class section kind: {kind} in {compound_object.location.file}"
768+
f"Unknown class section kind: {section_def.kind} in {compound_object.location.file}"
750769
)
751770
elif visibility == "friend":
752771
pass

0 commit comments

Comments
 (0)