History

tccpp.c: parse flag to accept stray \

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

Philip committed 11 years ago

Commit 0877ba71 parent a3d78b92 files · +9 −2Browse files

Unified · Split

2 files
  1. tcc.h +1 −0
  2. tccpp.c +8 −2
tcc.h+1−0
@@ -1152,6 +1152,7 @@ ST_DATA TokenSym **table_ident; · 1151 unmodified lines
11521152 returned at eof */
11531153 #define PARSE_FLAG_ASM_FILE 0x0008 /* we processing an asm file: '#' can be used for line comment, etc. */
11541154 #define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */
1155+#define PARSE_FLAG_ACCEPT_STRAYS 0x0020 /* next() returns '\\' token */
11551156
11561157 ST_FUNC TokenSym *tok_alloc(const char *str, int len);
11571158 ST_FUNC char *get_tok_str(int v, CValue *cv);
tccpp.c+8−2
@@ -2271,7 +2271,13 @@ static inline void next_nomacro1(void) · 2270 unmodified lines
22712271 } else {
22722272 file->buf_ptr = p;
22732273 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+ }
22752281 p = file->buf_ptr;
22762282 goto redo_no_start;
22772283 }
@@ -3307,7 +3313,7 @@ ST_FUNC int tcc_preprocess(TCCState *s1) · 1029 unmodified lines
33073313 ch = file->buf_ptr[0];
33083314 tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
33093315 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;
33113317 token_seen = 0;
33123318 file->line_ref = 0;
33133319 file_ref = NULL;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t