Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(36445)

Side by Side Diff: Python/ast.c

Issue 11682: PEP 380 reference implementation for 3.3
Patch Set: Created 7 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file includes functions to transform a concrete syntax tree (CST) to 2 * This file includes functions to transform a concrete syntax tree (CST) to
3 * an abstract syntax tree (AST). The main function is PyAST_FromNode(). 3 * an abstract syntax tree (AST). The main function is PyAST_FromNode().
4 * 4 *
5 */ 5 */
6 #include "Python.h" 6 #include "Python.h"
7 #include "Python-ast.h" 7 #include "Python-ast.h"
8 #include "node.h" 8 #include "node.h"
9 #include "ast.h" 9 #include "ast.h"
10 #include "token.h" 10 #include "token.h"
(...skipping 2351 matching lines...) Expand 10 before | Expand all | Expand 10 after
2362 case and_expr: 2362 case and_expr:
2363 case shift_expr: 2363 case shift_expr:
2364 case arith_expr: 2364 case arith_expr:
2365 case term: 2365 case term:
2366 if (NCH(n) == 1) { 2366 if (NCH(n) == 1) {
2367 n = CHILD(n, 0); 2367 n = CHILD(n, 0);
2368 goto loop; 2368 goto loop;
2369 } 2369 }
2370 return ast_for_binop(c, n); 2370 return ast_for_binop(c, n);
2371 case yield_expr: { 2371 case yield_expr: {
2372 node *an = NULL;
2373 node *en = NULL;
2374 int is_from = 0;
2372 expr_ty exp = NULL; 2375 expr_ty exp = NULL;
2373 if (NCH(n) == 2) { 2376 if (NCH(n) > 1)
2374 exp = ast_for_testlist(c, CHILD(n, 1)); 2377 an = CHILD(n, 1); /* yield_arg */
2378 if (an) {
2379 en = CHILD(an, NCH(an) - 1);
2380 if (NCH(an) == 2) {
2381 is_from = 1;
2382 exp = ast_for_expr(c, en);
2383 }
2384 else
2385 exp = ast_for_testlist(c, en);
2375 if (!exp) 2386 if (!exp)
2376 return NULL; 2387 return NULL;
2377 } 2388 }
2378 return Yield(exp, LINENO(n), n->n_col_offset, c->c_arena); 2389 return Yield(is_from, exp, LINENO(n), n->n_col_offset, c->c_arena);
2379 } 2390 }
2380 case factor: 2391 case factor:
2381 if (NCH(n) == 1) { 2392 if (NCH(n) == 1) {
2382 n = CHILD(n, 0); 2393 n = CHILD(n, 0);
2383 goto loop; 2394 goto loop;
2384 } 2395 }
2385 return ast_for_factor(c, n); 2396 return ast_for_factor(c, n);
2386 case power: 2397 case power:
2387 return ast_for_power(c, n); 2398 return ast_for_power(c, n);
2388 default: 2399 default:
2389 PyErr_Format(PyExc_SystemError, "unhandled expr: %d", TYPE(n)); 2400 PyErr_Format(PyExc_SystemError, "unhandled expr: %d", TYPE(n));
2390 return NULL; 2401 return NULL;
2391 } 2402 }
2392 /* should never get here unless if error is set */ 2403 /* should never get here unless if error is set */
2393 return NULL; 2404 return NULL;
2394 } 2405 }
2395 2406
2396 static expr_ty 2407 static expr_ty
2397 ast_for_call(struct compiling *c, const node *n, expr_ty func) 2408 ast_for_call(struct compiling *c, const node *n, expr_ty func)
2398 { 2409 {
2399 /* 2410 /*
2400 arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] 2411 arglist: (argument ',')* (argument [',']| '*' test [',' '**' test]
2401 | '**' test) 2412 | '**' test)
2402 argument: [test '='] test [comp_for] # Really [keyword '='] test 2413 argument: [test '='] (test) [comp_for] # Really [keyword '='] test
2403 */ 2414 */
2404 2415
2405 int i, nargs, nkeywords, ngens; 2416 int i, nargs, nkeywords, ngens;
2406 asdl_seq *args; 2417 asdl_seq *args;
2407 asdl_seq *keywords; 2418 asdl_seq *keywords;
2408 expr_ty vararg = NULL, kwarg = NULL; 2419 expr_ty vararg = NULL, kwarg = NULL;
2409 2420
2410 REQ(n, arglist); 2421 REQ(n, arglist);
2411 2422
2412 nargs = 0; 2423 nargs = 0;
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
2686 static stmt_ty 2697 static stmt_ty
2687 ast_for_flow_stmt(struct compiling *c, const node *n) 2698 ast_for_flow_stmt(struct compiling *c, const node *n)
2688 { 2699 {
2689 /* 2700 /*
2690 flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt 2701 flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt
2691 | yield_stmt 2702 | yield_stmt
2692 break_stmt: 'break' 2703 break_stmt: 'break'
2693 continue_stmt: 'continue' 2704 continue_stmt: 'continue'
2694 return_stmt: 'return' [testlist] 2705 return_stmt: 'return' [testlist]
2695 yield_stmt: yield_expr 2706 yield_stmt: yield_expr
2696 yield_expr: 'yield' testlist 2707 yield_expr: 'yield' testlist | 'yield' 'from' test
2697 raise_stmt: 'raise' [test [',' test [',' test]]] 2708 raise_stmt: 'raise' [test [',' test [',' test]]]
2698 */ 2709 */
2699 node *ch; 2710 node *ch;
2700 2711
2701 REQ(n, flow_stmt); 2712 REQ(n, flow_stmt);
2702 ch = CHILD(n, 0); 2713 ch = CHILD(n, 0);
2703 switch (TYPE(ch)) { 2714 switch (TYPE(ch)) {
2704 case break_stmt: 2715 case break_stmt:
2705 return Break(LINENO(n), n->n_col_offset, c->c_arena); 2716 return Break(LINENO(n), n->n_col_offset, c->c_arena);
2706 case continue_stmt: 2717 case continue_stmt:
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after
3849 goto onError; 3860 goto onError;
3850 } 3861 }
3851 } 3862 }
3852 } 3863 }
3853 return v; 3864 return v;
3854 3865
3855 onError: 3866 onError:
3856 Py_XDECREF(v); 3867 Py_XDECREF(v);
3857 return NULL; 3868 return NULL;
3858 } 3869 }
OLDNEW
« Objects/exceptions.c ('K') | « Parser/Python.asdl ('k') | Python/ceval.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+