Hi,

Thanks Ramsay and Sergey, sorry for misunderstanding about the mob branch! Working with git makes everything a lot easier - I was building the patch by hand.

I've attached a new patch for the mob branch which should work.

Thanks,

Dan

On 14/04/15 11:06, Ramsay Jones wrote:
On 14/04/15 04:47, Sergey Korshunoff wrote:
Hi!

2015-04-13 15:01 GMT, Daniel Holden <[email protected]>:
I've attached a new patch which tests for dollars in identifiers in C.
I've added a new parsing flag `PARSE_FLAG_ASM` to block the use of
dollar  identifiers when parsing asm. This could probably be combined
with the `PARSE_FLAG_ASM_COMMENTS` flag.
In the mob branch there is a flag PARSE_FLAG_ASM_FILE (in
tcc_add_file_internal) turned on before calling tcc_assmble. What is
needed in tcc_assemble is to keep it when changing parse_flags. Then
your patch must check PARSE_FLAG_ASM_FILE and not a PARSE_FLAG_ASM.

PARSE_FLAG_ASM_FILE is introduced to solve problems of the
preprocessor (different rules of the # parsing)

First version of the your patch is pushed to mob by me (with you as
the autor of the patch in comments). Only addons of the new patch must
be pushed to the mob. Your patch contain a \r chars.  Is this chars
are removed by git?
Ah, sorry Sergey, I hadn't noticed that you had already included an
earlier version of the patch. [Daniel, look on the mob branch for
commit dcb36587 ("-fdollar-in-identifiers switch which enables '$'
in identifiers", 12-04-2015)]

I notice that the mob branch does not contain Daniel's test '56_dollars.c'.
Since I had it laying around, I decided to hack the Makefile:

   $ git diff
   diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile
   index 35ab3c1..4334e75 100644
   --- a/tests/tests2/Makefile
   +++ b/tests/tests2/Makefile
   @@ -76,6 +76,7 @@ TESTS =       \
     54_goto.test \
     55_lshift_type.test \
     56_btype_excess-1.test \
   + 56_dollars.test \
     57_btype_excess-2.test \
     58_function_redefinition.test \
     59_function_array.test \
   $

It should probably be called '76_dollars.c' by now! Now test:

   $ make test
   ...
   Test: 56_btype_excess-1...
   Test: 56_dollars...
   --- 56_dollars.expect        2015-04-13 17:39:08.787672483 +0100
   +++ 56_dollars.output        2015-04-14 10:52:04.232805798 +0100
   @@ -1,14 +1 @@
   -fred=10
   -joe=20
   -henry=30
   -fred2=10
   -joe2=20
   -henry2=30
   -fred10=100
   -joe_10=2
   -local=10
   -a100$=100
   -a$$=1000
   -a$c$b=2121
   -$100=10000
   -$$$=money
   +56_dollars.c:3: error: invalid macro name '$'
   make[2]: *** [56_dollars.test] Error 1
   make[2]: Leaving directory `/home/ramsay/tinycc/tests/tests2'
   make[1]: *** [moretests] Error 2
   make[1]: Leaving directory `/home/ramsay/tinycc/tests'
   make: *** [test] Error 2
   $

HTH

ATB,
Ramsay Jones





_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel



--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

commit 82f8ba0e81c04598a565c2f3044aa8091ea29454
Author: Daniel Holden <[email protected]>
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 <stdio.h>
+
+#define $(x) x
+#define $fred 10
+#define joe$ 20
+#define hen$y 30
+
+#define $10(x) x*10
+#define _$10(x) x/10
+
+int main()
+{
+   printf("fred=%d\n", $fred);
+   printf("joe=%d\n", joe$);
+   printf("henry=%d\n", hen$y);
+
+   printf("fred2=%d\n", $($fred));
+   printf("joe2=%d\n", $(joe$));
+   printf("henry2=%d\n", $(hen$y));
+   
+   printf("fred10=%d\n", $10($fred));
+   printf("joe_10=%d\n", _$10(joe$));
+   
+   int $ = 10; 
+   int a100$ = 100;
+   int a$$ = 1000;
+   int a$c$b = 2121;
+   int $100 = 10000;
+   const char *$$$ = "money";
+   
+   printf("local=%d\n", $);
+   printf("a100$=%d\n", a100$);
+   printf("a$$=%d\n", a$$);
+   printf("a$c$b=%d\n", a$c$b);
+   printf("$100=%d\n", $100);
+   printf("$$$=%s", $$$);
+
+   return 0;
+}
+
+/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
+
diff --git a/tests/tests2/76_dollars_in_identifiers.expect b/tests/tests2/76_dollars_in_identifiers.expect
new file mode 100644
index 0000000..4a20a52
--- /dev/null
+++ b/tests/tests2/76_dollars_in_identifiers.expect
@@ -0,0 +1,14 @@
+fred=10
+joe=20
+henry=30
+fred2=10
+joe2=20
+henry2=30
+fred10=100
+joe_10=2
+local=10
+a100$=100
+a$$=1000
+a$c$b=2121
+$100=10000
+$$$=money
diff --git a/tests/tests2/Makefile b/tests/tests2/Makefile
index 35ab3c1..a5a18fb 100644
--- a/tests/tests2/Makefile
+++ b/tests/tests2/Makefile
@@ -94,8 +94,8 @@ TESTS =	\
  72_long_long_constant.test \
  73_arm64.test \
  74_nocode_wanted.test \
- 75_array_in_struct_init.test
-
+ 75_array_in_struct_init.test \
+ 76_dollars_in_identifiers.test
 
 # 34_array_assignment.test -- array assignment is not in C standard
 
@@ -121,15 +121,19 @@ ARGS =
 31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5
 46_grep.test : ARGS = '[^* ]*[:a:d: ]+\:\*-/: $$' 46_grep.c
 
+# Some tests might need different flags
+FLAGS =
+76_dollars_in_identifiers.test : FLAGS = -fdollars-in-identifiers
+
 all test: $(filter-out $(SKIP),$(TESTS))
 
 %.test: %.c
 	@echo Test: $*...
 
-	@$(TCC) -run $< $(ARGS) 2>&1 | grep -v 'warning: soft float ABI currently not supported: default to softfp' >$*.output || true
+	@$(TCC) -run $(FLAGS) $< $(ARGS) 2>&1 | grep -v 'warning: soft float ABI currently not supported: default to softfp' >$*.output || true
 	@diff -Nbu $*.expect $*.output && rm -f $*.output
 
-	@($(TCC) $< -o $*.exe && ./$*.exe $(ARGS)) 2>&1 | grep -v 'warning: soft float ABI currently not supported: default to softfp' >$*.output2 || true
+	@($(TCC) $(FLAGS) $< -o $*.exe && ./$*.exe $(ARGS)) 2>&1 | grep -v 'warning: soft float ABI currently not supported: default to softfp' >$*.output2 || true
 	@diff -Nbu $*.expect $*.output2 && rm -f $*.output2 $*.exe
 
 clean:
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to