Patch #1759: Backport of PEP 3129 class decorators

with some help from Georg
This commit is contained in:
Christian Heimes 2008-02-23 15:01:05 +00:00
parent b12f0b581a
commit 5224d28d38
15 changed files with 1591 additions and 1465 deletions

View file

@ -1498,7 +1498,7 @@ validate_small_stmt(node *tree)
/* compound_stmt:
* if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
* if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef | decorated
*/
static int
validate_compound_stmt(node *tree)
@ -1517,7 +1517,8 @@ validate_compound_stmt(node *tree)
|| (ntype == for_stmt)
|| (ntype == try_stmt)
|| (ntype == funcdef)
|| (ntype == classdef))
|| (ntype == classdef)
|| (ntype == decorated))
res = validate_node(tree);
else {
res = 0;
@ -1527,7 +1528,6 @@ validate_compound_stmt(node *tree)
return (res);
}
static int
validate_yield_or_testlist(node *tree)
{
@ -2558,28 +2558,40 @@ validate_decorators(node *tree)
/* funcdef:
*
* -6 -5 -4 -3 -2 -1
* [decorators] 'def' NAME parameters ':' suite
* -5 -4 -3 -2 -1
* 'def' NAME parameters ':' suite
*/
static int
validate_funcdef(node *tree)
{
int nch = NCH(tree);
int ok = (validate_ntype(tree, funcdef)
&& ((nch == 5) || (nch == 6))
&& (nch == 5)
&& validate_name(RCHILD(tree, -5), "def")
&& validate_ntype(RCHILD(tree, -4), NAME)
&& validate_colon(RCHILD(tree, -2))
&& validate_parameters(RCHILD(tree, -3))
&& validate_suite(RCHILD(tree, -1)));
if (ok && (nch == 6))
ok = validate_decorators(CHILD(tree, 0));
return ok;
}
/* decorated
* decorators (classdef | funcdef)
*/
static int
validate_decorated(node *tree)
{
int nch = NCH(tree);
int ok = (validate_ntype(tree, decorated)
&& (nch == 2)
&& validate_decorators(RCHILD(tree, -2))
&& (validate_funcdef(RCHILD(tree, -1))
|| validate_class(RCHILD(tree, -1)))
);
return ok;
}
static int
validate_lambdef(node *tree)
{
@ -2923,6 +2935,9 @@ validate_node(node *tree)
case classdef:
res = validate_class(tree);
break;
case decorated:
res = validate_decorated(tree);
break;
/*
* "Trivial" parse tree nodes.
* (Why did I call these trivial?)