Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(95907)

Side by Side Diff: Python/Python-ast.c

Issue 11682: PEP 380 reference implementation for 3.3
Patch Set: Created 7 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* File automatically generated by Parser/asdl_c.py. */ 1 /* File automatically generated by Parser/asdl_c.py. */
2 2
3 #include "Python.h" 3 #include "Python.h"
4 #include "Python-ast.h" 4 #include "Python-ast.h"
5 5
6 static PyTypeObject AST_type; 6 static PyTypeObject AST_type;
7 static PyTypeObject *mod_type; 7 static PyTypeObject *mod_type;
8 static PyObject* ast2obj_mod(void*); 8 static PyObject* ast2obj_mod(void*);
9 static PyTypeObject *Module_type; 9 static PyTypeObject *Module_type;
10 _Py_IDENTIFIER(body); 10 _Py_IDENTIFIER(body);
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 "key", 224 "key",
225 "value", 225 "value",
226 "generators", 226 "generators",
227 }; 227 };
228 static PyTypeObject *GeneratorExp_type; 228 static PyTypeObject *GeneratorExp_type;
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);
234 static char *Yield_fields[]={ 235 static char *Yield_fields[]={
236 "is_from",
235 "value", 237 "value",
236 }; 238 };
237 static PyTypeObject *Compare_type; 239 static PyTypeObject *Compare_type;
238 _Py_IDENTIFIER(ops); 240 _Py_IDENTIFIER(ops);
239 _Py_IDENTIFIER(comparators); 241 _Py_IDENTIFIER(comparators);
240 static char *Compare_fields[]={ 242 static char *Compare_fields[]={
241 "left", 243 "left",
242 "ops", 244 "ops",
243 "comparators", 245 "comparators",
244 }; 246 };
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 if (!Set_type) return 0; 805 if (!Set_type) return 0;
804 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); 806 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
805 if (!ListComp_type) return 0; 807 if (!ListComp_type) return 0;
806 SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); 808 SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);
807 if (!SetComp_type) return 0; 809 if (!SetComp_type) return 0;
808 DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); 810 DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3);
809 if (!DictComp_type) return 0; 811 if (!DictComp_type) return 0;
810 GeneratorExp_type = make_type("GeneratorExp", expr_type, 812 GeneratorExp_type = make_type("GeneratorExp", expr_type,
811 GeneratorExp_fields, 2); 813 GeneratorExp_fields, 2);
812 if (!GeneratorExp_type) return 0; 814 if (!GeneratorExp_type) return 0;
813 Yield_type = make_type("Yield", expr_type, Yield_fields, 1); 815 Yield_type = make_type("Yield", expr_type, Yield_fields, 2);
814 if (!Yield_type) return 0; 816 if (!Yield_type) return 0;
815 Compare_type = make_type("Compare", expr_type, Compare_fields, 3); 817 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
816 if (!Compare_type) return 0; 818 if (!Compare_type) return 0;
817 Call_type = make_type("Call", expr_type, Call_fields, 5); 819 Call_type = make_type("Call", expr_type, Call_fields, 5);
818 if (!Call_type) return 0; 820 if (!Call_type) return 0;
819 Num_type = make_type("Num", expr_type, Num_fields, 1); 821 Num_type = make_type("Num", expr_type, Num_fields, 1);
820 if (!Num_type) return 0; 822 if (!Num_type) return 0;
821 Str_type = make_type("Str", expr_type, Str_fields, 1); 823 Str_type = make_type("Str", expr_type, Str_fields, 1);
822 if (!Str_type) return 0; 824 if (!Str_type) return 0;
823 Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); 825 Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1);
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
1740 return NULL; 1742 return NULL;
1741 p->kind = GeneratorExp_kind; 1743 p->kind = GeneratorExp_kind;
1742 p->v.GeneratorExp.elt = elt; 1744 p->v.GeneratorExp.elt = elt;
1743 p->v.GeneratorExp.generators = generators; 1745 p->v.GeneratorExp.generators = generators;
1744 p->lineno = lineno; 1746 p->lineno = lineno;
1745 p->col_offset = col_offset; 1747 p->col_offset = col_offset;
1746 return p; 1748 return p;
1747 } 1749 }
1748 1750
1749 expr_ty 1751 expr_ty
1750 Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) 1752 Yield(int is_from, expr_ty value, int lineno, int col_offset, PyArena *arena)
1751 { 1753 {
1752 expr_ty p; 1754 expr_ty p;
1753 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); 1755 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1754 if (!p) 1756 if (!p)
1755 return NULL; 1757 return NULL;
1756 p->kind = Yield_kind; 1758 p->kind = Yield_kind;
1759 p->v.Yield.is_from = is_from;
1757 p->v.Yield.value = value; 1760 p->v.Yield.value = value;
1758 p->lineno = lineno; 1761 p->lineno = lineno;
1759 p->col_offset = col_offset; 1762 p->col_offset = col_offset;
1760 return p; 1763 return p;
1761 } 1764 }
1762 1765
1763 expr_ty 1766 expr_ty
1764 Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, 1767 Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1765 int col_offset, PyArena *arena) 1768 int col_offset, PyArena *arena)
1766 { 1769 {
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after
2788 value = ast2obj_list(o->v.GeneratorExp.generators, 2791 value = ast2obj_list(o->v.GeneratorExp.generators,
2789 ast2obj_comprehension); 2792 ast2obj_comprehension);
2790 if (!value) goto failed; 2793 if (!value) goto failed;
2791 if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) 2794 if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
2792 goto failed; 2795 goto failed;
2793 Py_DECREF(value); 2796 Py_DECREF(value);
2794 break; 2797 break;
2795 case Yield_kind: 2798 case Yield_kind:
2796 result = PyType_GenericNew(Yield_type, NULL, NULL); 2799 result = PyType_GenericNew(Yield_type, NULL, NULL);
2797 if (!result) goto failed; 2800 if (!result) goto failed;
2801 value = ast2obj_int(o->v.Yield.is_from);
2802 if (!value) goto failed;
2803 if (PyObject_SetAttrString(result, "is_from", value) == -1)
2804 goto failed;
2805 Py_DECREF(value);
2798 value = ast2obj_expr(o->v.Yield.value); 2806 value = ast2obj_expr(o->v.Yield.value);
2799 if (!value) goto failed; 2807 if (!value) goto failed;
2800 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) 2808 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
2801 goto failed; 2809 goto failed;
2802 Py_DECREF(value); 2810 Py_DECREF(value);
2803 break; 2811 break;
2804 case Compare_kind: 2812 case Compare_kind:
2805 result = PyType_GenericNew(Compare_type, NULL, NULL); 2813 result = PyType_GenericNew(Compare_type, NULL, NULL);
2806 if (!result) goto failed; 2814 if (!result) goto failed;
2807 value = ast2obj_expr(o->v.Compare.left); 2815 value = ast2obj_expr(o->v.Compare.left);
(...skipping 2522 matching lines...) Expand 10 before | Expand all | Expand 10 after
5330 } 5338 }
5331 *out = GeneratorExp(elt, generators, lineno, col_offset, arena); 5339 *out = GeneratorExp(elt, generators, lineno, col_offset, arena);
5332 if (*out == NULL) goto failed; 5340 if (*out == NULL) goto failed;
5333 return 0; 5341 return 0;
5334 } 5342 }
5335 isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); 5343 isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type);
5336 if (isinstance == -1) { 5344 if (isinstance == -1) {
5337 return 1; 5345 return 1;
5338 } 5346 }
5339 if (isinstance) { 5347 if (isinstance) {
5348 int is_from;
5340 expr_ty value; 5349 expr_ty value;
5341 5350
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_fr om\" missing from Yield");
5361 return 1;
5362 }
5342 if (_PyObject_HasAttrId(obj, &PyId_value)) { 5363 if (_PyObject_HasAttrId(obj, &PyId_value)) {
5343 int res; 5364 int res;
5344 tmp = _PyObject_GetAttrId(obj, &PyId_value); 5365 tmp = _PyObject_GetAttrId(obj, &PyId_value);
5345 if (tmp == NULL) goto failed; 5366 if (tmp == NULL) goto failed;
5346 res = obj2ast_expr(tmp, &value, arena); 5367 res = obj2ast_expr(tmp, &value, arena);
5347 if (res != 0) goto failed; 5368 if (res != 0) goto failed;
5348 Py_XDECREF(tmp); 5369 Py_XDECREF(tmp);
5349 tmp = NULL; 5370 tmp = NULL;
5350 } else { 5371 } else {
5351 value = NULL; 5372 value = NULL;
5352 } 5373 }
5353 *out = Yield(value, lineno, col_offset, arena); 5374 *out = Yield(is_from, value, lineno, col_offset, arena);
5354 if (*out == NULL) goto failed; 5375 if (*out == NULL) goto failed;
5355 return 0; 5376 return 0;
5356 } 5377 }
5357 isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); 5378 isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type);
5358 if (isinstance == -1) { 5379 if (isinstance == -1) {
5359 return 1; 5380 return 1;
5360 } 5381 }
5361 if (isinstance) { 5382 if (isinstance) {
5362 expr_ty left; 5383 expr_ty left;
5363 asdl_int_seq* ops; 5384 asdl_int_seq* ops;
(...skipping 1699 matching lines...) Expand 10 before | Expand all | Expand 10 after
7063 return res; 7084 return res;
7064 } 7085 }
7065 7086
7066 int PyAST_Check(PyObject* obj) 7087 int PyAST_Check(PyObject* obj)
7067 { 7088 {
7068 init_types(); 7089 init_types();
7069 return PyObject_IsInstance(obj, (PyObject*)&AST_type); 7090 return PyObject_IsInstance(obj, (PyObject*)&AST_type);
7070 } 7091 }
7071 7092
7072 7093
OLDNEW
« Objects/exceptions.c ('K') | « Python/opcode_targets.h ('k') | Python/symtable.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+