aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwelinder@troll.com <welinder@troll.com>2004-08-31 23:39:12 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:02:59 -0700
commit9c0a8e67f73064885300095866fc07127b8d50ec (patch)
treea4b320dd993e28b3c80d068a2f1b3cbd602651da /tokenize.c
parentMerge troll.com:/scratch/welinder/linus-sparse (diff)
downloadsparse-9c0a8e67f73064885300095866fc07127b8d50ec.tar.gz
sparse-9c0a8e67f73064885300095866fc07127b8d50ec.tar.bz2
sparse-9c0a8e67f73064885300095866fc07127b8d50ec.zip
pre-process.c:
Fix file-is-const for #define, #undef, C-code inside the #ifndef. Make it easy to debug file-is-const. tokenize.c: Fix check for identical-file. token.h: Introduce symbolic names for the stream->constant states and comment those states.
Diffstat (limited to 'tokenize.c')
-rw-r--r--tokenize.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/tokenize.c b/tokenize.c
index 373aeb1..17e8ede 100644
--- a/tokenize.c
+++ b/tokenize.c
@@ -150,6 +150,7 @@ int init_stream(const char *name, int fd)
{
int stream = input_stream_nr;
struct stream *current;
+ struct stat st;
if (stream >= input_streams_allocated) {
int newalloc = stream * 4 / 3 + 10;
@@ -162,21 +163,20 @@ int init_stream(const char *name, int fd)
memset(current, 0, sizeof(*current));
current->name = name;
current->fd = fd;
- current->constant = -1; // "unknown"
- if (fd > 0) {
+ current->constant = CONSTANT_FILE_MAYBE;
+ if (fd >= 0 && fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) {
int i;
- struct stat st;
- fstat(fd, &st);
- current->dev = st.st_dev;
- current->ino = st.st_ino;
for (i = 0; i < stream; i++) {
struct stream *s = input_streams + i;
- if (s->dev == st.st_dev && s->ino == st.st_ino) {
- if (s->constant > 0 && lookup_symbol(s->protect, NS_PREPROCESSOR))
- return -1;
- }
+ if (s->dev == st.st_dev && s->ino == st.st_ino &&
+ s->constant == CONSTANT_FILE_YES &&
+ lookup_symbol(s->protect, NS_PREPROCESSOR))
+ return -1;
}
+
+ current->dev = st.st_dev;
+ current->ino = st.st_ino;
}
input_stream_nr = stream+1;
return stream;
@@ -882,8 +882,10 @@ struct token * tokenize(const char *name, int fd, struct token *endtoken)
int idx;
idx = init_stream(name, fd);
- if (idx < 0)
+ if (idx < 0) {
+ // info(endtoken->pos, "File %s is const", name);
return endtoken;
+ }
begin = setup_stream(&stream, idx, fd, buffer, 0);
tokenize_stream(&stream, endtoken);