Mercurial > cpython-lru_cache-weakref
comparison Python/Python-ast.c @ 39693:d0b83c4630c0
SF patch 1547796 by Georg Brandl -- set literals.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 28 Aug 2006 15:27:34 +0000 |
| parents | c4d8c054616c |
| children | da3a9f402886 |
comparison
equal
deleted
inserted
replaced
| 39692:c093633bebec | 39693:d0b83c4630c0 |
|---|---|
| 175 }; | 175 }; |
| 176 static PyTypeObject *Dict_type; | 176 static PyTypeObject *Dict_type; |
| 177 static char *Dict_fields[]={ | 177 static char *Dict_fields[]={ |
| 178 "keys", | 178 "keys", |
| 179 "values", | 179 "values", |
| 180 }; | |
| 181 static PyTypeObject *Set_type; | |
| 182 static char *Set_fields[]={ | |
| 183 "elts", | |
| 180 }; | 184 }; |
| 181 static PyTypeObject *ListComp_type; | 185 static PyTypeObject *ListComp_type; |
| 182 static char *ListComp_fields[]={ | 186 static char *ListComp_fields[]={ |
| 183 "elt", | 187 "elt", |
| 184 "generators", | 188 "generators", |
| 515 if (!Lambda_type) return 0; | 519 if (!Lambda_type) return 0; |
| 516 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); | 520 IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
| 517 if (!IfExp_type) return 0; | 521 if (!IfExp_type) return 0; |
| 518 Dict_type = make_type("Dict", expr_type, Dict_fields, 2); | 522 Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
| 519 if (!Dict_type) return 0; | 523 if (!Dict_type) return 0; |
| 524 Set_type = make_type("Set", expr_type, Set_fields, 1); | |
| 525 if (!Set_type) return 0; | |
| 520 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); | 526 ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
| 521 if (!ListComp_type) return 0; | 527 if (!ListComp_type) return 0; |
| 522 GeneratorExp_type = make_type("GeneratorExp", expr_type, | 528 GeneratorExp_type = make_type("GeneratorExp", expr_type, |
| 523 GeneratorExp_fields, 2); | 529 GeneratorExp_fields, 2); |
| 524 if (!GeneratorExp_type) return 0; | 530 if (!GeneratorExp_type) return 0; |
| 1433 p->col_offset = col_offset; | 1439 p->col_offset = col_offset; |
| 1434 return p; | 1440 return p; |
| 1435 } | 1441 } |
| 1436 | 1442 |
| 1437 expr_ty | 1443 expr_ty |
| 1444 Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) | |
| 1445 { | |
| 1446 expr_ty p; | |
| 1447 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); | |
| 1448 if (!p) { | |
| 1449 PyErr_NoMemory(); | |
| 1450 return NULL; | |
| 1451 } | |
| 1452 p->kind = Set_kind; | |
| 1453 p->v.Set.elts = elts; | |
| 1454 p->lineno = lineno; | |
| 1455 p->col_offset = col_offset; | |
| 1456 return p; | |
| 1457 } | |
| 1458 | |
| 1459 expr_ty | |
| 1438 ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, | 1460 ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
| 1439 PyArena *arena) | 1461 PyArena *arena) |
| 1440 { | 1462 { |
| 1441 expr_ty p; | 1463 expr_ty p; |
| 1442 if (!elt) { | 1464 if (!elt) { |
| 2419 goto failed; | 2441 goto failed; |
| 2420 Py_DECREF(value); | 2442 Py_DECREF(value); |
| 2421 value = ast2obj_list(o->v.Dict.values, ast2obj_expr); | 2443 value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
| 2422 if (!value) goto failed; | 2444 if (!value) goto failed; |
| 2423 if (PyObject_SetAttrString(result, "values", value) == -1) | 2445 if (PyObject_SetAttrString(result, "values", value) == -1) |
| 2446 goto failed; | |
| 2447 Py_DECREF(value); | |
| 2448 break; | |
| 2449 case Set_kind: | |
| 2450 result = PyType_GenericNew(Set_type, NULL, NULL); | |
| 2451 if (!result) goto failed; | |
| 2452 value = ast2obj_list(o->v.Set.elts, ast2obj_expr); | |
| 2453 if (!value) goto failed; | |
| 2454 if (PyObject_SetAttrString(result, "elts", value) == -1) | |
| 2424 goto failed; | 2455 goto failed; |
| 2425 Py_DECREF(value); | 2456 Py_DECREF(value); |
| 2426 break; | 2457 break; |
| 2427 case ListComp_kind: | 2458 case ListComp_kind: |
| 2428 result = PyType_GenericNew(ListComp_type, NULL, NULL); | 2459 result = PyType_GenericNew(ListComp_type, NULL, NULL); |
| 3067 return; | 3098 return; |
| 3068 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) | 3099 if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) |
| 3069 return; | 3100 return; |
| 3070 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return; | 3101 if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return; |
| 3071 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return; | 3102 if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return; |
| 3103 if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return; | |
| 3072 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) | 3104 if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
| 3073 return; | 3105 return; |
| 3074 if (PyDict_SetItemString(d, "GeneratorExp", | 3106 if (PyDict_SetItemString(d, "GeneratorExp", |
| 3075 (PyObject*)GeneratorExp_type) < 0) return; | 3107 (PyObject*)GeneratorExp_type) < 0) return; |
| 3076 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return; | 3108 if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return; |
