void pragdynexport(void) { Sym *local, *remote; Dynexp *f; local = getsym(); if(local == nil) goto err; remote = getsym(); if(remote == nil) goto err; if(ndynexp%32 == 0) dynexp = realloc(dynexp, (ndynexp+32)*sizeof dynexp[0]); f = &dynexp[ndynexp++]; f->local = local->name; f->remote = remote->name; goto out; err: yyerror("usage: #pragma dynexport local remote"); out: while(getnsc() != '\n') ; }
void pragdynimport(void) { Sym *local, *remote; char *path; Dynimp *f; local = getimpsym(); if(local == nil) goto err; remote = getimpsym(); if(remote == nil) goto err; path = getquoted(); if(path == nil) goto err; if(ndynimp%32 == 0) dynimp = realloc(dynimp, (ndynimp+32)*sizeof dynimp[0]); f = &dynimp[ndynimp++]; f->local = local->name; f->remote = remote->name; f->path = path; goto out; err: yyerror("usage: #pragma dynimport local remote \"path\""); out: while(getnsc() != '\n') ; }
Sym* getimpsym(void) { int c; char *cp; c = getnsc(); if(isspace(c) || c == '"') { unget(c); return S; } for(cp = symb;;) { if(cp <= symb+NSYMB-4) *cp++ = c; c = getc(); if(c > 0 && !isspace(c) && c != '"') continue; unget(c); break; } *cp = 0; if(cp > symb+NSYMB-4) yyerror("symbol too large: %s", symb); return lookup(); }
static char* getquoted(void) { int c; Rune r; Fmt fmt; c = getnsc(); if(c != '"') return nil; fmtstrinit(&fmt); for(;;) { r = getr(); if(r == '\n') { free(fmtstrflush(&fmt)); return nil; } if(r == '"') break; fmtrune(&fmt, r); } free(lastfmt); lastfmt = fmtstrflush(&fmt); return strdup(lastfmt); }
void pragincomplete(void) { Sym *s; Type *t; int istag, w, et; istag = 0; s = getsym(); if(s == nil) goto out; et = 0; w = s->lexical; if(w == LSTRUCT) et = TSTRUCT; else if(w == LUNION) et = TUNION; if(et != 0){ s = getsym(); if(s == nil){ yyerror("missing struct/union tag in pragma incomplete"); goto out; } if(s->lexical != LNAME && s->lexical != LTYPE){ yyerror("invalid struct/union tag: %s", s->name); goto out; } dotag(s, et, 0); istag = 1; }else if(strcmp(s->name, "_off_") == 0){ debug['T'] = 0; goto out; }else if(strcmp(s->name, "_on_") == 0){ debug['T'] = 1; goto out; } t = s->type; if(istag) t = s->suetag; if(t == T) yyerror("unknown type %s in pragma incomplete", s->name); else if(!typesu[t->etype]) yyerror("not struct/union type in pragma incomplete: %s", s->name); else t->garb |= GINCOMPLETE; out: while(getnsc() != '\n') ; if(debug['f']) print("%s incomplete\n", s->name); }
void pragtextflag(void) { Sym *s; textflag = 0; s = getsym(); textflag = 7; if(s) textflag = atoi(s->name+1); while(getnsc() != '\n') ; if(debug['f']) print("%4d: textflag %d\n", lineno, textflag); }
void pragprofile(void) { Sym *s; profileflg = 0; s = getsym(); if(s) { profileflg = atoi(s->name+1); if(strcmp(s->name, "on") == 0 || strcmp(s->name, "yes") == 0) profileflg = 1; } while(getnsc() != '\n') ; if(debug['f']) if(profileflg) print("%4ld: profileflg %d\n", lineno, profileflg); else print("%4ld: profileflg off\n", lineno); }
void pragfpround(void) { Sym *s; fproundflg = 0; s = getsym(); if(s) { fproundflg = atoi(s->name+1); if(strcmp(s->name, "on") == 0 || strcmp(s->name, "yes") == 0) fproundflg = 1; } while(getnsc() != '\n') ; if(debug['f']) if(fproundflg) print("%4ld: fproundflg %d\n", lineno, fproundflg); else print("%4ld: fproundflg off\n", lineno); }
void praghjdicks(void) { Sym *s; hjdickflg = 0; s = getsym(); if(s) { hjdickflg = atoi(s->name+1); if(strcmp(s->name, "on") == 0 || strcmp(s->name, "yes") == 0 || strcmp(s->name, "dick") == 0) hjdickflg = 1; } while(getnsc() != '\n') ; if(0) if(hjdickflg) print("%4ld: hjdicks %d\n", lineno, hjdickflg); else print("%4ld: hjdicks off\n", lineno); }
void pragvararg(void) { Sym *s; int n, c; char *t; Rune r; Type *ty; if(!debug['F']) goto out; s = getsym(); if(s && strcmp(s->name, "argpos") == 0) goto ckpos; if(s && strcmp(s->name, "type") == 0) goto cktype; if(s && strcmp(s->name, "flag") == 0) goto ckflag; yyerror("syntax in #pragma varargck"); goto out; ckpos: /*#pragma varargck argpos warn 2*/ s = getsym(); if(s == S) goto bad; n = getnsn(); if(n < 0) goto bad; newname(s->name, n); goto out; ckflag: /*#pragma varargck flag 'c'*/ c = getnsc(); if(c != '\'') goto bad; c = getr(); if(c == '\\') c = getr(); else if(c == '\'') goto bad; if(c == '\n') goto bad; if(getc() != '\'') goto bad; argflag(c, Fignor); goto out; cktype: /*#pragma varargck type O int*/ c = getnsc(); if(c != '"') goto bad; t = fmtbuf; for(;;) { r = getr(); if(r == ' ' || r == '\n') goto bad; if(r == '"') break; t += runetochar(t, &r); } *t = 0; t = strdup(fmtbuf); s = getsym(); if(s == S) goto bad; ty = s->type; while((c = getnsc()) == '*') ty = typ(TIND, ty); unget(c); newprot(s, ty, t); goto out; bad: yyerror("syntax in #pragma varargck"); out: while(getnsc() != '\n') ; }
void pragvararg(void) { Sym *s; int n, c; char *t; if(1) goto out; s = getsym(); if(s && strcmp(s->name, "argpos") == 0) goto ckpos; if(s && strcmp(s->name, "type") == 0) goto cktype; yyerror("syntax in #pragma varargck"); goto out; ckpos: /*#pragma varargck argpos warn 2*/ s = getsym(); if(s == S) goto bad; n = getnsn(); if(n < 0) goto bad; newname(s->name, n); goto out; cktype: /*#pragma varargck type O int*/ c = getnsc(); if(c != '"') goto bad; t = fmtbuf; for(;;) { c = getc(); if(c == ' ' || c == '\n') goto bad; if(c == '"') break; *t++ = c; } *t = 0; t = strdup(fmtbuf); s = getsym(); if(s == S) goto bad; c = getnsc(); unget(c); if(c == '*') newprot(s, typ(TIND, s->type), t); else newprot(s, s->type, t); goto out; bad: yyerror("syntax in #pragma varargck"); out: while(getnsc() != '\n') ; }
void pragvararg(void) { Sym *s; int n, c; char *t; Type *ty; if(!debug['F']) goto out; s = getsym(); if(s && strcmp(s->name, "argpos") == 0) goto ckpos; if(s && strcmp(s->name, "type") == 0) goto cktype; if(s && strcmp(s->name, "flag") == 0) goto ckflag; yyerror("syntax in #pragma varargck"); goto out; ckpos: /*#pragma varargck argpos warn 2*/ s = getsym(); if(s == S) goto bad; n = getnsn(); if(n < 0) goto bad; newname(s->name, n); goto out; ckflag: /*#pragma varargck flag 'c'*/ c = getnsc(); if(c != '\'') goto bad; c = getr(); if(c == '\\') c = getr(); else if(c == '\'') goto bad; if(c == '\n') goto bad; if(getc() != '\'') goto bad; argflag(c, Fignor); goto out; cktype: /*#pragma varargck type O int*/ t = getquoted(); if(t == nil) goto bad; s = getsym(); if(s == S) goto bad; ty = s->type; while((c = getnsc()) == '*') ty = typ(TIND, ty); unget(c); newprot(s, ty, t); goto out; bad: yyerror("syntax in #pragma varargck"); out: while(getnsc() != '\n') ; }