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:17:24 -06:00
parent 25e98da92e
commit 215be15f16
105 changed files with 6772 additions and 1 deletions

View File

@@ -0,0 +1 @@
hello

View File

@@ -0,0 +1 @@
glop.

View File

@@ -0,0 +1 @@
glop.

View File

@@ -0,0 +1,2 @@
#define glop flop
glop

View File

@@ -0,0 +1 @@
flop

View File

@@ -0,0 +1,2 @@
#define glop(x) flop x
glop(boo)

View File

@@ -0,0 +1 @@
flop boo

View File

@@ -0,0 +1,2 @@
#define string(x) "x"
string(abc)

View File

@@ -0,0 +1 @@
"abc"

View File

@@ -0,0 +1,2 @@
#define concat(a, b) a/**/b
concat(abc,def)

View File

@@ -0,0 +1 @@
abcdef

View File

@@ -0,0 +1,2 @@
/*glop*/

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,3 @@
/*
* gloop
*/

View File

@@ -0,0 +1 @@

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;
}

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;
}

View File

@@ -0,0 +1,6 @@
#define STOP */
#define START /*
/*
* blah blah blah STOP fnord START goop moop
*/

View File

View File

@@ -0,0 +1,3 @@
#define mac(r)o
mac(3)
mac()

View File

@@ -0,0 +1,2 @@
o
o

View File

@@ -0,0 +1,2 @@
#define BOO BOO
BOO

View File

@@ -0,0 +1 @@
BOO

View File

@@ -0,0 +1,2 @@
#define BOO(yah) BOO(yah)
BOO(yah)

View File

@@ -0,0 +1 @@
BOO(yah)

View File

@@ -0,0 +1,4 @@
/*
#define FOO BAR
*/
FOO

View File

@@ -0,0 +1,2 @@
FOO

View File

@@ -0,0 +1,4 @@
/*
#define FOO BAR */
FOO
FOO

View File

@@ -0,0 +1,3 @@
FOO
FOO

View File

@@ -0,0 +1,3 @@
#define FOO /* BAR */ BAZ
FOO
FOO

View File

@@ -0,0 +1,2 @@
BAZ
BAZ

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

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

View File

@@ -0,0 +1,2 @@
#define file "subdir/test.h"
#include file

View File

@@ -0,0 +1 @@
hello

View File

@@ -0,0 +1,2 @@
#if FOO /* ignore me */
#endif

View File

View File

@@ -0,0 +1,3 @@
#define foo /* comment continues
into the next line */ baz
baz

View File

@@ -0,0 +1 @@
baz

View File

@@ -0,0 +1 @@
#undef foo /* blah */

View File

View File

@@ -0,0 +1,3 @@
# define FOO BAR
#undef FOO /* would be wrong */
FOO

View File

@@ -0,0 +1,2 @@
#undef BAR
BAR

View File

@@ -0,0 +1,2 @@
pa/*
*/ste

View File

@@ -0,0 +1 @@
paste

View File

@@ -0,0 +1,8 @@
/*
fnord1
/*
fnord2
*/
foo
*/
bar

View File

@@ -0,0 +1,4 @@
foo
*/
bar

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

View File

@@ -0,0 +1,5 @@
right
right
right
right
right

View File

@@ -0,0 +1,4 @@
#define FOO foo /*
#undef FOO
#define FOO bar */
FOO

View File

@@ -0,0 +1 @@
foo

View File

@@ -0,0 +1,4 @@
#define FOO foo
FOO
"FOO"
'FOO'

View File

@@ -0,0 +1,3 @@
foo
"FOO"
'FOO'

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(,,)

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);
(,,)

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

View File

@@ -0,0 +1,2 @@
. right
.. right

View File

@@ -0,0 +1,4 @@
#if 0
# if this is a syntax error
# endif
#endif

View File

View File

@@ -0,0 +1,2 @@
#define x(a,b,c) a;b;c;
x((,),x,",")

View File

@@ -0,0 +1 @@
(,);x;",";

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)

View File

@@ -0,0 +1,3 @@
this line 'has /* no' comment */ in it
"BELCH(123)": '123'
'BELCH(123)': '123'

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)

View File

@@ -0,0 +1,12 @@
"3"
'3'
"baz"
'baz'
"baz"
'baz'
"foo(baz)"
"bar(baz)"
"baz"
'baz'
"baz"
'baz'

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

View File

@@ -0,0 +1,3 @@
r
"

View File

@@ -0,0 +1,5 @@
#define Q "
#define FOO foo
Q FOO Q

View File

@@ -0,0 +1 @@
" foo "

View File

@@ -0,0 +1,6 @@
#define Q "
#define FOO foo
Q FOO Q 'I like "FOO" and "BAR"'

View File

@@ -0,0 +1 @@
" foo " 'I like "FOO" and "BAR"'

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)

View File

@@ -0,0 +1,4 @@
/* 3 */
/* abc ghi */
//**/* 3 */**//
//**/* abc ghi */**//

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

View File

@@ -0,0 +1,9 @@
/*
comment?
*/
/* comment? */
abc /* def */ ghi
abc /* def ghi */ jkl
/*
*/
baz

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
}