-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyze_types.py
More file actions
50 lines (43 loc) · 1.7 KB
/
Copy pathanalyze_types.py
File metadata and controls
50 lines (43 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import json
with open("output/LuaSF/sfml_api.json", "r", encoding="utf-8") as f:
data = json.load(f)
results = []
def walk_decl(decl, depth=0):
"""Recursively walk declarations looking for CLASS_DECL and STRUCT_DECL."""
kind = decl.get("kind")
if kind in ("CLASS_DECL", "STRUCT_DECL"):
children = decl.get("children", [])
field_names = []
has_constructor = False
for child in children:
ckind = child.get("kind")
if ckind == "FIELD_DECL":
field_names.append(child.get("name"))
elif ckind == "CONSTRUCTOR":
has_constructor = True
if field_names and not has_constructor:
base_classes = decl.get("base_classes", [])
results.append({
"kind": kind,
"qualified_name": decl.get("qualified_name"),
"field_names": field_names,
"has_base_classes": len(base_classes) > 0,
"base_class_names": [b.get("name") for b in base_classes]
})
# Recurse into children
for child in decl.get("children", []):
walk_decl(child, depth + 1)
# The top level has a "files" array
for file_entry in data.get("files", []):
for decl in file_entry.get("declarations", []):
walk_decl(decl)
# Print results
print(f"Found {len(results)} types with FIELD_DECL(s) but no CONSTRUCTOR:\n")
for r in sorted(results, key=lambda x: x["qualified_name"]):
suffix = ""
if r["has_base_classes"]:
suffix = f" [bases: {', '.join(r['base_class_names'])}]"
print(f" {r['kind']:12s} {r['qualified_name']}{suffix}")
for fn in r["field_names"]:
print(f" - {fn}")
print()