diff options
| author | bellard <bellard> | 2003-04-13 18:05:51 +0000 |
|---|---|---|
| committer | bellard <bellard> | 2003-04-13 18:05:51 +0000 |
| commit | cab6018913313278df161fce1770933902fac1ca (patch) | |
| tree | 2c7f2103a2c57010ebf9d71eb5469027f13b8818 /tcc.c | |
| parent | 0c618f4b7f0d8ee20b30a276efc8a2c17acb469c (diff) | |
| download | tinycc-cab6018913313278df161fce1770933902fac1ca.tar.gz tinycc-cab6018913313278df161fce1770933902fac1ca.tar.bz2 | |
fixed comment parsing
Diffstat (limited to 'tcc.c')
| -rw-r--r-- | tcc.c | 81 |
1 files changed, 46 insertions, 35 deletions
@@ -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(); + p = file->buf_ptr; if (ch == '*') { - parse_comment(); + p = parse_comment(p); } else if (ch == '/') { - parse_line_comment(); + p = parse_line_comment(p); } - p = file->buf_ptr; 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++; |
