commit 82f8ba0e81c04598a565c2f3044aa8091ea29454 Author: Daniel Holden
Date: Tue Apr 14 14:38:25 2015 +0100 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. 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..48c48fd --- /dev/null +++ b/tests/tests2/76_dollars_in_identifiers.c @@ -0,0 +1,42 @@ +#include