Add tradcpp to the repository, and use it as GENCPP (generic preprocessor)
With lots of experimenting, tradcpp (0.4) seems to work way better than gcc, and it's output is actually valid. We'll go with that for now.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
hello
|
||||
@@ -0,0 +1 @@
|
||||
glop.
|
||||
@@ -0,0 +1 @@
|
||||
glop.
|
||||
@@ -0,0 +1,2 @@
|
||||
#define glop flop
|
||||
glop
|
||||
@@ -0,0 +1 @@
|
||||
flop
|
||||
@@ -0,0 +1,2 @@
|
||||
#define glop(x) flop x
|
||||
glop(boo)
|
||||
@@ -0,0 +1 @@
|
||||
flop boo
|
||||
@@ -0,0 +1,2 @@
|
||||
#define string(x) "x"
|
||||
string(abc)
|
||||
@@ -0,0 +1 @@
|
||||
"abc"
|
||||
@@ -0,0 +1,2 @@
|
||||
#define concat(a, b) a/**/b
|
||||
concat(abc,def)
|
||||
@@ -0,0 +1 @@
|
||||
abcdef
|
||||
@@ -0,0 +1,2 @@
|
||||
/*glop*/
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
/*
|
||||
* gloop
|
||||
*/
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*#include <stdio.h>*/
|
||||
|
||||
int d =
|
||||
#if 2 > 1 ? 0 : 0 ? 1 : 1
|
||||
1
|
||||
#else
|
||||
0
|
||||
#endif
|
||||
;
|
||||
|
||||
int e =
|
||||
#if (2 > 1 ? 0 : 0) ? 1 : 1
|
||||
1
|
||||
#else
|
||||
0
|
||||
#endif
|
||||
;
|
||||
|
||||
int f =
|
||||
#if 2 > 1 ? 0 : (0 ? 1 : 1)
|
||||
1
|
||||
#else
|
||||
0
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int a, b, c;
|
||||
|
||||
a = 2 > 1 ? 0 : 0 ? 1 : 1;
|
||||
b = (2 > 1 ? 0 : 0) ? 1 : 1;
|
||||
c = 2 > 1 ? 0 : (0 ? 1 : 1);
|
||||
|
||||
printf("%d %d %d\n", a, b, c);
|
||||
printf("%d %d %d\n", d, e, f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
int d =
|
||||
0
|
||||
;
|
||||
int e =
|
||||
1
|
||||
;
|
||||
int f =
|
||||
0
|
||||
;
|
||||
int
|
||||
main()
|
||||
{
|
||||
int a, b, c;
|
||||
a = 2 > 1 ? 0 : 0 ? 1 : 1;
|
||||
b = (2 > 1 ? 0 : 0) ? 1 : 1;
|
||||
c = 2 > 1 ? 0 : (0 ? 1 : 1);
|
||||
printf("%d %d %d\n", a, b, c);
|
||||
printf("%d %d %d\n", d, e, f);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#define STOP */
|
||||
#define START /*
|
||||
|
||||
/*
|
||||
* blah blah blah STOP fnord START goop moop
|
||||
*/
|
||||
@@ -0,0 +1,3 @@
|
||||
#define mac(r)o
|
||||
mac(3)
|
||||
mac()
|
||||
@@ -0,0 +1,2 @@
|
||||
o
|
||||
o
|
||||
@@ -0,0 +1,2 @@
|
||||
#define BOO BOO
|
||||
BOO
|
||||
@@ -0,0 +1 @@
|
||||
BOO
|
||||
@@ -0,0 +1,2 @@
|
||||
#define BOO(yah) BOO(yah)
|
||||
BOO(yah)
|
||||
@@ -0,0 +1 @@
|
||||
BOO(yah)
|
||||
@@ -0,0 +1,4 @@
|
||||
/*
|
||||
#define FOO BAR
|
||||
*/
|
||||
FOO
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
FOO
|
||||
@@ -0,0 +1,4 @@
|
||||
/*
|
||||
#define FOO BAR */
|
||||
FOO
|
||||
FOO
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
FOO
|
||||
FOO
|
||||
@@ -0,0 +1,3 @@
|
||||
#define FOO /* BAR */ BAZ
|
||||
FOO
|
||||
FOO
|
||||
@@ -0,0 +1,2 @@
|
||||
BAZ
|
||||
BAZ
|
||||
@@ -0,0 +1,11 @@
|
||||
#define a() x
|
||||
a()
|
||||
a ()
|
||||
#define b(p) p
|
||||
x/**/b(1)/**/x
|
||||
x/**/b (1)/**/x
|
||||
x/**/b()/**/x
|
||||
#define c(p,q) p/**/q
|
||||
x/**/c(1,2)/**/x
|
||||
x/**/c(1)/**/x
|
||||
x/**/c()/**/x
|
||||
@@ -0,0 +1,11 @@
|
||||
x
|
||||
x
|
||||
x1x
|
||||
x1x
|
||||
xx
|
||||
x12x
|
||||
t16.c:10:1: Wrong number of arguments for macro c; found 1, expected 2
|
||||
x1x
|
||||
t16.c:11:1: Wrong number of arguments for macro c; found 0, expected 2
|
||||
xx
|
||||
FAILED
|
||||
@@ -0,0 +1,2 @@
|
||||
#define file "subdir/test.h"
|
||||
#include file
|
||||
@@ -0,0 +1 @@
|
||||
hello
|
||||
@@ -0,0 +1,2 @@
|
||||
#if FOO /* ignore me */
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
#define foo /* comment continues
|
||||
into the next line */ baz
|
||||
baz
|
||||
@@ -0,0 +1 @@
|
||||
baz
|
||||
@@ -0,0 +1 @@
|
||||
#undef foo /* blah */
|
||||
@@ -0,0 +1,3 @@
|
||||
# define FOO BAR
|
||||
#undef FOO /* would be wrong */
|
||||
FOO
|
||||
@@ -0,0 +1,2 @@
|
||||
#undef BAR
|
||||
BAR
|
||||
@@ -0,0 +1,2 @@
|
||||
pa/*
|
||||
*/ste
|
||||
@@ -0,0 +1 @@
|
||||
paste
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
fnord1
|
||||
/*
|
||||
fnord2
|
||||
*/
|
||||
foo
|
||||
*/
|
||||
bar
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
foo
|
||||
*/
|
||||
bar
|
||||
@@ -0,0 +1,67 @@
|
||||
#if 0
|
||||
wrong
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
right
|
||||
#endif
|
||||
|
||||
#if -1
|
||||
right
|
||||
#endif
|
||||
|
||||
#if 0 + 0
|
||||
wrong
|
||||
#endif
|
||||
|
||||
#if 1 + 1
|
||||
right
|
||||
#endif
|
||||
|
||||
#if 1 - 1
|
||||
wrong
|
||||
#endif
|
||||
|
||||
#if -1 + 1
|
||||
wrong
|
||||
#endif
|
||||
|
||||
#if 3 - 2 - 1
|
||||
wrong
|
||||
#endif
|
||||
|
||||
#if 3 * 2 - 6
|
||||
wrong
|
||||
#endif
|
||||
|
||||
#if 6 - 2 * 3
|
||||
wrong
|
||||
#endif
|
||||
|
||||
#if 3 - 3 && 1
|
||||
wrong
|
||||
#endif
|
||||
|
||||
#if 3 - 3 || 0
|
||||
wrong
|
||||
#endif
|
||||
|
||||
#if 1 && 0
|
||||
wrong
|
||||
#endif
|
||||
|
||||
#if 0 && 1
|
||||
wrong
|
||||
#endif
|
||||
|
||||
#if 1 || 0
|
||||
right
|
||||
#endif
|
||||
|
||||
#if 0 || 1
|
||||
right
|
||||
#endif
|
||||
|
||||
#if (0 || 1) && (0 || 0)
|
||||
wrong
|
||||
#endif
|
||||
@@ -0,0 +1,5 @@
|
||||
right
|
||||
right
|
||||
right
|
||||
right
|
||||
right
|
||||
@@ -0,0 +1,4 @@
|
||||
#define FOO foo /*
|
||||
#undef FOO
|
||||
#define FOO bar */
|
||||
FOO
|
||||
@@ -0,0 +1 @@
|
||||
foo
|
||||
@@ -0,0 +1,4 @@
|
||||
#define FOO foo
|
||||
FOO
|
||||
"FOO"
|
||||
'FOO'
|
||||
@@ -0,0 +1,3 @@
|
||||
foo
|
||||
"FOO"
|
||||
'FOO'
|
||||
@@ -0,0 +1,29 @@
|
||||
1.
|
||||
#define A(a) a
|
||||
A();
|
||||
|
||||
2.
|
||||
#define B(a, b) (a,b)
|
||||
B(a, );
|
||||
B(, b);
|
||||
B( , );
|
||||
B(a,);
|
||||
B(,b);
|
||||
B(,);
|
||||
|
||||
3.
|
||||
#define C(a, b, c) (a,b,c)
|
||||
C(a, b, );
|
||||
C(a, , c);
|
||||
C(, , c);
|
||||
C(a, , );
|
||||
C(, b, );
|
||||
C(, , c);
|
||||
C(, , )
|
||||
C(a,b,);
|
||||
C(a,,c);
|
||||
C(,,c);
|
||||
C(a,,);
|
||||
C(,b,);
|
||||
C(,,c);
|
||||
C(,,)
|
||||
@@ -0,0 +1,24 @@
|
||||
1.
|
||||
;
|
||||
2.
|
||||
(a, );
|
||||
(, b);
|
||||
( , );
|
||||
(a,);
|
||||
(,b);
|
||||
(,);
|
||||
3.
|
||||
(a, b, );
|
||||
(a, , c);
|
||||
(, , c);
|
||||
(a, , );
|
||||
(, b, );
|
||||
(, , c);
|
||||
(, , )
|
||||
(a,b,);
|
||||
(a,,c);
|
||||
(,,c);
|
||||
(a,,);
|
||||
(,b,);
|
||||
(,,c);
|
||||
(,,)
|
||||
@@ -0,0 +1,53 @@
|
||||
#if 1
|
||||
. right
|
||||
|
||||
# if 1
|
||||
.. right
|
||||
# elif 1
|
||||
.. wrong
|
||||
# elif 0
|
||||
.. wrong
|
||||
# else
|
||||
.. wrong
|
||||
# endif
|
||||
|
||||
#elif 1
|
||||
. wrong
|
||||
|
||||
# if 1
|
||||
.. wrong
|
||||
# elif 1
|
||||
.. wrong
|
||||
# elif 0
|
||||
.. wrong
|
||||
# else
|
||||
.. wrong
|
||||
# endif
|
||||
|
||||
#elif 0
|
||||
. wrong
|
||||
|
||||
# if 1
|
||||
.. wrong
|
||||
# elif 1
|
||||
.. wrong
|
||||
# elif 0
|
||||
.. wrong
|
||||
# else
|
||||
.. wrong
|
||||
# endif
|
||||
|
||||
#else
|
||||
. wrong
|
||||
|
||||
# if 1
|
||||
.. wrong
|
||||
# elif 1
|
||||
.. wrong
|
||||
# elif 0
|
||||
.. wrong
|
||||
# else
|
||||
.. wrong
|
||||
# endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
. right
|
||||
.. right
|
||||
@@ -0,0 +1,4 @@
|
||||
#if 0
|
||||
# if this is a syntax error
|
||||
# endif
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
#define x(a,b,c) a;b;c;
|
||||
x((,),x,",")
|
||||
@@ -0,0 +1 @@
|
||||
(,);x;",";
|
||||
@@ -0,0 +1,6 @@
|
||||
this line 'has /* no' comment */ in it
|
||||
|
||||
#define BELCH(x) 'x'
|
||||
"BELCH(123)": BELCH(123)
|
||||
'BELCH(123)': BELCH(123)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
this line 'has /* no' comment */ in it
|
||||
"BELCH(123)": '123'
|
||||
'BELCH(123)': '123'
|
||||
@@ -0,0 +1,21 @@
|
||||
#define foo(x) "x"
|
||||
#define bar(x) 'x'
|
||||
#define baz frob
|
||||
foo(3)
|
||||
bar(3)
|
||||
foo(baz)
|
||||
bar(baz)
|
||||
"baz"
|
||||
'baz'
|
||||
"foo(baz)"
|
||||
"bar(baz)"
|
||||
|
||||
#define foo2(x) foo(x)
|
||||
#define bar2(x) bar(x)
|
||||
foo2(baz)
|
||||
bar2(baz)
|
||||
|
||||
#define foo3(x) foo2(x)
|
||||
#define bar3(x) bar2(x)
|
||||
foo3(baz)
|
||||
bar3(baz)
|
||||
@@ -0,0 +1,12 @@
|
||||
"3"
|
||||
'3'
|
||||
"baz"
|
||||
'baz'
|
||||
"baz"
|
||||
'baz'
|
||||
"foo(baz)"
|
||||
"bar(baz)"
|
||||
"baz"
|
||||
'baz'
|
||||
"baz"
|
||||
'baz'
|
||||
@@ -0,0 +1,6 @@
|
||||
/* make sure that R gets defined and doesn't end up part of a string */
|
||||
#define Q "
|
||||
#define R r
|
||||
#define S "
|
||||
R
|
||||
Q
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
r
|
||||
"
|
||||
@@ -0,0 +1,5 @@
|
||||
#define Q "
|
||||
#define FOO foo
|
||||
Q FOO Q
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
" foo "
|
||||
@@ -0,0 +1,6 @@
|
||||
#define Q "
|
||||
#define FOO foo
|
||||
|
||||
Q FOO Q 'I like "FOO" and "BAR"'
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
" foo " 'I like "FOO" and "BAR"'
|
||||
@@ -0,0 +1,7 @@
|
||||
#define C(x) //**/* x */**//
|
||||
C(3)
|
||||
C(abc /* def */ ghi)
|
||||
|
||||
#define D(x) ///**/**/**///**/* x */**///**/**/**///
|
||||
D(3)
|
||||
D(abc /* def */ ghi)
|
||||
@@ -0,0 +1,4 @@
|
||||
/* 3 */
|
||||
/* abc ghi */
|
||||
//**/* 3 */**//
|
||||
//**/* abc ghi */**//
|
||||
@@ -0,0 +1,19 @@
|
||||
#define BC //**/*
|
||||
#define EC */**//
|
||||
|
||||
BC
|
||||
comment?
|
||||
EC
|
||||
|
||||
BC comment? EC
|
||||
|
||||
#define FOO(x) x
|
||||
FOO(abc BC def EC ghi)
|
||||
|
||||
#define BAR(x, y) x y
|
||||
BAR(abc BC def, ghi EC jkl)
|
||||
|
||||
BC
|
||||
#define BAZ baz
|
||||
EC
|
||||
BAZ
|
||||
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
comment?
|
||||
*/
|
||||
/* comment? */
|
||||
abc /* def */ ghi
|
||||
abc /* def ghi */ jkl
|
||||
/*
|
||||
*/
|
||||
baz
|
||||
@@ -0,0 +1,36 @@
|
||||
test_case() {
|
||||
local name="$1"
|
||||
local source="$2"
|
||||
local tradcpp="$3"
|
||||
local descr="Test tradcpp behavior"
|
||||
atf_test_case ${name}
|
||||
if [ -e "$(atf_get_srcdir)/${name}.txt" ]; then
|
||||
descr=$(cat "$(atf_get_srcdir)/${name}.txt")
|
||||
fi
|
||||
eval "${name}_head() { \
|
||||
atf_set descr \"${descr}\"; \
|
||||
atf_set require.progs \"/usr/bin/tradcpp\"; \
|
||||
}"
|
||||
local stdout="file:$(atf_get_srcdir)/${name}.good"
|
||||
local options=""
|
||||
local options_file="$(atf_get_srcdir)/${name}.cmdline"
|
||||
if [ -e ${options_file} ]; then
|
||||
options=$(cat ${options_file})
|
||||
fi
|
||||
eval "${name}_body() { \
|
||||
atf_check -s eq:0 -o ${stdout} -x '${tradcpp} ${options} ${source} 2>&1 || echo FAILED'; \
|
||||
}"
|
||||
}
|
||||
|
||||
atf_init_test_cases() {
|
||||
local tradcpp=$(make -V .OBJDIR -C $(atf_get_srcdir)/..)/tradcpp
|
||||
if [ ! -x ${tradcpp} ]; then
|
||||
tradcpp=/usr/bin/tradcpp
|
||||
fi
|
||||
cd $(atf_get_srcdir)
|
||||
for testfile in t*.c; do
|
||||
local name=${testfile%%.c}
|
||||
test_case ${name} ${testfile} ${tradcpp}
|
||||
atf_add_test_case ${name}
|
||||
done
|
||||
}
|
||||
Reference in New Issue
Block a user