diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-11-30 10:52:38 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-11-30 10:52:38 +0100 |
commit | 587829f398c9215731f32a6849110a799b91dab1 (patch) | |
tree | 1b638ec78189ae0a3f0fb02cf8dd731a1cf4b772 /src | |
parent | mds-kbdc: include processing, testing and error transfer has yet to be done (diff) | |
download | mds-587829f398c9215731f32a6849110a799b91dab1.tar.gz mds-587829f398c9215731f32a6849110a799b91dab1.tar.bz2 mds-587829f398c9215731f32a6849110a799b91dab1.tar.xz |
mds-kbdc: transfer of errors after inclusion
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/mds-kbdc/process-includes.c | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/src/mds-kbdc/process-includes.c b/src/mds-kbdc/process-includes.c index 1e9c5ff..9677671 100644 --- a/src/mds-kbdc/process-includes.c +++ b/src/mds-kbdc/process-includes.c @@ -59,6 +59,65 @@ static mds_kbdc_parsed_t* restrict result; /** + * Transfer errors from an included tree + * + * @param subresult The results of the processed include + * @param tree The include statement + */ +static int transfer_errors(mds_kbdc_parsed_t* restrict subresult, mds_kbdc_tree_include_t* restrict tree) +{ + mds_kbdc_parse_error_t** errors = NULL; + mds_kbdc_parse_error_t* suberror; + size_t errors_ptr = 0, i; + int saved_errno; + + /* List errors backwards, so that we can easily insert “included from here”-notes. */ + fail_if (xmalloc(errors, subresult->errors_ptr * 2, mds_kbdc_parse_error_t*)); + while (subresult->errors_ptr--) + { + suberror = subresult->errors[subresult->errors_ptr]; + if (suberror->severity > MDS_KBDC_PARSE_ERROR_NOTE) + { + NEW_ERROR(tree, NOTE, "included from here"); + errors[errors_ptr++] = error; + result->errors[--(result->errors_ptr)] = NULL; + } + errors[errors_ptr++] = suberror; + subresult->errors[subresult->errors_ptr] = NULL; + } + + /* Append errors. */ + for (i = 0; i < errors_ptr; errors[i++] = NULL) + { + if (result->errors_ptr + 1 >= result->errors_size) + { + size_t new_errors_size = result->errors_size ? (result->errors_size << 1) : 2; + mds_kbdc_parse_error_t** new_errors = result->errors; + + fail_if (xrealloc(new_errors, new_errors_size, mds_kbdc_parse_error_t*)); + result->errors = new_errors; + result->errors_size = new_errors_size; + } + + result->errors[result->errors_ptr++] = errors[i]; + result->errors[result->errors_ptr] = NULL; + } + + free(errors); + return 0; + pfail: + saved_errno = errno; + while (errors_ptr--) + if (errors[errors_ptr] == NULL) + break; + else + mds_kbdc_parse_error_free(errors[errors_ptr]); + free(errors); + return errno = saved_errno, -1; +} + + +/** * Process an include-statement * * @param tree The include-statement @@ -126,7 +185,7 @@ static int process_include(mds_kbdc_tree_include_t* restrict tree) result->severest_error_level = subresult.severest_error_level; /* Move over errors. */ - /* TODO */ + fail_if (transfer_errors(&subresult, tree)); /* Release resources. */ mds_kbdc_parsed_destroy(&subresult); |