~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/cmd/gc/sinit.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
        for(l=n->list; l; l=l->next)
38
38
                init1(l->n, out);
39
39
 
 
40
        if(n->left && n->type && n->left->op == OTYPE && n->class == PFUNC) {
 
41
                // Methods called as Type.Method(receiver, ...).
 
42
                // Definitions for method expressions are stored in type->nname.
 
43
                init1(n->type->nname, out);
 
44
        }
 
45
 
40
46
        if(n->op != ONAME)
41
47
                return;
42
48
        switch(n->class) {
44
50
        case PFUNC:
45
51
                break;
46
52
        default:
47
 
                if(isblank(n) && n->defn != N && n->defn->initorder == InitNotStarted) {
48
 
                        n->defn->initorder = InitDone;
49
 
                        *out = list(*out, n->defn);
 
53
                if(isblank(n) && n->curfn == N && n->defn != N && n->defn->initorder == InitNotStarted) {
 
54
                        // blank names initialization is part of init() but not
 
55
                        // when they are inside a function.
 
56
                        break;
50
57
                }
51
58
                return;
52
59
        }
56
63
        if(n->initorder == InitPending) {
57
64
                if(n->class == PFUNC)
58
65
                        return;
59
 
                
 
66
 
60
67
                // if there have already been errors printed,
61
68
                // those errors probably confused us and
62
69
                // there might not be a loop.  let the user
78
85
        }
79
86
        n->initorder = InitPending;
80
87
        l = malloc(sizeof *l);
 
88
        if(l == nil) {
 
89
                flusherrors();
 
90
                yyerror("out of memory");
 
91
                errorexit();
 
92
        }
81
93
        l->next = initlist;
82
94
        l->n = n;
83
95
        l->end = nil;
97
109
                case OAS:
98
110
                        if(n->defn->left != n)
99
111
                                goto bad;
 
112
                        if(isblank(n->defn->left) && candiscard(n->defn->right)) {
 
113
                                n->defn->op = OEMPTY;
 
114
                                n->defn->left = N;
 
115
                                n->defn->right = N;
 
116
                                break;
 
117
                        }
 
118
 
100
119
                /*
101
120
                        n->defn->dodata = 1;
102
121
                        init1(n->defn->right, out);
109
128
                                init2(n->defn->right, out);
110
129
                                if(debug['j'])
111
130
                                        print("%S\n", n->sym);
112
 
                                if(!staticinit(n, out)) {
113
 
if(debug['%']) dump("nonstatic", n->defn);
 
131
                                if(isblank(n) || !staticinit(n, out)) {
 
132
                                        if(debug['%']) dump("nonstatic", n->defn);
114
133
                                        *out = list(*out, n->defn);
115
134
                                }
116
135
                        } else if(0) {
131
150
                        n->defn->initorder = InitDone;
132
151
                        for(l=n->defn->rlist; l; l=l->next)
133
152
                                init1(l->n, out);
 
153
                        if(debug['%']) dump("nonstatic", n->defn);
134
154
                        *out = list(*out, n->defn);
135
155
                        break;
136
156
                }
167
187
        init2list(n->rlist, out);
168
188
        init2list(n->nbody, out);
169
189
        init2list(n->nelse, out);
 
190
        
 
191
        if(n->op == OCLOSURE)
 
192
                init2list(n->closure->nbody, out);
 
193
        if(n->op == ODOTMETH)
 
194
                init2(n->type->nname, out);
170
195
}
171
196
 
172
197
static void
291
316
                        n1.xoffset = l->xoffset + Array_array;
292
317
                        gdata(&n1, nod(OADDR, a, N), widthptr);
293
318
                        n1.xoffset = l->xoffset + Array_nel;
294
 
                        gdata(&n1, r->right, 4);
 
319
                        gdata(&n1, r->right, widthint);
295
320
                        n1.xoffset = l->xoffset + Array_cap;
296
 
                        gdata(&n1, r->right, 4);
 
321
                        gdata(&n1, r->right, widthint);
297
322
                        return 1;
298
323
                }
299
324
                // fall through
394
419
                        n1.xoffset = l->xoffset + Array_array;
395
420
                        gdata(&n1, nod(OADDR, a, N), widthptr);
396
421
                        n1.xoffset = l->xoffset + Array_nel;
397
 
                        gdata(&n1, r->right, 4);
 
422
                        gdata(&n1, r->right, widthint);
398
423
                        n1.xoffset = l->xoffset + Array_cap;
399
 
                        gdata(&n1, r->right, 4);
 
424
                        gdata(&n1, r->right, widthint);
400
425
                        // Fall through to init underlying array.
401
426
                        l = a;
402
427
                }
747
772
                index = r->left;
748
773
                value = r->right;
749
774
                a = nod(OINDEX, var, index);
750
 
                a->etype = 1;   // no bounds checking
 
775
                a->bounded = 1;
751
776
                // TODO need to check bounds?
752
777
 
753
778
                switch(value->op) {
778
803
{
779
804
        Node *r, *a;
780
805
        NodeList *l;
781
 
        int nerr, b;
 
806
        int nerr;
 
807
        int64 b;
782
808
        Type *t, *tk, *tv, *t1;
783
809
        Node *vstat, *index, *value;
784
810
        Sym *syma, *symb;
879
905
                index = temp(types[TINT]);
880
906
 
881
907
                a = nod(OINDEX, vstat, index);
882
 
                a->etype = 1;   // no bounds checking
 
908
                a->bounded = 1;
883
909
                a = nod(ODOT, a, newname(symb));
884
910
 
885
911
                r = nod(OINDEX, vstat, index);
886
 
                r->etype = 1;   // no bounds checking
 
912
                r->bounded = 1;
887
913
                r = nod(ODOT, r, newname(syma));
888
914
                r = nod(OINDEX, var, r);
889
915
 
930
956
anylit(int ctxt, Node *n, Node *var, NodeList **init)
931
957
{
932
958
        Type *t;
933
 
        Node *a, *vstat;
 
959
        Node *a, *vstat, *r;
934
960
 
935
961
        t = n->type;
936
962
        switch(n->op) {
941
967
                if(!isptr[t->etype])
942
968
                        fatal("anylit: not ptr");
943
969
 
944
 
                a = nod(OAS, var, callnew(t->type));
 
970
                r = nod(ONEW, N, N);
 
971
                r->typecheck = 1;
 
972
                r->type = t;
 
973
                r->esc = n->esc;
 
974
                walkexpr(&r, init);
 
975
 
 
976
                a = nod(OAS, var, r);
 
977
 
945
978
                typecheck(&a, Etop);
946
979
                *init = list(*init, a);
947
980
 
1112
1145
                l = getlit(n->right);
1113
1146
                if(l < 0)
1114
1147
                        break;
1115
 
                nam->xoffset += l*n->type->width;
 
1148
                // Check for overflow.
 
1149
                if(n->type->width != 0 && MAXWIDTH/n->type->width <= l)
 
1150
                        break;
 
1151
                nam->xoffset += l*n->type->width;
1116
1152
                nam->type = n->type;
1117
1153
                return 1;
1118
1154
        }
1223
1259
        gdata(&nam, nl, types[tptr]->width);
1224
1260
 
1225
1261
        nam.xoffset += Array_nel-Array_array;
1226
 
        nodconst(&nod1, types[TINT32], nr->type->bound);
1227
 
        gdata(&nam, &nod1, types[TINT32]->width);
 
1262
        nodconst(&nod1, types[TINT], nr->type->bound);
 
1263
        gdata(&nam, &nod1, widthint);
1228
1264
 
1229
1265
        nam.xoffset += Array_cap-Array_nel;
1230
 
        gdata(&nam, &nod1, types[TINT32]->width);
 
1266
        gdata(&nam, &nod1, widthint);
1231
1267
 
1232
1268
        goto yes;
1233
1269