Lines Matching refs:depth
26 def reflow_lines(s, depth): argument
36 size = MAX_COL - depth * TABSIZE
68 def reflow_c_string(s, depth): argument
69 return '"%s"' % s.replace('\n', '\\n"\n%s"' % (' ' * depth * TABSIZE))
117 def emit(self, s, depth, reflow=True): argument
120 lines = reflow_lines(s, depth)
125 line = (" " * TABSIZE * depth) + line
134 def visitType(self, type, depth=0): argument
135 self.visit(type.value, type.name, depth)
137 def visitSum(self, sum, name, depth): argument
139 self.simple_sum(sum, name, depth)
141 self.sum_with_constructors(sum, name, depth)
143 def simple_sum(self, sum, name, depth): argument
151 self.emit(s, depth)
152 self.emit("", depth)
154 def sum_with_constructors(self, sum, name, depth): argument
157 self.emit(s, depth)
158 self.emit("", depth)
160 def visitProduct(self, product, name, depth): argument
163 self.emit(s, depth)
164 self.emit("", depth)
174 def visitType(self, type, depth=0): argument
175 self.visit(type.value, type.name, depth)
177 def visitSum(self, sum, name, depth): argument
179 self.sum_with_constructors(sum, name, depth)
181 def sum_with_constructors(self, sum, name, depth): argument
182 def emit(s, depth=depth): argument
183 self.emit(s % sys._getframe(1).f_locals, depth)
192 emit("enum _%(name)s_kind kind;", depth + 1)
193 emit("union {", depth + 1)
195 self.visit(t, depth + 2)
196 emit("} v;", depth + 1)
201 emit("%s %s;" % (type, field.name), depth + 1);
205 def visitConstructor(self, cons, depth): argument
207 self.emit("struct {", depth)
209 self.visit(f, depth + 1)
210 self.emit("} %s;" % cons.name, depth)
211 self.emit("", depth)
213 def visitField(self, field, depth): argument
220 self.emit("asdl_int_seq *%(name)s;" % locals(), depth)
222 self.emit("asdl_seq *%(name)s;" % locals(), depth)
224 self.emit("%(ctype)s %(name)s;" % locals(), depth)
226 def visitProduct(self, product, name, depth): argument
227 self.emit("struct _%(name)s {" % locals(), depth)
229 self.visit(f, depth + 1)
234 self.emit("%s %s;" % (type, field.name), depth + 1);
235 self.emit("};", depth)
236 self.emit("", depth)
315 def emit(s, depth=0, reflow=True): argument
316 self.emit(s, depth, reflow)
349 def emit(s, depth=0, reflow=True): argument
350 self.emit(s, depth, reflow)
358 def emit(s, depth=0, reflow=True): argument
359 self.emit(s, depth, reflow)
449 self.visitField(a, name, sum=sum, depth=1)
458 self.visitFieldDeclaration(f, t.name, sum=sum, depth=2)
461 self.visitField(f, t.name, sum=sum, depth=2)
486 self.visitFieldDeclaration(f, name, prod=prod, depth=1)
488 self.visitFieldDeclaration(a, name, prod=prod, depth=1)
491 self.visitField(f, name, prod=prod, depth=1)
493 self.visitField(a, name, prod=prod, depth=1)
504 def visitFieldDeclaration(self, field, name, sum=None, prod=None, depth=0): argument
508 self.emit("asdl_int_seq* %s;" % field.name, depth)
510 self.emit("asdl_seq* %s;" % field.name, depth)
513 self.emit("%s %s;" % (ctype, field.name), depth)
526 def visitField(self, field, name, sum=None, prod=None, depth=0): argument
529 self.emit(line % field.name, depth)
530 self.emit("return 1;", depth+1)
531 self.emit("}", depth)
533 self.emit("if (tmp == NULL) {", depth)
536 self.emit(format % message, depth+1, reflow=False)
537 self.emit("return 1;", depth+1)
539 self.emit("if (tmp == NULL || tmp == Py_None) {", depth)
540 self.emit("Py_CLEAR(tmp);", depth+1)
542 self.emit("%s = 0;" % field.name, depth+1)
544 self.emit("%s = NULL;" % field.name, depth+1)
547 self.emit("}", depth)
548 self.emit("else {", depth)
550 self.emit("int res;", depth+1)
552 self.emit("Py_ssize_t len;", depth+1)
553 self.emit("Py_ssize_t i;", depth+1)
554 self.emit("if (!PyList_Check(tmp)) {", depth+1)
558 depth+2, reflow=False)
559 self.emit("goto failed;", depth+2)
560 self.emit("}", depth+1)
561 self.emit("len = PyList_GET_SIZE(tmp);", depth+1)
563 self.emit("%s = _Py_asdl_int_seq_new(len, arena);" % field.name, depth+1)
565 self.emit("%s = _Py_asdl_seq_new(len, arena);" % field.name, depth+1)
566 self.emit("if (%s == NULL) goto failed;" % field.name, depth+1)
567 self.emit("for (i = 0; i < len; i++) {", depth+1)
568 self.emit("%s val;" % ctype, depth+2)
569 self.emit("PyObject *tmp2 = PyList_GET_ITEM(tmp, i);", depth+2)
570 self.emit("Py_INCREF(tmp2);", depth+2)
572 field.type, depth+2, reflow=False)
573 self.emit("Py_DECREF(tmp2);", depth+2)
574 self.emit("if (res != 0) goto failed;", depth+2)
575 self.emit("if (len != PyList_GET_SIZE(tmp)) {", depth+2)
579 depth+3, reflow=False)
580 self.emit("goto failed;", depth+3)
581 self.emit("}", depth+2)
582 self.emit("asdl_seq_SET(%s, i, val);" % field.name, depth+2)
583 self.emit("}", depth+1)
586 (field.type, field.name), depth+1)
587 self.emit("if (res != 0) goto failed;", depth+1)
589 self.emit("Py_CLEAR(tmp);", depth+1)
590 self.emit("}", depth)
1045 def emit_defaults(self, name, fields, depth): argument
1049 (name, field.name), depth)
1050 self.emit("return 0;", depth+1)
1226 def visitField(self, field, name, depth, product): argument
1228 self.emit(s, depth + d)
1233 self.set(field, value, depth)
1239 def emitSeq(self, field, value, depth, emit): argument
1245 self.set("value", field, "asdl_seq_GET(seq, i)", depth + 1)
1251 def set(self, field, value, depth): argument
1257 self.emit("{", depth)
1258 self.emit("Py_ssize_t i, n = asdl_seq_LEN(%s);" % value, depth+1)
1259 self.emit("value = PyList_New(n);", depth+1)
1260 self.emit("if (!value) goto failed;", depth+1)
1261 self.emit("for(i = 0; i < n; i++)", depth+1)
1264 depth+2, reflow=False)
1265 self.emit("}", depth)
1267 … self.emit("value = ast2obj_list(state, %s, ast2obj_%s);" % (value, field.type), depth)
1270 self.emit("value = ast2obj_%s(state, %s);" % (field.type, value), depth, reflow=False)