diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-07-19 00:54:57 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-07-22 18:02:45 +0200 |
commit | 4c6cbe557c48205f9b3d2aae4c166cd66446b240 (patch) | |
tree | 976730b6fc1b7944546f6def958b1681a836cac5 | |
parent | e140005c44ef962f5ee2a72735ea727e5db7f7f6 (diff) | |
download | sparse-4c6cbe557c48205f9b3d2aae4c166cd66446b240.tar.gz |
add position to struct stream
Now that struct stream contains the parent's stream, it
might as well contains the position so that all information
about the parent is available.
So, add a struct position to struct stream, initialize it
with the information from the '#include' token (if there is one)
and use this positions's ::stream as previous/parent stream.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | lib.c | 2 | ||||
-rw-r--r-- | pre-process.c | 4 | ||||
-rw-r--r-- | symbol.c | 2 | ||||
-rw-r--r-- | token.h | 7 | ||||
-rw-r--r-- | tokenize.c | 13 |
5 files changed, 16 insertions, 12 deletions
@@ -351,7 +351,7 @@ static struct symbol_list *sparse_file(const char *filename) base_filename = filename; // Tokenize the input stream - token = tokenize(filename, fd, -1, NULL, includepath); + token = tokenize(NULL, filename, fd, NULL, includepath); close(fd); return sparse_tokenstream(token); diff --git a/pre-process.c b/pre-process.c index 6f4bf897..ee0e9954 100644 --- a/pre-process.c +++ b/pre-process.c @@ -911,7 +911,7 @@ static int try_include(struct position pos, const char *path, const char *filena fd = open(fullname, O_RDONLY); if (fd >= 0) { char *streamname = xmemdup(fullname, plen + flen); - *where = tokenize(streamname, fd, pos.stream, *where, next_path); + *where = tokenize(&pos, streamname, fd, *where, next_path); close(fd); return 1; } @@ -2091,7 +2091,7 @@ static void create_arglist(struct symbol *sym, int count) static void init_preprocessor(void) { int i; - int stream = init_stream("preprocessor", -1, includepath, -1); + int stream = init_stream(NULL, "preprocessor", -1, includepath); static struct { const char *name; int (*handler)(struct stream *, struct token **, struct token *); @@ -776,7 +776,7 @@ struct symbol zero_int; void init_symbols(void) { - int stream = init_stream("builtin", -1, includepath, -1); + int stream = init_stream(NULL, "builtin", -1, includepath); #define __IDENT(n,str,res) \ hash_ident(&n) @@ -49,10 +49,11 @@ enum constantfile { extern const char *includepath[]; struct stream { - int fd, prev; + int fd; const char *name; const char *path; // input-file path - see set_stream_include_path() const char **next_path; + struct position pos; //position of the #include, if any /* Use these to check for "already parsed" */ enum constantfile constant; @@ -214,7 +215,7 @@ static inline struct token *containing_token(struct token **p) 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, int prev_stream); +extern int init_stream(const struct position *pos, const char *, int fd, const char **next_path); extern int stream_prev(int stream); extern const char *stream_name(int stream); extern struct ident *hash_ident(struct ident *); @@ -225,7 +226,7 @@ extern const char *show_ident(const struct ident *); extern const char *show_string(const struct string *string); extern const char *show_token(const struct token *); extern const char *quote_token(const struct token *); -extern struct token * tokenize(const char *, int, int, struct token *, const char **next_path); +extern struct token * tokenize(const struct position *pos, const char *, int, struct token *, const char **next_path); extern struct token * tokenize_buffer(void *, unsigned long, struct token **); extern void show_identifier_stats(void); @@ -66,7 +66,7 @@ int stream_prev(int stream) { if (stream < 0 || stream > input_stream_nr) return -1; - return input_streams[stream].prev; + return input_streams[stream].pos.stream; } static struct position stream_pos(stream_t *stream) @@ -307,7 +307,7 @@ int *hash_stream(const char *name) return input_stream_hashes + hash; } -int init_stream(const char *name, int fd, const char **next_path, int prev_stream) +int init_stream(const struct position *pos, const char *name, int fd, const char **next_path) { int stream = input_stream_nr, *hash; struct stream *current; @@ -326,7 +326,10 @@ int init_stream(const char *name, int fd, const char **next_path, int prev_strea current->next_path = next_path; current->path = NULL; current->constant = CONSTANT_FILE_MAYBE; - current->prev = prev_stream; + if (pos) + current->pos = *pos; + else + current->pos.stream = -1; input_stream_nr = stream+1; hash = hash_stream(name); current->next_stream = *hash; @@ -1014,14 +1017,14 @@ struct token * tokenize_buffer(void *buffer, unsigned long size, struct token ** return begin; } -struct token * tokenize(const char *name, int fd, int prev_stream, struct token *endtoken, const char **next_path) +struct token * tokenize(const struct position *pos, const char *name, int fd, struct token *endtoken, const char **next_path) { struct token *begin, *end; stream_t stream; unsigned char buffer[BUFSIZE]; int idx; - idx = init_stream(name, fd, next_path, prev_stream); + idx = init_stream(pos, name, fd, next_path); if (idx < 0) { // info(endtoken->pos, "File %s is const", name); return endtoken; |