comparison Python/Python-ast.c @ 41226:19f7ff443718

Implement PEP 3115 -- new metaclass syntax and semantics. The compiler package hasn't been updated yet; test_compiler.py fails. Otherwise all tests seem to be passing now. There are no occurrences of __metaclass__ left in the standard library. Docs have not been updated.
author Guido van Rossum <guido@python.org>
date Sun, 18 Mar 2007 15:41:51 +0000
parents c3b28ba918f8
children 5e24f636ac75
comparison
equal deleted inserted replaced
41223:3c73a8a20839 41226:19f7ff443718
47 }; 47 };
48 static PyTypeObject *ClassDef_type; 48 static PyTypeObject *ClassDef_type;
49 static char *ClassDef_fields[]={ 49 static char *ClassDef_fields[]={
50 "name", 50 "name",
51 "bases", 51 "bases",
52 "keywords",
53 "starargs",
54 "kwargs",
52 "body", 55 "body",
53 }; 56 };
54 static PyTypeObject *Return_type; 57 static PyTypeObject *Return_type;
55 static char *Return_fields[]={ 58 static char *Return_fields[]={
56 "value", 59 "value",
475 if (!stmt_type) return 0; 478 if (!stmt_type) return 0;
476 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; 479 if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0;
477 FunctionDef_type = make_type("FunctionDef", stmt_type, 480 FunctionDef_type = make_type("FunctionDef", stmt_type,
478 FunctionDef_fields, 5); 481 FunctionDef_fields, 5);
479 if (!FunctionDef_type) return 0; 482 if (!FunctionDef_type) return 0;
480 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 3); 483 ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 6);
481 if (!ClassDef_type) return 0; 484 if (!ClassDef_type) return 0;
482 Return_type = make_type("Return", stmt_type, Return_fields, 1); 485 Return_type = make_type("Return", stmt_type, Return_fields, 1);
483 if (!Return_type) return 0; 486 if (!Return_type) return 0;
484 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); 487 Delete_type = make_type("Delete", stmt_type, Delete_fields, 1);
485 if (!Delete_type) return 0; 488 if (!Delete_type) return 0;
833 p->col_offset = col_offset; 836 p->col_offset = col_offset;
834 return p; 837 return p;
835 } 838 }
836 839
837 stmt_ty 840 stmt_ty
838 ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno, int 841 ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, expr_ty
839 col_offset, PyArena *arena) 842 starargs, expr_ty kwargs, asdl_seq * body, int lineno, int col_offset,
843 PyArena *arena)
840 { 844 {
841 stmt_ty p; 845 stmt_ty p;
842 if (!name) { 846 if (!name) {
843 PyErr_SetString(PyExc_ValueError, 847 PyErr_SetString(PyExc_ValueError,
844 "field name is required for ClassDef"); 848 "field name is required for ClassDef");
848 if (!p) 852 if (!p)
849 return NULL; 853 return NULL;
850 p->kind = ClassDef_kind; 854 p->kind = ClassDef_kind;
851 p->v.ClassDef.name = name; 855 p->v.ClassDef.name = name;
852 p->v.ClassDef.bases = bases; 856 p->v.ClassDef.bases = bases;
857 p->v.ClassDef.keywords = keywords;
858 p->v.ClassDef.starargs = starargs;
859 p->v.ClassDef.kwargs = kwargs;
853 p->v.ClassDef.body = body; 860 p->v.ClassDef.body = body;
854 p->lineno = lineno; 861 p->lineno = lineno;
855 p->col_offset = col_offset; 862 p->col_offset = col_offset;
856 return p; 863 return p;
857 } 864 }
1970 goto failed; 1977 goto failed;
1971 Py_DECREF(value); 1978 Py_DECREF(value);
1972 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); 1979 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
1973 if (!value) goto failed; 1980 if (!value) goto failed;
1974 if (PyObject_SetAttrString(result, "bases", value) == -1) 1981 if (PyObject_SetAttrString(result, "bases", value) == -1)
1982 goto failed;
1983 Py_DECREF(value);
1984 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
1985 if (!value) goto failed;
1986 if (PyObject_SetAttrString(result, "keywords", value) == -1)
1987 goto failed;
1988 Py_DECREF(value);
1989 value = ast2obj_expr(o->v.ClassDef.starargs);
1990 if (!value) goto failed;
1991 if (PyObject_SetAttrString(result, "starargs", value) == -1)
1992 goto failed;
1993 Py_DECREF(value);
1994 value = ast2obj_expr(o->v.ClassDef.kwargs);
1995 if (!value) goto failed;
1996 if (PyObject_SetAttrString(result, "kwargs", value) == -1)
1975 goto failed; 1997 goto failed;
1976 Py_DECREF(value); 1998 Py_DECREF(value);
1977 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); 1999 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
1978 if (!value) goto failed; 2000 if (!value) goto failed;
1979 if (PyObject_SetAttrString(result, "body", value) == -1) 2001 if (PyObject_SetAttrString(result, "body", value) == -1)