88import os
99import re
1010from enum import Enum
11- from pprint import pprint
1211
1312from doxmlparser import compound , index
1413
2120 TypedefMember ,
2221 VariableMember ,
2322)
24- from .scope import ProtocolScopeKind , StructLikeScopeKind
23+ from .scope import InterfaceScopeKind , ProtocolScopeKind , StructLikeScopeKind
2524from .snapshot import Snapshot
2625from .template import Template
2726from .utils import Argument , extract_qualifiers , parse_qualified_path
@@ -608,6 +607,66 @@ def create_protocol_scope(snapshot: Snapshot, scope_def: compound.CompounddefTyp
608607 )
609608
610609
610+ def create_interface_scope (snapshot : Snapshot , scope_def : compound .CompounddefType ):
611+ """
612+ Create an interface scope in the snapshot (Objective-C @interface).
613+ """
614+ interface_name = scope_def .compoundname
615+
616+ interface_scope = snapshot .create_interface (interface_name )
617+ base_classes = get_base_classes (scope_def , base_class = InterfaceScopeKind .Base )
618+ interface_scope .kind .add_base (base_classes )
619+ interface_scope .location = scope_def .location .file
620+
621+ for section_def in scope_def .sectiondef :
622+ kind = section_def .kind
623+ parts = kind .split ("-" )
624+ visibility = parts [0 ]
625+ is_static = "static" in parts
626+ member_type = parts [- 1 ]
627+
628+ if visibility == "private" :
629+ pass
630+ elif visibility in ("public" , "protected" ):
631+ if member_type == "attrib" :
632+ for member_def in section_def .memberdef :
633+ if member_def .kind == "variable" :
634+ interface_scope .add_member (
635+ get_variable_member (member_def , visibility , is_static )
636+ )
637+ elif member_type == "func" :
638+ for function_def in section_def .memberdef :
639+ interface_scope .add_member (
640+ get_function_member (function_def , visibility , is_static )
641+ )
642+ elif member_type == "type" :
643+ for member_def in section_def .memberdef :
644+ if member_def .kind == "enum" :
645+ create_enum_scope (snapshot , member_def )
646+ elif member_def .kind == "typedef" :
647+ interface_scope .add_member (
648+ get_typedef_member (member_def , visibility )
649+ )
650+ else :
651+ print (
652+ f"Unknown section member kind: { member_def .kind } in { scope_def .location .file } "
653+ )
654+ else :
655+ print (
656+ f"Unknown interface section kind: { kind } in { scope_def .location .file } "
657+ )
658+ elif visibility == "property" :
659+ for member_def in section_def .memberdef :
660+ if member_def .kind == "property" :
661+ interface_scope .add_member (
662+ get_property_member (member_def , "public" , is_static )
663+ )
664+ else :
665+ print (
666+ f"Unknown interface visibility: { visibility } in { scope_def .location .file } "
667+ )
668+
669+
611670def build_snapshot (xml_dir : str ) -> Snapshot :
612671 """
613672 Reads the Doxygen XML output and builds a snapshot of the C++ API.
@@ -628,12 +687,23 @@ def build_snapshot(xml_dir: str) -> Snapshot:
628687 doxygen_object = compound .parse (detail_file , silence = True )
629688
630689 for compound_object in doxygen_object .compounddef :
690+ # Check if this is an Objective-C interface by looking at the compound id
691+ # Doxygen reports ObjC interfaces as kind="class" but with id starting with "interface"
692+ is_objc_interface = (
693+ compound_object .kind == "class"
694+ and compound_object .id .startswith ("interface" )
695+ )
696+
631697 # classes and structs are represented by the same scope with a different kind
632698 if (
633699 compound_object .kind == "class"
634700 or compound_object .kind == "struct"
635701 or compound_object .kind == "union"
636702 ):
703+ # Handle Objective-C interfaces separately
704+ if is_objc_interface :
705+ create_interface_scope (snapshot , compound_object )
706+ continue
637707 class_scope = (
638708 snapshot .create_struct_like (
639709 compound_object .compoundname , StructLikeScopeKind .Type .CLASS
@@ -781,6 +851,8 @@ def build_snapshot(xml_dir: str) -> Snapshot:
781851 pass
782852 elif compound_object .kind == "protocol" :
783853 create_protocol_scope (snapshot , compound_object )
854+ elif compound_object .kind == "interface" :
855+ create_interface_scope (snapshot , compound_object )
784856 else :
785857 print (f"Unknown compound kind: { compound_object .kind } " )
786858
0 commit comments