aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-kbdc/validate-tree.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/mds-kbdc/validate-tree.c63
1 files changed, 36 insertions, 27 deletions
diff --git a/src/mds-kbdc/validate-tree.c b/src/mds-kbdc/validate-tree.c
index ed96343..466f138 100644
--- a/src/mds-kbdc/validate-tree.c
+++ b/src/mds-kbdc/validate-tree.c
@@ -106,11 +106,13 @@ static int validate_include(mds_kbdc_tree_include_t* restrict tree)
{
void* data;
int r;
- if (mds_kbdc_include_stack_push(tree, &data))
- return -1;
+ fail_if (mds_kbdc_include_stack_push(tree, &data));
r = validate_subtree(tree->inner);
mds_kbdc_include_stack_pop(data);
- return r;
+ fail_if (r);
+ return 0;
+ fail:
+ return -1;
}
@@ -151,7 +153,7 @@ static int validate_function(mds_kbdc_tree_function_t* restrict tree)
def_includes_ptr = includes_ptr;
r = validate_subtree(tree->inner);
return function = NULL, r;
- pfail:
+ fail:
return -1;
}
@@ -193,7 +195,7 @@ static int validate_macro(mds_kbdc_tree_macro_t* restrict tree)
def_includes_ptr = includes_ptr;
r = validate_subtree(tree->inner);
return macro = NULL, r;
- pfail:
+ fail:
return -1;
}
@@ -235,7 +237,7 @@ static int validate_information(mds_kbdc_tree_information_t* restrict tree)
def_includes_ptr = includes_ptr;
r = validate_subtree(tree->inner);
return information = NULL, r;
- pfail:
+ fail:
return -1;
}
@@ -277,7 +279,7 @@ static int validate_assumption(mds_kbdc_tree_assumption_t* restrict tree)
def_includes_ptr = includes_ptr;
r = validate_subtree(tree->inner);
return assumption = NULL, r;
- pfail:
+ fail:
return -1;
}
@@ -305,7 +307,7 @@ static int validate_map(mds_kbdc_tree_map_t* restrict tree)
else if (function)
NEW_ERROR(tree, includes_ptr, ERROR, "mapping-statement inside function definition");
return 0;
- pfail:
+ fail:
return -1;
}
@@ -325,7 +327,7 @@ static int validate_macro_call(mds_kbdc_tree_macro_call_t* restrict tree)
else if (function)
NEW_ERROR(tree, includes_ptr, ERROR, "macro call inside function definition");
return 0;
- pfail:
+ fail:
return -1;
}
@@ -339,9 +341,11 @@ static int validate_macro_call(mds_kbdc_tree_macro_call_t* restrict tree)
static int validate_for(mds_kbdc_tree_for_t* restrict tree)
{
int r;
- fors++;
- r = validate_subtree(tree->inner);
- return fors--, r;
+ fors++, r = validate_subtree(tree->inner), fors--;
+ fail_if (r);
+ return 0;
+ fail:
+ return -1;
}
@@ -353,8 +357,10 @@ static int validate_for(mds_kbdc_tree_for_t* restrict tree)
*/
static int validate_if(mds_kbdc_tree_if_t* restrict tree)
{
- return -(validate_subtree(tree->inner) ||
- validate_subtree(tree->otherwise));
+ fail_if ((validate_subtree(tree->inner) || validate_subtree(tree->otherwise)));
+ return 0;
+ fail:
+ return -1;
}
@@ -369,7 +375,7 @@ static int validate_return(mds_kbdc_tree_return_t* restrict tree)
if ((function == NULL) && (macro == NULL))
NEW_ERROR(tree, includes_ptr, ERROR, "‘return’ outside function and macro definition");
return 0;
- pfail:
+ fail:
return -1;
}
@@ -385,7 +391,7 @@ static int validate_break(mds_kbdc_tree_break_t* restrict tree)
if (fors == 0)
NEW_ERROR(tree, includes_ptr, ERROR, "‘break’ outside ‘for’");
return 0;
- pfail:
+ fail:
return -1;
}
@@ -401,7 +407,7 @@ static int validate_continue(mds_kbdc_tree_continue_t* restrict tree)
if (fors == 0)
NEW_ERROR(tree, includes_ptr, ERROR, "‘continue’ outside ‘for’");
return 0;
- pfail:
+ fail:
return -1;
}
@@ -417,7 +423,7 @@ static int validate_assumption_data(mds_kbdc_tree_t* restrict tree)
if (assumption == NULL)
NEW_ERROR(tree, includes_ptr, ERROR, "assumption outside assumption clause");
return 0;
- pfail:
+ fail:
return -1;
}
@@ -433,7 +439,7 @@ static int validate_information_data(mds_kbdc_tree_t* restrict tree)
if (information == NULL)
NEW_ERROR(tree, includes_ptr, ERROR, "information outside information clause");
return 0;
- pfail:
+ fail:
return -1;
}
@@ -446,9 +452,8 @@ static int validate_information_data(mds_kbdc_tree_t* restrict tree)
*/
static int validate_subtree(mds_kbdc_tree_t* restrict tree)
{
-#define v(type) if ((r = validate_##type(&(tree->type)))) return r
-#define V(type) if ((r = validate_##type(&(tree->type##_)))) return r
- int r;
+#define v(type) fail_if (validate_##type(&(tree->type)))
+#define V(type) fail_if (validate_##type(&(tree->type##_)))
again:
if (tree == NULL)
return 0;
@@ -470,14 +475,12 @@ static int validate_subtree(mds_kbdc_tree_t* restrict tree)
case C(INFORMATION_LANGUAGE):
case C(INFORMATION_COUNTRY):
case C(INFORMATION_VARIANT):
- if ((r = validate_information_data(tree)))
- return r;
+ fail_if (validate_information_data(tree));
break;
case C(ASSUMPTION_HAVE):
case C(ASSUMPTION_HAVE_CHARS):
case C(ASSUMPTION_HAVE_RANGE):
- if ((r = validate_assumption_data(tree)))
- return r;
+ fail_if (validate_assumption_data(tree));
break;
default:
break;
@@ -485,6 +488,8 @@ static int validate_subtree(mds_kbdc_tree_t* restrict tree)
tree = tree->next;
goto again;
+ fail:
+ return -1;
#undef V
#undef v
}
@@ -502,7 +507,11 @@ int validate_tree(mds_kbdc_parsed_t* restrict result_)
mds_kbdc_include_stack_begin(result = result_);
r = validate_subtree(result_->tree);
fors = 0;
- return mds_kbdc_include_stack_end(), r;
+ mds_kbdc_include_stack_end();
+ fail_if (r);
+ return 0;
+ fail:
+ return -1;
}