MCPcopy Index your code
hub / github.com/python/cpython / TypeDefVisitor

Class TypeDefVisitor

Parser/asdl_c.py:203–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201
202
203class TypeDefVisitor(EmitVisitor):
204 def visitModule(self, mod):
205 for dfn in mod.dfns:
206 self.visit(dfn)
207
208 def visitType(self, type, depth=0):
209 self.visit(type.value, type.name, depth)
210
211 def visitSum(self, sum, name, depth):
212 if is_simple(sum):
213 self.simple_sum(sum, name, depth)
214 else:
215 self.sum_with_constructors(sum, name, depth)
216
217 def simple_sum(self, sum, name, depth):
218 enum = []
219 for i in range(len(sum.types)):
220 type = sum.types[i]
221 enum.append("%s=%d" % (type.name, i + 1))
222 enums = ", ".join(enum)
223 ctype = get_c_type(name)
224 s = "typedef enum _%s { %s } %s;" % (name, enums, ctype)
225 self.emit(s, depth)
226 self.emit("", depth)
227
228 def sum_with_constructors(self, sum, name, depth):
229 ctype = get_c_type(name)
230 s = "typedef struct _%(name)s *%(ctype)s;" % locals()
231 self.emit(s, depth)
232 self.emit("", depth)
233
234 def visitProduct(self, product, name, depth):
235 ctype = get_c_type(name)
236 s = "typedef struct _%(name)s *%(ctype)s;" % locals()
237 self.emit(s, depth)
238 self.emit("", depth)
239
240class SequenceDefVisitor(EmitVisitor):
241 def visitModule(self, mod):

Callers 1

write_headerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…