diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-11-16 21:08:47 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-11-16 21:08:52 +0100 |
commit | 73963c3f7ec3f7e099a0d683d7d839897f31cf1e (patch) | |
tree | e51f04097c35cd05254a48ac807e7a003511310d | |
parent | mds-kbdc: working on transing mapping statements into trees (diff) | |
download | mds-73963c3f7ec3f7e099a0d683d7d839897f31cf1e.tar.gz mds-73963c3f7ec3f7e099a0d683d7d839897f31cf1e.tar.bz2 mds-73963c3f7ec3f7e099a0d683d7d839897f31cf1e.tar.xz |
mds-kbdc: fix stack bug when parsing mapping statements
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/mds-kbdc/make-tree.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/mds-kbdc/make-tree.c b/src/mds-kbdc/make-tree.c index d646fc3..8cdc91b 100644 --- a/src/mds-kbdc/make-tree.c +++ b/src/mds-kbdc/make-tree.c @@ -30,6 +30,29 @@ #include <stdio.h> +#ifndef DEBUG +# define DEBUG_PROC(statements) +#else +# define DEBUG_PROC(statements) statements +#endif + + +/** + * Print the current keyword stack, this is intended to + * as a compiler debugging feature and should be used from + * inside `DEBUG_PROC` + */ +#define PRINT_STACK \ + do \ + { \ + size_t i = stack_ptr; \ + fprintf(stderr, "stack {\n"); \ + while (i--) \ + fprintf(stderr, " %s\n", keyword_stack[i]); \ + fprintf(stderr, "}\n"); \ + } \ + while (0) + /** * Wrapper around `asprintf` that makes sure that first @@ -514,8 +537,9 @@ break; \ end = line + 1; \ NEW_ERROR(1, ERROR, "premature end of sequence"); \ - for (; stack_ptr > stack_orig; stack_ptr--) \ + while (stack_ptr > stack_orig) \ { \ + stack_ptr--; \ NEW_ERROR(1, NOTE, "missing associated ‘%s’", keyword_stack[stack_ptr]); \ error->start = tree_stack[stack_ptr][0]->loc_start; \ error->end = tree_stack[stack_ptr][0]->loc_end; \ |