id
int64
1
6.07M
name
stringlengths
1
295
code
stringlengths
12
426k
language
stringclasses
1 value
source_file
stringlengths
5
202
start_line
int64
1
158k
end_line
int64
1
158k
repo
dict
10,501
visitSum
def visitSum(self, sum, name, depth): if not is_simple(sum): self.sum_with_constructors(sum, name, depth)
python
Parser/asdl_c.py
277
279
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,502
sum_with_constructors
def sum_with_constructors(self, sum, name, depth): def emit(s, depth=depth): self.emit(s % sys._getframe(1).f_locals, depth) enum = [] for i in range(len(sum.types)): type = sum.types[i] enum.append("%s_kind=%d" % (type.name, i + 1)) emit("enum _%(nam...
python
Parser/asdl_c.py
281
303
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,503
emit
def emit(s, depth=depth): self.emit(s % sys._getframe(1).f_locals, depth)
python
Parser/asdl_c.py
282
283
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,504
visitConstructor
def visitConstructor(self, cons, depth): if cons.fields: self.emit("struct {", depth) for f in cons.fields: self.visit(f, depth + 1) self.emit("} %s;" % cons.name, depth) self.emit("", depth)
python
Parser/asdl_c.py
305
311
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,505
visitField
def visitField(self, field, depth): # XXX need to lookup field.type, because it might be something # like a builtin... ctype = get_c_type(field.type) name = field.name if field.seq: if field.type in self.metadata.simple_sums: self.emit("asdl_int_seq *%...
python
Parser/asdl_c.py
313
325
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,506
visitProduct
def visitProduct(self, product, name, depth): self.emit("struct _%(name)s {" % locals(), depth) for f in product.fields: self.visit(f, depth + 1) for field in product.attributes: # rudimentary attribute handling type = str(field.type) assert type i...
python
Parser/asdl_c.py
327
337
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,507
ast_func_name
def ast_func_name(name): return f"_PyAST_{name}"
python
Parser/asdl_c.py
340
341
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,508
visitModule
def visitModule(self, mod): for dfn in mod.dfns: self.visit(dfn)
python
Parser/asdl_c.py
347
349
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,509
visitType
def visitType(self, type): self.visit(type.value, type.name)
python
Parser/asdl_c.py
351
352
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,510
visitSum
def visitSum(self, sum, name): if is_simple(sum): pass # XXX else: for t in sum.types: self.visit(t, name, sum.attributes)
python
Parser/asdl_c.py
354
359
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,511
get_args
def get_args(self, fields): """Return list of C argument info, one for each field. Argument info is 3-tuple of a C type, variable name, and flag that is true if type can be NULL. """ args = [] unnamed = {} for f in fields: if f.name is None: ...
python
Parser/asdl_c.py
361
386
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,512
visitConstructor
def visitConstructor(self, cons, type, attrs): args = self.get_args(cons.fields) attrs = self.get_args(attrs) ctype = get_c_type(type) self.emit_function(cons.name, ctype, args, attrs)
python
Parser/asdl_c.py
388
392
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,513
emit_function
def emit_function(self, name, ctype, args, attrs, union=True): args = args + attrs if args: argstr = ", ".join(["%s %s" % (atype, aname) for atype, aname, opt in args]) argstr += ", PyArena *arena" else: argstr = "PyArena *arena...
python
Parser/asdl_c.py
394
402
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,514
visitProduct
def visitProduct(self, prod, name): self.emit_function(name, get_c_type(name), self.get_args(prod.fields), self.get_args(prod.attributes), union=False)
python
Parser/asdl_c.py
404
408
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,515
emit_function
def emit_function(self, name, ctype, args, attrs, union=True): def emit(s, depth=0, reflow=True): self.emit(s, depth, reflow) argstr = ", ".join(["%s %s" % (atype, aname) for atype, aname, opt in args + attrs]) if argstr: argstr += ", PyArena *...
python
Parser/asdl_c.py
414
446
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,516
emit
def emit(s, depth=0, reflow=True): self.emit(s, depth, reflow)
python
Parser/asdl_c.py
415
416
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,517
emit_body_union
def emit_body_union(self, name, args, attrs): def emit(s, depth=0, reflow=True): self.emit(s, depth, reflow) emit("p->kind = %s_kind;" % name, 1) for argtype, argname, opt in args: emit("p->v.%s.%s = %s;" % (name, argname, argname), 1) for argtype, argname, opt in...
python
Parser/asdl_c.py
448
455
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,518
emit
def emit(s, depth=0, reflow=True): self.emit(s, depth, reflow)
python
Parser/asdl_c.py
449
450
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,519
emit_body_struct
def emit_body_struct(self, name, args, attrs): def emit(s, depth=0, reflow=True): self.emit(s, depth, reflow) for argtype, argname, opt in args: emit("p->%s = %s;" % (argname, argname), 1) for argtype, argname, opt in attrs: emit("p->%s = %s;" % (argname, argn...
python
Parser/asdl_c.py
457
463
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,520
emit
def emit(s, depth=0, reflow=True): self.emit(s, depth, reflow)
python
Parser/asdl_c.py
458
459
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,521
visitModule
def visitModule(self, mod): for dfn in mod.dfns: self.visit(dfn)
python
Parser/asdl_c.py
468
470
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,522
visitType
def visitType(self, type): self.visit(type.value, type.name)
python
Parser/asdl_c.py
472
473
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,523
visitSum
def visitSum(self, sum, name): pass
python
Parser/asdl_c.py
475
476
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,524
visitProduct
def visitProduct(self, sum, name): pass
python
Parser/asdl_c.py
478
479
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,525
visitConstructor
def visitConstructor(self, cons, name): pass
python
Parser/asdl_c.py
481
482
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,526
visitField
def visitField(self, sum): pass
python
Parser/asdl_c.py
484
485
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,527
visitProduct
def visitProduct(self, prod, name): code = "static int obj2ast_%s(struct ast_state *state, PyObject* obj, %s* out, PyArena* arena);" self.emit(code % (name, get_c_type(name)), 0)
python
Parser/asdl_c.py
489
491
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,528
recursive_call
def recursive_call(self, node, level): self.emit('if (_Py_EnterRecursiveCall(" while traversing \'%s\' node")) {' % node, level, reflow=False) self.emit('goto failed;', level + 1) self.emit('}', level) yield self.emit('_Py_LeaveRecursiveCall();', level)
python
Parser/asdl_c.py
504
509
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,529
funcHeader
def funcHeader(self, name): ctype = get_c_type(name) self.emit("int", 0) self.emit("obj2ast_%s(struct ast_state *state, PyObject* obj, %s* out, PyArena* arena)" % (name, ctype), 0) self.emit("{", 0) self.emit("int isinstance;", 1) self.emit("", 0)
python
Parser/asdl_c.py
511
517
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,530
sumTrailer
def sumTrailer(self, name, add_label=False): self.emit("", 0) # there's really nothing more we can do if this fails ... error = "expected some sort of %s, but got %%R" % name format = "PyErr_Format(PyExc_TypeError, \"%s\", obj);" self.emit(format % error, 1, reflow=False) ...
python
Parser/asdl_c.py
519
530
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,531
simpleSum
def simpleSum(self, sum, name): self.funcHeader(name) for t in sum.types: line = ("isinstance = PyObject_IsInstance(obj, " "state->%s_type);") self.emit(line % (t.name,), 1) self.emit("if (isinstance == -1) {", 1) self.emit("return -1;"...
python
Parser/asdl_c.py
532
545
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,532
buildArgs
def buildArgs(self, fields): return ", ".join(fields + ["arena"])
python
Parser/asdl_c.py
547
548
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,533
complexSum
def complexSum(self, sum, name): self.funcHeader(name) self.emit("PyObject *tmp = NULL;", 1) self.emit("PyObject *tp;", 1) for a in sum.attributes: self.visitAttributeDeclaration(a, name, sum=sum) self.emit("", 0) # XXX: should we only do this for 'expr'? ...
python
Parser/asdl_c.py
550
581
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,534
visitAttributeDeclaration
def visitAttributeDeclaration(self, a, name, sum=sum): ctype = get_c_type(a.type) self.emit("%s %s;" % (ctype, a.name), 1)
python
Parser/asdl_c.py
583
585
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,535
visitSum
def visitSum(self, sum, name): if is_simple(sum): self.simpleSum(sum, name) else: self.complexSum(sum, name)
python
Parser/asdl_c.py
587
591
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,536
visitProduct
def visitProduct(self, prod, name): ctype = get_c_type(name) self.emit("int", 0) self.emit("obj2ast_%s(struct ast_state *state, PyObject* obj, %s* out, PyArena* arena)" % (name, ctype), 0) self.emit("{", 0) self.emit("PyObject* tmp = NULL;", 1) for f in prod.fields: ...
python
Parser/asdl_c.py
593
617
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,537
visitFieldDeclaration
def visitFieldDeclaration(self, field, name, sum=None, prod=None, depth=0): ctype = get_c_type(field.type) if field.seq: if self.isSimpleType(field): self.emit("asdl_int_seq* %s;" % field.name, depth) else: _type = field.type self.e...
python
Parser/asdl_c.py
619
629
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,538
isNumeric
def isNumeric(self, field): return get_c_type(field.type) in ("int", "bool")
python
Parser/asdl_c.py
631
632
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,539
isSimpleType
def isSimpleType(self, field): return field.type in self.metadata.simple_sums or self.isNumeric(field)
python
Parser/asdl_c.py
634
635
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,540
visitField
def visitField(self, field, name, sum=None, prod=None, depth=0): ctype = get_c_type(field.type) line = "if (PyObject_GetOptionalAttr(obj, state->%s, &tmp) < 0) {" self.emit(line % field.name, depth) self.emit("return -1;", depth+1) self.emit("}", depth) if field.seq: ...
python
Parser/asdl_c.py
637
717
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,541
visitModule
def visitModule(self, mod): for dfn in mod.dfns: self.visit(dfn)
python
Parser/asdl_c.py
721
723
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,542
visitType
def visitType(self, type): self.visit(type.value, type.name)
python
Parser/asdl_c.py
725
726
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,543
visitProduct
def visitProduct(self, prod, name): self.emit_sequence_constructor(name, get_c_type(name))
python
Parser/asdl_c.py
728
729
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,544
visitSum
def visitSum(self, sum, name): if not is_simple(sum): self.emit_sequence_constructor(name, get_c_type(name))
python
Parser/asdl_c.py
731
733
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,545
emit_sequence_constructor
def emit_sequence_constructor(self, name, type): self.emit(f"GENERATE_ASDL_SEQ_CONSTRUCTOR({name}, {type})", depth=0)
python
Parser/asdl_c.py
735
736
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,546
visitProduct
def visitProduct(self, prod, name): self.emit("static PyObject* ast2obj_%s(struct ast_state *state, struct validator *vstate, void*);" % name, 0) if prod.attributes: self.emit("static const char * const %s_attributes[] = {" % name, 0) for a in prod.attributes: sel...
python
Parser/asdl_c.py
740
751
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,547
visitSum
def visitSum(self, sum, name): if sum.attributes: self.emit("static const char * const %s_attributes[] = {" % name, 0) for a in sum.attributes: self.emit('"%s",' % a.name, 1) self.emit("};", 0) ptype = "void*" if is_simple(sum): pty...
python
Parser/asdl_c.py
753
764
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,548
visitConstructor
def visitConstructor(self, cons, name): if cons.fields: self.emit("static const char * const %s_fields[]={" % cons.name, 0) for t in cons.fields: self.emit('"%s",' % t.name, 1) self.emit("};",0)
python
Parser/asdl_c.py
766
771
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,549
visitModule
def visitModule(self, mod): self.file.write(textwrap.dedent(''' static int add_ast_annotations(struct ast_state *state) { bool cond; ''')) for dfn in mod.dfns: self.visit(dfn) self.file.write(textwrap.dedent(''' ...
python
Parser/asdl_c.py
775
787
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,550
visitProduct
def visitProduct(self, prod, name): self.emit_annotations(name, prod.fields)
python
Parser/asdl_c.py
789
790
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,551
visitSum
def visitSum(self, sum, name): for t in sum.types: self.visitConstructor(t, name)
python
Parser/asdl_c.py
792
794
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,552
visitConstructor
def visitConstructor(self, cons, name): self.emit_annotations(cons.name, cons.fields)
python
Parser/asdl_c.py
796
797
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,553
emit_annotations
def emit_annotations(self, name, fields): self.emit(f"PyObject *{name}_annotations = PyDict_New();", 1) self.emit(f"if (!{name}_annotations) return 0;", 1) for field in fields: self.emit("{", 1) if field.type in builtin_type_to_c_type: self.emit(f"PyObject...
python
Parser/asdl_c.py
799
826
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,554
emit_annotations_error
def emit_annotations_error(self, name, depth): self.emit("if (!cond) {", depth) self.emit(f"Py_DECREF({name}_annotations);", depth + 1) self.emit("return 0;", depth + 1) self.emit("}", depth)
python
Parser/asdl_c.py
828
832
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,555
visitModule
def visitModule(self, mod): self.emit(""" typedef struct { PyObject_HEAD PyObject *dict; } AST_object; static void ast_dealloc(AST_object *self) { /* bpo-31095: UnTrack is needed before calling any callbacks */ PyTypeObject *tp = Py_TYPE(self); PyObject_GC_UnTrack(self); Py_CLEAR(self-...
python
Parser/asdl_c.py
837
1,357
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,556
visitProduct
def visitProduct(self, prod, name): if prod.fields: fields = name+"_fields" else: fields = "NULL" self.emit('state->%s_type = make_type(state, "%s", state->AST_type, %s, %d,' % (name, name, fields, len(prod.fields)), 1) self.emit('%s);' % r...
python
Parser/asdl_c.py
1,359
1,374
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,557
visitSum
def visitSum(self, sum, name): self.emit('state->%s_type = make_type(state, "%s", state->AST_type, NULL, 0,' % (name, name), 1) self.emit('%s);' % reflow_c_string(asdl_of(name, sum), 2), 2, reflow=False) self.emit("if (!state->%s_type) return -1;" % name, 1) if sum.attr...
python
Parser/asdl_c.py
1,376
1,389
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,558
visitConstructor
def visitConstructor(self, cons, name, simple): if cons.fields: fields = cons.name+"_fields" else: fields = "NULL" self.emit('state->%s_type = make_type(state, "%s", state->%s_type, %s, %d,' % (cons.name, cons.name, name, fields, len(cons.field...
python
Parser/asdl_c.py
1,391
1,405
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,559
emit_defaults
def emit_defaults(self, name, fields, depth): for field in fields: if field.opt: self.emit('if (PyObject_SetAttr(state->%s_type, state->%s, Py_None) == -1)' % (name, field.name), depth) self.emit("return -1;", depth+1)
python
Parser/asdl_c.py
1,407
1,412
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,560
visitModule
def visitModule(self, mod): self.emit("static int", 0) self.emit("astmodule_exec(PyObject *m)", 0) self.emit("{", 0) self.emit('struct ast_state *state = get_ast_state();', 1) self.emit('if (state == NULL) {', 1) self.emit('return -1;', 2) self.emit('}', 1) ...
python
Parser/asdl_c.py
1,417
1,466
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,561
visitProduct
def visitProduct(self, prod, name): self.addObj(name)
python
Parser/asdl_c.py
1,468
1,469
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,562
visitSum
def visitSum(self, sum, name): self.addObj(name) for t in sum.types: self.visitConstructor(t, name)
python
Parser/asdl_c.py
1,471
1,474
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,563
visitConstructor
def visitConstructor(self, cons, name): self.addObj(cons.name)
python
Parser/asdl_c.py
1,476
1,477
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,564
addObj
def addObj(self, name): self.emit("if (PyModule_AddObjectRef(m, \"%s\", " "state->%s_type) < 0) {" % (name, name), 1) self.emit("return -1;", 2) self.emit('}', 1)
python
Parser/asdl_c.py
1,479
1,483
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,565
visit
def visit(self, object): self.emit(self.CODE, 0, reflow=False)
python
Parser/asdl_c.py
1,489
1,490
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,566
func_begin
def func_begin(self, name): ctype = get_c_type(name) self.emit("PyObject*", 0) self.emit("ast2obj_%s(struct ast_state *state, struct validator *vstate, void* _o)" % (name), 0) self.emit("{", 0) self.emit("%s o = (%s)_o;" % (ctype, ctype), 1) self.emit("PyObject *result = ...
python
Parser/asdl_c.py
1,495
1,510
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,567
func_end
def func_end(self): self.emit("vstate->recursion_depth--;", 1) self.emit("return result;", 1) self.emit("failed:", 0) self.emit("vstate->recursion_depth--;", 1) self.emit("Py_XDECREF(value);", 1) self.emit("Py_XDECREF(result);", 1) self.emit("return NULL;", 1) ...
python
Parser/asdl_c.py
1,512
1,521
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,568
visitSum
def visitSum(self, sum, name): if is_simple(sum): self.simpleSum(sum, name) return self.func_begin(name) self.emit("switch (o->kind) {", 1) for i in range(len(sum.types)): t = sum.types[i] self.visitConstructor(t, i + 1, name) self....
python
Parser/asdl_c.py
1,523
1,539
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,569
simpleSum
def simpleSum(self, sum, name): self.emit("PyObject* ast2obj_%s(struct ast_state *state, struct validator *vstate, %s_ty o)" % (name, name), 0) self.emit("{", 0) self.emit("switch(o) {", 1) for t in sum.types: self.emit("case %s:" % t.name, 2) self.emit("return Py...
python
Parser/asdl_c.py
1,541
1,550
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,570
visitProduct
def visitProduct(self, prod, name): self.func_begin(name) self.emit("tp = (PyTypeObject *)state->%s_type;" % name, 1) self.emit("result = PyType_GenericNew(tp, NULL, NULL);", 1); self.emit("if (!result) return NULL;", 1) for field in prod.fields: self.visitField(field...
python
Parser/asdl_c.py
1,552
1,565
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,571
visitConstructor
def visitConstructor(self, cons, enum, name): self.emit("case %s_kind:" % cons.name, 1) self.emit("tp = (PyTypeObject *)state->%s_type;" % cons.name, 2) self.emit("result = PyType_GenericNew(tp, NULL, NULL);", 2); self.emit("if (!result) goto failed;", 2) for f in cons.fields: ...
python
Parser/asdl_c.py
1,567
1,574
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,572
visitField
def visitField(self, field, name, depth, product): def emit(s, d): self.emit(s, depth + d) if product: value = "o->%s" % field.name else: value = "o->v.%s.%s" % (name, field.name) self.set(field, value, depth) emit("if (!value) goto failed;", 0...
python
Parser/asdl_c.py
1,576
1,587
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,573
emit
def emit(s, d): self.emit(s, depth + d)
python
Parser/asdl_c.py
1,577
1,578
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,574
set
def set(self, field, value, depth): if field.seq: if field.type in self.metadata.simple_sums: # While the sequence elements are stored as void*, # simple sums expects an enum self.emit("{", depth) self.emit("Py_ssize_t i, n = asdl_seq_L...
python
Parser/asdl_c.py
1,589
1,612
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,575
__init__
def __init__(self, *visitors, metadata = None): self.visitors = visitors self.metadata = metadata
python
Parser/asdl_c.py
1,698
1,700
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,576
visit
def visit(self, object): for v in self.visitors: v.metadata = self.metadata v.visit(object) v.emit("", 0)
python
Parser/asdl_c.py
1,702
1,706
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,577
generate_ast_state
def generate_ast_state(module_state, f): f.write('struct ast_state {\n') f.write(' _PyOnceFlag once;\n') f.write(' int finalized;\n') for s in module_state: f.write(' PyObject *' + s + ';\n') f.write('};')
python
Parser/asdl_c.py
1,709
1,715
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,578
generate_ast_fini
def generate_ast_fini(module_state, f): f.write(textwrap.dedent(""" void _PyAST_Fini(PyInterpreterState *interp) { struct ast_state *state = &interp->ast; """)) for s in module_state: f.write(" Py_CLEAR(state->" + s + ');\n') f.write(textwrap.dedent(""...
python
Parser/asdl_c.py
1,718
1,734
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,579
generate_module_def
def generate_module_def(mod, metadata, f, internal_h): # Gather all the data needed for ModuleSpec state_strings = { "ast", "_fields", "__match_args__", "__doc__", "__dict__", "__module__", "_attributes", *metadata.identifiers } module_sta...
python
Parser/asdl_c.py
1,737
1,807
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,580
write_header
def write_header(mod, metadata, f): f.write(textwrap.dedent(""" #ifndef Py_INTERNAL_AST_H #define Py_INTERNAL_AST_H #ifdef __cplusplus extern "C" { #endif #ifndef Py_BUILD_CORE # error "this header requires Py_BUILD_CORE define" #endif #incl...
python
Parser/asdl_c.py
1,809
1,857
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,581
write_internal_h_header
def write_internal_h_header(mod, f): print(textwrap.dedent(""" #ifndef Py_INTERNAL_AST_STATE_H #define Py_INTERNAL_AST_STATE_H #include "pycore_lock.h" // _PyOnceFlag #ifdef __cplusplus extern "C" { #endif #ifndef Py_BUILD_CORE # error "this hea...
python
Parser/asdl_c.py
1,860
1,874
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,582
write_internal_h_footer
def write_internal_h_footer(mod, f): print(textwrap.dedent(""" #ifdef __cplusplus } #endif #endif /* !Py_INTERNAL_AST_STATE_H */ """), file=f)
python
Parser/asdl_c.py
1,877
1,884
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,583
write_source
def write_source(mod, metadata, f, internal_h_file): generate_module_def(mod, metadata, f, internal_h_file) v = ChainOfVisitors( SequenceConstructorVisitor(f), PyTypesDeclareVisitor(f), AnnotationsVisitor(f), PyTypesVisitor(f), Obj2ModPrototypeVisitor(f), Functio...
python
Parser/asdl_c.py
1,886
1,902
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,584
main
def main(input_filename, c_filename, h_filename, internal_h_filename, dump_module=False): auto_gen_msg = AUTOGEN_MESSAGE.format("/".join(Path(__file__).parts[-2:])) mod = asdl.parse(input_filename) if dump_module: print('Parsed Module:') print(mod) if not asdl.check(mod): sys.exi...
python
Parser/asdl_c.py
1,904
1,929
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,585
isclean
def isclean(name): if name in ('CVS', '.cvsignore', '.svn'): return 0 if name.lower() == '.ds_store': return 0 if name.endswith('~'): return 0 if name.endswith('.BAK'): return 0 if name.endswith('.pyc'): return 0 if name.endswith('.pyo'): return 0 if name.endswith('.orig'): return 0 ...
python
Mac/Extras.install.py
11
20
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,586
copycleandir
def copycleandir(src, dst): for cursrc, dirs, files in os.walk(src): assert cursrc.startswith(src) curdst = dst + cursrc[len(src):] if verbose: print("mkdir", curdst) if not debug: if not os.path.exists(curdst): os.makedirs(curdst) for ...
python
Mac/Extras.install.py
22
44
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,587
main
def main(): if len(sys.argv) != 3: sys.stderr.write("Usage: %s srcdir dstdir\n" % sys.argv[0]) sys.exit(1) copycleandir(sys.argv[1], sys.argv[2])
python
Mac/Extras.install.py
46
50
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,588
nsstr
def nsstr(value): return NSString.alloc().initWithString_(value)
python
Mac/Tools/plistlib_generate_testdata.py
20
21
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,589
main
def main(): pl = OrderedDict() # Note: pl is an OrderedDict to control the order # of keys, and hence have some control on the structure # of the output file. # New keys should be added in alphabetical order. seconds = datetime.datetime(2004, 10, 26, 10, 33, 33, tzinfo=datetime.timezone(dateti...
python
Mac/Tools/plistlib_generate_testdata.py
24
96
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,590
_encode_base64
def _encode_base64(s, maxlinelength=60): maxbinsize = (maxlinelength//4)*3 pieces = [] for i in range(0, len(s), maxbinsize): chunk = s[i : i + maxbinsize] pieces.append(binascii.b2a_base64(chunk)) return b' '.join(pieces)
python
Mac/Tools/plistlib_generate_testdata.py
98
104
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,591
writePlist
def writePlist(path, plist): with open(plist, 'wb') as fp: dump(path, fp)
python
Mac/BuildScript/build-installer.py
62
64
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,592
shellQuote
def shellQuote(value): """ Return the string value in a form that can safely be inserted into a shell command. """ return "'%s'"%(value.replace("'", "'\"'\"'"))
python
Mac/BuildScript/build-installer.py
66
71
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,593
grepValue
def grepValue(fn, variable): """ Return the unquoted value of a variable from a file.. QUOTED_VALUE='quotes' -> str('quotes') UNQUOTED_VALUE=noquotes -> str('noquotes') """ variable = variable + '=' for ln in open(fn, 'r'): if ln.startswith(variable): value = ln[len(v...
python
Mac/BuildScript/build-installer.py
73
84
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,594
getVersion
def getVersion(): global _cache_getVersion if _cache_getVersion is None: _cache_getVersion = grepValue( os.path.join(SRCDIR, 'configure'), 'PACKAGE_VERSION') return _cache_getVersion
python
Mac/BuildScript/build-installer.py
88
93
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,595
getVersionMajorMinor
def getVersionMajorMinor(): return tuple([int(n) for n in getVersion().split('.', 2)])
python
Mac/BuildScript/build-installer.py
95
96
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,596
getFullVersion
def getFullVersion(): global _cache_getFullVersion if _cache_getFullVersion is not None: return _cache_getFullVersion fn = os.path.join(SRCDIR, 'Include', 'patchlevel.h') for ln in open(fn): if 'PY_VERSION' in ln: _cache_getFullVersion = ln.split()[-1][1:-1] retur...
python
Mac/BuildScript/build-installer.py
100
109
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,597
getDeptargetTuple
def getDeptargetTuple(): return tuple([int(n) for n in DEPTARGET.split('.')[0:2]])
python
Mac/BuildScript/build-installer.py
157
158
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,598
getBuildTuple
def getBuildTuple(): return tuple([int(n) for n in platform.mac_ver()[0].split('.')[0:2]])
python
Mac/BuildScript/build-installer.py
160
161
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,599
getTargetCompilers
def getTargetCompilers(): target_cc_map = { '10.4': ('gcc-4.0', 'g++-4.0'), '10.5': ('gcc', 'g++'), '10.6': ('gcc', 'g++'), '10.7': ('gcc', 'g++'), '10.8': ('gcc', 'g++'), } return target_cc_map.get(DEPTARGET, ('clang', 'clang++') )
python
Mac/BuildScript/build-installer.py
163
171
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,600
internalTk
def internalTk(): return getDeptargetTuple() >= (10, 6)
python
Mac/BuildScript/build-installer.py
201
202
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }