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:
Jon Trulson
2019-10-30 19:19:21 -06:00
parent 25e98da92e
commit 215be15f16
105 changed files with 6772 additions and 1 deletions
+1
View File
@@ -0,0 +1 @@
hello
+1
View File
@@ -0,0 +1 @@
glop.
+1
View File
@@ -0,0 +1 @@
glop.
+2
View File
@@ -0,0 +1,2 @@
#define glop flop
glop
+1
View File
@@ -0,0 +1 @@
flop
+2
View File
@@ -0,0 +1,2 @@
#define glop(x) flop x
glop(boo)
+1
View File
@@ -0,0 +1 @@
flop boo
+2
View File
@@ -0,0 +1,2 @@
#define string(x) "x"
string(abc)
+1
View File
@@ -0,0 +1 @@
"abc"
+2
View File
@@ -0,0 +1,2 @@
#define concat(a, b) a/**/b
concat(abc,def)
+1
View File
@@ -0,0 +1 @@
abcdef
+2
View File
@@ -0,0 +1,2 @@
/*glop*/
+1
View File
@@ -0,0 +1 @@
+3
View File
@@ -0,0 +1,3 @@
/*
* gloop
*/
+1
View File
@@ -0,0 +1 @@
+41
View File
@@ -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;
}
+21
View File
@@ -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;
}
+6
View File
@@ -0,0 +1,6 @@
#define STOP */
#define START /*
/*
* blah blah blah STOP fnord START goop moop
*/
View File
+3
View File
@@ -0,0 +1,3 @@
#define mac(r)o
mac(3)
mac()
+2
View File
@@ -0,0 +1,2 @@
o
o
+2
View File
@@ -0,0 +1,2 @@
#define BOO BOO
BOO
+1
View File
@@ -0,0 +1 @@
BOO
+2
View File
@@ -0,0 +1,2 @@
#define BOO(yah) BOO(yah)
BOO(yah)
+1
View File
@@ -0,0 +1 @@
BOO(yah)
+4
View File
@@ -0,0 +1,4 @@
/*
#define FOO BAR
*/
FOO
+2
View File
@@ -0,0 +1,2 @@
FOO
+4
View File
@@ -0,0 +1,4 @@
/*
#define FOO BAR */
FOO
FOO
+3
View File
@@ -0,0 +1,3 @@
FOO
FOO
+3
View File
@@ -0,0 +1,3 @@
#define FOO /* BAR */ BAZ
FOO
FOO
+2
View File
@@ -0,0 +1,2 @@
BAZ
BAZ
+11
View File
@@ -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
+11
View File
@@ -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
+2
View File
@@ -0,0 +1,2 @@
#define file "subdir/test.h"
#include file
+1
View File
@@ -0,0 +1 @@
hello
+2
View File
@@ -0,0 +1,2 @@
#if FOO /* ignore me */
#endif
View File
+3
View File
@@ -0,0 +1,3 @@
#define foo /* comment continues
into the next line */ baz
baz
+1
View File
@@ -0,0 +1 @@
baz
+1
View File
@@ -0,0 +1 @@
#undef foo /* blah */
View File
+3
View File
@@ -0,0 +1,3 @@
# define FOO BAR
#undef FOO /* would be wrong */
FOO
+2
View File
@@ -0,0 +1,2 @@
#undef BAR
BAR
+2
View File
@@ -0,0 +1,2 @@
pa/*
*/ste
+1
View File
@@ -0,0 +1 @@
paste
+8
View File
@@ -0,0 +1,8 @@
/*
fnord1
/*
fnord2
*/
foo
*/
bar
+4
View File
@@ -0,0 +1,4 @@
foo
*/
bar
+67
View File
@@ -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
+5
View File
@@ -0,0 +1,5 @@
right
right
right
right
right
+4
View File
@@ -0,0 +1,4 @@
#define FOO foo /*
#undef FOO
#define FOO bar */
FOO
+1
View File
@@ -0,0 +1 @@
foo
+4
View File
@@ -0,0 +1,4 @@
#define FOO foo
FOO
"FOO"
'FOO'
+3
View File
@@ -0,0 +1,3 @@
foo
"FOO"
'FOO'
+29
View File
@@ -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(,,)
+24
View File
@@ -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);
(,,)
+53
View File
@@ -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
+2
View File
@@ -0,0 +1,2 @@
. right
.. right
+4
View File
@@ -0,0 +1,4 @@
#if 0
# if this is a syntax error
# endif
#endif
View File
+2
View File
@@ -0,0 +1,2 @@
#define x(a,b,c) a;b;c;
x((,),x,",")
+1
View File
@@ -0,0 +1 @@
(,);x;",";
+6
View File
@@ -0,0 +1,6 @@
this line 'has /* no' comment */ in it
#define BELCH(x) 'x'
"BELCH(123)": BELCH(123)
'BELCH(123)': BELCH(123)
+3
View File
@@ -0,0 +1,3 @@
this line 'has /* no' comment */ in it
"BELCH(123)": '123'
'BELCH(123)': '123'
+21
View File
@@ -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)
+12
View File
@@ -0,0 +1,12 @@
"3"
'3'
"baz"
'baz'
"baz"
'baz'
"foo(baz)"
"bar(baz)"
"baz"
'baz'
"baz"
'baz'
+6
View File
@@ -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
+3
View File
@@ -0,0 +1,3 @@
r
"
+5
View File
@@ -0,0 +1,5 @@
#define Q "
#define FOO foo
Q FOO Q
+1
View File
@@ -0,0 +1 @@
" foo "
+6
View File
@@ -0,0 +1,6 @@
#define Q "
#define FOO foo
Q FOO Q 'I like "FOO" and "BAR"'
+1
View File
@@ -0,0 +1 @@
" foo " 'I like "FOO" and "BAR"'
+7
View File
@@ -0,0 +1,7 @@
#define C(x) //**/* x */**//
C(3)
C(abc /* def */ ghi)
#define D(x) ///**/**/**///**/* x */**///**/**/**///
D(3)
D(abc /* def */ ghi)
+4
View File
@@ -0,0 +1,4 @@
/* 3 */
/* abc ghi */
//**/* 3 */**//
//**/* abc ghi */**//
+19
View File
@@ -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
+9
View File
@@ -0,0 +1,9 @@
/*
comment?
*/
/* comment? */
abc /* def */ ghi
abc /* def ghi */ jkl
/*
*/
baz
+36
View File
@@ -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
}