Skip to content

Commit 4fb964e

Browse files
committed
Merge commit '7c8dd6f53b788e37fae9ee89385bdd0674a50e35' into update-subtrees
2 parents b5bda24 + 7c8dd6f commit 4fb964e

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

misc/packcc/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ Some macros are prepared to customize the parser. The macro definition should be
339339

340340
```
341341
%source {
342-
#define PCC_GETCHAR(auxil) get_character(auxil->input)
342+
#define PCC_GETCHAR(auxil) get_character((auxil)->input)
343343
#define PCC_BUFFERSIZE 1024
344344
}
345345
```
@@ -430,8 +430,7 @@ A very simple implementation could look like this:
430430
```C
431431
static const char *dbg_str[] = { "Evaluating rule", "Matched rule", "Abandoning rule" };
432432
#define PCC_DEBUG(event, rule, level, pos, buffer, length) \
433-
fprintf(stderr, "%*s%s %s @%d [%.*s]\n", level * 2, "", dbg_str[event], rule, pos, length, buffer)
434-
}
433+
fprintf(stderr, "%*s%s %s @%zu [%.*s]\n", (int)((level) * 2), "", dbg_str[event], rule, pos, (int)(length), buffer)
435434
```
436435

437436
The default is to do nothing:

misc/packcc/src/packcc.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ static size_t strnlen_(const char *str, size_t maxlen) {
6464
#include <unistd.h> /* for unlink() */
6565
#endif
6666

67-
#ifndef __attribute__
67+
#ifndef __has_attribute
6868
#define __attribute__(x)
6969
#endif
7070

7171
#undef TRUE /* to avoid macro definition conflicts with the system header file of IBM AIX */
7272
#undef FALSE
7373

74-
#define VERSION "1.5.0"
74+
#define VERSION "1.5.1"
7575

7676
#ifndef BUFFER_INIT_SIZE
7777
#define BUFFER_INIT_SIZE 256
@@ -285,7 +285,8 @@ typedef enum code_reach_tag {
285285

286286
static const char *g_cmdname = "packcc"; /* replaced later with actual one */
287287

288-
static int print_error(const char *format, ...) __attribute__((format(printf, 1, 2))) {
288+
__attribute__((format(printf, 1, 2)))
289+
static int print_error(const char *format, ...) {
289290
int n;
290291
va_list a;
291292
va_start(a, format);
@@ -352,7 +353,8 @@ static int fputs_e(const char *s, FILE *stream) {
352353
return r;
353354
}
354355

355-
static int fprintf_e(FILE *stream, const char *format, ...) __attribute__((format(printf, 2, 3))) {
356+
__attribute__((format(printf, 2, 3)))
357+
static int fprintf_e(FILE *stream, const char *format, ...) {
356358
int n;
357359
va_list a;
358360
va_start(a, format);
@@ -1436,8 +1438,8 @@ static void verify_captures(context_t *ctx, node_t *node, node_const_array_t *ca
14361438
if (node->data.expand.index == capts->buf[i]->data.capture.index) break;
14371439
}
14381440
if (i >= capts->len && node->data.expand.index != VOID_VALUE) {
1439-
print_error("%s:" FMT_LU ":" FMT_LU ": Capture %d not available at this position\n",
1440-
ctx->iname, (ulong_t)(node->data.expand.line + 1), (ulong_t)(node->data.expand.col + 1), node->data.expand.index + 1);
1441+
print_error("%s:" FMT_LU ":" FMT_LU ": Capture " FMT_LU " not available at this position\n",
1442+
ctx->iname, (ulong_t)(node->data.expand.line + 1), (ulong_t)(node->data.expand.col + 1), (ulong_t)(node->data.expand.index + 1));
14411443
ctx->errnum++;
14421444
}
14431445
}
@@ -2730,26 +2732,20 @@ static code_reach_t generate_predicating_code(generate_t *gen, const node_t *exp
27302732
}
27312733
write_characters(gen->stream, ' ', indent);
27322734
fputs_e("const size_t p = ctx->cur;\n", gen->stream);
2733-
write_characters(gen->stream, ' ', indent);
2734-
fputs_e("const size_t n = chunk->thunks.len;\n", gen->stream);
27352735
if (neg) {
27362736
const int l = ++gen->label;
27372737
r = generate_code(gen, expr, l, indent, FALSE);
27382738
if (r != CODE_REACH__ALWAYS_FAIL) {
27392739
write_characters(gen->stream, ' ', indent);
27402740
fputs_e("ctx->cur = p;\n", gen->stream);
27412741
write_characters(gen->stream, ' ', indent);
2742-
fputs_e("pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);\n", gen->stream);
2743-
write_characters(gen->stream, ' ', indent);
27442742
fprintf_e(gen->stream, "goto L%04d;\n", onfail);
27452743
}
27462744
if (r != CODE_REACH__ALWAYS_SUCCEED) {
27472745
if (indent > 4) write_characters(gen->stream, ' ', indent - 4);
27482746
fprintf_e(gen->stream, "L%04d:;\n", l);
27492747
write_characters(gen->stream, ' ', indent);
27502748
fputs_e("ctx->cur = p;\n", gen->stream);
2751-
write_characters(gen->stream, ' ', indent);
2752-
fputs_e("pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);\n", gen->stream);
27532749
}
27542750
switch (r) {
27552751
case CODE_REACH__ALWAYS_SUCCEED: r = CODE_REACH__ALWAYS_FAIL; break;
@@ -2764,8 +2760,6 @@ static code_reach_t generate_predicating_code(generate_t *gen, const node_t *exp
27642760
if (r != CODE_REACH__ALWAYS_FAIL) {
27652761
write_characters(gen->stream, ' ', indent);
27662762
fputs_e("ctx->cur = p;\n", gen->stream);
2767-
write_characters(gen->stream, ' ', indent);
2768-
fputs_e("pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);\n", gen->stream);
27692763
}
27702764
if (r == CODE_REACH__BOTH) {
27712765
write_characters(gen->stream, ' ', indent);
@@ -2777,8 +2771,6 @@ static code_reach_t generate_predicating_code(generate_t *gen, const node_t *exp
27772771
write_characters(gen->stream, ' ', indent);
27782772
fputs_e("ctx->cur = p;\n", gen->stream);
27792773
write_characters(gen->stream, ' ', indent);
2780-
fputs_e("pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);\n", gen->stream);
2781-
write_characters(gen->stream, ' ', indent);
27822774
fprintf_e(gen->stream, "goto L%04d;\n", onfail);
27832775
}
27842776
if (r == CODE_REACH__BOTH) {
@@ -4283,8 +4275,8 @@ static bool_t generate(context_t *ctx) {
42834275
}
42844276
fprintf_e(
42854277
sstream,
4286-
"static void pcc_action_%s_%d(%s_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {\n",
4287-
r->name, d, get_prefix(ctx)
4278+
"static void pcc_action_%s_" FMT_LU "(%s_context_t *__pcc_ctx, pcc_thunk_t *__pcc_in, pcc_value_t *__pcc_out) {\n",
4279+
r->name, (ulong_t)d, get_prefix(ctx)
42884280
);
42894281
fputs_e(
42904282
"#define auxil (__pcc_ctx->auxil)\n"
@@ -4303,8 +4295,8 @@ static bool_t generate(context_t *ctx) {
43034295
}
43044296
fputs_e(
43054297
"#define _0 pcc_get_capture_string(__pcc_ctx, &__pcc_in->data.leaf.capt0)\n"
4306-
"#define _0s ((const size_t)__pcc_in->data.leaf.capt0.range.start)\n"
4307-
"#define _0e ((const size_t)__pcc_in->data.leaf.capt0.range.end)\n",
4298+
"#define _0s ((const size_t)(__pcc_ctx->pos + __pcc_in->data.leaf.capt0.range.start))\n"
4299+
"#define _0e ((const size_t)(__pcc_ctx->pos + __pcc_in->data.leaf.capt0.range.end))\n",
43084300
sstream
43094301
);
43104302
k = 0;

misc/packcc/tests/debug_macro.d/input.peg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%source {
22
static const char *dbg_str[] = { "Evaluating rule", "Matched rule", "Abandoning rule" };
33
#define PCC_DEBUG(event, rule, level, pos, buffer, length) \
4-
fprintf(stdout, "%*s%s %s @%d [%.*s]\n", level * 2, "", dbg_str[event], rule, pos, length, buffer)
4+
fprintf(stdout, "%*s%s %s @%zu [%.*s]\n", (int)((level) * 2), "", dbg_str[event], rule, pos, (int)(length), buffer)
55
/* NOTE: To guarantee the output order, stderr, which can lead a race condition with stdout, is not used. */
66
}
77

0 commit comments

Comments
 (0)