Skip to content

Commit dd52f21

Browse files
committed
Squashed 'misc/packcc/' changes from 4a7dbab60..43934f352
43934f352 Improve makefiles 29a2a1b06 Support gcc for IBM AIX 53aefcb47 Update README.md 6035daaba Change macro to check for size_t byte size 6015afca6 Fix #34 dfc33e6bf Merge pull request #33 from dolik-rce/test-improvements 8176c6492 fix uncrustify version check fa144ef7c properly quote load statements df95cbde7 refactor test utils 1ff5f9100 test --ascii option e54a94c03 avoid copying calc.peg into test directories a6a7ef719 test grammar dump (--debug option) f1323e5ec display coverage 223b264fa allow options in CC environment variable git-subtree-dir: misc/packcc git-subtree-split: 43934f35254c08f0827801f80bbbec0e03c69fe0
1 parent 769d691 commit dd52f21

File tree

18 files changed

+290
-52
lines changed

18 files changed

+290
-52
lines changed

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Overview ##
44

5-
**PackCC** is a packrat parser generator for C. Its main features are as follows:
5+
**PackCC** is a parser generator for C. Its main features are as follows:
66

77
- Generates your parser in C from a grammar described in a **PEG**,
88
- Gives your parser great efficiency by **packrat parsing**,
@@ -34,6 +34,8 @@ For convenience, the build environments using GCC, Clang, and Microsoft Visual S
3434

3535
### Using GCC ###
3636

37+
#### Other than MinGW ####
38+
3739
`packcc` will be built in both directories `build/gcc/debug/bin` and `build/gcc/release/bin` using `gcc` by executing the following commands:
3840

3941
```
@@ -44,8 +46,22 @@ make check # bats-core and uncrustify are required (see tests/README.md)
4446

4547
`packcc` in the directory `build/gcc/release/bin` is suitable for practical use.
4648

49+
#### MinGW ####
50+
51+
`packcc` will be built in both directories `build/mingw-gcc/debug/bin` and `build/mingw-gcc/release/bin` using `gcc` by executing the following commands:
52+
53+
```
54+
cd build/mingw-gcc
55+
make
56+
make check # bats-core and uncrustify are required (see tests/README.md)
57+
```
58+
59+
`packcc` in the directory `build/mingw-gcc/release/bin` is suitable for practical use.
60+
4761
### Using Clang ###
4862

63+
#### Other than MinGW ####
64+
4965
`packcc` will be built in both directories `build/clang/debug/bin` and `build/clang/release/bin` using `clang` by executing the following commands:
5066

5167
```
@@ -56,6 +72,18 @@ make check # bats-core and uncrustify are required (see tests/README.md)
5672

5773
`packcc` in the directory `build/clang/release/bin` is suitable for practical use.
5874

75+
#### MinGW ####
76+
77+
`packcc` will be built in both directories `build/mingw-clang/debug/bin` and `build/mingw-clang/release/bin` using `clang` by executing the following commands:
78+
79+
```
80+
cd build/mingw-clang
81+
make
82+
make check # bats-core and uncrustify are required (see tests/README.md)
83+
```
84+
85+
`packcc` in the directory `build/mingw-clang/release/bin` is suitable for practical use.
86+
5987
### Using Microsoft Visual Studio ###
6088

6189
You have to install Microsoft Visual Studio 2019 in advance.

build/clang/Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CC=clang
2-
CFLAGS_D=-std=gnu89 -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -O0 -g2
3-
CFLAGS_R=-std=gnu89 -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -O2 -DNDEBUG
2+
CFLAGS_D=-std=gnu89 -fsigned-char -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -O0 -g2
3+
CFLAGS_R=-std=gnu89 -fsigned-char -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -O2 -DNDEBUG
44
LDFLAGS_D=
55
LDFLAGS_R=
66

@@ -24,7 +24,7 @@ SRCS= \
2424
$(patsubst %,$(TMPDIR_R)/%.c,$(EXAMPLES)) \
2525
$(patsubst %,$(TMPDIR_R)/%.h,$(EXAMPLES))
2626

27-
.PHONY: all clean
27+
.PHONY: all check clean
2828

2929
.SECONDARY: $(SRCS)
3030

