fix: preserve attributed Objective-C enum members

Allow clean enumerator attributes while keeping unsupported preprocessor bodies fail-closed.

AI-Assistance: OpenAI Codex
(cherry picked from commit 0f59982d5e)
This commit is contained in:
Alex Tumanov authored and safishamsi committed 2026-10-13 11:14:16 +01:00
1 parent 810a02ef28
commit 62094a7626
2 files changed
+19 -1

No files matched your search

+1 -1
View File
@@ -378,7 +378,7 @@ def extract_objc(path: Path) -> dict:
continue
# Conditional members need preprocessor handling. Do not emit a
# partial enum when a clean body contains unsupported child nodes.
if any(child.type not in {"{", "}", ",", "comment", "enumerator"}
if any(child.type not in {"{", "}", ",", "comment", "enumerator", "attribute_specifier"}
for child in body.children):
continue
+18
View File
@@ -232,3 +232,21 @@ def test_objc_macro_enum_unsupported_parts_do_not_emit_partial_enums(tmp_path, d
result = extract([source], cache_root=tmp_path)
assert {n["label"] for n in result["nodes"]}.isdisjoint({"Broken", "Bad", "Other"})
assert _edge_labels(result, "case_of") == {("Good", "Kept")}
@pytest.mark.parametrize("macro", ["NS_ENUM", "NS_OPTIONS"])
def test_objc_macro_enum_preserves_members_with_attributes(tmp_path, macro):
source = tmp_path / "Attributes.h"
source.write_text(
"#import <Foundation/Foundation.h>\n"
f"typedef {macro}(NSInteger, Kind) {{\n"
" First __attribute__((deprecated)),\n"
" Second,\n"
"};\n",
encoding="utf-8",
)
result = extract([source], cache_root=tmp_path)
assert _edge_labels(result, "case_of") == {("Kind", "First"), ("Kind", "Second")}
nodes = {n["label"]: n for n in result["nodes"]}
assert nodes["First"]["source_location"] == "L3"
assert nodes["Second"]["source_location"] == "L4"