diff options
| author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2004-12-09 11:55:30 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-07 21:05:46 -0700 |
| commit | b4dcd7de02472d98ce22dd334b0a1bd5aa86717c (patch) | |
| tree | 0135570cb2398e9ae8d6bbc069d891e50e55d5b2 | |
| parent | fd46a87b9e1d032863c41f54009e5e6386862f8b (diff) | |
| download | sparse-dev-b4dcd7de02472d98ce22dd334b0a1bd5aa86717c.tar.gz | |
Add "stream_name()" helper function, and use it.
Much prettier than "input_streams[x].name", since most
users really don't want to know about the internals of
how the preprocessor lays out its stream tracking.
| -rw-r--r-- | compile-i386.c | 2 | ||||
| -rw-r--r-- | compile.c | 2 | ||||
| -rw-r--r-- | evaluate.c | 2 | ||||
| -rw-r--r-- | lib.c | 2 | ||||
| -rw-r--r-- | linearize.c | 6 | ||||
| -rw-r--r-- | pre-process.c | 4 | ||||
| -rw-r--r-- | show-parse.c | 4 | ||||
| -rw-r--r-- | token.h | 1 | ||||
| -rw-r--r-- | tokenize.c | 11 |
9 files changed, 21 insertions, 13 deletions
diff --git a/compile-i386.c b/compile-i386.c index 9e72a548..f7400059 100644 --- a/compile-i386.c +++ b/compile-i386.c @@ -2317,7 +2317,7 @@ static struct storage *x86_expression(struct expression *expr) if (!expr->ctype) { struct position *pos = &expr->pos; printf("\tno type at %s:%d:%d\n", - input_streams[pos->stream].name, + stream_name(pos->stream), pos->line, pos->pos); return NULL; } @@ -42,7 +42,7 @@ int main(int argc, char **argv) list = sparse(argc, argv); - filename = input_streams[1].name; + filename = stream_name(1); basename = strrchr(filename, '/'); if (basename) filename = basename+1; @@ -2282,7 +2282,7 @@ static void check_duplicates(struct symbol *sym) if (typediff) { warning(sym->pos, "symbol '%s' redeclared with different type (originally declared at %s:%d) - %s", show_ident(sym->ident), - input_streams[next->pos.stream].name, next->pos.line, typediff); + stream_name(next->pos.stream), next->pos.line, typediff); return; } } @@ -280,7 +280,7 @@ static void do_warn(const char *type, struct position pos, const char * fmt, va_ const char *name; vsprintf(buffer, fmt, args); - name = input_streams[pos.stream].name; + name = stream_name(pos.stream); fprintf(stderr, "%s:%d:%d: %s%s\n", name, pos.line, pos.pos, type, buffer); diff --git a/linearize.c b/linearize.c index 2f92d898..832fac2b 100644 --- a/linearize.c +++ b/linearize.c @@ -439,7 +439,7 @@ void show_bb(struct basic_block *bb) printf(".L%p:\n", bb); if (verbose) { pseudo_t needs, defines; - printf("%s:%d\n", input_streams[bb->pos.stream].name, bb->pos.line); + printf("%s:%d\n", stream_name(bb->pos.stream), bb->pos.line); FOR_EACH_PTR(bb->needs, needs) { struct instruction *def = needs->def; @@ -467,7 +467,7 @@ void show_bb(struct basic_block *bb) struct basic_block *from; FOR_EACH_PTR(bb->parents, from) { printf(" **from %p (%s:%d:%d)**\n", from, - input_streams[from->pos.stream].name, from->pos.line, from->pos.pos); + stream_name(from->pos.stream), from->pos.line, from->pos.pos); } END_FOR_EACH_PTR(from); } @@ -475,7 +475,7 @@ void show_bb(struct basic_block *bb) struct basic_block *to; FOR_EACH_PTR(bb->children, to) { printf(" **to %p (%s:%d:%d)**\n", to, - input_streams[to->pos.stream].name, to->pos.line, to->pos.pos); + stream_name(to->pos.stream), to->pos.line, to->pos.pos); } END_FOR_EACH_PTR(to); } } diff --git a/pre-process.c b/pre-process.c index 0a24f56e..c502074d 100644 --- a/pre-process.c +++ b/pre-process.c @@ -131,7 +131,7 @@ static int expand_one_symbol(struct token **list) if (token->ident == &__LINE___ident) { replace_with_integer(token, token->pos.line); } else if (token->ident == &__FILE___ident) { - replace_with_string(token, (input_streams + token->pos.stream)->name); + replace_with_string(token, stream_name(token->pos.stream)); } return 1; } @@ -601,7 +601,7 @@ static int already_tokenized(const char *path) int i; struct stream *s = input_streams; - for (i = input_stream_nr-1; i >= 0; i--, s++) { + for (i = input_stream_nr; --i >= 0; s++) { if (s->constant != CONSTANT_FILE_YES) continue; if (strcmp(path, s->name)) diff --git a/show-parse.c b/show-parse.c index 2b8e4715..695a1be8 100644 --- a/show-parse.c +++ b/show-parse.c @@ -58,7 +58,7 @@ static void do_debug_symbol(struct symbol *sym, int indent) sym->bit_size, sym->ctype.alignment, sym->ctype.modifiers, show_ident(sym->ident), sym->ctype.as, sym->ctype.in_context, sym->ctype.out_context, - sym, input_streams[sym->pos.stream].name, sym->pos.line, sym->pos.pos); + sym, stream_name(sym->pos.stream), sym->pos.line, sym->pos.pos); if (sym->type == SYM_FN) { int i = 1; struct symbol *arg; @@ -961,7 +961,7 @@ int show_expression(struct expression *expr) if (!expr->ctype) { struct position *pos = &expr->pos; printf("\tno type at %s:%d:%d\n", - input_streams[pos->stream].name, + stream_name(pos->stream), pos->line, pos->pos); return 0; } @@ -178,6 +178,7 @@ extern struct token eof_token_entry; #define eof_token(x) ((x) == &eof_token_entry) extern int init_stream(const char *, int fd, const char **next_path); +extern const char *stream_name(int stream); extern struct ident *hash_ident(struct ident *); extern struct ident *built_in_ident(const char *); extern struct token *built_in_token(int, const char *); @@ -37,6 +37,13 @@ typedef struct { unsigned char *buffer; } stream_t; +const char *stream_name(int stream) +{ + if (stream < 0 || stream > input_stream_nr) + return "<bad stream>"; + return input_streams[stream].name; +} + struct position stream_pos(stream_t *stream) { struct position pos; @@ -149,11 +156,11 @@ const char *show_token(const struct token *token) } case TOKEN_STREAMBEGIN: - sprintf(buffer, "<beginning of '%s'>", (input_streams + token->pos.stream)->name); + sprintf(buffer, "<beginning of '%s'>", stream_name(token->pos.stream)); return buffer; case TOKEN_STREAMEND: - sprintf(buffer, "<end of '%s'>", (input_streams + token->pos.stream)->name); + sprintf(buffer, "<end of '%s'>", stream_name(token->pos.stream)); return buffer; default: |
