diff --git a/tcc.c b/tcc.c index c557bea..26851f9 100644 --- a/tcc.c +++ b/tcc.c @@ -1772,22 +1772,40 @@ static void minp(void) } -static void parse_line_comment(void) +/* single line C++ comments */ +static uint8_t *parse_line_comment(uint8_t *p) { - /* single line C++ comments */ - /* XXX: accept '\\\n' ? */ - inp(); - while (ch != '\n' && ch != CH_EOF) - inp(); + int c; + + p++; + for(;;) { + c = *p; + if (c == '\n' || c == CH_EOF) { + break; + } else if (c == '\\') { + PEEKC_EOB(c, p); + if (c == '\n') { + file->line_num++; + PEEKC_EOB(c, p); + } else if (c == '\r') { + PEEKC_EOB(c, p); + if (c == '\n') { + file->line_num++; + PEEKC_EOB(c, p); + } + } + } else { + p++; + } + } + return p; } -static void parse_comment(void) +/* C comments */ +static uint8_t *parse_comment(uint8_t *p) { - uint8_t *p; int c; - /* C comments */ - p = file->buf_ptr; p++; for(;;) { /* fast skip loop */ @@ -1816,32 +1834,30 @@ static void parse_comment(void) } else if (c == '\\') { file->buf_ptr = p; c = handle_eob(); + p = file->buf_ptr; if (c == '\\') { - /* skip '\\n', but if '\' followed but another - char, behave asif a stray was parsed */ - ch = file->buf_ptr[0]; - while (ch == '\\') { - inp(); - if (ch == '\n') { + /* skip '\[\r]\n', otherwise just skip the stray */ + while (c == '\\') { + PEEKC_EOB(c, p); + if (c == '\n') { file->line_num++; - inp(); - } else if (ch == '\r') { - inp(); - if (ch == '\n') { + PEEKC_EOB(c, p); + } else if (c == '\r') { + PEEKC_EOB(c, p); + if (c == '\n') { file->line_num++; - inp(); + PEEKC_EOB(c, p); } } else { - p = file->buf_ptr; - break; + goto after_star; } } } - p = file->buf_ptr; } else { break; } } + after_star: ; } else { /* stray, eob or eof */ file->buf_ptr = p; @@ -1856,8 +1872,7 @@ static void parse_comment(void) } end_of_comment: p++; - file->buf_ptr = p; - ch = *p; + return p; } #define cinp minp @@ -1984,12 +1999,12 @@ void preprocess_skip(void) file->buf_ptr = p; ch = *p; minp(); - if (ch == '*') { - parse_comment(); - } else if (ch == '/') { - parse_line_comment(); - } p = file->buf_ptr; + if (ch == '*') { + p = parse_comment(p); + } else if (ch == '/') { + p = parse_line_comment(p); + } break; case '#': @@ -3541,14 +3556,10 @@ static inline void next_nomacro1(void) case '/': PEEKC(c, p); if (c == '*') { - file->buf_ptr = p; - parse_comment(); - p = file->buf_ptr; + p = parse_comment(p); goto redo_no_start; } else if (c == '/') { - file->buf_ptr = p; - parse_line_comment(); - p = file->buf_ptr; + p = parse_line_comment(p); goto redo_no_start; } else if (c == '=') { p++; diff --git a/tccelf.c b/tccelf.c index 1e4898d..891a68b 100644 --- a/tccelf.c +++ b/tccelf.c @@ -1868,7 +1868,8 @@ static int ld_next(TCCState *s1, char *name, int name_size) case '/': minp(); if (ch == '*') { - parse_comment(); + file->buf_ptr = parse_comment(file->buf_ptr); + ch = file->buf_ptr[0]; goto redo; } else { q = name;