aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Li <spase@chrisli.org>2008-12-17 22:01:17 +0300
committerAlexey Zaytsev <alexey.zaytsev@gmail.com>2008-12-18 20:30:22 +0300
commit9a46ba1b5f134fdab62b60374073476cf5ff0599 (patch)
tree935d3c9935449d9f5807d08861ee3ffab291935d
parented3d4c5cf65ff50220312353b340e5f6609a5944 (diff)
downloadsparse-9a46ba1b5f134fdab62b60374073476cf5ff0599.tar.gz
sparse-9a46ba1b5f134fdab62b60374073476cf5ff0599.tar.xz
sparse-9a46ba1b5f134fdab62b60374073476cf5ff0599.zip
Remove pre_buffer
This patch removes the pre_buffer completely. Instead, sparse will tokenized the buffer during add_pre_buffer(). Sparse just tracks the beginning and end of pre_buffer. Reviewed-by: Alexey Zaytsev <alexey.zaytsev@gmail.com> Signed-Off-By: Christopher Li <spase@chrisli.org>
-rw-r--r--lib.c23
-rw-r--r--token.h2
-rw-r--r--tokenize.c21
3 files changed, 26 insertions, 20 deletions
diff --git a/lib.c b/lib.c
index 0abcc9a..ea40ce1 100644
--- a/lib.c
+++ b/lib.c
@@ -185,8 +185,8 @@ void die(const char *fmt, ...)
exit(1);
}
-static unsigned int pre_buffer_size;
-static char pre_buffer[8192];
+static struct token *pre_buffer_begin = NULL;
+static struct token *pre_buffer_end = NULL;
int Waddress_space = 1;
int Wbitwise = 0;
@@ -230,14 +230,18 @@ void add_pre_buffer(const char *fmt, ...)
{
va_list args;
unsigned int size;
+ struct token *begin, *end;
+ char buffer[4096];
va_start(args, fmt);
- size = pre_buffer_size;
- size += vsnprintf(pre_buffer + size,
- sizeof(pre_buffer) - size,
- fmt, args);
- pre_buffer_size = size;
+ size = vsnprintf(buffer, sizeof(buffer), fmt, args);
va_end(args);
+ begin = tokenize_buffer(buffer, size, &end);
+ if (!pre_buffer_begin)
+ pre_buffer_begin = begin;
+ if (pre_buffer_end)
+ pre_buffer_end->next = begin;
+ pre_buffer_end = end;
}
static char **handle_switch_D(char *arg, char **next)
@@ -819,8 +823,9 @@ static struct symbol_list *sparse_initial(void)
token, includepath);
// Prepend the initial built-in stream
- token = tokenize_buffer(pre_buffer, pre_buffer_size, token);
- return sparse_tokenstream(token);
+ if (token)
+ pre_buffer_end->next = token;
+ return sparse_tokenstream(pre_buffer_begin);
}
struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list **filelist)
diff --git a/token.h b/token.h
index ba7866d..fda880f 100644
--- a/token.h
+++ b/token.h
@@ -195,7 +195,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 struct token * tokenize(const char *, int, struct token *, const char **next_path);
-extern struct token * tokenize_buffer(void *, unsigned long, struct token *);
+extern struct token * tokenize_buffer(void *, unsigned long, struct token **);
extern void show_identifier_stats(void);
extern struct token *preprocess(struct token *);
diff --git a/tokenize.c b/tokenize.c
index d154882..7c41a56 100644
--- a/tokenize.c
+++ b/tokenize.c
@@ -304,7 +304,7 @@ static inline int nextchar(stream_t *stream)
struct token eof_token_entry;
-static void mark_eof(stream_t *stream, struct token *end_token)
+static struct token *mark_eof(stream_t *stream)
{
struct token *end;
@@ -315,11 +315,10 @@ static void mark_eof(stream_t *stream, struct token *end_token)
eof_token_entry.next = &eof_token_entry;
eof_token_entry.pos.newline = 1;
- if (!end_token)
- end_token = &eof_token_entry;
- end->next = end_token;
+ end->next = &eof_token_entry;
*stream->tokenlist = end;
stream->tokenlist = NULL;
+ return end;
}
static void add_token(stream_t *stream)
@@ -912,7 +911,7 @@ static struct token *setup_stream(stream_t *stream, int idx, int fd,
return begin;
}
-static void tokenize_stream(stream_t *stream, struct token *endtoken)
+static struct token *tokenize_stream(stream_t *stream)
{
int c = nextchar(stream);
while (c != EOF) {
@@ -927,22 +926,22 @@ static void tokenize_stream(stream_t *stream, struct token *endtoken)
stream->whitespace = 1;
c = nextchar(stream);
}
- mark_eof(stream, endtoken);
+ return mark_eof(stream);
}
-struct token * tokenize_buffer(void *buffer, unsigned long size, struct token *endtoken)
+struct token * tokenize_buffer(void *buffer, unsigned long size, struct token **endtoken)
{
stream_t stream;
struct token *begin;
begin = setup_stream(&stream, 0, -1, buffer, size);
- tokenize_stream(&stream, endtoken);
+ *endtoken = tokenize_stream(&stream);
return begin;
}
struct token * tokenize(const char *name, int fd, struct token *endtoken, const char **next_path)
{
- struct token *begin;
+ struct token *begin, *end;
stream_t stream;
unsigned char buffer[BUFSIZE];
int idx;
@@ -954,6 +953,8 @@ struct token * tokenize(const char *name, int fd, struct token *endtoken, const
}
begin = setup_stream(&stream, idx, fd, buffer, 0);
- tokenize_stream(&stream, endtoken);
+ end = tokenize_stream(&stream);
+ if (endtoken)
+ end->next = endtoken;
return begin;
}