Mercurial > cpython-lru_cache-weakref
comparison Python/Python-ast.c @ 74391:e1177b9167ce
make YieldFrom its own distinct from Yield (closes #13780)
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 14 Jan 2012 08:58:23 -0500 |
| parents | 87331661042b |
| children | 3877bf2e3235 |
comparison
equal
deleted
inserted
replaced
| 74390:347f6305bd26 | 74391:e1177b9167ce |
|---|---|
| 229 static char *GeneratorExp_fields[]={ | 229 static char *GeneratorExp_fields[]={ |
| 230 "elt", | 230 "elt", |
| 231 "generators", | 231 "generators", |
| 232 }; | 232 }; |
| 233 static PyTypeObject *Yield_type; | 233 static PyTypeObject *Yield_type; |
| 234 _Py_IDENTIFIER(is_from); | |
| 235 static char *Yield_fields[]={ | 234 static char *Yield_fields[]={ |
| 236 "is_from", | 235 "value", |
| 236 }; | |
| 237 static PyTypeObject *YieldFrom_type; | |
| 238 static char *YieldFrom_fields[]={ | |
| 237 "value", | 239 "value", |
| 238 }; | 240 }; |
| 239 static PyTypeObject *Compare_type; | 241 static PyTypeObject *Compare_type; |
| 240 _Py_IDENTIFIER(ops); | 242 _Py_IDENTIFIER(ops); |
| 241 _Py_IDENTIFIER(comparators); | 243 _Py_IDENTIFIER(comparators); |
| 810 DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); | 812 DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
| 811 if (!DictComp_type) return 0; | 813 if (!DictComp_type) return 0; |
| 812 GeneratorExp_type = make_type("GeneratorExp", expr_type, | 814 GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 813 GeneratorExp_fields, 2); | 815 GeneratorExp_fields, 2); |
| 814 if (!GeneratorExp_type) return 0; | 816 if (!GeneratorExp_type) return 0; |
| 815 Yield_type = make_type("Yield", expr_type, Yield_fields, 2); | 817 Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
| 816 if (!Yield_type) return 0; | 818 if (!Yield_type) return 0; |
| 819 YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); | |
| 820 if (!YieldFrom_type) return 0; | |
| 817 Compare_type = make_type("Compare", expr_type, Compare_fields, 3); | 821 Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
| 818 if (!Compare_type) return 0; | 822 if (!Compare_type) return 0; |
| 819 Call_type = make_type("Call", expr_type, Call_fields, 5); | 823 Call_type = make_type("Call", expr_type, Call_fields, 5); |
| 820 if (!Call_type) return 0; | 824 if (!Call_type) return 0; |
| 821 Num_type = make_type("Num", expr_type, Num_fields, 1); | 825 Num_type = make_type("Num", expr_type, Num_fields, 1); |
| 1747 p->col_offset = col_offset; | 1751 p->col_offset = col_offset; |
| 1748 return p; | 1752 return p; |
| 1749 } | 1753 } |
| 1750 | 1754 |
| 1751 expr_ty | 1755 expr_ty |
| 1752 Yield(int is_from, expr_ty value, int lineno, int col_offset, PyArena *arena) | 1756 Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
| 1753 { | 1757 { |
| 1754 expr_ty p; | 1758 expr_ty p; |
| 1755 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | 1759 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
| 1756 if (!p) | 1760 if (!p) |
| 1757 return NULL; | 1761 return NULL; |
| 1758 p->kind = Yield_kind; | 1762 p->kind = Yield_kind; |
| 1759 p->v.Yield.is_from = is_from; | |
| 1760 p->v.Yield.value = value; | 1763 p->v.Yield.value = value; |
| 1764 p->lineno = lineno; | |
| 1765 p->col_offset = col_offset; | |
| 1766 return p; | |
| 1767 } | |
| 1768 | |
| 1769 expr_ty | |
| 1770 YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena) | |
| 1771 { | |
| 1772 expr_ty p; | |
| 1773 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1774 if (!p) | |
| 1775 return NULL; | |
| 1776 p->kind = YieldFrom_kind; | |
| 1777 p->v.YieldFrom.value = value; | |
| 1761 p->lineno = lineno; | 1778 p->lineno = lineno; |
| 1762 p->col_offset = col_offset; | 1779 p->col_offset = col_offset; |
| 1763 return p; | 1780 return p; |
| 1764 } | 1781 } |
| 1765 | 1782 |
| 2796 Py_DECREF(value); | 2813 Py_DECREF(value); |
| 2797 break; | 2814 break; |
| 2798 case Yield_kind: | 2815 case Yield_kind: |
| 2799 result = PyType_GenericNew(Yield_type, NULL, NULL); | 2816 result = PyType_GenericNew(Yield_type, NULL, NULL); |
| 2800 if (!result) goto failed; | 2817 if (!result) goto failed; |
| 2801 value = ast2obj_int(o->v.Yield.is_from); | |
| 2802 if (!value) goto failed; | |
| 2803 if (_PyObject_SetAttrId(result, &PyId_is_from, value) == -1) | |
| 2804 goto failed; | |
| 2805 Py_DECREF(value); | |
| 2806 value = ast2obj_expr(o->v.Yield.value); | 2818 value = ast2obj_expr(o->v.Yield.value); |
| 2819 if (!value) goto failed; | |
| 2820 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) | |
| 2821 goto failed; | |
| 2822 Py_DECREF(value); | |
| 2823 break; | |
| 2824 case YieldFrom_kind: | |
| 2825 result = PyType_GenericNew(YieldFrom_type, NULL, NULL); | |
| 2826 if (!result) goto failed; | |
| 2827 value = ast2obj_expr(o->v.YieldFrom.value); | |
| 2807 if (!value) goto failed; | 2828 if (!value) goto failed; |
| 2808 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) | 2829 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
| 2809 goto failed; | 2830 goto failed; |
| 2810 Py_DECREF(value); | 2831 Py_DECREF(value); |
| 2811 break; | 2832 break; |
| 5343 isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); | 5364 isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
| 5344 if (isinstance == -1) { | 5365 if (isinstance == -1) { |
| 5345 return 1; | 5366 return 1; |
| 5346 } | 5367 } |
| 5347 if (isinstance) { | 5368 if (isinstance) { |
| 5348 int is_from; | |
| 5349 expr_ty value; | 5369 expr_ty value; |
| 5350 | 5370 |
| 5351 if (_PyObject_HasAttrId(obj, &PyId_is_from)) { | |
| 5352 int res; | |
| 5353 tmp = _PyObject_GetAttrId(obj, &PyId_is_from); | |
| 5354 if (tmp == NULL) goto failed; | |
| 5355 res = obj2ast_int(tmp, &is_from, arena); | |
| 5356 if (res != 0) goto failed; | |
| 5357 Py_XDECREF(tmp); | |
| 5358 tmp = NULL; | |
| 5359 } else { | |
| 5360 PyErr_SetString(PyExc_TypeError, "required field \"is_from\" missing from Yield"); | |
| 5361 return 1; | |
| 5362 } | |
| 5363 if (_PyObject_HasAttrId(obj, &PyId_value)) { | 5371 if (_PyObject_HasAttrId(obj, &PyId_value)) { |
| 5364 int res; | 5372 int res; |
| 5365 tmp = _PyObject_GetAttrId(obj, &PyId_value); | 5373 tmp = _PyObject_GetAttrId(obj, &PyId_value); |
| 5366 if (tmp == NULL) goto failed; | 5374 if (tmp == NULL) goto failed; |
| 5367 res = obj2ast_expr(tmp, &value, arena); | 5375 res = obj2ast_expr(tmp, &value, arena); |
| 5369 Py_XDECREF(tmp); | 5377 Py_XDECREF(tmp); |
| 5370 tmp = NULL; | 5378 tmp = NULL; |
| 5371 } else { | 5379 } else { |
| 5372 value = NULL; | 5380 value = NULL; |
| 5373 } | 5381 } |
| 5374 *out = Yield(is_from, value, lineno, col_offset, arena); | 5382 *out = Yield(value, lineno, col_offset, arena); |
| 5383 if (*out == NULL) goto failed; | |
| 5384 return 0; | |
| 5385 } | |
| 5386 isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); | |
| 5387 if (isinstance == -1) { | |
| 5388 return 1; | |
| 5389 } | |
| 5390 if (isinstance) { | |
| 5391 expr_ty value; | |
| 5392 | |
| 5393 if (_PyObject_HasAttrId(obj, &PyId_value)) { | |
| 5394 int res; | |
| 5395 tmp = _PyObject_GetAttrId(obj, &PyId_value); | |
| 5396 if (tmp == NULL) goto failed; | |
| 5397 res = obj2ast_expr(tmp, &value, arena); | |
| 5398 if (res != 0) goto failed; | |
| 5399 Py_XDECREF(tmp); | |
| 5400 tmp = NULL; | |
| 5401 } else { | |
| 5402 value = NULL; | |
| 5403 } | |
| 5404 *out = YieldFrom(value, lineno, col_offset, arena); | |
| 5375 if (*out == NULL) goto failed; | 5405 if (*out == NULL) goto failed; |
| 5376 return 0; | 5406 return 0; |
| 5377 } | 5407 } |
| 5378 isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); | 5408 isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
| 5379 if (isinstance == -1) { | 5409 if (isinstance == -1) { |
| 6926 return NULL; | 6956 return NULL; |
| 6927 if (PyDict_SetItemString(d, "GeneratorExp", | 6957 if (PyDict_SetItemString(d, "GeneratorExp", |
| 6928 (PyObject*)GeneratorExp_type) < 0) return NULL; | 6958 (PyObject*)GeneratorExp_type) < 0) return NULL; |
| 6929 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return | 6959 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
| 6930 NULL; | 6960 NULL; |
| 6961 if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < | |
| 6962 0) return NULL; | |
| 6931 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) | 6963 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) |
| 6932 return NULL; | 6964 return NULL; |
| 6933 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return | 6965 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return |
| 6934 NULL; | 6966 NULL; |
| 6935 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return | 6967 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return |
