>From e3f4b4e3c115274b61efafa6bab7171c7d504352 Mon Sep 17 00:00:00 2001 From: Daniel Holden
Date: Tue, 14 Apr 2015 18:21:33 +0100 Subject: [PATCH] Fixed Dollars in Identifiers Patch Added tests for dollars in identifiers flag and also fixed issue with compile flags not being ready at the time of preprocessor construction. Added fix for syntax conflict with asm where identifier with $ as first character has different meaning. --- tccasm.c | 3 +- tccpp.c | 18 +++++++----- tests/Makefile | 2 +- tests/tests2/76_dollars_in_identifiers.c | 41 +++++++++++++++++++++++++++ tests/tests2/76_dollars_in_identifiers.expect | 14 +++++++++ tests/tests2/Makefile | 12 +++++--- 6 files changed, 77 insertions(+), 13 deletions(-) create mode 100644 tests/tests2/76_dollars_in_identifiers.c create mode 100644 tests/tests2/76_dollars_in_identifiers.expect diff --git a/tccasm.c b/tccasm.c index d9c929c..25277fe 100644 --- a/tccasm.c +++ b/tccasm.c @@ -747,7 +747,7 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess) ch = file->buf_ptr[0]; tok_flags = TOK_FLAG_BOL | TOK_FLAG_BOF; - parse_flags = PARSE_FLAG_ASM_COMMENTS; + parse_flags |= PARSE_FLAG_ASM_COMMENTS; if (do_preprocess) parse_flags |= PARSE_FLAG_PREPROCESS; next(); @@ -853,6 +853,7 @@ static void tcc_assemble_inline(TCCState *s1, char *str, int len) memcpy(file->buffer, str, len); macro_ptr = NULL; + parse_flags |= PARSE_FLAG_ASM_FILE; tcc_assemble_internal(s1, 0); tcc_close(); diff --git a/tccpp.c b/tccpp.c index 111ea2b..d9300da 100644 --- a/tccpp.c +++ b/tccpp.c @@ -2287,9 +2287,11 @@ maybe_newline: } break; - /* treat $ as allowed char in indentifier */ - case '$': if (!tcc_state->dollars_in_identifiers) goto parse_simple; - + /* dollar is allowed to start identifiers when not parsing asm */ + case '$': + if (!tcc_state->dollars_in_identifiers + || (parse_flags & PARSE_FLAG_ASM_FILE)) goto parse_simple; + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': @@ -2312,7 +2314,8 @@ maybe_newline: p++; for(;;) { c = *p; - if (!isidnum_table[c-CH_EOF]) + if (!isidnum_table[c-CH_EOF] + && (tcc_state->dollars_in_identifiers ? c != '$' : 1)) break; h = TOK_HASH_FUNC(h, c); p++; @@ -2347,7 +2350,8 @@ maybe_newline: p--; PEEKC(c, p); parse_ident_slow: - while (isidnum_table[c-CH_EOF]) { + while (isidnum_table[c-CH_EOF] + || (tcc_state->dollars_in_identifiers ? c == '$' : 0)) { cstr_ccat(&tokcstr, c); PEEKC(c, p); } @@ -3176,9 +3180,9 @@ ST_FUNC void preprocess_new(void) const char *p, *r; /* init isid table */ + for(i=CH_EOF;i<256;i++) - isidnum_table[i-CH_EOF] = (isid(i) || isnum(i) || - (tcc_state->dollars_in_identifiers ? i == '$' : 0)); + isidnum_table[i-CH_EOF] = isid(i) || isnum(i); /* add all tokens */ if (table_ident) { diff --git a/tests/Makefile b/tests/Makefile index bc68de0..98ccb1e 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -199,7 +199,7 @@ ex%: $(top_srcdir)/examples/ex%.c # tiny assembler testing asmtest.ref: asmtest.S - $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S + $(CC) -m32 -Wa,-W -o asmtest.ref.o -c asmtest.S objdump -D asmtest.ref.o > asmtest.ref asmtest: asmtest.ref diff --git a/tests/tests2/76_dollars_in_identifiers.c b/tests/tests2/76_dollars_in_identifiers.c new file mode 100644 index 0000000..c5fcf99 --- /dev/null +++ b/tests/tests2/76_dollars_in_identifiers.c @@ -0,0 +1,41 @@ +#include