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

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

Issue 11682: PEP 380 reference implementation for 3.3
Patch Set: Created 7 years, 9 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
« no previous file with comments | « Python/opcode_targets.h ('k') | Python/symtable.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 if (!Set_type) return 0; 809 if (!Set_type) return 0;
808 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); 810 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2);
809 if (!ListComp_type) return 0; 811 if (!ListComp_type) return 0;
810 SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); 812 SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2);
811 if (!SetComp_type) return 0; 813 if (!SetComp_type) return 0;
812 DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); 814 DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3);
813 if (!DictComp_type) return 0; 815 if (!DictComp_type) return 0;
814 GeneratorExp_type = make_type("GeneratorExp", expr_type, 816 GeneratorExp_type = make_type("GeneratorExp", expr_type,
815 GeneratorExp_fields, 2); 817 GeneratorExp_fields, 2);
816 if (!GeneratorExp_type) return 0; 818 if (!GeneratorExp_type) return 0;
817 Yield_type = make_type("Yield", expr_type, Yield_fields, 1); 819 Yield_type = make_type("Yield", expr_type, Yield_fields, 2);
818 if (!Yield_type) return 0; 820 if (!Yield_type) return 0;
819 Compare_type = make_type("Compare", expr_type, Compare_fields, 3); 821 Compare_type = make_type("Compare", expr_type, Compare_fields, 3);
820 if (!Compare_type) return 0; 822 if (!Compare_type) return 0;
821 Call_type = make_type("Call", expr_type, Call_fields, 5); 823 Call_type = make_type("Call", expr_type, Call_fields, 5);
822 if (!Call_type) return 0; 824 if (!Call_type) return 0;
823 Num_type = make_type("Num", expr_type, Num_fields, 1); 825 Num_type = make_type("Num", expr_type, Num_fields, 1);
824 if (!Num_type) return 0; 826 if (!Num_type) return 0;
825 Str_type = make_type("Str", expr_type, Str_fields, 1); 827 Str_type = make_type("Str", expr_type, Str_fields, 1);
826 if (!Str_type) return 0; 828 if (!Str_type) return 0;
827 Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); 829 Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1);
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 return NULL; 1746 return NULL;
1745 p->kind = GeneratorExp_kind; 1747 p->kind = GeneratorExp_kind;
1746 p->v.GeneratorExp.elt = elt; 1748 p->v.GeneratorExp.elt = elt;
1747 p->v.GeneratorExp.generators = generators; 1749 p->v.GeneratorExp.generators = generators;
1748 p->lineno = lineno; 1750 p->lineno = lineno;
1749 p->col_offset = col_offset; 1751 p->col_offset = col_offset;
1750 return p; 1752 return p;
1751 } 1753 }
1752 1754
1753 expr_ty 1755 expr_ty
1754 Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) 1756 Yield(int is_from, expr_ty value, int lineno, int col_offset, PyArena *arena)
1755 { 1757 {
1756 expr_ty p; 1758 expr_ty p;
1757 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); 1759 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1758 if (!p) 1760 if (!p)
1759 return NULL; 1761 return NULL;
1760 p->kind = Yield_kind; 1762 p->kind = Yield_kind;
1763 p->v.Yield.is_from = is_from;
1761 p->v.Yield.value = value; 1764 p->v.Yield.value = value;
1762 p->lineno = lineno; 1765 p->lineno = lineno;
1763 p->col_offset = col_offset; 1766 p->col_offset = col_offset;
1764 return p; 1767 return p;
1765 } 1768 }
1766 1769
1767 expr_ty 1770 expr_ty
1768 Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, 1771 Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
1769 int col_offset, PyArena *arena) 1772 int col_offset, PyArena *arena)
1770 { 1773 {
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after
2792 value = ast2obj_list(o->v.GeneratorExp.generators, 2795 value = ast2obj_list(o->v.GeneratorExp.generators,
2793 ast2obj_comprehension); 2796 ast2obj_comprehension);
2794 if (!value) goto failed; 2797 if (!value) goto failed;
2795 if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) 2798 if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1)
2796 goto failed; 2799 goto failed;
2797 Py_DECREF(value); 2800 Py_DECREF(value);
2798 break; 2801 break;
2799 case Yield_kind: 2802 case Yield_kind:
2800 result = PyType_GenericNew(Yield_type, NULL, NULL); 2803 result = PyType_GenericNew(Yield_type, NULL, NULL);
2801 if (!result) goto failed; 2804 if (!result) goto failed;
2805 value = ast2obj_int(o->v.Yield.is_from);
2806 if (!value) goto failed;
2807 if (PyObject_SetAttrString(result, "is_from", value) == -1)
2808 goto failed;
2809 Py_DECREF(value);
2802 value = ast2obj_expr(o->v.Yield.value); 2810 value = ast2obj_expr(o->v.Yield.value);
2803 if (!value) goto failed; 2811 if (!value) goto failed;
2804 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) 2812 if (_PyObject_SetAttrId(result, &PyId_value, value) == -1)
2805 goto failed; 2813 goto failed;
2806 Py_DECREF(value); 2814 Py_DECREF(value);
2807 break; 2815 break;
2808 case Compare_kind: 2816 case Compare_kind:
2809 result = PyType_GenericNew(Compare_type, NULL, NULL); 2817 result = PyType_GenericNew(Compare_type, NULL, NULL);
2810 if (!result) goto failed; 2818 if (!result) goto failed;
2811 value = ast2obj_expr(o->v.Compare.left); 2819 value = ast2obj_expr(o->v.Compare.left);
(...skipping 2522 matching lines...) Expand 10 before | Expand all | Expand 10 after
5334 } 5342 }
5335 *out = GeneratorExp(elt, generators, lineno, col_offset, arena); 5343 *out = GeneratorExp(elt, generators, lineno, col_offset, arena);
5336 if (*out == NULL) goto failed; 5344 if (*out == NULL) goto failed;
5337 return 0; 5345 return 0;
5338 } 5346 }
5339 isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); 5347 isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type);
5340 if (isinstance == -1) { 5348 if (isinstance == -1) {
5341 return 1; 5349 return 1;
5342 } 5350 }
5343 if (isinstance) { 5351 if (isinstance) {
5352 int is_from;
5344 expr_ty value; 5353 expr_ty value;
5345 5354
5355 if (_PyObject_HasAttrId(obj, &PyId_is_from)) {
5356 int res;
5357 tmp = _PyObject_GetAttrId(obj, &PyId_is_from);
5358 if (tmp == NULL) goto failed;
5359 res = obj2ast_int(tmp, &is_from, arena);
5360 if (res != 0) goto failed;
5361 Py_XDECREF(tmp);
5362 tmp = NULL;
5363 } else {
5364 PyErr_SetString(PyExc_TypeError, "required field \"is_fr om\" missing from Yield");
5365 return 1;
5366 }
5346 if (_PyObject_HasAttrId(obj, &PyId_value)) { 5367 if (_PyObject_HasAttrId(obj, &PyId_value)) {
5347 int res; 5368 int res;
5348 tmp = _PyObject_GetAttrId(obj, &PyId_value); 5369 tmp = _PyObject_GetAttrId(obj, &PyId_value);
5349 if (tmp == NULL) goto failed; 5370 if (tmp == NULL) goto failed;
5350 res = obj2ast_expr(tmp, &value, arena); 5371 res = obj2ast_expr(tmp, &value, arena);
5351 if (res != 0) goto failed; 5372 if (res != 0) goto failed;
5352 Py_XDECREF(tmp); 5373 Py_XDECREF(tmp);
5353 tmp = NULL; 5374 tmp = NULL;
5354 } else { 5375 } else {
5355 value = NULL; 5376 value = NULL;
5356 } 5377 }
5357 *out = Yield(value, lineno, col_offset, arena); 5378 *out = Yield(is_from, value, lineno, col_offset, arena);
5358 if (*out == NULL) goto failed; 5379 if (*out == NULL) goto failed;
5359 return 0; 5380 return 0;
5360 } 5381 }
5361 isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); 5382 isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type);
5362 if (isinstance == -1) { 5383 if (isinstance == -1) {
5363 return 1; 5384 return 1;
5364 } 5385 }
5365 if (isinstance) { 5386 if (isinstance) {
5366 expr_ty left; 5387 expr_ty left;
5367 asdl_int_seq* ops; 5388 asdl_int_seq* ops;
(...skipping 1699 matching lines...) Expand 10 before | Expand all | Expand 10 after
7067 return res; 7088 return res;
7068 } 7089 }
7069 7090
7070 int PyAST_Check(PyObject* obj) 7091 int PyAST_Check(PyObject* obj)
7071 { 7092 {
7072 init_types(); 7093 init_types();
7073 return PyObject_IsInstance(obj, (PyObject*)&AST_type); 7094 return PyObject_IsInstance(obj, (PyObject*)&AST_type);
7074 } 7095 }
7075 7096
7076 7097
OLDNEW
« no previous file with comments | « Python/opcode_targets.h ('k') | Python/symtable.c » ('j') | no next file with comments »

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