move grow_symbol function into unicode.h
authorMatthias Braun <matze@braunis.de>
Tue, 26 Jul 2011 12:58:14 +0000 (14:58 +0200)
committerMatthias Braun <matze@braunis.de>
Tue, 9 Aug 2011 18:19:27 +0000 (20:19 +0200)
lexer.c
preprocessor.c
unicode.h

diff --git a/lexer.c b/lexer.c
index e29ec4a..e85895e 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -632,26 +632,6 @@ string_t make_string(const char *string)
        return identify_string(space, len);
 }
 
-static void grow_symbol(utf32 const tc)
-{
-       struct obstack *const o  = &symbol_obstack;
-       if (tc < 0x80U) {
-               obstack_1grow(o, tc);
-       } else if (tc < 0x800) {
-               obstack_1grow(o, 0xC0 | (tc >> 6));
-               obstack_1grow(o, 0x80 | (tc & 0x3F));
-       } else if (tc < 0x10000) {
-               obstack_1grow(o, 0xE0 | ( tc >> 12));
-               obstack_1grow(o, 0x80 | ((tc >>  6) & 0x3F));
-               obstack_1grow(o, 0x80 | ( tc        & 0x3F));
-       } else {
-               obstack_1grow(o, 0xF0 | ( tc >> 18));
-               obstack_1grow(o, 0x80 | ((tc >> 12) & 0x3F));
-               obstack_1grow(o, 0x80 | ((tc >>  6) & 0x3F));
-               obstack_1grow(o, 0x80 | ( tc        & 0x3F));
-       }
-}
-
 /**
  * Parse a string literal and set lexer_token.
  */
@@ -681,7 +661,7 @@ static void parse_string_literal(void)
                        goto end_of_string;
 
                default:
-                       grow_symbol(c);
+                       obstack_grow_symbol(&symbol_obstack, c);
                        next_char();
                        break;
                }
@@ -711,7 +691,7 @@ static void parse_wide_character_constant(void)
                switch (c) {
                case '\\': {
                        const utf32 tc = parse_escape_sequence();
-                       grow_symbol(tc);
+                       obstack_grow_symbol(&symbol_obstack, tc);
                        break;
                }
 
@@ -732,7 +712,7 @@ static void parse_wide_character_constant(void)
                }
 
                default:
-                       grow_symbol(c);
+                       obstack_grow_symbol(&symbol_obstack, c);
                        next_char();
                        break;
                }
@@ -796,7 +776,7 @@ static void parse_character_constant(void)
                }
 
                default:
-                       grow_symbol(c);
+                       obstack_grow_symbol(&symbol_obstack, c);
                        next_char();
                        break;
 
index 75b01d7..e3e65fb 100644 (file)
@@ -440,26 +440,6 @@ static int parse_escape_sequence(void)
        }
 }
 
-static void grow_symbol(utf32 const tc)
-{
-       struct obstack *const o  = &symbol_obstack;
-       if (tc < 0x80U) {
-               obstack_1grow(o, tc);
-       } else if (tc < 0x800) {
-               obstack_1grow(o, 0xC0 | (tc >> 6));
-               obstack_1grow(o, 0x80 | (tc & 0x3F));
-       } else if (tc < 0x10000) {
-               obstack_1grow(o, 0xE0 | ( tc >> 12));
-               obstack_1grow(o, 0x80 | ((tc >>  6) & 0x3F));
-               obstack_1grow(o, 0x80 | ( tc        & 0x3F));
-       } else {
-               obstack_1grow(o, 0xF0 | ( tc >> 18));
-               obstack_1grow(o, 0x80 | ((tc >> 12) & 0x3F));
-               obstack_1grow(o, 0x80 | ((tc >>  6) & 0x3F));
-               obstack_1grow(o, 0x80 | ( tc        & 0x3F));
-       }
-}
-
 static const char *identify_string(char *string)
 {
        const char *result = strset_insert(&stringset, string);
@@ -511,7 +491,7 @@ static void parse_string_literal(void)
                        goto end_of_string;
 
                default:
-                       grow_symbol(input.c);
+                       obstack_grow_symbol(&symbol_obstack, input.c);
                        next_char();
                        break;
                }
@@ -545,7 +525,7 @@ static void parse_wide_character_constant(void)
                switch (input.c) {
                case '\\': {
                        const utf32 tc = parse_escape_sequence();
-                       grow_symbol(tc);
+                       obstack_grow_symbol(&symbol_obstack, tc);
                        break;
                }
 
@@ -564,7 +544,7 @@ static void parse_wide_character_constant(void)
                        return;
 
                default:
-                       grow_symbol(input.c);
+                       obstack_grow_symbol(&symbol_obstack, input.c);
                        next_char();
                        break;
                }
index 2088197..18b19d5 100644 (file)
--- a/unicode.h
+++ b/unicode.h
@@ -2,6 +2,7 @@
 #define UNICODE_H
 
 #include <assert.h>
+#include "adt/obst.h"
 
 typedef unsigned int utf32;
 #define UTF32_PRINTF_FORMAT "%u"
@@ -44,4 +45,23 @@ static inline utf32 read_utf8_char(const char **p)
        return result;
 }
 
+static inline void obstack_grow_symbol(struct obstack *obstack, utf32 const tc)
+{
+       if (tc < 0x80U) {
+               obstack_1grow(obstack, tc);
+       } else if (tc < 0x800) {
+               obstack_1grow(obstack, 0xC0 | (tc >> 6));
+               obstack_1grow(obstack, 0x80 | (tc & 0x3F));
+       } else if (tc < 0x10000) {
+               obstack_1grow(obstack, 0xE0 | ( tc >> 12));
+               obstack_1grow(obstack, 0x80 | ((tc >>  6) & 0x3F));
+               obstack_1grow(obstack, 0x80 | ( tc        & 0x3F));
+       } else {
+               obstack_1grow(obstack, 0xF0 | ( tc >> 18));
+               obstack_1grow(obstack, 0x80 | ((tc >> 12) & 0x3F));
+               obstack_1grow(obstack, 0x80 | ((tc >>  6) & 0x3F));
+               obstack_1grow(obstack, 0x80 | ( tc        & 0x3F));
+       }
+}
+
 #endif