comparison Python/Python-ast.c @ 40788:e9a6234b26af

* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes. * Fix some docstrings and one Print -> print. * Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}. These were the ones that generated code with a print statement. In most remaining failing tests there's an issue with the soft space.
author Georg Brandl <georg@python.org>
date Fri, 09 Feb 2007 21:28:07 +0000
parents 47f9efdc0855
children 5ef70c49d85a
comparison
equal deleted inserted replaced
40787:6917c676c92f 40788:e9a6234b26af
58 static PyTypeObject *AugAssign_type; 58 static PyTypeObject *AugAssign_type;
59 static char *AugAssign_fields[]={ 59 static char *AugAssign_fields[]={
60 "target", 60 "target",
61 "op", 61 "op",
62 "value", 62 "value",
63 };
64 static PyTypeObject *Print_type;
65 static char *Print_fields[]={
66 "dest",
67 "values",
68 "nl",
69 }; 63 };
70 static PyTypeObject *For_type; 64 static PyTypeObject *For_type;
71 static char *For_fields[]={ 65 static char *For_fields[]={
72 "target", 66 "target",
73 "iter", 67 "iter",
478 if (!Delete_type) return 0; 472 if (!Delete_type) return 0;
479 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); 473 Assign_type = make_type("Assign", stmt_type, Assign_fields, 2);
480 if (!Assign_type) return 0; 474 if (!Assign_type) return 0;
481 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); 475 AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3);
482 if (!AugAssign_type) return 0; 476 if (!AugAssign_type) return 0;
483 Print_type = make_type("Print", stmt_type, Print_fields, 3);
484 if (!Print_type) return 0;
485 For_type = make_type("For", stmt_type, For_fields, 4); 477 For_type = make_type("For", stmt_type, For_fields, 4);
486 if (!For_type) return 0; 478 if (!For_type) return 0;
487 While_type = make_type("While", stmt_type, While_fields, 3); 479 While_type = make_type("While", stmt_type, While_fields, 3);
488 if (!While_type) return 0; 480 if (!While_type) return 0;
489 If_type = make_type("If", stmt_type, If_fields, 3); 481 If_type = make_type("If", stmt_type, If_fields, 3);
947 p->col_offset = col_offset; 939 p->col_offset = col_offset;
948 return p; 940 return p;
949 } 941 }
950 942
951 stmt_ty 943 stmt_ty
952 Print(expr_ty dest, asdl_seq * values, bool nl, int lineno, int col_offset,
953 PyArena *arena)
954 {
955 stmt_ty p;
956 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
957 if (!p) {
958 PyErr_NoMemory();
959 return NULL;
960 }
961 p->kind = Print_kind;
962 p->v.Print.dest = dest;
963 p->v.Print.values = values;
964 p->v.Print.nl = nl;
965 p->lineno = lineno;
966 p->col_offset = col_offset;
967 return p;
968 }
969
970 stmt_ty
971 For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int 944 For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int
972 lineno, int col_offset, PyArena *arena) 945 lineno, int col_offset, PyArena *arena)
973 { 946 {
974 stmt_ty p; 947 stmt_ty p;
975 if (!target) { 948 if (!target) {
2113 goto failed; 2086 goto failed;
2114 Py_DECREF(value); 2087 Py_DECREF(value);
2115 value = ast2obj_expr(o->v.AugAssign.value); 2088 value = ast2obj_expr(o->v.AugAssign.value);
2116 if (!value) goto failed; 2089 if (!value) goto failed;
2117 if (PyObject_SetAttrString(result, "value", value) == -1) 2090 if (PyObject_SetAttrString(result, "value", value) == -1)
2118 goto failed;
2119 Py_DECREF(value);
2120 break;
2121 case Print_kind:
2122 result = PyType_GenericNew(Print_type, NULL, NULL);
2123 if (!result) goto failed;
2124 value = ast2obj_expr(o->v.Print.dest);
2125 if (!value) goto failed;
2126 if (PyObject_SetAttrString(result, "dest", value) == -1)
2127 goto failed;
2128 Py_DECREF(value);
2129 value = ast2obj_list(o->v.Print.values, ast2obj_expr);
2130 if (!value) goto failed;
2131 if (PyObject_SetAttrString(result, "values", value) == -1)
2132 goto failed;
2133 Py_DECREF(value);
2134 value = ast2obj_bool(o->v.Print.nl);
2135 if (!value) goto failed;
2136 if (PyObject_SetAttrString(result, "nl", value) == -1)
2137 goto failed; 2091 goto failed;
2138 Py_DECREF(value); 2092 Py_DECREF(value);
2139 break; 2093 break;
2140 case For_kind: 2094 case For_kind:
2141 result = PyType_GenericNew(For_type, NULL, NULL); 2095 result = PyType_GenericNew(For_type, NULL, NULL);
3147 return; 3101 return;
3148 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) 3102 if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0)
3149 return; 3103 return;
3150 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 3104 if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) <
3151 0) return; 3105 0) return;
3152 if (PyDict_SetItemString(d, "Print", (PyObject*)Print_type) < 0) return;
3153 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return; 3106 if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return;
3154 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return; 3107 if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return;
3155 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return; 3108 if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return;
3156 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return; 3109 if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return;
3157 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return; 3110 if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return;