From 6bae16a81c509e684c6f555dd389a7e544d9eee4 Mon Sep 17 00:00:00 2001 From: Alexey Dobriyan Date: Tue, 30 Mar 2010 00:48:06 +0300 Subject: [PATCH] acc: start parsing pp-directives --- main.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/main.c b/main.c index 9ebe7cf..d05226f 100644 --- a/main.c +++ b/main.c @@ -580,17 +580,62 @@ empty: error_exit(pos, "empty character constant"); } +static unsigned int whitespace_end(const uint32_t *c, unsigned int nr_c, unsigned int start) +{ + unsigned int i; + + i = start; + while (i < nr_c && (c[i] == ' ' || c[i] == '\t')) + i++; + return i; +} + static struct pp_token *pp_tokenize(const uint32_t *c, unsigned int nr_c, struct pos *_pos) { struct pp_token *ppt_head, *ppt_tail; + int pp_directive_allowed; unsigned int i; ppt_head = NULL; + pp_directive_allowed = 1; i = 0; while (i < nr_c) { struct pos *pos = &_pos[i]; struct pp_token *ppt; + if (pp_directive_allowed) { + static const uint32_t _error[] = {'e', 'r', 'r', 'o', 'r'}; + unsigned int sharp_start, directive_start, directive_end; + unsigned int j; + + j = whitespace_end(c, nr_c, i); + if (j >= nr_c || c[j] != '#') + goto not_pp_directive; + sharp_start = j; + j = whitespace_end(c, nr_c, j + 1); + if (j >= nr_c) { + warning(&_pos[sharp_start], "empty preprocessor directive"); + i = j; + continue; + } + if (c[j] == LS) { + warning(&_pos[sharp_start], "empty preprocessor directive"); + /* Eat newline after # */ + i = j + 1; + continue; + } + directive_start = j; + while (j < nr_c && 'a' <= c[j] && c[j] <= 'z') + j++; + directive_end = j; + + if (directive_end - directive_start == sizeof(_error) / sizeof(_error[0]) && memcmp(&c[directive_start], _error, sizeof(_error)) == 0) + error_exit(&_pos[sharp_start], "%s", ""); + + error_exit(&_pos[sharp_start], "unknown preprocessor directive"); + } + +not_pp_directive: switch (c[i]) { unsigned int j; @@ -745,6 +790,13 @@ pp_token_simple: else ppt_tail->next = ppt; ppt_tail = ppt; + + if (ppt->type == LS) + pp_directive_allowed = 1; + else if (ppt->type == ' ') + ; + else + pp_directive_allowed = 0; } return ppt_head; } -- 2.11.4.GIT