aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLinus Torvalds <torvalds@ppc970.osdl.org>2004-12-09 11:55:30 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:05:46 -0700
commitb4dcd7de02472d98ce22dd334b0a1bd5aa86717c (patch)
tree0135570cb2398e9ae8d6bbc069d891e50e55d5b2
parentfd46a87b9e1d032863c41f54009e5e6386862f8b (diff)
downloadsparse-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.c2
-rw-r--r--compile.c2
-rw-r--r--evaluate.c2
-rw-r--r--lib.c2
-rw-r--r--linearize.c6
-rw-r--r--pre-process.c4
-rw-r--r--show-parse.c4
-rw-r--r--token.h1
-rw-r--r--tokenize.c11
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;
}
diff --git a/compile.c b/compile.c
index f8fb6219..8dfe6f71 100644
--- a/compile.c
+++ b/compile.c
@@ -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;
diff --git a/evaluate.c b/evaluate.c
index 26fcbdb7..e4eb7442 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -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;
}
}
diff --git a/lib.c b/lib.c
index 55153aaa..b34d584f 100644
--- a/lib.c
+++ b/lib.c
@@ -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;
}
diff --git a/token.h b/token.h
index 27983119..c7bca7ab 100644
--- a/token.h
+++ b/token.h
@@ -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 *);
diff --git a/tokenize.c b/tokenize.c
index 25c79e30..ad521897 100644
--- a/tokenize.c
+++ b/tokenize.c
@@ -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: