-
Notifications
You must be signed in to change notification settings - Fork 648
/
check_reflect.py
executable file
·134 lines (113 loc) · 3.74 KB
/
check_reflect.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python3
import json
import os
import re
import xml.etree.ElementTree as etree
def process_node(path, node):
"""
if node.tag == "TestCase":
if node.attrib.get("result", "UNKNOWN") != "passed":
failset.add(node)
return
if node.tag in ["TestResult", "TestSuite"]:
for child in node:
cpath = path+"/"+child.attrib["name"]
process_node(cpath, child)
return
"""
#print("unknown node", node.tag)
print(node.tag)
return
name2members_doxygen = {}
def process_class_node(node):
result = {"name":"", "vmembers":[]}
for child in node:
if child.tag == "name":
result["name"] = child.text
elif child.tag == "member":
kind = child.attrib.get("kind")
if kind == "variable":
result["vmembers"].append(child[0].text)
name2members_doxygen[result["name"]] = result["vmembers"]
return
tree = etree.parse("doxygen/xml/index.xml")
root = tree.getroot()
for child in root:
if (child.tag == "compound") and (child.attrib.get("kind") in ["struct", "class"]):
process_class_node(child)
s_static_names = set(["space_id", "type_id"])
for k, v in name2members_doxygen.items():
name2members_doxygen[k] = [x for x in v if x not in s_static_names]
#with open("stuff/member_enumerator.out", "r") as f:
# name2members_fc = json.load(f)
# scan for FC_REFLECT( graphene::... in all cpp,hpp files under libraries/ programs/ tests/
re_reflect = re.compile(r"""
FC_REFLECT\s*[(]
\s*(graphene::[a-zA-Z0-9_:]+)
\s*,
((?:\s*[(]\s*[a-zA-Z0-9_]+\s*[)])*)
""", re.VERBOSE)
re_reflect_derived = re.compile(r"""
FC_REFLECT_DERIVED\s*[(]
\s*(graphene::[a-zA-Z0-9_:]+)
\s*,
\s*[(]\s*(graphene::[a-zA-Z0-9_:]+)\s*[)]
\s*,
((?:\s*[(]\s*[a-zA-Z0-9_]+\s*[)])*)
""", re.VERBOSE)
re_bubble_item = re.compile(r"\s*[(]\s*([a-zA-Z0-9_]+)\s*")
def bubble_list(x):
return [re_bubble_item.match(e).group(1) for e in x.split(")")[:-1]]
name2members_re = {}
for root, dirs, files in os.walk("."):
if root == ".":
dirs[:] = ["libraries", "programs", "tests"]
for filename in files:
if not (filename.endswith(".cpp") or filename.endswith(".hpp")):
continue
try:
with open( os.path.join(root, filename), "r" ) as f:
content = f.read()
for m in re_reflect.finditer(content):
cname = m.group(1)
members = bubble_list(m.group(2))
name2members_re[cname] = members
if cname.endswith("_object"):
print("FC_REFLECT on {} should be FC_REFLECT_DERIVED".format(cname))
for m in re_reflect_derived.finditer(content):
cname = m.group(1)
members = bubble_list(m.group(3))
name2members_re[cname] = members
except OSError as e:
pass
def validate_members(name2members_ref, name2members_test):
ok_items = []
ne_items = []
error_items = []
for name in sorted(name2members_ref.keys()):
if name not in name2members_test:
ne_items.append(name)
elif sorted(name2members_ref[name]) != sorted(name2members_test[name]):
error_items.append(name)
print("")
print("error in", name)
print("doxygen:", name2members_ref[name])
print("fc :", name2members_test[name])
else:
ok_items.append(name)
return
"""
print("")
print("ok:")
for item in ok_items:
print(item)
print("")
print("not evaluated:")
for item in ne_items:
print(item)
print("")
print("error:")
for item in error_items:
print(item)
"""
validate_members(name2members_doxygen, name2members_re)