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

Side by Side Diff: src/cmd/gc/go.y

Issue 6847078: code review 6847078: cmd/gc: do not overflow parser stack on a long chain of... (Closed)
Patch Set: diff -r d1f2902e0f0d https://go.googlecode.com/hg/ Created 11 years, 3 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
« no previous file with comments | « no previous file | src/cmd/gc/y.tab.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 /* 5 /*
6 * Go language grammar. 6 * Go language grammar.
7 * 7 *
8 * The Go semicolon rules are: 8 * The Go semicolon rules are:
9 * 9 *
10 * 1. all statements and declarations are terminated by semicolons. 10 * 1. all statements and declarations are terminated by semicolons.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 %type <i> lbrace import_here 50 %type <i> lbrace import_here
51 %type <sym> sym packname 51 %type <sym> sym packname
52 %type <val> oliteral 52 %type <val> oliteral
53 53
54 %type <node> stmt ntype 54 %type <node> stmt ntype
55 %type <node> arg_type 55 %type <node> arg_type
56 %type <node> case caseblock 56 %type <node> case caseblock
57 %type <node> compound_stmt dotname embed expr complitexpr 57 %type <node> compound_stmt dotname embed expr complitexpr
58 %type <node> expr_or_type 58 %type <node> expr_or_type
59 %type <node> fndcl hidden_fndcl fnliteral 59 %type <node> fndcl hidden_fndcl fnliteral
60 %type» <node>» for_body for_header for_stmt if_header if_stmt else non_dcl_stmt 60 %type» <node>» for_body for_header for_stmt if_header if_stmt non_dcl_stmt
61 %type <node> interfacedcl keyval labelname name 61 %type <node> interfacedcl keyval labelname name
62 %type <node> name_or_type non_expr_type 62 %type <node> name_or_type non_expr_type
63 %type <node> new_name dcl_name oexpr typedclname 63 %type <node> new_name dcl_name oexpr typedclname
64 %type <node> onew_name 64 %type <node> onew_name
65 %type <node> osimple_stmt pexpr pexpr_no_paren 65 %type <node> osimple_stmt pexpr pexpr_no_paren
66 %type <node> pseudocall range_stmt select_stmt 66 %type <node> pseudocall range_stmt select_stmt
67 %type <node> simple_stmt 67 %type <node> simple_stmt
68 %type <node> switch_stmt uexpr 68 %type <node> switch_stmt uexpr
69 %type <node> xfndcl typedcl start_complit 69 %type <node> xfndcl typedcl start_complit
70 70
71 %type <list> xdcl fnbody fnres loop_body dcl_name_list 71 %type <list> xdcl fnbody fnres loop_body dcl_name_list
72 %type <list> new_name_list expr_list keyval_list braced_keyval_list expr_or_t ype_list xdcl_list 72 %type <list> new_name_list expr_list keyval_list braced_keyval_list expr_or_t ype_list xdcl_list
73 %type» <list>» oexpr_list caseblock_list stmt_list oarg_type_list_ocomma arg_ty pe_list 73 %type» <list>» oexpr_list caseblock_list elseif elseif_list else stmt_list oarg _type_list_ocomma arg_type_list
74 %type <list> interfacedcl_list vardcl vardcl_list structdcl structdcl_list 74 %type <list> interfacedcl_list vardcl vardcl_list structdcl structdcl_list
75 %type <list> common_dcl constdcl constdcl1 constdcl_list typedcl_list 75 %type <list> common_dcl constdcl constdcl1 constdcl_list typedcl_list
76 76
77 %type <node> convtype comptype dotdotdot 77 %type <node> convtype comptype dotdotdot
78 %type <node> indcl interfacetype structtype ptrtype 78 %type <node> indcl interfacetype structtype ptrtype
79 %type <node> recvchantype non_recvchantype othertype fnret_type fntype 79 %type <node> recvchantype non_recvchantype othertype fnret_type fntype
80 80
81 %type <sym> hidden_importsym hidden_pkg_importsym 81 %type <sym> hidden_importsym hidden_pkg_importsym
82 82
83 %type <node> hidden_constant hidden_literal hidden_funarg 83 %type <node> hidden_constant hidden_literal hidden_funarg
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 } 654 }
655 if_header 655 if_header
656 { 656 {
657 if($3->ntest == N) 657 if($3->ntest == N)
658 yyerror("missing condition in if statement"); 658 yyerror("missing condition in if statement");
659 } 659 }
660 loop_body 660 loop_body
661 { 661 {
662 $3->nbody = $5; 662 $3->nbody = $5;
663 } 663 }
664 » else 664 » elseif_list else
665 { 665 {
666 Node *n;
667 NodeList *nn;
668
669 $$ = $3;
670 n = $3;
666 popdcl(); 671 popdcl();
667 » » $$ = $3; 672 » » for(nn = concat($7, $8); nn; nn = nn->next) {
668 » » if($7 != N) 673 » » » if(nn->n->op == OIF)
669 » » » $$->nelse = list1($7); 674 » » » » popdcl();
675 » » » n->nelse = list1(nn->n);
676 » » » n = nn->n;
677 » » }
678 » }
679
680 elseif:
681 » LELSE LIF·
682 » {
683 » » markdcl();
684 » }
685 » if_header loop_body
686 » {
687 » » if($4->ntest == N)
688 » » » yyerror("missing condition in if statement");
689 » » $4->nbody = $5;
690 » » $$ = list1($4);
691 » }
692
693 elseif_list:
694 » {
695 » » $$ = nil;
696 » }
697 |» elseif_list elseif
698 » {
699 » » $$ = concat($1, $2);
670 } 700 }
671 701
672 else: 702 else:
673 { 703 {
674 » » $$ = N; 704 » » $$ = nil;
675 » }
676 |» LELSE if_stmt
677 » {
678 » » $$ = $2;
679 } 705 }
680 | LELSE compound_stmt 706 | LELSE compound_stmt
681 { 707 {
682 » » $$ = $2; 708 » » NodeList *node;
709 » »·······
710 » » node = mal(sizeof *node);
711 » » node->n = $2;
712 » » node->end = node;
713 » » $$ = node;
683 } 714 }
684 715
685 switch_stmt: 716 switch_stmt:
686 LSWITCH 717 LSWITCH
687 { 718 {
688 markdcl(); 719 markdcl();
689 } 720 }
690 if_header 721 if_header
691 { 722 {
692 Node *n; 723 Node *n;
(...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after
2095 static void 2126 static void
2096 fixlbrace(int lbr) 2127 fixlbrace(int lbr)
2097 { 2128 {
2098 // If the opening brace was an LBODY, 2129 // If the opening brace was an LBODY,
2099 // set up for another one now that we're done. 2130 // set up for another one now that we're done.
2100 // See comment in lex.c about loophack. 2131 // See comment in lex.c about loophack.
2101 if(lbr == LBODY) 2132 if(lbr == LBODY)
2102 loophack = 1; 2133 loophack = 1;
2103 } 2134 }
2104 2135
OLDNEW
« no previous file with comments | « no previous file | src/cmd/gc/y.tab.h » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b