changeset 505:9311fc3f8e39

Every use of isid() can be replaced by isidnum_table[], so do it.
author Rob Landley <rob@landley.net>
date Sat, 10 Nov 2007 13:20:41 -0600
parents e3ca505c9c66
children 68a80edf5e12
files tcc.c tccelf.c
diffstat 2 files changed, 12 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/tcc.c	Sat Nov 10 13:19:40 2007 -0600
+++ b/tcc.c	Sat Nov 10 13:20:41 2007 -0600
@@ -88,7 +88,7 @@
 static SValue vstack[VSTACK_SIZE];
 /* some predefined types */
 static CType int_type;
-/* true if isid(c) || isnum(c) */
+/* Whether each char is a C identifier and/or number */
 static unsigned char isidnum_table[256];
 
 /* compile with debug symbol (and use them if error during execution) */
@@ -438,13 +438,6 @@
     put_elf_reloc(symtab_section, s, offset, type, sym->c);
 }
 
-static inline int isid(int c)
-{
-    return (c >= 'a' && c <= 'z') ||
-        (c >= 'A' && c <= 'Z') ||
-        c == '_';
-}
-
 static inline int isnum(int c)
 {
     return c >= '0' && c <= '9';
@@ -2814,7 +2807,7 @@
             t = c;
             cstr_ccat(&tokcstr, c);
             PEEKC(c, p);
-            if (!(isnum(c) || isid(c) || c == '.' ||
+            if (!(isidnum_table[c] || c == '.' ||
                   ((c == '+' || c == '-') && 
                    (t == 'e' || t == 'E' || t == 'p' || t == 'P'))))
                 break;
@@ -3386,7 +3379,7 @@
                                 if (c == '\0')
                                     break;
                                 p++;
-                                if (!isnum(c) && !isid(c))
+                                if (!isidnum_table[c])
                                     goto error_pasting;
                             }
                         }
@@ -8789,6 +8782,8 @@
     return (*prog_main)(argc, argv);
 }
 
+// Initialize tcc state
+
 TCCState *tcc_new(void)
 {
     const char *p, *r;
@@ -8796,15 +8791,13 @@
     TokenSym *ts;
     int i, c;
 
-    s = tcc_mallocz(sizeof(TCCState));
-    if (!s)
-        return NULL;
-    tcc_state = s;
-    s->output_type = TCC_OUTPUT_MEMORY;
-
-    /* init isid table */
+    s = tcc_state = tcc_mallocz(sizeof(TCCState));
+    tcc_state->output_type = TCC_OUTPUT_MEMORY;
+
+    /* init isidnum table */
     for(i=0;i<256;i++)
-        isidnum_table[i] = isid(i) || isnum(i);
+        isidnum_table[i] = (i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z')
+            || i == '_' || isnum(i);
 
     /* add all tokens */
     table_ident = NULL;
--- a/tccelf.c	Sat Nov 10 13:19:40 2007 -0600
+++ b/tccelf.c	Sat Nov 10 13:20:41 2007 -0600
@@ -1064,7 +1064,7 @@
                 ch = *p;
                 if (!ch)
                     break;
-                if (!isid(ch) && !isnum(ch))
+                if (!isidnum_table[ch])
                     goto next_sec;
                 p++;
             }