comparison Python/Python-ast.c @ 39783:7a0ad110e91e

Patch #1550786: ellipsis literal.
author Georg Brandl <georg@python.org>
date Wed, 06 Sep 2006 07:06:08 +0000
parents c94f37054f19
children 1cce0526d9b0
comparison
equal deleted inserted replaced
39782:c94f37054f19 39783:7a0ad110e91e
210 }; 210 };
211 static PyTypeObject *Str_type; 211 static PyTypeObject *Str_type;
212 static char *Str_fields[]={ 212 static char *Str_fields[]={
213 "s", 213 "s",
214 }; 214 };
215 static PyTypeObject *Ellipsis_type;
215 static PyTypeObject *Attribute_type; 216 static PyTypeObject *Attribute_type;
216 static char *Attribute_fields[]={ 217 static char *Attribute_fields[]={
217 "value", 218 "value",
218 "attr", 219 "attr",
219 "ctx", 220 "ctx",
249 static PyTypeObject *AugLoad_type; 250 static PyTypeObject *AugLoad_type;
250 static PyTypeObject *AugStore_type; 251 static PyTypeObject *AugStore_type;
251 static PyTypeObject *Param_type; 252 static PyTypeObject *Param_type;
252 static PyTypeObject *slice_type; 253 static PyTypeObject *slice_type;
253 static PyObject* ast2obj_slice(void*); 254 static PyObject* ast2obj_slice(void*);
254 static PyTypeObject *Ellipsis_type;
255 static PyTypeObject *Slice_type; 255 static PyTypeObject *Slice_type;
256 static char *Slice_fields[]={ 256 static char *Slice_fields[]={
257 "lower", 257 "lower",
258 "upper", 258 "upper",
259 "step", 259 "step",
528 if (!Call_type) return 0; 528 if (!Call_type) return 0;
529 Num_type = make_type("Num", expr_type, Num_fields, 1); 529 Num_type = make_type("Num", expr_type, Num_fields, 1);
530 if (!Num_type) return 0; 530 if (!Num_type) return 0;
531 Str_type = make_type("Str", expr_type, Str_fields, 1); 531 Str_type = make_type("Str", expr_type, Str_fields, 1);
532 if (!Str_type) return 0; 532 if (!Str_type) return 0;
533 Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0);
534 if (!Ellipsis_type) return 0;
533 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); 535 Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3);
534 if (!Attribute_type) return 0; 536 if (!Attribute_type) return 0;
535 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); 537 Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3);
536 if (!Subscript_type) return 0; 538 if (!Subscript_type) return 0;
537 Name_type = make_type("Name", expr_type, Name_fields, 2); 539 Name_type = make_type("Name", expr_type, Name_fields, 2);
568 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); 570 Param_singleton = PyType_GenericNew(Param_type, NULL, NULL);
569 if (!Param_singleton) return 0; 571 if (!Param_singleton) return 0;
570 slice_type = make_type("slice", AST_type, NULL, 0); 572 slice_type = make_type("slice", AST_type, NULL, 0);
571 if (!slice_type) return 0; 573 if (!slice_type) return 0;
572 if (!add_attributes(slice_type, NULL, 0)) return 0; 574 if (!add_attributes(slice_type, NULL, 0)) return 0;
573 Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0);
574 if (!Ellipsis_type) return 0;
575 Slice_type = make_type("Slice", slice_type, Slice_fields, 3); 575 Slice_type = make_type("Slice", slice_type, Slice_fields, 3);
576 if (!Slice_type) return 0; 576 if (!Slice_type) return 0;
577 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); 577 ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1);
578 if (!ExtSlice_type) return 0; 578 if (!ExtSlice_type) return 0;
579 Index_type = make_type("Index", slice_type, Index_fields, 1); 579 Index_type = make_type("Index", slice_type, Index_fields, 1);
1577 p->col_offset = col_offset; 1577 p->col_offset = col_offset;
1578 return p; 1578 return p;
1579 } 1579 }
1580 1580
1581 expr_ty 1581 expr_ty
1582 Ellipsis(int lineno, int col_offset, PyArena *arena)
1583 {
1584 expr_ty p;
1585 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
1586 if (!p) {
1587 PyErr_NoMemory();
1588 return NULL;
1589 }
1590 p->kind = Ellipsis_kind;
1591 p->lineno = lineno;
1592 p->col_offset = col_offset;
1593 return p;
1594 }
1595
1596 expr_ty
1582 Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int 1597 Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
1583 col_offset, PyArena *arena) 1598 col_offset, PyArena *arena)
1584 { 1599 {
1585 expr_ty p; 1600 expr_ty p;
1586 if (!value) { 1601 if (!value) {
1715 p->kind = Tuple_kind; 1730 p->kind = Tuple_kind;
1716 p->v.Tuple.elts = elts; 1731 p->v.Tuple.elts = elts;
1717 p->v.Tuple.ctx = ctx; 1732 p->v.Tuple.ctx = ctx;
1718 p->lineno = lineno; 1733 p->lineno = lineno;
1719 p->col_offset = col_offset; 1734 p->col_offset = col_offset;
1720 return p;
1721 }
1722
1723 slice_ty
1724 Ellipsis(PyArena *arena)
1725 {
1726 slice_ty p;
1727 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
1728 if (!p) {
1729 PyErr_NoMemory();
1730 return NULL;
1731 }
1732 p->kind = Ellipsis_kind;
1733 return p; 1735 return p;
1734 } 1736 }
1735 1737
1736 slice_ty 1738 slice_ty
1737 Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) 1739 Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
2512 value = ast2obj_string(o->v.Str.s); 2514 value = ast2obj_string(o->v.Str.s);
2513 if (!value) goto failed; 2515 if (!value) goto failed;
2514 if (PyObject_SetAttrString(result, "s", value) == -1) 2516 if (PyObject_SetAttrString(result, "s", value) == -1)
2515 goto failed; 2517 goto failed;
2516 Py_DECREF(value); 2518 Py_DECREF(value);
2519 break;
2520 case Ellipsis_kind:
2521 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2522 if (!result) goto failed;
2517 break; 2523 break;
2518 case Attribute_kind: 2524 case Attribute_kind:
2519 result = PyType_GenericNew(Attribute_type, NULL, NULL); 2525 result = PyType_GenericNew(Attribute_type, NULL, NULL);
2520 if (!result) goto failed; 2526 if (!result) goto failed;
2521 value = ast2obj_expr(o->v.Attribute.value); 2527 value = ast2obj_expr(o->v.Attribute.value);
2646 Py_INCREF(Py_None); 2652 Py_INCREF(Py_None);
2647 return Py_None; 2653 return Py_None;
2648 } 2654 }
2649 2655
2650 switch (o->kind) { 2656 switch (o->kind) {
2651 case Ellipsis_kind:
2652 result = PyType_GenericNew(Ellipsis_type, NULL, NULL);
2653 if (!result) goto failed;
2654 break;
2655 case Slice_kind: 2657 case Slice_kind:
2656 result = PyType_GenericNew(Slice_type, NULL, NULL); 2658 result = PyType_GenericNew(Slice_type, NULL, NULL);
2657 if (!result) goto failed; 2659 if (!result) goto failed;
2658 value = ast2obj_expr(o->v.Slice.lower); 2660 value = ast2obj_expr(o->v.Slice.lower);
2659 if (!value) goto failed; 2661 if (!value) goto failed;
3057 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) 3059 if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0)
3058 return; 3060 return;
3059 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return; 3061 if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return;
3060 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return; 3062 if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return;
3061 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return; 3063 if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return;
3064 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3065 return;
3062 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 3066 if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) <
3063 0) return; 3067 0) return;
3064 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 3068 if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) <
3065 0) return; 3069 0) return;
3066 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return; 3070 if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return;
3075 return; 3079 return;
3076 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) 3080 if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0)
3077 return; 3081 return;
3078 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return; 3082 if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return;
3079 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return; 3083 if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return;
3080 if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0)
3081 return;
3082 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return; 3084 if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return;
3083 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) 3085 if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0)
3084 return; 3086 return;
3085 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return; 3087 if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return;
3086 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) 3088 if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0)