[Python-checkins] python/dist/src/Python newcompile.c, 1.1.2.75, 1.1.2.76

nnorwitz at users.sourceforge.net nnorwitz at users.sourceforge.net
Sat Mar 20 12:10:49 EST 2004


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17930/Python
Modified Files:
 Tag: ast-branch
	newcompile.c 
Log Message:
Get docstrings working for classes
Index: newcompile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v
retrieving revision 1.1.2.75
retrieving revision 1.1.2.76
diff -C2 -d -r1.1.2.75 -r1.1.2.76
*** newcompile.c	16 Feb 2004 22:11:34 -0000	1.1.2.75
--- newcompile.c	20 Mar 2004 17:10:46 -0000	1.1.2.76
***************
*** 157,160 ****
--- 157,161 ----
 
 static char *opnames[];
+ static PyObject *__doc__;
 
 int
***************
*** 204,207 ****
--- 205,214 ----
 	PyCodeObject *co = NULL;
 
+ if (!__doc__) {
+ __doc__ = PyString_InternFromString("__doc__");
+ if (!__doc__)
+ goto error;
+ }
+ 
 	if (!compiler_init(&c))
 		goto error;
***************
*** 911,917 ****
 
 static int
 compiler_class(struct compiler *c, stmt_ty s)
 {
! 	int n;
 	PyCodeObject *co;
 PyObject *str;
--- 918,932 ----
 
 static int
+ compiler_isdocstring(stmt_ty s)
+ {
+ if (s->kind != Expr_kind)
+ return 0;
+ return s->v.Expr.value->kind == Str_kind;
+ }
+ 
+ static int
 compiler_class(struct compiler *c, stmt_ty s)
 {
! 	int n, i;
 	PyCodeObject *co;
 PyObject *str;
***************
*** 939,944 ****
 Py_DECREF(str);
 
! /* XXX: doc strings go POP_TOP, instead of STORE_NAME (__doc__) */
! 	VISIT_SEQ(c, stmt, s->v.ClassDef.body);
 	ADDOP(c, LOAD_LOCALS);
 	ADDOP(c, RETURN_VALUE);
--- 954,969 ----
 Py_DECREF(str);
 
! stmt_ty st = asdl_seq_GET(s->v.ClassDef.body, 0);
! i = 0;
! if (compiler_isdocstring(st)) {
! i++;
! VISIT(c, expr, st->v.Expr.value);
! if (!compiler_nameop(c, __doc__, Store))
! return 0;
! }
! 
! for (; i < asdl_seq_LEN(s->v.ClassDef.body); i++)
! VISIT(c, stmt, asdl_seq_GET(s->v.ClassDef.body, i));
! 
 	ADDOP(c, LOAD_LOCALS);
 	ADDOP(c, RETURN_VALUE);


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /