diff options
author | Georg Brandl <georg@python.org> | 2006-09-06 07:06:08 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-09-06 07:06:08 (GMT) |
commit | 52318d6215f9f9626d38a9b81b52d411dbbdb36a (patch) | |
tree | 72563f6321f9265fb9d77702ee729e68048bdd07 /Python | |
parent | 7cae87ca7b0a3a7ce497cbd335c8ec82fe680476 (diff) | |
download | cpython-52318d6215f9f9626d38a9b81b52d411dbbdb36a.zip cpython-52318d6215f9f9626d38a9b81b52d411dbbdb36a.tar.gz cpython-52318d6215f9f9626d38a9b81b52d411dbbdb36a.tar.bz2 |
Patch #1550786: ellipsis literal.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/Python-ast.c | 46 | ||||
-rw-r--r-- | Python/ast.c | 11 | ||||
-rw-r--r-- | Python/compile.c | 14 | ||||
-rw-r--r-- | Python/graminit.c | 138 | ||||
-rw-r--r-- | Python/symtable.c | 3 |
5 files changed, 106 insertions, 106 deletions
diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 6ba978b..0ecddb7 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -212,6 +212,7 @@ static PyTypeObject *Str_type; static char *Str_fields[]={ "s", }; +static PyTypeObject *Ellipsis_type; static PyTypeObject *Attribute_type; static char *Attribute_fields[]={ "value", @@ -251,7 +252,6 @@ static PyTypeObject *AugStore_type; static PyTypeObject *Param_type; static PyTypeObject *slice_type; static PyObject* ast2obj_slice(void*); -static PyTypeObject *Ellipsis_type; static PyTypeObject *Slice_type; static char *Slice_fields[]={ "lower", @@ -530,6 +530,8 @@ static int init_types(void) if (!Num_type) return 0; Str_type = make_type("Str", expr_type, Str_fields, 1); if (!Str_type) return 0; + Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); + if (!Ellipsis_type) return 0; Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); if (!Attribute_type) return 0; Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); @@ -570,8 +572,6 @@ static int init_types(void) slice_type = make_type("slice", AST_type, NULL, 0); if (!slice_type) return 0; if (!add_attributes(slice_type, NULL, 0)) return 0; - Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0); - if (!Ellipsis_type) return 0; Slice_type = make_type("Slice", slice_type, Slice_fields, 3); if (!Slice_type) return 0; ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); @@ -1579,6 +1579,21 @@ Str(string s, int lineno, int col_offset, PyArena *arena) } expr_ty +Ellipsis(int lineno, int col_offset, PyArena *arena) +{ + expr_ty p; + p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); + if (!p) { + PyErr_NoMemory(); + return NULL; + } + p->kind = Ellipsis_kind; + p->lineno = lineno; + p->col_offset = col_offset; + return p; +} + +expr_ty Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int col_offset, PyArena *arena) { @@ -1721,19 +1736,6 @@ Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena } slice_ty -Ellipsis(PyArena *arena) -{ - slice_ty p; - p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); - if (!p) { - PyErr_NoMemory(); - return NULL; - } - p->kind = Ellipsis_kind; - return p; -} - -slice_ty Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) { slice_ty p; @@ -2515,6 +2517,10 @@ ast2obj_expr(void* _o) goto failed; Py_DECREF(value); break; + case Ellipsis_kind: + result = PyType_GenericNew(Ellipsis_type, NULL, NULL); + if (!result) goto failed; + break; case Attribute_kind: result = PyType_GenericNew(Attribute_type, NULL, NULL); if (!result) goto failed; @@ -2648,10 +2654,6 @@ ast2obj_slice(void* _o) } switch (o->kind) { - case Ellipsis_kind: - result = PyType_GenericNew(Ellipsis_type, NULL, NULL); - if (!result) goto failed; - break; case Slice_kind: result = PyType_GenericNew(Slice_type, NULL, NULL); if (!result) goto failed; @@ -3059,6 +3061,8 @@ init_ast(void) if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return; if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return; if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return; + if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) + return; if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0) return; if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < @@ -3077,8 +3081,6 @@ init_ast(void) return; if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return; if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return; - if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) - return; if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return; if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) return; diff --git a/Python/ast.c b/Python/ast.c index 36f706e..bb2f3a3 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -399,6 +399,9 @@ set_context(expr_ty e, expr_context_ty ctx, const node *n) case Str_kind: expr_name = "literal"; break; + case Ellipsis_kind: + expr_name = "Ellipsis"; + break; case Compare_kind: expr_name = "comparison"; break; @@ -1213,6 +1216,9 @@ ast_for_atom(struct compiling *c, const node *n) PyArena_AddPyObject(c->c_arena, pynum); return Num(pynum, LINENO(n), n->n_col_offset, c->c_arena); } + case DOT: + /* Ellipsis */ + return Ellipsis(LINENO(n), n->n_col_offset, c->c_arena); case LPAR: /* some parenthesized expressions */ ch = CHILD(n, 1); @@ -1308,13 +1314,10 @@ ast_for_slice(struct compiling *c, const node *n) REQ(n, subscript); /* - subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop] + subscript: test | [test] ':' [test] [sliceop] sliceop: ':' [test] */ ch = CHILD(n, 0); - if (TYPE(ch) == DOT) - return Ellipsis(c->c_arena); - if (NCH(n) == 1 && TYPE(ch) == test) { /* 'step' variable hold no significance in terms of being used over other vars */ diff --git a/Python/compile.c b/Python/compile.c index ac82b84..40ac2d7 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -2746,6 +2746,8 @@ static int expr_constant(expr_ty e) { switch (e->kind) { + case Ellipsis_kind: + return 1; case Num_kind: return PyObject_IsTrue(e->v.Num.n); case Str_kind: @@ -2977,6 +2979,9 @@ compiler_visit_expr(struct compiler *c, expr_ty e) case Str_kind: ADDOP_O(c, LOAD_CONST, e->v.Str.s, consts); break; + case Ellipsis_kind: + ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts); + break; /* The following exprs can be assignment targets. */ case Attribute_kind: if (e->v.Attribute.ctx != AugStore) @@ -3255,9 +3260,6 @@ compiler_visit_nested_slice(struct compiler *c, slice_ty s, expr_context_ty ctx) { switch (s->kind) { - case Ellipsis_kind: - ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts); - break; case Slice_kind: return compiler_slice(c, s, ctx); case Index_kind: @@ -3284,12 +3286,6 @@ compiler_visit_slice(struct compiler *c, slice_ty s, expr_context_ty ctx) VISIT(c, expr, s->v.Index.value); } break; - case Ellipsis_kind: - kindname = "ellipsis"; - if (ctx != AugStore) { - ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts); - } - break; case Slice_kind: kindname = "slice"; if (!s->v.Slice.step) diff --git a/Python/graminit.c b/Python/graminit.c index 1d49a8c..912fdf2 100644 --- a/Python/graminit.c +++ b/Python/graminit.c @@ -1209,25 +1209,26 @@ static state states_59[4] = { {1, arcs_59_2}, {1, arcs_59_3}, }; -static arc arcs_60_0[6] = { +static arc arcs_60_0[7] = { {13, 1}, {142, 2}, {145, 3}, {19, 4}, {148, 4}, {149, 5}, + {74, 6}, }; static arc arcs_60_1[3] = { - {42, 6}, - {141, 6}, + {42, 7}, + {141, 7}, {15, 4}, }; static arc arcs_60_2[2] = { - {143, 7}, + {143, 8}, {144, 4}, }; static arc arcs_60_3[2] = { - {146, 8}, + {146, 9}, {147, 4}, }; static arc arcs_60_4[1] = { @@ -1238,16 +1239,22 @@ static arc arcs_60_5[2] = { {0, 5}, }; static arc arcs_60_6[1] = { - {15, 4}, + {74, 10}, }; static arc arcs_60_7[1] = { - {144, 4}, + {15, 4}, }; static arc arcs_60_8[1] = { + {144, 4}, +}; +static arc arcs_60_9[1] = { {147, 4}, }; -static state states_60[9] = { - {6, arcs_60_0}, +static arc arcs_60_10[1] = { + {74, 4}, +}; +static state states_60[11] = { + {7, arcs_60_0}, {3, arcs_60_1}, {2, arcs_60_2}, {2, arcs_60_3}, @@ -1256,6 +1263,8 @@ static state states_60[9] = { {1, arcs_60_6}, {1, arcs_60_7}, {1, arcs_60_8}, + {1, arcs_60_9}, + {1, arcs_60_10}, }; static arc arcs_61_0[1] = { {26, 1}, @@ -1381,41 +1390,32 @@ static state states_65[3] = { {2, arcs_65_1}, {2, arcs_65_2}, }; -static arc arcs_66_0[3] = { - {74, 1}, - {26, 2}, - {21, 3}, +static arc arcs_66_0[2] = { + {26, 1}, + {21, 2}, }; -static arc arcs_66_1[1] = { - {74, 4}, +static arc arcs_66_1[2] = { + {21, 2}, + {0, 1}, }; -static arc arcs_66_2[2] = { - {21, 3}, +static arc arcs_66_2[3] = { + {26, 3}, + {154, 4}, {0, 2}, }; -static arc arcs_66_3[3] = { - {26, 5}, - {154, 6}, +static arc arcs_66_3[2] = { + {154, 4}, {0, 3}, }; static arc arcs_66_4[1] = { - {74, 6}, -}; -static arc arcs_66_5[2] = { - {154, 6}, - {0, 5}, -}; -static arc arcs_66_6[1] = { - {0, 6}, + {0, 4}, }; -static state states_66[7] = { - {3, arcs_66_0}, - {1, arcs_66_1}, - {2, arcs_66_2}, - {3, arcs_66_3}, +static state states_66[5] = { + {2, arcs_66_0}, + {2, arcs_66_1}, + {3, arcs_66_2}, + {2, arcs_66_3}, {1, arcs_66_4}, - {2, arcs_66_5}, - {1, arcs_66_6}, }; static arc arcs_67_0[1] = { {21, 1}, @@ -1753,11 +1753,11 @@ static state states_82[3] = { }; static dfa dfas[83] = { {256, "single_input", 0, 3, states_0, - "\004\050\014\000\000\000\200\012\236\202\201\054\001\004\001\000\030\102\062\010\010"}, + "\004\050\014\000\000\000\200\012\236\206\201\054\001\004\001\000\030\102\062\010\010"}, {257, "file_input", 0, 2, states_1, - "\204\050\014\000\000\000\200\012\236\202\201\054\001\004\001\000\030\102\062\010\010"}, + "\204\050\014\000\000\000\200\012\236\206\201\054\001\004\001\000\030\102\062\010\010"}, {258, "eval_input", 0, 3, states_2, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\004\001\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\004\001\000\030\102\062\000\000"}, {259, "decorator", 0, 7, states_3, "\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {260, "decorators", 0, 2, states_4, @@ -1773,13 +1773,13 @@ static dfa dfas[83] = { {265, "fplist", 0, 3, states_9, "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {266, "stmt", 0, 2, states_10, - "\000\050\014\000\000\000\200\012\236\202\201\054\001\004\001\000\030\102\062\010\010"}, + "\000\050\014\000\000\000\200\012\236\206\201\054\001\004\001\000\030\102\062\010\010"}, {267, "simple_stmt", 0, 4, states_11, - "\000\040\010\000\000\000\200\012\236\202\001\000\000\004\001\000\030\102\062\000\010"}, + "\000\040\010\000\000\000\200\012\236\206\001\000\000\004\001\000\030\102\062\000\010"}, {268, "small_stmt", 0, 2, states_12, - "\000\040\010\000\000\000\200\012\236\202\001\000\000\004\001\000\030\102\062\000\010"}, + "\000\040\010\000\000\000\200\012\236\206\001\000\000\004\001\000\030\102\062\000\010"}, {269, "expr_stmt", 0, 6, states_13, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\004\001\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\004\001\000\030\102\062\000\000"}, {270, "augassign", 0, 2, states_14, "\000\000\000\000\000\370\177\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {271, "print_stmt", 0, 9, states_15, @@ -1837,69 +1837,69 @@ static dfa dfas[83] = { {297, "except_clause", 0, 5, states_41, "\000\000\000\000\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000"}, {298, "suite", 0, 5, states_42, - "\004\040\010\000\000\000\200\012\236\202\001\000\000\004\001\000\030\102\062\000\010"}, + "\004\040\010\000\000\000\200\012\236\206\001\000\000\004\001\000\030\102\062\000\010"}, {299, "testlist_safe", 0, 5, states_43, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\004\001\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\004\001\000\030\102\062\000\000"}, {300, "old_test", 0, 2, states_44, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\004\001\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\004\001\000\030\102\062\000\000"}, {301, "old_lambdef", 0, 5, states_45, "\000\000\000\000\000\000\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000"}, {302, "test", 0, 6, states_46, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\004\001\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\004\001\000\030\102\062\000\000"}, {303, "or_test", 0, 2, states_47, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\001\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\000\001\000\030\102\062\000\000"}, {304, "and_test", 0, 2, states_48, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\001\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\000\001\000\030\102\062\000\000"}, {305, "not_test", 0, 3, states_49, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\001\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\000\001\000\030\102\062\000\000"}, {306, "comparison", 0, 2, states_50, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\000\000\000\030\102\062\000\000"}, {307, "comp_op", 0, 4, states_51, "\000\000\000\000\000\000\000\000\000\000\000\020\000\000\371\003\000\000\000\000\000"}, {308, "expr", 0, 2, states_52, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\000\000\000\030\102\062\000\000"}, {309, "xor_expr", 0, 2, states_53, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\000\000\000\030\102\062\000\000"}, {310, "and_expr", 0, 2, states_54, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\000\000\000\030\102\062\000\000"}, {311, "shift_expr", 0, 2, states_55, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\000\000\000\030\102\062\000\000"}, {312, "arith_expr", 0, 2, states_56, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\000\000\000\030\102\062\000\000"}, {313, "term", 0, 2, states_57, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\000\000\000\030\102\062\000\000"}, {314, "factor", 0, 3, states_58, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\000\000\000\030\102\062\000\000"}, {315, "power", 0, 4, states_59, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\100\062\000\000"}, - {316, "atom", 0, 9, states_60, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\100\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\000\000\000\000\100\062\000\000"}, + {316, "atom", 0, 11, states_60, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\000\000\000\000\100\062\000\000"}, {317, "listmaker", 0, 5, states_61, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\004\001\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\004\001\000\030\102\062\000\000"}, {318, "testlist_gexp", 0, 5, states_62, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\004\001\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\004\001\000\030\102\062\000\000"}, {319, "lambdef", 0, 5, states_63, "\000\000\000\000\000\000\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000"}, {320, "trailer", 0, 7, states_64, "\000\040\000\000\000\000\000\000\000\004\000\000\000\000\000\000\000\100\000\000\000"}, {321, "subscriptlist", 0, 3, states_65, "\000\040\050\000\000\000\000\000\000\004\000\000\000\004\001\000\030\102\062\000\000"}, - {322, "subscript", 0, 7, states_66, + {322, "subscript", 0, 5, states_66, "\000\040\050\000\000\000\000\000\000\004\000\000\000\004\001\000\030\102\062\000\000"}, {323, "sliceop", 0, 3, states_67, "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {324, "exprlist", 0, 3, states_68, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\000\000\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\000\000\000\030\102\062\000\000"}, {325, "testlist", 0, 3, states_69, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\004\001\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\004\001\000\030\102\062\000\000"}, {326, "dictsetmaker", 0, 8, states_70, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\004\001\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\004\001\000\030\102\062\000\000"}, {327, "classdef", 0, 8, states_71, "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\010\000"}, {328, "arglist", 0, 8, states_72, - "\000\040\010\060\000\000\000\000\000\000\000\000\000\004\001\000\030\102\062\000\000"}, + "\000\040\010\060\000\000\000\000\000\004\000\000\000\004\001\000\030\102\062\000\000"}, {329, "argument", 0, 4, states_73, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\004\001\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\004\001\000\030\102\062\000\000"}, {330, "list_iter", 0, 2, states_74, "\000\000\000\000\000\000\000\000\000\000\200\010\000\000\000\000\000\000\000\000\000"}, {331, "list_for", 0, 6, states_75, @@ -1913,7 +1913,7 @@ static dfa dfas[83] = { {335, "gen_if", 0, 4, states_79, "\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000\000\000\000"}, {336, "testlist1", 0, 2, states_80, - "\000\040\010\000\000\000\000\000\000\000\000\000\000\004\001\000\030\102\062\000\000"}, + "\000\040\010\000\000\000\000\000\000\004\000\000\000\004\001\000\030\102\062\000\000"}, {337, "encoding_decl", 0, 2, states_81, "\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"}, {338, "yield_expr", 0, 3, states_82, diff --git a/Python/symtable.c b/Python/symtable.c index 81020a9..8f19e0b 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -1161,6 +1161,7 @@ symtable_visit_expr(struct symtable *st, expr_ty e) break; case Num_kind: case Str_kind: + case Ellipsis_kind: /* Nothing to do here. */ break; /* The following exprs can be assignment targets. */ @@ -1365,8 +1366,6 @@ symtable_visit_slice(struct symtable *st, slice_ty s) case Index_kind: VISIT(st, expr, s->v.Index.value) break; - case Ellipsis_kind: - break; } return 1; } |