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 fmt += runetochar(fmt, &c);
80 if(c == 0 || c >= nelem(flagbits))
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);
170 flagbits['x'] = flagbits['o'];
171 flagbits['X'] = flagbits['o'];
186 if(s && strcmp(s->name, "argpos") == 0)
188 if(s && strcmp(s->name, "type") == 0)
190 if(s && strcmp(s->name, "flag") == 0)
192 yyerror("syntax in #pragma varargck");
196 /*#pragma varargck argpos warn 2*/
207 /*#pragma varargck flag 'c'*/
224 /*#pragma varargck type O int*/
229 e = t + sizeof(fmtbuf)-1;
232 if(r == ' ' || r == '\n')
238 t += runetochar(t, &r);
246 while((c = getnsc()) == '*')
253 yyerror("syntax in #pragma varargck");
256 while(getnsc() != '\n')
261 nextarg(Node *n, Node **a)
276 checkargs(Node *nn, char *s, int pos)
290 warn(nn, "more arguments than format %T",
301 warn(nn, "more format than arguments %s",
307 if(!sametype(types[TINT], a->type) &&
308 !sametype(types[TUINT], a->type))
309 warn(nn, "format mismatch '*' in %s %T, arg %d",
310 fmtbuf, a->type, pos);
312 for(l=tprot; l; l=l->link)
313 if(sametype(types[TVOID], l->type)) {
314 if(beq(flag, l->flag)) {
323 warn(nn, "more format than arguments %s",
329 for(l=tprot; l; l=l->link)
330 if(sametype(a->type, l->type)) {
331 /*print("checking %T/%ulx %T/%ulx\n", a->type, flag.b[0], l->type, l->flag.b[0]);*/
332 if(beq(flag, l->flag))
335 warn(nn, "format mismatch %s %T, arg %d", fmtbuf, a->type, pos);
351 if(b == Z || b->op != ONAME)
354 for(l=tname; l; l=l->link)
355 if(strcmp(s, l->name) == 0)
367 warn(n, "cant find format arg");
370 if(!sametype(indchar, a->type)) {
371 warn(n, "format arg type %T", a->type);
374 if(a->op != OADDR || a->left->op != ONAME || a->left->sym != symstring) {
375 /* warn(n, "format arg not constant string");*/
378 s = a->left->cstring;
379 checkargs(b, s, l->param);
390 packflg = atoi(s->name+1);
391 if(strcmp(s->name, "on") == 0 ||
392 strcmp(s->name, "yes") == 0)
395 while(getnsc() != '\n')
399 print("%4ld: pack %d\n", lineno, packflg);
401 print("%4ld: pack off\n", lineno);
412 fproundflg = atoi(s->name+1);
413 if(strcmp(s->name, "on") == 0 ||
414 strcmp(s->name, "yes") == 0)
417 while(getnsc() != '\n')
421 print("%4ld: fproundflg %d\n", lineno, fproundflg);
423 print("%4ld: fproundflg off\n", lineno);
434 profileflg = atoi(s->name+1);
435 if(strcmp(s->name, "on") == 0 ||
436 strcmp(s->name, "yes") == 0)
439 while(getnsc() != '\n')
443 print("%4ld: profileflg %d\n", lineno, profileflg);
445 print("%4ld: profileflg off\n", lineno);
468 yyerror("missing struct/union tag in pragma incomplete");
471 if(s->lexical != LNAME && s->lexical != LTYPE){
472 yyerror("invalid struct/union tag: %s", s->name);
477 }else if(strcmp(s->name, "_off_") == 0){
480 }else if(strcmp(s->name, "_on_") == 0){
488 yyerror("unknown type %s in pragma incomplete", s->name);
489 else if(!typesu[t->etype])
490 yyerror("not struct/union type in pragma incomplete: %s", s->name);
492 t->garb |= GINCOMPLETE;
494 while(getnsc() != '\n')
497 print("%s incomplete\n", s->name);