Em Sat, Aug 13, 2005 at 08:49:17PM -0700, Linus Torvalds escreveu:
> In short, why not just pass in the whole token_struct list, and let the 
> "preprocess_only()" function just see it all in one go. If it wants to 
> print it out, it can copy the existing "make up some whitespace around the 
> tokens" logic, but it's not necessarily the case that it needs/cares about 
> that at all. So why feed things one token at a time together with 
> whitespace hints that are somethign that the other side can really just 
> calculate itself?

OK, take a look at this one, hope you find it acceptable.
 
> What alternative preprocessor output stuff do you want, anyway?

Hope you had time to read the explanation in the other message.

Signed-off-by: Arnaldo Carvalho de Melo <[EMAIL PROTECTED]>

Best Regards,

- Arnaldo

diff --git a/lib.c b/lib.c
--- a/lib.c
+++ b/lib.c
@@ -171,10 +171,33 @@ int Wcontext = 0;
 int Wundefined_preprocessor = 0;
 int Wptr_subtraction_blows = 0;
 int Wtransparent_union = 1;
-int preprocess_only;
+struct token *(*sparse_custom_preprocessor)(struct token *token);
 char *include;
 int include_fd = -1;
 
+struct token *sparse_preprocess_only(struct token *token)
+{
+       token = preprocess(token);
+
+       while (!eof_token(token)) {
+               int prec = 1;
+               struct token *next = token->next;
+               const char *separator = "";
+               if (next->pos.whitespace)
+                       separator = " ";
+               if (next->pos.newline) {
+                       separator = "\n\t\t\t\t\t";
+                       prec = next->pos.pos;
+                       if (prec > 4)
+                               prec = 4;
+               }
+               printf("%s%.*s", show_token(token), prec, separator);
+               token = next;
+       }
+       putchar('\n');
+       return NULL;
+}
+
 void add_pre_buffer(const char *fmt, ...)
 {
        va_list args;
@@ -210,7 +233,7 @@ static char **handle_switch_D(char *arg,
 
 static char **handle_switch_E(char *arg, char **next)
 {
-       preprocess_only = 1;
+       sparse_custom_preprocessor = sparse_preprocess_only;
        return next;
 }
 
@@ -448,28 +471,12 @@ void create_builtin_stream(void)
 static struct symbol_list *sparse_tokenstream(struct token *token)
 {
        // Pre-process the stream
-       token = preprocess(token);
-
-       if (preprocess_only) {
-               while (!eof_token(token)) {
-                       int prec = 1;
-                       struct token *next = token->next;
-                       const char *separator = "";
-                       if (next->pos.whitespace)
-                               separator = " ";
-                       if (next->pos.newline) {
-                               separator = "\n\t\t\t\t\t";
-                               prec = next->pos.pos;
-                               if (prec > 4)
-                                       prec = 4;
-                       }
-                       printf("%s%.*s", show_token(token), prec, separator);
-                       token = next;
-               }
-               putchar('\n');
-
-               return NULL;
-       } 
+       if (sparse_custom_preprocessor) {
+               token = sparse_custom_preprocessor(token);
+               if (!token)
+                       return NULL;
+       } else
+               token = preprocess(token);
 
        // Parse the resulting C code
        while (!eof_token(token))
@@ -554,7 +561,7 @@ int sparse_initialize(int argc, char **a
 
                create_builtin_stream();
                add_pre_buffer("#define __CHECKER__ 1\n");
-               if (!preprocess_only)
+               if (!sparse_custom_preprocessor)
                        declare_builtin_functions();
 
                sparse_initial();
diff --git a/lib.h b/lib.h
--- a/lib.h
+++ b/lib.h
@@ -73,7 +73,8 @@ extern void add_pre_buffer(const char *f
 
 extern int include_fd;
 extern char *include;
-extern int preprocess_only;
+extern struct token *sparse_preprocess_only(struct token *token);
+extern struct token *(*sparse_custom_preprocessor)(struct token *token);
 extern int Wptr_subtraction_blows;
 extern int Wdefault_bitfield_sign;
 extern int Wundefined_preprocessor;
diff --git a/test-lexing.c b/test-lexing.c
--- a/test-lexing.c
+++ b/test-lexing.c
@@ -20,7 +20,7 @@
 
 int main(int argc, char **argv)
 {
-       preprocess_only = 1;
+       sparse_custom_preprocessor = sparse_preprocess_only;
        sparse_initialize(argc, argv);
        while (*argv)
                sparse(argv);
-
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to