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

Delta Between Two Patch Sets: src/cmd/gc/go.y

Issue 6905055: cmd/gc: introduce a Field type to reduce Nodes used in ...
Left Patch Set: diff -r 6b602ab487d6 https://go.googlecode.com/hg/ Created 11 years, 3 months ago
Right Patch Set: diff -r 7bc28d72d49c https://go.googlecode.com/hg/ Created 11 years, 2 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/cmd/gc/go.h ('k') | src/cmd/gc/reflect.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 %token LANDAND LANDNOT LBODY LCOMM LDEC LEQ LGE LGT 49 %token LANDAND LANDNOT LBODY LCOMM LDEC LEQ LGE LGT
50 %token LIGNORE LINC LLE LLSH LLT LNE LOROR LRSH 50 %token LIGNORE LINC LLE LLSH LLT LNE LOROR LRSH
51 51
52 %type <i> lbrace import_here 52 %type <i> lbrace import_here
53 %type <sym> sym packname 53 %type <sym> sym packname
54 %type <val> oliteral 54 %type <val> oliteral
55 55
56 %type <node> stmt ntype 56 %type <node> stmt ntype
57 %type <node> arg_type 57 %type <node> arg_type
58 %type <node> case caseblock 58 %type <node> case caseblock
59 %type» <node>» compound_stmt dotname embed expr complitexpr 59 %type» <node>» compound_stmt dotname embed expr complitexpr bare_complitexpr
60 %type <node> expr_or_type 60 %type <node> expr_or_type
61 %type <node> fndcl hidden_fndcl fnliteral 61 %type <node> fndcl hidden_fndcl fnliteral
62 %type <node> for_body for_header for_stmt if_header if_stmt non_dcl_stmt 62 %type <node> for_body for_header for_stmt if_header if_stmt non_dcl_stmt
63 %type <node> interfacedcl keyval labelname name 63 %type <node> interfacedcl keyval labelname name
64 %type <node> name_or_type non_expr_type 64 %type <node> name_or_type non_expr_type
65 %type <node> new_name dcl_name oexpr typedclname 65 %type <node> new_name dcl_name oexpr typedclname
66 %type <node> onew_name 66 %type <node> onew_name
67 %type <node> osimple_stmt pexpr pexpr_no_paren 67 %type <node> osimple_stmt pexpr pexpr_no_paren
68 %type <node> pseudocall range_stmt select_stmt 68 %type <node> pseudocall range_stmt select_stmt
69 %type <node> simple_stmt 69 %type <node> simple_stmt
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 // make node early so we get the right line number. 970 // make node early so we get the right line number.
971 $$ = nod(OCOMPLIT, N, N); 971 $$ = nod(OCOMPLIT, N, N);
972 } 972 }
973 973
974 keyval: 974 keyval:
975 expr ':' complitexpr 975 expr ':' complitexpr
976 { 976 {
977 $$ = nod(OKEY, $1, $3); 977 $$ = nod(OKEY, $1, $3);
978 } 978 }
979 979
980 bare_complitexpr:
981 expr
982 {
983 // These nodes do not carry line numbers.
984 // Since a composite literal commonly spans several lines,
985 // the line number on errors may be misleading.
986 // Introduce a wrapper node to give the correct line.
987 $$ = $1;
988 switch($$->op) {
989 case ONAME:
990 case ONONAME:
991 case OTYPE:
992 case OPACK:
993 case OLITERAL:
994 $$ = nod(OPAREN, $$, N);
995 }
996 }
997 | '{' start_complit braced_keyval_list '}'
998 {
999 $$ = $2;
1000 $$->list = $3;
1001 }
1002
980 complitexpr: 1003 complitexpr:
981 expr 1004 expr
982 | '{' start_complit braced_keyval_list '}' 1005 | '{' start_complit braced_keyval_list '}'
983 { 1006 {
984 $$ = $2; 1007 $$ = $2;
985 $$->list = $3; 1008 $$->list = $3;
986 } 1009 }
987 1010
988 pexpr: 1011 pexpr:
989 pexpr_no_paren 1012 pexpr_no_paren
990 | '(' expr_or_type ')' 1013 | '(' expr_or_type ')'
991 { 1014 {
992 $$ = $2; 1015 $$ = $2;
993 ················ 1016 ················
994 // Need to know on lhs of := whether there are ( ). 1017 // Need to know on lhs of := whether there are ( ).
995 // Don't bother with the OPAREN in other cases: 1018 // Don't bother with the OPAREN in other cases:
996 // it's just a waste of memory and time. 1019 // it's just a waste of memory and time.
997 switch($$->op) { 1020 switch($$->op) {
998 case ONAME: 1021 case ONAME:
999 case ONONAME: 1022 case ONONAME:
1000 case OPACK: 1023 case OPACK:
1001 case OTYPE: 1024 case OTYPE:
1002 case OLITERAL: 1025 case OLITERAL:
1026 case OTYPESW:
1003 $$ = nod(OPAREN, $$, N); 1027 $$ = nod(OPAREN, $$, N);
1004 } 1028 }
1005 } 1029 }
1006 1030
1007 expr_or_type: 1031 expr_or_type:
1008 expr 1032 expr
1009 | non_expr_type %prec PreferToRightParen 1033 | non_expr_type %prec PreferToRightParen
1010 1034
1011 name_or_type: 1035 name_or_type:
1012 ntype 1036 ntype
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 1341
1318 hidden_fndcl: 1342 hidden_fndcl:
1319 hidden_pkg_importsym '(' ohidden_funarg_list ')' ohidden_funres 1343 hidden_pkg_importsym '(' ohidden_funarg_list ')' ohidden_funres
1320 { 1344 {
1321 Sym *s; 1345 Sym *s;
1322 Type *t; 1346 Type *t;
1323 1347
1324 $$ = N; 1348 $$ = N;
1325 1349
1326 s = $1; 1350 s = $1;
1327 t = functype(F, $3, $5);
1328
1329 importsym(s, ONAME); 1351 importsym(s, ONAME);
1330 if(s->def != N && s->def->op == ONAME) { 1352 if(s->def != N && s->def->op == ONAME) {
1331 » » » if(eqtype(t, s->def->type)) { 1353 » » » if(eqfunctype(s->def->type, nil, $3, $5)) {
1332 dclcontext = PDISCARD; // since we skip funchdr below 1354 dclcontext = PDISCARD; // since we skip funchdr below
1333 break; 1355 break;
1334 } 1356 }
1357 t = functype(F, $3, $5);
1335 yyerror("inconsistent definition for func %S during impo rt\n\t%T\n\t%T", s, s->def->type, t); 1358 yyerror("inconsistent definition for func %S during impo rt\n\t%T\n\t%T", s, s->def->type, t);
1336 } 1359 }
1337 1360
1361 t = functype(F, $3, $5);
1338 $$ = newname(s); 1362 $$ = newname(s);
1339 $$->type = t; 1363 $$->type = t;
1340 declare($$, PFUNC); 1364 declare($$, PFUNC);
1341 1365
1342 funchdr($$); 1366 funchdr($$);
1343 } 1367 }
1344 | '(' hidden_funarg_list ')' sym '(' ohidden_funarg_list ')' ohidden_funre s 1368 | '(' hidden_funarg_list ')' sym '(' ohidden_funarg_list ')' ohidden_funre s
1345 { 1369 {
1346 $$ = N; 1370 $$ = N;
1347 if(!mustaddmethod($4, $2, $6, $8)) { 1371 if(!mustaddmethod($4, $2, $6, $8)) {
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 } 1786 }
1763 1787
1764 /* 1788 /*
1765 * list of combo of keyval and val 1789 * list of combo of keyval and val
1766 */ 1790 */
1767 keyval_list: 1791 keyval_list:
1768 keyval 1792 keyval
1769 { 1793 {
1770 $$ = list1($1); 1794 $$ = list1($1);
1771 } 1795 }
1772 |» complitexpr 1796 |» bare_complitexpr
1773 { 1797 {
1774 $$ = list1($1); 1798 $$ = list1($1);
1775 } 1799 }
1776 | keyval_list ',' keyval 1800 | keyval_list ',' keyval
1777 { 1801 {
1778 $$ = list($1, $3); 1802 $$ = list($1, $3);
1779 } 1803 }
1780 |» keyval_list ',' complitexpr 1804 |» keyval_list ',' bare_complitexpr
1781 { 1805 {
1782 $$ = list($1, $3); 1806 $$ = list($1, $3);
1783 } 1807 }
1784 1808
1785 braced_keyval_list: 1809 braced_keyval_list:
1786 { 1810 {
1787 $$ = nil; 1811 $$ = nil;
1788 } 1812 }
1789 | keyval_list ocomma 1813 | keyval_list ocomma
1790 { 1814 {
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
2130 static void 2154 static void
2131 fixlbrace(int lbr) 2155 fixlbrace(int lbr)
2132 { 2156 {
2133 // If the opening brace was an LBODY, 2157 // If the opening brace was an LBODY,
2134 // set up for another one now that we're done. 2158 // set up for another one now that we're done.
2135 // See comment in lex.c about loophack. 2159 // See comment in lex.c about loophack.
2136 if(lbr == LBODY) 2160 if(lbr == LBODY)
2137 loophack = 1; 2161 loophack = 1;
2138 } 2162 }
2139 2163
LEFTRIGHT

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