~ubuntu-branches/ubuntu/saucy/golang/saucy

« back to all changes in this revision

Viewing changes to src/cmd/gc/go.y

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-07-08 05:52:37 UTC
  • mfrom: (29.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130708055237-at01839e0hp8z3ni
Tags: 2:1.1-1ubuntu1
016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
// |sed 's/.*   //' |9 fmt -l1 |sort |9 fmt -l50 | sed 's/^/%xxx                /'
38
38
 
39
39
%token  <val>   LLITERAL
40
 
%token  <i>     LASOP
41
 
%token  <sym>   LBREAK LCASE LCHAN LCOLAS LCONST LCONTINUE LDDD
 
40
%token  <i>     LASOP LCOLAS
 
41
%token  <sym>   LBREAK LCASE LCHAN LCONST LCONTINUE LDDD
42
42
%token  <sym>   LDEFAULT LDEFER LELSE LFALL LFOR LFUNC LGO LGOTO
43
43
%token  <sym>   LIF LIMPORT LINTERFACE LMAP LNAME
44
44
%token  <sym>   LPACKAGE LRANGE LRETURN LSELECT LSTRUCT LSWITCH
54
54
%type   <node>  stmt ntype
55
55
%type   <node>  arg_type
56
56
%type   <node>  case caseblock
57
 
%type   <node>  compound_stmt dotname embed expr complitexpr
 
57
%type   <node>  compound_stmt dotname embed expr complitexpr bare_complitexpr
58
58
%type   <node>  expr_or_type
59
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
61
%type   <node>  interfacedcl keyval labelname name
62
62
%type   <node>  name_or_type non_expr_type
63
63
%type   <node>  new_name dcl_name oexpr typedclname
70
70
 
71
71
%type   <list>  xdcl fnbody fnres loop_body dcl_name_list
72
72
%type   <list>  new_name_list expr_list keyval_list braced_keyval_list expr_or_type_list xdcl_list
73
 
%type   <list>  oexpr_list caseblock_list stmt_list oarg_type_list_ocomma arg_type_list
 
73
%type   <list>  oexpr_list caseblock_list elseif elseif_list else stmt_list oarg_type_list_ocomma arg_type_list
74
74
%type   <list>  interfacedcl_list vardcl vardcl_list structdcl structdcl_list
75
75
%type   <list>  common_dcl constdcl constdcl1 constdcl_list typedcl_list
76
76
 
251
251
                } else if(strcmp(importpkg->name, $2->name) != 0)
252
252
                        yyerror("conflicting names %s and %s for package \"%Z\"", importpkg->name, $2->name, importpkg->path);
253
253
                importpkg->direct = 1;
254
 
                
 
254
                importpkg->safe = curio.importsafe;
 
255
 
255
256
                if(safemode && !curio.importsafe)
256
257
                        yyerror("cannot import unsafe package \"%Z\"", importpkg->path);
257
258
        }
405
406
        expr
406
407
        {
407
408
                $$ = $1;
 
409
 
 
410
                // These nodes do not carry line numbers.
 
411
                // Since a bare name used as an expression is an error,
 
412
                // introduce a wrapper node to give the correct line.
 
413
                switch($$->op) {
 
414
                case ONAME:
 
415
                case ONONAME:
 
416
                case OTYPE:
 
417
                case OPACK:
 
418
                case OLITERAL:
 
419
                        $$ = nod(OPAREN, $$, N);
 
420
                        $$->implicit = 1;
 
421
                        break;
 
422
                }
408
423
        }
409
424
|       expr LASOP expr
410
425
        {
437
452
                                $$->left = dclname($1->n->sym);  // it's a colas, so must not re-use an oldname.
438
453
                        break;
439
454
                }
440
 
                $$ = colas($1, $3);
 
455
                $$ = colas($1, $3, $2);
441
456
        }
442
457
|       expr LINC
443
458
        {
496
511
                // done in casebody()
497
512
                markdcl();
498
513
                $$ = nod(OXCASE, N, N);
499
 
                $$->list = list1(colas($2, list1($4)));
 
514
                $$->list = list1(colas($2, list1($4), $3));
500
515
        }
501
516
|       LDEFAULT ':'
502
517
        {
522
537
        }
523
538
        stmt_list '}'
