Parse __extension__ like GCC: External declarations may start with it.
[cparser] / lexer.c
diff --git a/lexer.c b/lexer.c
index 9697a51..38a8e1d 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -56,7 +56,7 @@
 static utf32             c;
 static source_position_t lexer_pos;
 token_t                  lexer_token;
-symbol_t                *symbol_L;
+static symbol_t         *symbol_L;
 static FILE             *input;
 static utf32             buf[BUF_SIZE + MAX_PUTBACK];
 static const utf32      *bufend;
@@ -400,7 +400,7 @@ static inline void next_char(void);
                lexer_pos.colno = 1; \
                code
 
-#define eat(c_type)  do { assert(c == c_type); next_char(); } while (0)
+#define eat(c_type) (assert(c == c_type), next_char())
 
 static void maybe_concat_lines(void)
 {
@@ -688,19 +688,7 @@ static void parse_number_hex(void)
  */
 static bool is_octal_digit(utf32 chr)
 {
-       switch (chr) {
-       case '0':
-       case '1':
-       case '2':
-       case '3':
-       case '4':
-       case '5':
-       case '6':
-       case '7':
-               return true;
-       default:
-               return false;
-       }
+       return '0' <= chr && chr <= '7';
 }
 
 /**
@@ -963,7 +951,7 @@ static void parse_string_literal(void)
                case '\\': {
                        utf32 const tc = parse_escape_sequence();
                        if (tc >= 0x100) {
-                               warningf(&lexer_pos, "escape sequence out of range");
+                               warningf(WARN_OTHER, &lexer_pos, "escape sequence out of range");
                        }
                        obstack_1grow(&symbol_obstack, tc);
                        break;
@@ -1071,7 +1059,7 @@ static void parse_character_constant(void)
                case '\\': {
                        utf32 const tc = parse_escape_sequence();
                        if (tc >= 0x100) {
-                               warningf(&lexer_pos, "escape sequence out of range");
+                               warningf(WARN_OTHER, &lexer_pos, "escape sequence out of range");
                        }
                        obstack_1grow(&symbol_obstack, tc);
                        break;
@@ -1124,9 +1112,7 @@ static void skip_multiline_comment(void)
                        next_char();
                        if (c == '*') {
                                /* nested comment, warn here */
-                               if (warning.comment) {
-                                       warningf(&lexer_pos, "'/*' within comment");
-                               }
+                               warningf(WARN_COMMENT, &lexer_pos, "'/*' within comment");
                        }
                        break;
                case '*':
@@ -1168,8 +1154,7 @@ static void skip_line_comment(void)
                case '\\':
                        next_char();
                        if (c == '\n' || c == '\r') {
-                               if (warning.comment)
-                                       warningf(&lexer_pos, "multi-line comment");
+                               warningf(WARN_COMMENT, &lexer_pos, "multi-line comment");
                                return;
                        }
                        break;
@@ -1328,8 +1313,8 @@ static void parse_pragma(void)
                unknown_pragma = true;
        }
        eat_until_newline();
-       if (unknown_pragma && warning.unknown_pragmas) {
-               warningf(&pp_token.source_position, "encountered unknown #pragma");
+       if (unknown_pragma) {
+               warningf(WARN_UNKNOWN_PRAGMAS, &pp_token.source_position, "encountered unknown #pragma");
        }
 }
 
@@ -1423,14 +1408,13 @@ static void parse_preprocessor_directive(void)
 #define ELSE_CODE(code)                                    \
                                default:                                   \
                                        code                                   \
+                                       return;                                \
                                }                                          \
                        } /* end of while (true) */                    \
-                       break;
 
 #define ELSE(set_type)                                     \
                ELSE_CODE(                                         \
                        lexer_token.type = set_type;                   \
-                       return;                                        \
                )
 
 void lexer_next_preprocessing_token(void)
@@ -1487,7 +1471,6 @@ void lexer_next_preprocessing_token(void)
                                                put_back(c);
                                                c = '.';
                                                lexer_token.type = '.';
-                                               return;
                                        )
                        ELSE('.')
                case '&':
@@ -1541,7 +1524,6 @@ void lexer_next_preprocessing_token(void)
                                                                put_back(c);
                                                                c = '%';
                                                                lexer_token.type = '#';
-                                                               return;
                                                        )
                                        ELSE('#')
                        ELSE('%')