diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-11-16 05:06:01 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-11-16 05:06:01 +0100 |
commit | 9940529e836131cfcb4c60984a73cdceb660636e (patch) | |
tree | 36d4fbd6f118c8fa9d7e71d43fbb76db35ec350e | |
parent | m (diff) | |
download | mds-9940529e836131cfcb4c60984a73cdceb660636e.tar.gz mds-9940529e836131cfcb4c60984a73cdceb660636e.tar.bz2 mds-9940529e836131cfcb4c60984a73cdceb660636e.tar.xz |
mds-kbdc: annotate tree with source code locations and report where unpopped scopes were pushed
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/mds-kbdc/make-tree.c | 34 | ||||
-rw-r--r-- | src/mds-kbdc/tree.h | 12 |
2 files changed, 31 insertions, 15 deletions
diff --git a/src/mds-kbdc/make-tree.c b/src/mds-kbdc/make-tree.c index 311afdc..e749a7f 100644 --- a/src/mds-kbdc/make-tree.c +++ b/src/mds-kbdc/make-tree.c @@ -101,10 +101,13 @@ * @param LOWERCASE:identifier The keyword, for the node type, in lower case * @param UPPERCASE:identifier The keyword, for the node type, in upper case */ -#define NEW_NODE(LOWERCASE, UPPERCASE) \ - mds_kbdc_tree_##LOWERCASE##_t* node; \ - fail_if (xcalloc(node, 1, mds_kbdc_tree_##LOWERCASE##_t)); \ - node->type = MDS_KBDC_TREE_TYPE_##UPPERCASE +#define NEW_NODE(LOWERCASE, UPPERCASE) \ + mds_kbdc_tree_##LOWERCASE##_t* node; \ + fail_if (xcalloc(node, 1, mds_kbdc_tree_##LOWERCASE##_t)); \ + node->type = MDS_KBDC_TREE_TYPE_##UPPERCASE; \ + node->loc_line = line_i; \ + node->loc_start = (size_t)(line - source_code.lines[line_i]); \ + node->loc_end = (size_t)(end - source_code.lines[line_i]) /** @@ -696,6 +699,7 @@ int parse_to_tree(const char* restrict filename, mds_kbdc_tree_t** restrict resu NEW_NODE(array, ARRAY); #define inner elements BRANCH("}"); + node->loc_end = node->loc_start + 1; #undef inner #undef node in_array = 1; @@ -765,15 +769,19 @@ int parse_to_tree(const char* restrict filename, mds_kbdc_tree_t** restrict resu char* end = NULL; NEW_ERROR(0, ERROR, "premature end of file"); while (stack_ptr--) - /* TODO from where? */ - if (!strcmp(keyword_stack[stack_ptr], "}")) - { - NEW_ERROR(0, NOTE, "missing ‘%s’", keyword_stack[stack_ptr]); - } - else - { - NEW_ERROR(0, NOTE, "missing ‘end %s’", keyword_stack[stack_ptr]); - } + { + line_i = tree_stack[stack_ptr][0]->loc_line; + line = source_code.lines[line_i] + tree_stack[stack_ptr][0]->loc_start; + end = source_code.lines[line_i] + tree_stack[stack_ptr][0]->loc_end; + if (!strcmp(keyword_stack[stack_ptr], "}")) + { + NEW_ERROR(1, NOTE, "missing associated ‘%s’", keyword_stack[stack_ptr]); + } + else + { + NEW_ERROR(1, NOTE, "missing associated ‘end %s’", keyword_stack[stack_ptr]); + } + } } free(pathname); diff --git a/src/mds-kbdc/tree.h b/src/mds-kbdc/tree.h index 1f31e34..7bdbf3d 100644 --- a/src/mds-kbdc/tree.h +++ b/src/mds-kbdc/tree.h @@ -170,8 +170,16 @@ typedef union mds_kbdc_tree mds_kbdc_tree_t; * It defines: * - int type; -- Integer that specifies which structure is used * - mds_kbdc_tree_t*; -- The next node in the tree, at the same level; a sibling - */ -#define MDS_KBDC_TREE_COMMON int type; mds_kbdc_tree_t* next + * - loc_line; -- The line in the source code where this is found + * - loc_start; -- The first byte in the source code where this is found, inclusive + * - loc_end; -- The last byte in the source code where this is found, exclusive + */ +#define MDS_KBDC_TREE_COMMON \ + int type; \ + mds_kbdc_tree_t* next; \ + size_t loc_line; \ + size_t loc_start; \ + size_t loc_end /** * This macro is used in this header file, and is then |