MCPcopy Create free account
hub / github.com/vispy/vispy / parse

Method parse

codegen/headerparser.py:55–111  ·  view source on GitHub ↗

Parse the header file!

(self)

Source from the content-addressed store, hash-verified

53 self.parse()
54
55 def parse(self):
56 """Parse the header file!"""
57 self._parse_constants_and_functions_from_file()
58
59 # Remove invalid defs
60 self._functionDefs = [d for d in self._functionDefs if d.isvalid]
61 self._constantDefs = [d for d in self._constantDefs if d.isvalid]
62
63 # Collect multipe similar functions in groups
64 self._functionDefs.sort(key=lambda x: x.glname)
65 keyDef = None
66 keyDefs = []
67 for funcDef in [f for f in self._functionDefs]:
68 # Check if we need a new keydef
69 if funcDef.extrachars:
70 # Create new keydef or use old one?
71 if keyDef and keyDef.glname == funcDef.keyname:
72 pass # Keep same keydef
73 else:
74 keyDef = FunctionGroup.from_function_def(funcDef)
75 keyDefs.append(keyDef)
76 # Add to group
77 keyDef.group.append(funcDef)
78 # Process function groups
79 for keyDef in keyDefs:
80 if len(keyDef.group) > 1:
81 self._functionDefs.append(keyDef)
82 for d in keyDef.group:
83 self._functionDefs.remove(d)
84
85 # Sort constants and functions
86 self._functionDefs.sort(key=lambda x: x.glname)
87 self._constantDefs.sort(key=lambda x: x.glname)
88
89 # Get dicts
90 for definition in self._functionDefs:
91 self._functions[definition.shortname] = definition
92 for definition in self._constantDefs:
93 self._constants[definition.shortname] = definition
94
95 # Get some stats
96 for funcDef in self._functionDefs:
97 for arg in funcDef.args:
98 self.stat_types.add(arg.ctype)
99
100 # Show stats
101 # TODO: Remove iteration
102 n1 = len([d for d in self._constantDefs])
103 n2 = len([d for d in self._functionDefs])
104 n3 = len([d for d in self._functionDefs if d.group])
105 n4 = sum([len(d.group) for d in self._functionDefs if d.group])
106 print(
107 'Found %i constants and %i unique functions (%i groups contain %i functions)").'
108 % (n1, n2, n3, n4)
109 )
110
111 print("C-types found in args:", self.stat_types)
112

Callers 1

__init__Method · 0.95

Calls 5

from_function_defMethod · 0.80
appendMethod · 0.45
removeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected