aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/mds-kbdc/validate-tree.c33
-rw-r--r--test-files/mds-kbdc/validate-tree/invalid/for-return13
-rw-r--r--test-files/mds-kbdc/validate-tree/invalid/if-else-break22
-rw-r--r--test-files/mds-kbdc/validate-tree/invalid/misplaced_assumption46
-rw-r--r--test-files/mds-kbdc/validate-tree/invalid/misplaced_information38
-rw-r--r--test-files/mds-kbdc/validate-tree/invalid/runaway_break7
-rw-r--r--test-files/mds-kbdc/validate-tree/invalid/runaway_continue7
-rw-r--r--test-files/mds-kbdc/validate-tree/valid/assumption18
-rw-r--r--test-files/mds-kbdc/validate-tree/valid/for-break10
-rw-r--r--test-files/mds-kbdc/validate-tree/valid/for-continue10
-rw-r--r--test-files/mds-kbdc/validate-tree/valid/for-for-end-break15
-rw-r--r--test-files/mds-kbdc/validate-tree/valid/function-return10
-rw-r--r--test-files/mds-kbdc/validate-tree/valid/information14
-rw-r--r--test-files/mds-kbdc/validate-tree/valid/macro-return10
14 files changed, 230 insertions, 23 deletions
diff --git a/src/mds-kbdc/validate-tree.c b/src/mds-kbdc/validate-tree.c
index e1369e0..a2d128d 100644
--- a/src/mds-kbdc/validate-tree.c
+++ b/src/mds-kbdc/validate-tree.c
@@ -102,19 +102,9 @@ static size_t includes_size = 0;
static size_t includes_ptr = 0;
/**
- * Stack of visited for-statements
+ * The number visited for-statements
*/
-static mds_kbdc_tree_for_t** restrict fors = NULL;
-
-/**
- * The number elements allocated for `fors`
- */
-static size_t fors_size = 0;
-
-/**
- * The number elements stored in `fors`
- */
-static size_t fors_ptr = 0;
+static size_t fors = 0;
/**
* The function definition that is currently being visited
@@ -429,14 +419,10 @@ static int validate_macro_call(mds_kbdc_tree_macro_call_t* restrict tree)
*/
static int validate_for(mds_kbdc_tree_for_t* restrict tree)
{
- mds_kbdc_tree_for_t** old;
- int r, saved_errno;
- if (fors_ptr == fors_size)
- if (xxrealloc(old, fors, fors_size += 4, mds_kbdc_tree_for_t*))
- return saved_errno = errno, free(old), errno = saved_errno, -1;
- fors[fors_ptr++] = tree;
+ int r;
+ fors++;
r = validate_subtree(tree->inner);
- return fors_ptr--, r;
+ return fors--, r;
}
@@ -477,7 +463,7 @@ static int validate_return(mds_kbdc_tree_return_t* restrict tree)
*/
static int validate_break(mds_kbdc_tree_break_t* restrict tree)
{
- if (fors_ptr == 0)
+ if (fors == 0)
NEW_ERROR_WITH_INCLUDES(tree, includes_ptr, ERROR, "‘break’ outside ‘for’");
return 0;
pfail:
@@ -493,7 +479,7 @@ static int validate_break(mds_kbdc_tree_break_t* restrict tree)
*/
static int validate_continue(mds_kbdc_tree_continue_t* restrict tree)
{
- if (fors_ptr == 0)
+ if (fors == 0)
NEW_ERROR_WITH_INCLUDES(tree, includes_ptr, ERROR, "‘continue’ outside ‘for’");
return 0;
pfail:
@@ -601,8 +587,9 @@ int validate_tree(mds_kbdc_parsed_t* restrict result_)
saved_errno = errno;
result_->pathname = original_pathname;
result_->source_code = original_source_code;
- free(includes), includes = NULL, includes_size = includes_ptr = 0;
- free(fors), fors = NULL, fors_size = fors_ptr = 0;
+ free(includes), includes = NULL;
+ includes_size = includes_ptr = 0;
+ fors = 0;
return errno = saved_errno, r;
}
diff --git a/test-files/mds-kbdc/validate-tree/invalid/for-return b/test-files/mds-kbdc/validate-tree/invalid/for-return
new file mode 100644
index 0000000..af59736
--- /dev/null
+++ b/test-files/mds-kbdc/validate-tree/invalid/for-return
@@ -0,0 +1,13 @@
+for 1 to 9 as \1
+ return
+end for
+
+# (for (@ 1 0-3) ‘1’ ‘9’ (.variable ‘\1’)
+# (.inner
+# (return (@ 2 2-8))
+# )
+# )
+# :2:2–8: error: ‘return’ outside function and macro definition
+# return
+# ^^^^^^
+
diff --git a/test-files/mds-kbdc/validate-tree/invalid/if-else-break b/test-files/mds-kbdc/validate-tree/invalid/if-else-break
new file mode 100644
index 0000000..0e8ae81
--- /dev/null
+++ b/test-files/mds-kbdc/validate-tree/invalid/if-else-break
@@ -0,0 +1,22 @@
+if 1
+ if 0
+ else
+ break
+ end if
+end if
+
+# (if (@ 1 0-2) ‘1’
+# (.inner
+# (if (@ 2 2-4) ‘0’
+# (.inner nil)
+# (.otherwise
+# (break (@ 4 4-9))
+# )
+# )
+# )
+# (.otherwise nil)
+# )
+# :4:4–9: error: ‘break’ outside ‘for’
+# break
+# ^^^^^
+
diff --git a/test-files/mds-kbdc/validate-tree/invalid/misplaced_assumption b/test-files/mds-kbdc/validate-tree/invalid/misplaced_assumption
new file mode 100644
index 0000000..904ffd5
--- /dev/null
+++ b/test-files/mds-kbdc/validate-tree/invalid/misplaced_assumption
@@ -0,0 +1,46 @@
+have <space>
+have_chars " "
+have_range "a" "z"
+information
+ have <space>
+ have_chars " "
+ have_range "a" "z"
+end information
+
+# (have (@ 1 0-4)
+# (.data
+# (keys (@ 1 5-12) ‘<space>’)
+# )
+# )
+# (have_chars (@ 2 0-10) ‘" "’)
+# (have_range (@ 3 0-10) ‘"a"’ ‘"z"’)
+# (information (@ 4 0-11)
+# (.inner
+# (have (@ 5 2-6)
+# (.data
+# (keys (@ 5 7-14) ‘<space>’)
+# )
+# )
+# (have_chars (@ 6 2-12) ‘" "’)
+# (have_range (@ 7 2-12) ‘"a"’ ‘"z"’)
+# )
+# )
+# :1:0–4: error: assumption outside assumption clause
+# have <space>
+# ^^^^
+# :2:0–10: error: assumption outside assumption clause
+# have_chars " "
+# ^^^^^^^^^^
+# :3:0–10: error: assumption outside assumption clause
+# have_range "a" "z"
+# ^^^^^^^^^^
+# :5:2–6: error: assumption outside assumption clause
+# have <space>
+# ^^^^
+# :6:2–12: error: assumption outside assumption clause
+# have_chars " "
+# ^^^^^^^^^^
+# :7:2–12: error: assumption outside assumption clause
+# have_range "a" "z"
+# ^^^^^^^^^^
+
diff --git a/test-files/mds-kbdc/validate-tree/invalid/misplaced_information b/test-files/mds-kbdc/validate-tree/invalid/misplaced_information
new file mode 100644
index 0000000..248a212
--- /dev/null
+++ b/test-files/mds-kbdc/validate-tree/invalid/misplaced_information
@@ -0,0 +1,38 @@
+language ""
+country ""
+variant ""
+assumption
+ language ""
+ country ""
+ variant ""
+end assumption
+
+# (language (@ 1 0-8) ‘""’)
+# (country (@ 2 0-7) ‘""’)
+# (variant (@ 3 0-7) ‘""’)
+# (assumption (@ 4 0-10)
+# (.inner
+# (language (@ 5 2-10) ‘""’)
+# (country (@ 6 2-9) ‘""’)
+# (variant (@ 7 2-9) ‘""’)
+# )
+# )
+# :1:0–8: error: information outside information clause
+# language ""
+# ^^^^^^^^
+# :2:0–7: error: information outside information clause
+# country ""
+# ^^^^^^^
+# :3:0–7: error: information outside information clause
+# variant ""
+# ^^^^^^^
+# :5:2–10: error: information outside information clause
+# language ""
+# ^^^^^^^^
+# :6:2–9: error: information outside information clause
+# country ""
+# ^^^^^^^
+# :7:2–9: error: information outside information clause
+# variant ""
+# ^^^^^^^
+
diff --git a/test-files/mds-kbdc/validate-tree/invalid/runaway_break b/test-files/mds-kbdc/validate-tree/invalid/runaway_break
new file mode 100644
index 0000000..0e9911d
--- /dev/null
+++ b/test-files/mds-kbdc/validate-tree/invalid/runaway_break
@@ -0,0 +1,7 @@
+break
+
+# (break (@ 1 0-5))
+# :1:0–5: error: ‘break’ outside ‘for’
+# break
+# ^^^^^
+
diff --git a/test-files/mds-kbdc/validate-tree/invalid/runaway_continue b/test-files/mds-kbdc/validate-tree/invalid/runaway_continue
new file mode 100644
index 0000000..a68b7e4
--- /dev/null
+++ b/test-files/mds-kbdc/validate-tree/invalid/runaway_continue
@@ -0,0 +1,7 @@
+continue
+
+# (continue (@ 1 0-8))
+# :1:0–8: error: ‘continue’ outside ‘for’
+# continue
+# ^^^^^^^^
+
diff --git a/test-files/mds-kbdc/validate-tree/valid/assumption b/test-files/mds-kbdc/validate-tree/valid/assumption
new file mode 100644
index 0000000..b8db1af
--- /dev/null
+++ b/test-files/mds-kbdc/validate-tree/valid/assumption
@@ -0,0 +1,18 @@
+assumption
+ have <space>
+ have_chars " "
+ have_range "a" "z"
+end assumption
+
+# (assumption (@ 1 0-10)
+# (.inner
+# (have (@ 2 2-6)
+# (.data
+# (keys (@ 2 7-14) ‘<space>’)
+# )
+# )
+# (have_chars (@ 3 2-12) ‘" "’)
+# (have_range (@ 4 2-12) ‘"a"’ ‘"z"’)
+# )
+# )
+
diff --git a/test-files/mds-kbdc/validate-tree/valid/for-break b/test-files/mds-kbdc/validate-tree/valid/for-break
new file mode 100644
index 0000000..2d726c3
--- /dev/null
+++ b/test-files/mds-kbdc/validate-tree/valid/for-break
@@ -0,0 +1,10 @@
+for 1 to 9 as \1
+ break
+end for
+
+# (for (@ 1 0-3) ‘1’ ‘9’ (.variable ‘\1’)
+# (.inner
+# (break (@ 2 2-7))
+# )
+# )
+
diff --git a/test-files/mds-kbdc/validate-tree/valid/for-continue b/test-files/mds-kbdc/validate-tree/valid/for-continue
new file mode 100644
index 0000000..a8424b8
--- /dev/null
+++ b/test-files/mds-kbdc/validate-tree/valid/for-continue
@@ -0,0 +1,10 @@
+for 1 to 9 as \1
+ continue
+end for
+
+# (for (@ 1 0-3) ‘1’ ‘9’ (.variable ‘\1’)
+# (.inner
+# (continue (@ 2 2-10))
+# )
+# )
+
diff --git a/test-files/mds-kbdc/validate-tree/valid/for-for-end-break b/test-files/mds-kbdc/validate-tree/valid/for-for-end-break
new file mode 100644
index 0000000..f910969
--- /dev/null
+++ b/test-files/mds-kbdc/validate-tree/valid/for-for-end-break
@@ -0,0 +1,15 @@
+for 1 to 9 as \1
+ for 1 to 9 as \2
+ end for
+ break
+end for
+
+# (for (@ 1 0-3) ‘1’ ‘9’ (.variable ‘\1’)
+# (.inner
+# (for (@ 2 2-5) ‘1’ ‘9’ (.variable ‘\2’)
+# (.inner nil)
+# )
+# (break (@ 4 2-7))
+# )
+# )
+
diff --git a/test-files/mds-kbdc/validate-tree/valid/function-return b/test-files/mds-kbdc/validate-tree/valid/function-return
new file mode 100644
index 0000000..a534c37
--- /dev/null
+++ b/test-files/mds-kbdc/validate-tree/valid/function-return
@@ -0,0 +1,10 @@
+function f/0
+ return
+end function
+
+# (function (@ 1 0-8) ‘f/0’
+# (.inner
+# (return (@ 2 2-8))
+# )
+# )
+
diff --git a/test-files/mds-kbdc/validate-tree/valid/information b/test-files/mds-kbdc/validate-tree/valid/information
new file mode 100644
index 0000000..9e2beac
--- /dev/null
+++ b/test-files/mds-kbdc/validate-tree/valid/information
@@ -0,0 +1,14 @@
+information
+ language ""
+ country ""
+ variant ""
+end information
+
+# (information (@ 1 0-11)
+# (.inner
+# (language (@ 2 2-10) ‘""’)
+# (country (@ 3 2-9) ‘""’)
+# (variant (@ 4 2-9) ‘""’)
+# )
+# )
+
diff --git a/test-files/mds-kbdc/validate-tree/valid/macro-return b/test-files/mds-kbdc/validate-tree/valid/macro-return
new file mode 100644
index 0000000..e29786d
--- /dev/null
+++ b/test-files/mds-kbdc/validate-tree/valid/macro-return
@@ -0,0 +1,10 @@
+macro m/0
+ return
+end macro
+
+# (macro (@ 1 0-5) ‘m/0’
+# (.inner
+# (return (@ 2 2-8))
+# )
+# )
+