This adds a PARSE_FLAG_ACCEPT_STRAYS parse flag to accept stray backslashes in the source code, and uses it for pure preprocessing. For absolutely correct behaviour of # stringification, we need to use this flag when parsing macro definitions and in macro arguments, as well; this patch does not yet do so. The test case for that is something like #define STRINGIFY2(x) #x #define STRINGIFY(x) STRINGIFY2(x) STRINGIFY(\n) which should produce "\n", not a parse error or "\\n". See http://lists.nongnu.org/archive/html/tinycc-devel/2015-05/msg00002.html
Unified · Split
| @@ -1152,6 +1152,7 @@ ST_DATA TokenSym **table_ident; · 1151 unmodified lines | |||
| 1152 | returned at eof */ | 1152 | returned at eof */ |
| 1153 | #define PARSE_FLAG_ASM_FILE 0x0008 /* we processing an asm file: '#' can be used for line comment, etc. */ | 1153 | #define PARSE_FLAG_ASM_FILE 0x0008 /* we processing an asm file: '#' can be used for line comment, etc. */ |
| 1154 | #define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */ | 1154 | #define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */ |
| 1155 | #define PARSE_FLAG_ACCEPT_STRAYS 0x0020 /* next() returns '\\' token */ | ||
| 1155 | 1156 | ||
| 1156 | ST_FUNC TokenSym *tok_alloc(const char *str, int len); | 1157 | ST_FUNC TokenSym *tok_alloc(const char *str, int len); |
| 1157 | ST_FUNC char *get_tok_str(int v, CValue *cv); | 1158 | ST_FUNC char *get_tok_str(int v, CValue *cv); |
| @@ -2271,7 +2271,13 @@ static inline void next_nomacro1(void) · 2270 unmodified lines | |||
| 2271 | } else { | 2271 | } else { |
| 2272 | file->buf_ptr = p; | 2272 | file->buf_ptr = p; |
| 2273 | ch = *p; | 2273 | ch = *p; |
| 2274 | handle_stray(); | 2274 | if (parse_flags & PARSE_FLAG_ACCEPT_STRAYS) { |
| 2275 | if (handle_stray_noerror() != 0) { | ||
| 2276 | goto parse_simple; | ||
| 2277 | } | ||
| 2278 | } else { | ||
| 2279 | handle_stray(); | ||
| 2280 | } | ||
| 2275 | p = file->buf_ptr; | 2281 | p = file->buf_ptr; |
| 2276 | goto redo_no_start; | 2282 | goto redo_no_start; |
| 2277 | } | 2283 | } |
| @@ -3307,7 +3313,7 @@ ST_FUNC int tcc_preprocess(TCCState *s1) · 1029 unmodified lines | |||
| 3307 | ch = file->buf_ptr[0]; | 3313 | ch = file->buf_ptr[0]; |
| 3308 | tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF; | 3314 | tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF; |
| 3309 | parse_flags &= PARSE_FLAG_ASM_FILE; | 3315 | parse_flags &= PARSE_FLAG_ASM_FILE; |
| 3310 | parse_flags |= PARSE_FLAG_PREPROCESS | PARSE_FLAG_LINEFEED | PARSE_FLAG_SPACES; | 3316 | parse_flags |= PARSE_FLAG_PREPROCESS | PARSE_FLAG_LINEFEED | PARSE_FLAG_SPACES | PARSE_FLAG_ACCEPT_STRAYS; |
| 3311 | token_seen = 0; | 3317 | token_seen = 0; |
| 3312 | file->line_ref = 0; | 3318 | file->line_ref = 0; |
| 3313 | file_ref = NULL; | 3319 | file_ref = NULL; |