comparison Python/Python-ast.c @ 37453:16a64e394602 legacy-trunk

Add lineno, col_offset to excephandler to enable future fix for tracing/line number table in except blocks. Reflow long lines introduced by col_offset changes. Update test_ast to handle new fields in excepthandler. As note in Python.asdl says, we might want to rethink how attributes are handled. Perhaps they should be the same as other fields, with the primary difference being how they are defined for all types within a sum. Also fix asdl_c so that constructors with int fields don't fail when passed a zero value.
author Jeremy Hylton <jeremy@alum.mit.edu>
date Tue, 04 Apr 2006 04:00:23 +0000
parents dfc33ec7f73a
children a9470eb637f1
comparison
equal deleted inserted replaced
37452:49dbedfb1d74 37453:16a64e394602
329 static PyObject* ast2obj_excepthandler(void*); 329 static PyObject* ast2obj_excepthandler(void*);
330 static char *excepthandler_fields[]={ 330 static char *excepthandler_fields[]={
331 "type", 331 "type",
332 "name", 332 "name",
333 "body", 333 "body",
334 "lineno",
335 "col_offset",
334 }; 336 };
335 static PyTypeObject *arguments_type; 337 static PyTypeObject *arguments_type;
336 static PyObject* ast2obj_arguments(void*); 338 static PyObject* ast2obj_arguments(void*);
337 static char *arguments_fields[]={ 339 static char *arguments_fields[]={
338 "args", 340 "args",
710 if (!NotIn_singleton) return 0; 712 if (!NotIn_singleton) return 0;
711 comprehension_type = make_type("comprehension", AST_type, 713 comprehension_type = make_type("comprehension", AST_type,
712 comprehension_fields, 3); 714 comprehension_fields, 3);
713 if (!comprehension_type) return 0; 715 if (!comprehension_type) return 0;
714 excepthandler_type = make_type("excepthandler", AST_type, 716 excepthandler_type = make_type("excepthandler", AST_type,
715 excepthandler_fields, 3); 717 excepthandler_fields, 5);
716 if (!excepthandler_type) return 0; 718 if (!excepthandler_type) return 0;
717 arguments_type = make_type("arguments", AST_type, arguments_fields, 4); 719 arguments_type = make_type("arguments", AST_type, arguments_fields, 4);
718 if (!arguments_type) return 0; 720 if (!arguments_type) return 0;
719 keyword_type = make_type("keyword", AST_type, keyword_fields, 2); 721 keyword_type = make_type("keyword", AST_type, keyword_fields, 2);
720 if (!keyword_type) return 0; 722 if (!keyword_type) return 0;
1841 p->ifs = ifs; 1843 p->ifs = ifs;
1842 return p; 1844 return p;
1843 } 1845 }
1844 1846
1845 excepthandler_ty 1847 excepthandler_ty
1846 excepthandler(expr_ty type, expr_ty name, asdl_seq * body, PyArena *arena) 1848 excepthandler(expr_ty type, expr_ty name, asdl_seq * body, int lineno, int
1849 col_offset, PyArena *arena)
1847 { 1850 {
1848 excepthandler_ty p; 1851 excepthandler_ty p;
1849 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); 1852 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
1850 if (!p) { 1853 if (!p) {
1851 PyErr_NoMemory(); 1854 PyErr_NoMemory();
1852 return NULL; 1855 return NULL;
1853 } 1856 }
1854 p->type = type; 1857 p->type = type;
1855 p->name = name; 1858 p->name = name;
1856 p->body = body; 1859 p->body = body;
1860 p->lineno = lineno;
1861 p->col_offset = col_offset;
1857 return p; 1862 return p;
1858 } 1863 }
1859 1864
1860 arguments_ty 1865 arguments_ty
1861 arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq * 1866 arguments(asdl_seq * args, identifier vararg, identifier kwarg, asdl_seq *
2915 value = ast2obj_list(o->body, ast2obj_stmt); 2920 value = ast2obj_list(o->body, ast2obj_stmt);
2916 if (!value) goto failed; 2921 if (!value) goto failed;
2917 if (PyObject_SetAttrString(result, "body", value) == -1) 2922 if (PyObject_SetAttrString(result, "body", value) == -1)
2918 goto failed; 2923 goto failed;
2919 Py_DECREF(value); 2924 Py_DECREF(value);
2925 value = ast2obj_int(o->lineno);
2926 if (!value) goto failed;
2927 if (PyObject_SetAttrString(result, "lineno", value) == -1)
2928 goto failed;
2929 Py_DECREF(value);
2930 value = ast2obj_int(o->col_offset);
2931 if (!value) goto failed;
2932 if (PyObject_SetAttrString(result, "col_offset", value) == -1)
2933 goto failed;
2934 Py_DECREF(value);
2920 return result; 2935 return result;
2921 failed: 2936 failed:
2922 Py_XDECREF(value); 2937 Py_XDECREF(value);
2923 Py_XDECREF(result); 2938 Py_XDECREF(result);
2924 return NULL; 2939 return NULL;
3031 if (!m) return; 3046 if (!m) return;
3032 d = PyModule_GetDict(m); 3047 d = PyModule_GetDict(m);
3033 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return; 3048 if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
3034 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) 3049 if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
3035 return; 3050 return;
3036 if (PyModule_AddStringConstant(m, "__version__", "42753") < 0) 3051 if (PyModule_AddStringConstant(m, "__version__", "") < 0)
3037 return; 3052 return;
3038 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return; 3053 if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
3039 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) 3054 if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)
3040 return; 3055 return;
3041 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) 3056 if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type)