Generate function prototypes for the .h file
| 342 | |
| 343 | |
| 344 | class PrototypeVisitor(EmitVisitor): |
| 345 | """Generate function prototypes for the .h file""" |
| 346 | |
| 347 | def visitModule(self, mod): |
| 348 | for dfn in mod.dfns: |
| 349 | self.visit(dfn) |
| 350 | |
| 351 | def visitType(self, type): |
| 352 | self.visit(type.value, type.name) |
| 353 | |
| 354 | def visitSum(self, sum, name): |
| 355 | if is_simple(sum): |
| 356 | pass # XXX |
| 357 | else: |
| 358 | for t in sum.types: |
| 359 | self.visit(t, name, sum.attributes) |
| 360 | |
| 361 | def get_args(self, fields): |
| 362 | """Return list of C argument info, one for each field. |
| 363 | |
| 364 | Argument info is 3-tuple of a C type, variable name, and flag |
| 365 | that is true if type can be NULL. |
| 366 | """ |
| 367 | args = [] |
| 368 | unnamed = {} |
| 369 | for f in fields: |
| 370 | if f.name is None: |
| 371 | name = f.type |
| 372 | c = unnamed[name] = unnamed.get(name, 0) + 1 |
| 373 | if c > 1: |
| 374 | name = "name%d" % (c - 1) |
| 375 | else: |
| 376 | name = f.name |
| 377 | # XXX should extend get_c_type() to handle this |
| 378 | if f.seq: |
| 379 | if f.type in self.metadata.simple_sums: |
| 380 | ctype = "asdl_int_seq *" |
| 381 | else: |
| 382 | ctype = f"asdl_{f.type}_seq *" |
| 383 | else: |
| 384 | ctype = get_c_type(f.type) |
| 385 | args.append((ctype, name, f.opt or f.seq)) |
| 386 | return args |
| 387 | |
| 388 | def visitConstructor(self, cons, type, attrs): |
| 389 | args = self.get_args(cons.fields) |
| 390 | attrs = self.get_args(attrs) |
| 391 | ctype = get_c_type(type) |
| 392 | self.emit_function(cons.name, ctype, args, attrs) |
| 393 | |
| 394 | def emit_function(self, name, ctype, args, attrs, union=True): |
| 395 | args = args + attrs |
| 396 | if args: |
| 397 | argstr = ", ".join(["%s %s" % (atype, aname) |
| 398 | for atype, aname, opt in args]) |
| 399 | argstr += ", PyArena *arena" |
| 400 | else: |
| 401 | argstr = "PyArena *arena" |
no outgoing calls
no test coverage detected
searching dependent graphs…