summaryrefslogtreecommitdiff
path: root/src/tree_alg.ml
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2025-10-27 22:42:37 -0500
committerJohn Estabrook <jestabro@vyos.io>2025-11-03 08:11:05 -0600
commit2aea7ddbc092b03dbf07dce385786b9c5c16a881 (patch)
tree3c837d8e16cb52d1d7bb85ea4afc5ffb913a81d0 /src/tree_alg.ml
parent6ced0e36b3f98675d82007f8c77193e2836c4b60 (diff)
downloadvyos1x-config-2aea7ddbc092b03dbf07dce385786b9c5c16a881.tar.gz
vyos1x-config-2aea7ddbc092b03dbf07dce385786b9c5c16a881.zip
T7915: add compiler alerts and annotations
Diffstat (limited to 'src/tree_alg.ml')
-rw-r--r--src/tree_alg.ml24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/tree_alg.ml b/src/tree_alg.ml
index 23af99d..a734285 100644
--- a/src/tree_alg.ml
+++ b/src/tree_alg.ml
@@ -30,12 +30,26 @@ module Alg (D: Data) (T: Tree with module D = D) = struct
let find_child n c = Vytree.find n (Vytree.name_of_node c)
- let insert_child n c = Vytree.insert ~position:Vytree.Lexical ~children:(Vytree.children_of_node c) n [(Vytree.name_of_node c)] (Vytree.data_of_node c)
+ let insert_child n c =
+ (* alert exn Vytree.insert:
+ [Vytree.Empty_path] not possible as called on name_of_node for existing child
+ [Not_found] not possible for postion=Lexical
+ [Vytree.Duplicate_child] not possible as find_child is None
+ [Vytree.Insert_error] not possible as no intermediary nodes
+ *)
+ (Vytree.insert[@alert "-exn"]) ~position:Vytree.Lexical ~children:(Vytree.children_of_node c) n [(Vytree.name_of_node c)] (Vytree.data_of_node c)
let replace_child n c =
- Vytree.replace n c
+ (* alert exn Vytree.replace:
+ [Not_found] not possible as child name already present
+ *)
+ (Vytree.replace[@alert "-exn"]) n c
let rec tree_union s t f =
+ (* raises:
+ [Incompatible_union]
+ [Nonexistent_child]
+ *)
if (Vytree.name_of_node s) <> (Vytree.name_of_node t) then
raise Incompatible_union
else
@@ -44,14 +58,16 @@ module Alg (D: Data) (T: Tree with module D = D) = struct
let t_c = find_child t c in
match s_c, t_c with
| Some child, None ->
- insert_child t child
+ insert_child t child
| None, Some _ -> t
| Some u, Some v ->
if (Vytree.data_of_node u <> Vytree.data_of_node v) then
replace_child t (tree_union u (f u v) f)
else
replace_child t (tree_union u v f)
- | None, None -> raise Nonexistent_child
+ | None, None ->
+ (* Not possible in fold over union_of_children *)
+ raise Nonexistent_child
in
List.fold_left (fun x c -> child_of_union s x c) t (union_of_children s t)
end