524
539
        {
525
 
                $$ = liststmt($3);
 
540
                if($3 == nil)
 
541
                        $$ = nod(OEMPTY, N, N);
 
542
                else
 
543
                        $$ = liststmt($3);
526
544
                popdcl();
527
545
        }
528
546
 
661
679
        {
662
680
                $3->nbody = $5;
663
681
        }
664
 
        else
 
682
        elseif_list else
665
683
        {
 
684
                Node *n;
 
685
                NodeList *nn;
 
686
 
 
687
                $$ = $3;
 
688
                n = $3;
666
689
                popdcl();
667
 
                $$ = $3;
668
 
                if($7 != N)
669
 
                        $$->nelse = list1($7);
 
690
                for(nn = concat($7, $8); nn; nn = nn->next) {
 
691
                        if(nn->n->op == OIF)
 
692
                                popdcl();
 
693
                        n->nelse = list1(nn->n);
 
694
                        n = nn->n;
 
695
                }
 
696
        }
 
697
 
 
698
elseif:
 
699
        LELSE LIF 
 
700
        {
 
701
                markdcl();
 
702
        }
 
703
        if_header loop_body
 
704
        {
 
705
                if($4->ntest == N)
 
706
                        yyerror("missing condition in if statement");
 
707
                $4->nbody = $5;
 
708
                $$ = list1($4);
 
709
        }
 
710
 
 
711
elseif_list:
 
712
        {
 
713
                $$ = nil;
 
714
        }
 
715
|       elseif_list elseif
 
716
        {
 
717
                $$ = concat($1, $2);
670
718
        }
671
719
 
672
720
else:
673
721
        {
674
 
                $$ = N;
675
 
        }
676
 
|       LELSE if_stmt
677
 
        {
678
 
                $$ = $2;
 
722
                $$ = nil;
679
723
        }
680
724
|       LELSE compound_stmt
681
725
        {
682
 
                $$ = $2;
 
726
                NodeList *node;
 
727
                
 
728
                node = mal(sizeof *node);
 
729
                node->n = $2;
 
730
                node->end = node;
 
731
                $$ = node;
683
732
        }
684
733
 
685
734
switch_stmt:
902
951
                $$ = nod(OSLICE, $1, nod(OKEY, $3, $5));
903
952
        }
904
953
|       pseudocall
905
 
|       convtype '(' expr ')'
 
954
|       convtype '(' expr ocomma ')'
906
955
        {
907
956
                // conversion
908
957
                $$ = nod(OCALL, $1, N);
943
992
                $$ = nod(OKEY, $1, $3);
944
993
        }
945
994
 
 
995
bare_complitexpr:
 
996
        expr
 
997
        {
 
998
                // These nodes do not carry line numbers.
 
999
                // Since a composite literal commonly spans several lines,
 
1000
                // the line number on errors may be misleading.
 
1001
                // Introduce a wrapper node to give the correct line.
 
1002
                $$ = $1;
 
1003
                switch($$->op) {
 
1004
                case ONAME:
 
1005
                case ONONAME:
 
1006
                case OTYPE:
 
1007
                case OPACK:
 
1008
                case OLITERAL:
 
1009
                        $$ = nod(OPAREN, $$, N);
 
1010
                        $$->implicit = 1;
 
1011
                }
 
1012
        }
 
1013
|       '{' start_complit braced_keyval_list '}'
 
1014
        {
 
1015
                $$ = $2;
 
1016
                $$->list = $3;
 
1017
        }
 
1018
 
946
1019
complitexpr:
947
1020
        expr
948
1021
|       '{' start_complit braced_keyval_list '}'
966
1039
                case OPACK:
967
1040
                case OTYPE:
968
1041
                case OLITERAL:
 
1042
                case OTYPESW:
969
1043
                        $$ = nod(OPAREN, $$, N);
970
1044
                }
971
1045
        }
1030
1104
hidden_importsym:
1031
1105
        '@' LLITERAL '.' LNAME