@@ -48,8 +48,9 @@ $(TMPDIR_D)/examples/%.c $(TMPDIR_D)/examples/%.h: $(SRCDIR)/examples/%.peg $(BI
4848
$(TMPDIR_R)/examples/%.c $(TMPDIR_R)/examples/%.h: $(SRCDIR)/examples/%.peg $(BINDIR_R)/packcc
4949
mkdir -p $(dir $@) && $(BINDIR_R)/packcc -o $(basename $@) $<
5050

51-
check: $(BINDIR_R)/packcc
52-
PACKCC=$$PWD/$^ $(TESTDIR)/test.sh
51+
check: $(BINDIR_D)/packcc $(BINDIR_R)/packcc
52+
@echo "== Debug Version ==" && PACKCC=$$PWD/$(BINDIR_D)/packcc CC="$(CC) $(CFLAGS_D)" $(TESTDIR)/test.sh
53+
@echo "== Release Version ==" && PACKCC=$$PWD/$(BINDIR_R)/packcc CC="$(CC) $(CFLAGS_R)" $(TESTDIR)/test.sh
5354

5455
clean:
5556
rm -f $(BINS) $(SRCS)

build/gcc/Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CC=gcc
2-
CFLAGS_D=-std=gnu89 -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -O0 -g2
3-
CFLAGS_R=-std=gnu89 -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -O2 -DNDEBUG
2+
CFLAGS_D=-std=gnu89 -fsigned-char -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -O0 -g2
3+
CFLAGS_R=-std=gnu89 -fsigned-char -Wall -Wextra -Wno-unused-parameter -Wno-overlength-strings -pedantic -O2 -DNDEBUG
44
LDFLAGS_D=
55
LDFLAGS_R=
66

@@ -24,7 +24,7 @@ SRCS= \
2424
$(patsubst %,$(TMPDIR_R)/%.c,$(EXAMPLES)) \
2525
$(patsubst %,$(TMPDIR_R)/%.h,$(EXAMPLES))
2626

27-
.PHONY: all clean
27+
.PHONY: all check clean
2828

2929
.SECONDARY: $(SRCS)
3030

@@ -48,8 +48,9 @@ $(TMPDIR_D)/examples/%.c $(TMPDIR_D)/examples/%.h: $(SRCDIR)/examples/%.peg $(BI
4848
$(TMPDIR_R)/examples/%.c $(TMPDIR_R)/examples/%.h: $(SRCDIR)/examples/%.peg $(BINDIR_R)/packcc
4949
mkdir -p $(dir $@) && $(BINDIR_R)/packcc -o $(basename $@) $<
5050

51-
check: $(BINDIR_R)/packcc
52-
PACKCC=$$PWD/$^ $(TESTDIR)/test.sh
51+
check: $(BINDIR_D)/packcc $(BINDIR_R)/packcc
52+
@echo "== Debug Version ==" && PACKCC=$$PWD/$(BINDIR_D)/packcc CC="$(CC) $(CFLAGS_D)" $(TESTDIR)/test.sh
53+
@echo "== Release Version ==" && PACKCC=$$PWD/$(BINDIR_R)/packcc CC="$(CC) $(CFLAGS_R)" $(TESTDIR)/test.sh
5354

5455
clean:
5556
rm -f $(BINS) $(SRCS)

build/mingw-clang/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SRCS= \
2424
$(patsubst %,$(TMPDIR_R)/%.c,$(EXAMPLES)) \
2525
$(patsubst %,$(TMPDIR_R)/%.h,$(EXAMPLES))
2626

27-
.PHONY: all clean
27+
.PHONY: all check clean
2828

2929
.SECONDARY: $(SRCS)
3030

@@ -48,8 +48,9 @@ $(TMPDIR_D)/examples/%.c $(TMPDIR_D)/examples/%.h: $(SRCDIR)/examples/%.peg $(BI
4848
$(TMPDIR_R)/examples/%.c $(TMPDIR_R)/examples/%.h: $(SRCDIR)/examples/%.peg $(BINDIR_R)/packcc
4949
mkdir -p $(dir $@) && $(BINDIR_R)/packcc -o $(basename $@) $<
5050

51-
check: $(BINDIR_R)/packcc
52-
PACKCC=$$PWD/$^ $(TESTDIR)/test.sh
51+
check: $(BINDIR_D)/packcc $(BINDIR_R)/packcc
52+
@echo "== Debug Version ==" && PACKCC=$$PWD/$(BINDIR_D)/packcc CC="$(CC) $(CFLAGS_D)" $(TESTDIR)/test.sh
53+
@echo "== Release Version ==" && PACKCC=$$PWD/$(BINDIR_R)/packcc CC="$(CC) $(CFLAGS_R)" $(TESTDIR)/test.sh
5354

5455
clean:
5556
rm -f $(BINS) $(SRCS)

build/mingw-gcc/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SRCS= \
2424
$(patsubst %,$(TMPDIR_R)/%.c,$(EXAMPLES)) \
2525
$(patsubst %,$(TMPDIR_R)/%.h,$(EXAMPLES))
2626

27-
.PHONY: all clean
27+
.PHONY: all check clean
2828

2929
.SECONDARY: $(SRCS)
3030

@@ -48,8 +48,9 @@ $(TMPDIR_D)/examples/%.c $(TMPDIR_D)/examples/%.h: $(SRCDIR)/examples/%.peg $(BI
4848
$(TMPDIR_R)/examples/%.c $(TMPDIR_R)/examples/%.h: $(SRCDIR)/examples/%.peg $(BINDIR_R)/packcc
4949
mkdir -p $(dir $@) && $(BINDIR_R)/packcc -o $(basename $@) $<
5050

51-
check: $(BINDIR_R)/packcc
52-
PACKCC=$$PWD/$^ $(TESTDIR)/test.sh
51+
check: $(BINDIR_D)/packcc $(BINDIR_R)/packcc
52+
@echo "== Debug Version ==" && PACKCC=$$PWD/$(BINDIR_D)/packcc CC="$(CC) $(CFLAGS_D)" $(TESTDIR)/test.sh
53+
@echo "== Release Version ==" && PACKCC=$$PWD/$(BINDIR_R)/packcc CC="$(CC) $(CFLAGS_R)" $(TESTDIR)/test.sh
5354

5455
clean:
5556
rm -f $(BINS) $(SRCS)

src/packcc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ static size_t strnlen_(const char *str, size_t maxlen) {
6868
#define __attribute__(x)
6969
#endif
7070

71+
#undef TRUE /* to avoid macro definition conflicts with the system header file of IBM AIX */
72+
#undef FALSE
73+
7174
#define VERSION "1.5.0"
7275

7376
#ifndef BUFFER_INIT_SIZE
@@ -910,7 +913,7 @@ static size_t populate_bits(size_t x) {
910913
x |= x >> 4;
911914
x |= x >> 8;
912915
x |= x >> 16;
913-
#ifndef _M_IX86 /* not Windows for x86 (32-bit) */
916+
#if (defined __SIZEOF_SIZE_T__ && __SIZEOF_SIZE_T__ == 8) /* gcc or clang */ || defined _WIN64 /* MSVC */
914917
x |= x >> 32;
915918
#endif
916919
return x;

tests/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
packcc
22
packcc.exe
3-
*/parser.peg
3+
packcc.gcda
4+
packcc.gcno
5+
packcc.c.gcov
46
*/parser.c
57
*/parser.h
68
*/parser

tests/ascii.d/ascii.bats

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bats
2+
3+
load "$TESTDIR/utils.sh"
4+
5+
@test "Testing ascii.d - generation" {
6+
PACKCC_OPTS=("--ascii")
7+
test_generate
8+
}
9+
10+
@test "Testing ascii.d - check code" {
11+
! in_source "pcc_get_char_as_utf32"
12+
}
13+
14+
@test "Testing ascii.d - compilation" {
15+
test_compile
16+
}
17+
@test "Testing ascii.d - run" {
18+
run_for_input "ascii.d/input.txt"
19+
}

tests/ascii.d/expected.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This
2+
is
3+
a
4+
test

tests/ascii.d/input.peg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FILE <- WORD / SPACE
2+
WORD <- [^ \r\n\t]+ { PRINT($0); }
3+
SPACE <- [ \r\n\t]+

0 commit comments

Comments
 (0)