aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip <pipcet@gmail.com>2015-05-02 12:58:37 +0000
committerPhilip <pipcet@gmail.com>2015-05-02 12:58:37 +0000
commit0877ba7cbf275fdcd45e3c33768d258fc75feb5b (patch)
treedc52b5c3b27496aca61f6ffd72b082181c7da1de
parenta3d78b95d7564c92afa09604fde6387a03d3acde (diff)
downloadtinycc-0877ba7cbf275fdcd45e3c33768d258fc75feb5b.tar.gz
tinycc-0877ba7cbf275fdcd45e3c33768d258fc75feb5b.tar.bz2
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
-rw-r--r--tcc.h1
-rw-r--r--tccpp.c10
2 files changed, 9 insertions, 2 deletions
diff --git a/tcc.h b/tcc.h
index 384e8de..a0d0635 100644
--- a/tcc.h
+++ b/tcc.h
@@ -1152,6 +1152,7 @@ ST_DATA TokenSym **table_ident;
returned at eof */
#define PARSE_FLAG_ASM_FILE 0x0008 /* we processing an asm file: '#' can be used for line comment, etc. */
#define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */
+#define PARSE_FLAG_ACCEPT_STRAYS 0x0020 /* next() returns '\\' token */
ST_FUNC TokenSym *tok_alloc(const char *str, int len);
ST_FUNC char *get_tok_str(int v, CValue *cv);
diff --git a/tccpp.c b/tccpp.c
index 56779e0..ed3168f 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -2271,7 +2271,13 @@ static inline void next_nomacro1(void)
} else {
file->buf_ptr = p;
ch = *p;
- handle_stray();
+ if (parse_flags & PARSE_FLAG_ACCEPT_STRAYS) {
+ if (handle_stray_noerror() != 0) {
+ goto parse_simple;
+ }
+ } else {
+ handle_stray();
+ }
p = file->buf_ptr;
goto redo_no_start;
}
@@ -3307,7 +3313,7 @@ ST_FUNC int tcc_preprocess(TCCState *s1)
ch = file->buf_ptr[0];
tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF;
parse_flags &= PARSE_FLAG_ASM_FILE;
- parse_flags |= PARSE_FLAG_PREPROCESS | PARSE_FLAG_LINEFEED | PARSE_FLAG_SPACES;
+ parse_flags |= PARSE_FLAG_PREPROCESS | PARSE_FLAG_LINEFEED | PARSE_FLAG_SPACES | PARSE_FLAG_ACCEPT_STRAYS;
token_seen = 0;
file->line_ref = 0;
file_ref = NULL;