tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] [PATCH 2/2] tcc -E: preserve spaces (partial solution


From: grischka
Subject: Re: [Tinycc-devel] [PATCH 2/2] tcc -E: preserve spaces (partial solution)
Date: Wed, 21 Jan 2009 19:07:43 +0100
User-agent: Thunderbird 1.5.0.10 (Windows/20070221)

Kirill Smelkov wrote:
[...] But the problem turned out to be in `tcc -E` inability to preserve
spaces between tokens. So e.g. the following ~/.Xresources

    XTerm*VT100*foreground: black
    ...

got translated to

    XTerm * VT100 * foreground : black

which is bad, bacause now X don't understand it.

Below is a newbie "fix" for the problem.


Thanks.  I don't know whether you know but this is the
third approach to the issue by now actually.

1) One using flags in parallel to the token stream:
   http://landley.net/hg/tinycc/rev/a70ac19d704b

2) One by myself (unpublished so far) that uses space tokens
   (and is so old that it probably doesn't apply anymore,
    anyway, see below)

3) And now yours which is nice because it's rather small, just
   also less complete.


--- grischka


# Comment pre
# Name GR_stringify_fix

diff -uwr src1/tcc.c src/tcc.c
--- src1/tcc.c  Thu May 10 13:24:40 2007
+++ src/tcc.c   Thu May 10 13:41:26 2007
@@ -792,6 +792,7 @@
 void set_page_executable(void *ptr, unsigned long length);

 static void next(void);
+static void next_nomacro_s(void); //YYY
 static void next_nomacro(void);
 static void parse_expr_type(CType *type);
 static void expr_type(CType *type);
@@ -2763,11 +2764,11 @@
         t = MACRO_FUNC;
     }
     tok_str_new(&str);
-    next_nomacro();
+    next_nomacro_s();//YYY
     /* EOF testing necessary for '-D' handling */
     while (tok != TOK_LINEFEED && tok != TOK_EOF) {
         tok_str_add2(&str, tok, &tokc);
-        next_nomacro();
+        next_nomacro_s();//YYY
     }
     tok_str_add(&str, 0);
 #ifdef PP_DEBUG
@@ -3580,6 +3581,13 @@
     switch(c) {
     case ' ':
     case '\t':
+        if (parse_flags & PARSE_FLAG_PREPROCESS) {//YYY
+            tok = ' ';
+            ++p;
+            while (' ' == *p || '\t' == *p)
+                ++p;
+            goto _break2;
+        }
     case '\f':
     case '\v':
     case '\r':
@@ -3978,8 +3986,9 @@
         error("unrecognized character \\x%02x", c);
         break;
     }
-    file->buf_ptr = p;
     tok_flags = 0;
+_break2://YYY
+    file->buf_ptr = p;
 #if defined(PARSE_DEBUG)
     printf("token = %s\n", get_tok_str(tok, &tokc));
 #endif
@@ -3987,7 +3996,7 @@

 /* return next token without macro substitution. Can read input from
    macro_ptr buffer */
-static void next_nomacro(void)
+static void next_nomacro_s(void)
 {
     if (macro_ptr) {
     redo:
@@ -4004,6 +4013,10 @@
     }
 }

+static void next_nomacro(void)//YYY
+{
+    do next_nomacro_s(); while (tok == ' ');
+}

 /* substitute args in macro_str and return allocated string */
 static int *macro_arg_subst(Sym **nested_list, int *macro_str, Sym *args)
@@ -4034,9 +4047,10 @@
                     if (notfirst)
                         cstr_ccat(&cstr, ' ');
                     TOK_GET(t, st, cval);
+                    if (t == ' ' && (' ' == *st || 0 == *st))//YYY
+                        continue;
                     cstr_cat(&cstr, get_tok_str(t, &cval));
-                    //gr case_4 - hmm, should we?
-                    notfirst = 1;
+                    //notfirst = 1;
                 }
                 cstr_ccat(&cstr, '\0');
 #ifdef PP_DEBUG
@@ -4209,7 +4223,7 @@
                     else if (tok == ')')
                         parlevel--;
                     tok_str_add2(&str, tok, &tokc);
-                    next_nomacro();
+                    next_nomacro_s();//YYY
                 }
                 tok_str_add(&str, 0);
                 sym_push2(&args, sa->v & ~SYM_FIELD, sa->type.t, (int)str.str);
@@ -4271,10 +4285,12 @@
     /* we search the first '##' */
     for(;;) {
         macro_ptr1 = macro_str;
-        TOK_GET(t, macro_str, cval);
+        //TOK_GET(t, macro_str, cval);
+        do { TOK_GET(t, macro_str, cval); } while (' ' == t);//YYY
         /* nothing more to do if end of string */
         if (t == 0)
             return NULL;
+        while (' ' == *macro_str) ++macro_str;//YYY
         if (*macro_str == TOK_TWOSHARPS)
             break;
     }
@@ -4299,7 +4315,8 @@
             macro_ptr1 = macro_ptr;
             t = *macro_ptr;
             if (t) {
-                TOK_GET(t, macro_ptr, cval);
+                //TOK_GET(t, macro_ptr, cval);
+                do { TOK_GET(t, macro_ptr, cval); } while (' ' == t);//YYY
                 /* We concatenate the two tokens if we have an
                    identifier or a preprocessing number */
                 cstr_reset(&cstr);
@@ -4380,7 +4397,7 @@
             }
         }
         tok_str_add2(&macro_str1, tok, &tokc);
-        next_nomacro();
+        next_nomacro_s();
         if (tok == 0)
             break;
     }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]