~john-koepi/ubuntu/trusty/golang/default

« back to all changes in this revision

Viewing changes to src/cmd/cc/dpchk.c

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29
29
// THE SOFTWARE.
30
30
 
 
31
#include        <u.h>
 
32
#include        <ctype.h>
31
33
#include        "cc.h"
32
34
#include        "y.tab.h"
33
35
 
56
58
{
57
59
        char*   name;
58
60
        int     param;
 
61
        int     count;
59
62
        Tname*  link;
 
63
        Tprot*  prot;
60
64
};
61
65
 
62
66
static  Type*   indchar;
131
135
        return flag;
132
136
}
133
137
 
134
 
void
135
 
newprot(Sym *m, Type *t, char *s)
 
138
static void
 
139
newprot(Sym *m, Type *t, char *s, Tprot **prot)
136
140
{
137
141
        Bits flag;
138
142
        Tprot *l;
142
146
                return;
143
147
        }
144
148
        flag = getflag(s);
145
 
        for(l=tprot; l; l=l->link)
 
149
        for(l=*prot; l; l=l->link)
146
150
                if(beq(flag, l->flag) && sametype(t, l->type))
147
151
                        return;
148
152
        l = alloc(sizeof(*l));
149
153
        l->type = t;
150
154
        l->flag = flag;
151
 
        l->link = tprot;
152
 
        tprot = l;
 
155
        l->link = *prot;
 
156
        *prot = l;
153
157
}
154
158
 
155
 
void
156
 
newname(char *s, int p)
 
159
static Tname*
 
160
newname(char *s, int p, int count)
157
161
{
158
162
        Tname *l;
159
163
 
160
164
        for(l=tname; l; l=l->link)
161
165
                if(strcmp(l->name, s) == 0) {
162
 
                        if(l->param != p)
 
166
                        if(p >= 0 && l->param != p)
163
167
                                yyerror("vargck %s already defined\n", s);
164
 
                        return;
 
168
                        return l;
165
169
                }
 
170
        if(p < 0)
 
171
                return nil;
 
172
 
166
173
        l = alloc(sizeof(*l));
167
174
        l->name = s;
168
175
        l->param = p;
169
176
        l->link = tname;
 
177
        l->count = count;
170
178
        tname = l;
 
179
        return l;
171
180
}
172
181
 
173
182
void
234
243
        int n, c;
235
244
        char *t;
236
245
        Type *ty;
 
246
        Tname *l;
237
247
 
238
248
        if(!debug['F'])
239
249
                goto out;
244
254
                goto cktype;
245
255
        if(s && strcmp(s->name, "flag") == 0)
246
256
                goto ckflag;
 
257
        if(s && strcmp(s->name, "countpos") == 0)
 
258
                goto ckcount;
247
259
        yyerror("syntax in #pragma varargck");
248
260
        goto out;
249
261
 
255
267
        n = getnsn();
256
268
        if(n < 0)
257
269
                goto bad;
258
 
        newname(s->name, n);
 
270
        newname(s->name, n, 0);
 
271
        goto out;
 
272
 
 
273
ckcount:
 
274
/*#pragma       varargck        countpos        name 2*/
 
275
        s = getsym();
 
276
        if(s == S)
 
277
                goto bad;
 
278
        n = getnsn();
 
279
        if(n < 0)
 
280
                goto bad;
 
281
        newname(s->name, 0, n);
259
282
        goto out;
260
283
 
261
284
ckflag:
276
299
        goto out;
277
300
 
278
301
cktype:
 
302
        c = getnsc();
 
303
        unget(c);
 
304
        if(c != '"') {
 
305
/*#pragma       varargck        type    name    int*/
 
306
                s = getsym();
 
307
                if(s == S)
 
308
                        goto bad;
 
309
                l = newname(s->name, -1, -1);
 
310
                s = getsym();
 
311
                if(s == S)
 
312
                        goto bad;
 
313
                ty = s->type;
 
314
                while((c = getnsc()) == '*')
 
315
                        ty = typ(TIND, ty);
 
316
                unget(c);
 
317
                newprot(s, ty, "a", &l->prot);
 
318
                goto out;
 
319
        }
 
320
 
279
321
/*#pragma       varargck        type    O       int*/
280
322
        t = getquoted();
281
323
        if(t == nil)
287
329
        while((c = getnsc()) == '*')
288
330
                ty = typ(TIND, ty);
289
331
        unget(c);
290
 
        newprot(s, ty, t);
 
332
        newprot(s, ty, t, &tprot);
291
333
        goto out;
292
334
 
293
335
bad:
384
426
        char *s;
385
427
        Node *a, *b;
386
428
        Tname *l;
387
 
        int i;
 
429
        Tprot *tl;
 
430
        int i, j;
388
431
 
389
432
        if(n == Z)
390
433
                return;
398
441
        if(l == 0)
399
442
                return;
400
443
 
 
444
        if(l->count > 0) {
 
445
                // fetch count, then check remaining length
 
446
                i = l->count;
 
447
                a = nil;
 
448
                b = n->right;
 
449
                while(i > 0) {
 
450
                        b = nextarg(b, &a);
 
451
                        i--;
 
452
                }
 
453
                if(a == Z) {
 
454
                        diag(n, "can't find count arg");
 
455
                        return;
 
456
                }
 
457
                if(a->op != OCONST || !typechl[a->type->etype]) {
 
458
                        diag(n, "count is invalid constant");
 
459
                        return;
 
460
                }
 
461
                j = a->vconst;
 
462
                i = 0;
 
463
                while(b != Z) {
 
464
                        b = nextarg(b, &a);
 
465
                        i++;
 
466
                }
 
467
                if(i != j)
 
468
                        diag(n, "found %d argument%s after count %d", i, i == 1 ? "" : "s", j);
 
469
        }
 
470
 
 
471
        if(l->prot != nil) {
 
472
                // check that all arguments after param or count
 
473
                // are listed in type list.
 
474
                i = l->count;
 
475
                if(i == 0)
 
476
                        i = l->param;
 
477
                if(i == 0)
 
478
                        return;
 
479
                a = nil;
 
480
                b = n->right;
 
481
                while(i > 0) {
 
482
                        b = nextarg(b, &a);
 
483
                        i--;
 
484
                }
 
485
                if(a == Z) {
 
486
                        diag(n, "can't find count/param arg");
 
487
                        return;
 
488
                }
 
489
                while(b != Z) {
 
490
                        b = nextarg(b, &a);
 
491
                        for(tl=l->prot; tl; tl=tl->link)
 
492
                                if(sametype(a->type, tl->type))
 
493
                                        break;
 
494
                        if(tl == nil)
 
495
                                diag(a, "invalid type %T in call to %s", a->type, s);
 
496
                }
 
497
        }
 
498
 
 
499
        if(l->param <= 0)
 
500
                return;
401
501
        i = l->param;
402
502
        a = nil;
403
503
        b = n->right;
404
 
        a = Z;
405
504
        while(i > 0) {
406
505
                b = nextarg(b, &a);
407
506
                i--;
408
507
        }
409
508
        if(a == Z) {
410
 
                warn(n, "cant find format arg");
 
509
                diag(n, "can't find format arg");
411
510
                return;
412
511
        }
413
512
        if(!sametype(indchar, a->type)) {
414
 
                warn(n, "format arg type %T", a->type);
 
513
                diag(n, "format arg type %T", a->type);
415
514
                return;
416
515
        }
417
516
        if(a->op != OADDR || a->left->op != ONAME || a->left->sym != symstring) {