16 typedef struct Tprot Tprot;
24 typedef struct Tname Tname;
33 static uchar flagbits[512];
34 static char fmtbuf[100];
53 flagbits[c] = lastverb;
54 /*print("flag-v %c %d\n", c, lastadj);*/
58 flagbits[c] = lastadj;
59 /*print("flag-l %c %d\n", c, lastadj);*/
74 e = fmtbuf + sizeof(fmtbuf)-1;
78 s += chartorune(&c, s);
79 if(c == 0 || c >= nelem(flagbits))
81 fmt += runetochar(fmt, &c);
94 flag = bor(flag, blsh(Fvl));
96 flag = bor(flag, blsh(f));
105 newprot(Sym *m, Type *t, char *s)
111 warn(Z, "%s: newprot: type not defined", m->name);
115 for(l=tprot; l; l=l->link)
116 if(beq(flag, l->flag) && sametype(t, l->type))
118 l = alloc(sizeof(*l));
126 newname(char *s, int p)
130 for(l=tname; l; l=l->link)
131 if(strcmp(l->name, s) == 0) {
133 yyerror("vargck %s already defined\n", s);
136 l = alloc(sizeof(*l));
153 indchar = typ(TIND, types[TCHAR]);
155 memset(flagbits, Fnone, sizeof(flagbits));
157 for(i='0'; i<='9'; i++)
159 argflag('.', Fignor);
160 argflag('#', Fignor);
161 argflag('u', Fignor);
162 argflag('h', Fignor);
163 argflag('+', Fignor);
164 argflag('-', Fignor);
168 argflag('z', ewidth[TVLONG]==ewidth[TIND] ? Fvl : Fl);
171 flagbits['x'] = flagbits['o'];
172 flagbits['X'] = flagbits['o'];
187 if(s && strcmp(s->name, "argpos") == 0)
189 if(s && strcmp(s->name, "type") == 0)
191 if(s && strcmp(s->name, "flag") == 0)
193 yyerror("syntax in #pragma varargck");
197 /*#pragma varargck argpos warn 2*/
208 /*#pragma varargck flag 'c'*/
225 /*#pragma varargck type O int*/
230 e = t + sizeof(fmtbuf)-1;
233 if(r == ' ' || r == '\n')
239 t += runetochar(t, &r);
247 while((c = getnsc()) == '*')
254 yyerror("syntax in #pragma varargck");
257 while(getnsc() != '\n')
262 nextarg(Node *n, Node **a)
277 checkargs(Node *nn, char *s, int pos)
291 warn(nn, "more arguments than format %T",
302 warn(nn, "more format than arguments %s",
308 if(!sametype(types[TINT], a->type) &&
309 !sametype(types[TUINT], a->type))
310 warn(nn, "format mismatch '*' in %s %T, arg %d",
311 fmtbuf, a->type, pos);
313 for(l=tprot; l; l=l->link)
314 if(sametype(types[TVOID], l->type)) {
315 if(beq(flag, l->flag)) {
324 warn(nn, "more format than arguments %s",
330 for(l=tprot; l; l=l->link)
331 if(sametype(a->type, l->type)) {
332 /*print("checking %T/%ulx %T/%ulx\n", a->type, flag.b[0], l->type, l->flag.b[0]);*/
333 if(beq(flag, l->flag))
336 warn(nn, "format mismatch %s %T, arg %d", fmtbuf, a->type, pos);
352 if(b == Z || b->op != ONAME)
355 for(l=tname; l; l=l->link)
356 if(strcmp(s, l->name) == 0)
368 warn(n, "cant find format arg");
371 if(!sametype(indchar, a->type)) {
372 warn(n, "format arg type %T", a->type);
375 if(a->op != OADDR || a->left->op != ONAME || a->left->sym != symstring) {
376 /* warn(n, "format arg not constant string");*/
379 s = a->left->cstring;
380 checkargs(b, s, l->param);
391 packflg = atoi(s->name+1);
392 if(strcmp(s->name, "on") == 0 ||
393 strcmp(s->name, "yes") == 0)
396 while(getnsc() != '\n')
400 print("%4ld: pack %d\n", lineno, packflg);
402 print("%4ld: pack off\n", lineno);
413 fproundflg = atoi(s->name+1);
414 if(strcmp(s->name, "on") == 0 ||
415 strcmp(s->name, "yes") == 0)
418 while(getnsc() != '\n')
422 print("%4ld: fproundflg %d\n", lineno, fproundflg);
424 print("%4ld: fproundflg off\n", lineno);
435 profileflg = atoi(s->name+1);
436 if(strcmp(s->name, "on") == 0 ||
437 strcmp(s->name, "yes") == 0)
440 while(getnsc() != '\n')
444 print("%4ld: profileflg %d\n", lineno, profileflg);
446 print("%4ld: profileflg off\n", lineno);
469 yyerror("missing struct/union tag in pragma incomplete");
472 if(s->lexical != LNAME && s->lexical != LTYPE){
473 yyerror("invalid struct/union tag: %s", s->name);
478 }else if(strcmp(s->name, "_off_") == 0){
481 }else if(strcmp(s->name, "_on_") == 0){
489 yyerror("unknown type %s in pragma incomplete", s->name);
490 else if(!typesu[t->etype])
491 yyerror("not struct/union type in pragma incomplete: %s", s->name);
493 t->garb |= GINCOMPLETE;
495 while(getnsc() != '\n')
498 print("%s incomplete\n", s->name);