1032
1106
        {
 
1107
                Pkg *p;
 
1108
 
1033
1109
                if($2.u.sval->len == 0)
1034
 
                        $$ = pkglookup($4->name, importpkg);
1035
 
                else
1036
 
                        $$ = pkglookup($4->name, mkpkg($2.u.sval));
 
1110
                        p = importpkg;
 
1111
                else {
 
1112
                        if(isbadimport($2.u.sval))
 
1113
                                errorexit();
 
1114
                        p = mkpkg($2.u.sval);
 
1115
                }
 
1116
                $$ = pkglookup($4->name, p);
1037
1117
        }
1038
1118
 
1039
1119
name:
1201
1281
                $$ = $2;
1202
1282
                if($$ == N)
1203
1283
                        break;
 
1284
                if(noescape && $3 != nil)
 
1285
                        yyerror("can only use //go:noescape with external func implementations");
1204
1286
                $$->nbody = $3;
1205
1287
                $$->endlineno = lineno;
 
1288
                $$->noescape = noescape;
1206
1289
                funcbody($$);
1207
1290
        }
1208
1291
 
1269
1352
                $$->nname = methodname1($$->shortname, rcvr->right);
1270
1353
                $$->nname->defn = $$;
1271
1354
                $$->nname->ntype = t;
 
1355
                $$->nname->nointerface = nointerface;
1272
1356
                declare($$->nname, PFUNC);
1273
1357
 
1274
1358
                funchdr($$);
1287
1371
 
1288
1372
                importsym(s, ONAME);
1289
1373
                if(s->def != N && s->def->op == ONAME) {
1290
 
                        if(eqtype(t, s->def->type))
 
1374
                        if(eqtype(t, s->def->type)) {
 
1375
                                dclcontext = PDISCARD;  // since we skip funchdr below
1291
1376
                                break;
 
1377
                        }
1292
1378
                        yyerror("inconsistent definition for func %S during import\n\t%T\n\t%T", s, s->def->type, t);
1293
1379
                }
1294
1380
 
1304
1390
                $$->type = functype($2->n, $6, $8);
1305
1391
 
1306
1392
                checkwidth($$->type);
1307
 
                addmethod($4, $$->type, 0);
 
1393
                addmethod($4, $$->type, 0, nointerface);
 
1394
                nointerface = 0;
1308
1395
                funchdr($$);
1309
1396
                
1310
1397
                // inl.c's inlnode in on a dotmeth node expects to find the inlineable body as
1381
1468
                $$ = concat($1, $2);
1382
1469
                if(nsyntaxerrors == 0)
1383
1470
                        testdclstack();
 
1471
                nointerface = 0;
 
1472
                noescape = 0;
1384
1473
        }
1385
1474
 
1386
1475
vardcl_list:
1719
1808
        {
1720
1809
                $$ = list1($1);
1721
1810
        }
1722
 
|       complitexpr
 
1811
|       bare_complitexpr
1723
1812
        {
1724
1813
                $$ = list1($1);
1725
1814
        }
1727
1816
        {
1728
1817
                $$ = list($1, $3);
1729
1818
        }
1730
 
|       keyval_list ',' complitexpr
 
1819
|       keyval_list ',' bare_complitexpr
1731
1820
        {
1732
1821
                $$ = list($1, $3);
1733
1822
        }
1818
1907
        }
1819
1908
|       LFUNC hidden_fndcl fnbody ';'
1820
1909
        {
1821
 
                if($2 == N)
 
1910
                if($2 == N) {
 
1911
                        dclcontext = PEXTERN;  // since we skip the funcbody below
1822
1912
                        break;
 
1913
                }
1823
1914
 
1824
1915
                $2->inl = $3;
1825
1916
 
1828
1919
 
1829
1920
                if(debug['E']) {
1830
1921
                        print("import [%Z] func %lN \n", importpkg->path, $2);
1831
 
                        if(debug['l'] > 2 && $2->inl)
 
1922
                        if(debug['m'] > 2 && $2->inl)
1832
1923
                                print("inl body:%+H\n", $2->inl);
1833
1924
                }
1834
1925
        }
2039
2130
                        mpaddfixfix($2->val.u.xval, $4->val.u.xval, 0);
2040
2131
                        break;
2041
2132
                }
 
2133
                $4->val.u.cval->real = $4->val.u.cval->imag;
 
2134
                mpmovecflt(&$4->val.u.cval->imag, 0.0);
2042
2135
                $$ = nodcplxlit($2->val, $4->val);
2043
2136
        }
2044
2137