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

Method complexSum

Parser/asdl_c.py:550–581  ·  view source on GitHub ↗
(self, sum, name)

Source from the content-addressed store, hash-verified

548 return ", ".join(fields + ["arena"])
549
550 def complexSum(self, sum, name):
551 self.funcHeader(name)
552 self.emit("PyObject *tmp = NULL;", 1)
553 self.emit("PyObject *tp;", 1)
554 for a in sum.attributes:
555 self.visitAttributeDeclaration(a, name, sum=sum)
556 self.emit("", 0)
557 # XXX: should we only do this for 'expr'?
558 self.emit("if (obj == Py_None) {", 1)
559 self.emit("*out = NULL;", 2)
560 self.emit("return 0;", 2)
561 self.emit("}", 1)
562 for a in sum.attributes:
563 self.visitField(a, name, sum=sum, depth=1)
564 for t in sum.types:
565 self.emit("tp = state->%s_type;" % (t.name,), 1)
566 self.emit("isinstance = PyObject_IsInstance(obj, tp);", 1)
567 self.emit("if (isinstance == -1) {", 1)
568 self.emit("return -1;", 2)
569 self.emit("}", 1)
570 self.emit("if (isinstance) {", 1)
571 for f in t.fields:
572 self.visitFieldDeclaration(f, t.name, sum=sum, depth=2)
573 self.emit("", 0)
574 for f in t.fields:
575 self.visitField(f, t.name, sum=sum, depth=2)
576 args = [f.name for f in t.fields] + [a.name for a in sum.attributes]
577 self.emit("*out = %s(%s);" % (ast_func_name(t.name), self.buildArgs(args)), 2)
578 self.emit("if (*out == NULL) goto failed;", 2)
579 self.emit("return 0;", 2)
580 self.emit("}", 1)
581 self.sumTrailer(name, True)
582
583 def visitAttributeDeclaration(self, a, name, sum=sum):
584 ctype = get_c_type(a.type)

Callers 1

visitSumMethod · 0.95

Calls 8

funcHeaderMethod · 0.95
visitFieldMethod · 0.95
visitFieldDeclarationMethod · 0.95
buildArgsMethod · 0.95
sumTrailerMethod · 0.95
ast_func_nameFunction · 0.85
emitMethod · 0.45

Tested by

no test coverage detected