output space after TOK_PPNUM which followed by '+' or '-'

* correct -E output for the case ++ + ++ concatenation
        do this only for expanded from macro string
        and only when tcc_state->output_type == TCC_OUTPUT_PREPROCESS
This commit is contained in:
seyko
2016-05-01 05:43:57 +03:00
parent 256078933c
commit a1c139063b
9 changed files with 114 additions and 9 deletions

View File

@ -1,5 +1,6 @@
f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);
f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
f(2 * (2 +(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
char c[2][6] = { "hello", "" };
f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);
f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
f(2 * (2 +(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);

11
tests/pp/14.c Normal file
View File

@ -0,0 +1,11 @@
extern int printf(const char *format, ...);
#define P ++
#define n(x) x
int main(void)
{
int a = 0, b = -1;
int i1 = a P+P b;
printf("i1 = %d\n", i1);
return n(0x1e)n(-1);
}

8
tests/pp/14.expect Normal file
View File

@ -0,0 +1,8 @@
extern int printf(const char *format, ...);
int main(void)
{
int a = 0, b = -1;
int i1 = a +++ ++ b;
printf("i1 = %d\n", i1);
return 0x1e -1;
}

21
tests/pp/15.c Normal file
View File

@ -0,0 +1,21 @@
#define Y(x) Z(x)
#define X Y
X(1)
X(X(1))
X(X(X(X(X(1)))))
#define A B
#define B A
return A + B;
#undef A
#undef B
#define A B+1
#define B A
return A + B;
#define A1 B1+1
#define B1 C1+2
#define C1 A1+3
return A1 + B1;

6
tests/pp/15.expect Normal file
View File

@ -0,0 +1,6 @@
Z(1)
Z(Z(1))
Z(Z(Z(Z(Z(1)))))
return A + B;
return A+1 + B+1;
return A1+3 +2 +1 + B1+1 +3 +2;

View File

@ -6,17 +6,17 @@ TCC = ../../tcc
TESTS = $(patsubst %.c,%.test,$(wildcard *.c))
TESTS += $(patsubst %.S,%.test,$(wildcard *.S))
all test : $(TESTS)
all test : $(sort $(TESTS))
%.test: %.c %.expect
@echo PPTest $* ...
@$(TCC) -E -P $< >$*.output 2>&1 ; \
-@$(TCC) -E -P $< >$*.output 2>&1 ; \
diff -Nu -b -B -I "^#" $(EXTRA_DIFF_OPTS) $*.expect $*.output \
&& rm -f $*.output
%.test: %.S %.expect
@echo PPTest $* ...
@$(TCC) -E -P $< >$*.output 2>&1 ; \
-@$(TCC) -E -P $< >$*.output 2>&1 ; \
diff -Nu -b -B -I "^#" $(EXTRA_DIFF_OPTS) $*.expect $*.output \
&& rm -f $*.output