Make the has string and has vector functions public.
This commit is contained in:
24
src/tree.c
24
src/tree.c
@@ -1,22 +1,22 @@
|
||||
#include "tree.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int _tree_has_vector(libab_tree* tree) {
|
||||
return tree->variant == BASE || tree->variant == OP ||
|
||||
tree->variant == UNARY_OP || tree->variant == BLOCK ||
|
||||
tree->variant == IF;
|
||||
int libab_tree_has_vector(libab_tree_variant variant) {
|
||||
return variant == BASE || variant == OP ||
|
||||
variant == UNARY_OP || variant == BLOCK ||
|
||||
variant == IF;
|
||||
}
|
||||
|
||||
int libab_tree_has_string(libab_tree_variant variant) {
|
||||
return variant == ID || variant == NUM ||
|
||||
variant == OP || variant == UNARY_OP;
|
||||
}
|
||||
|
||||
void libab_tree_free(libab_tree* tree) {
|
||||
int free_string = 0;
|
||||
int free_vector = 0;
|
||||
if(_tree_has_vector(tree)) {
|
||||
free_vector = 1;
|
||||
}
|
||||
if(tree->variant == ID || tree->variant == NUM ||
|
||||
tree->variant == OP || tree->variant == UNARY_OP) {
|
||||
free_string = 1;
|
||||
}
|
||||
free_vector = libab_tree_has_vector(tree->variant);
|
||||
free_string = libab_tree_has_string(tree->variant);
|
||||
if(free_string) free(tree->string_value);
|
||||
if(free_vector) vec_free(&tree->children);
|
||||
}
|
||||
@@ -27,7 +27,7 @@ int _tree_foreach_free(void* data, va_list args) {
|
||||
}
|
||||
|
||||
void libab_tree_free_recursive(libab_tree* tree) {
|
||||
if(_tree_has_vector(tree)) {
|
||||
if(libab_tree_has_vector(tree->variant)) {
|
||||
vec_foreach(&tree->children, NULL, compare_always, _tree_foreach_free);
|
||||
}
|
||||
libab_tree_free(tree);
|
||||
|
||||
Reference in New Issue
Block a user