Add a function to check if a tree node has a scope.

This commit is contained in:
Danila Fedorin 2018-03-24 00:36:10 -07:00
parent b6ab42f53a
commit 77123561f0
2 changed files with 13 additions and 0 deletions

View File

@ -98,6 +98,13 @@ int libab_tree_has_string(libab_tree_variant var);
* @return true if the tree node variant contains a type. * @return true if the tree node variant contains a type.
*/ */
int libab_tree_has_type(libab_tree_variant var); int libab_tree_has_type(libab_tree_variant var);
/**
* Determines if the given tree node
* variant contains a scope.
* @param var the variant of the tree node.
* @return true if the node variant contains a scope.
*/
int libab_tree_has_scope(libab_tree_variant var);
/** /**
* Determines if the given tree node variant * Determines if the given tree node variant
* should contain a vector. * should contain a vector.

View File

@ -16,6 +16,12 @@ int libab_tree_has_string(libab_tree_variant variant) {
variant == TREE_RESERVED_OP; variant == TREE_RESERVED_OP;
} }
int libab_tree_has_scope(libab_tree_variant variant) {
return variant == TREE_BASE || variant == TREE_BLOCK ||
variant == TREE_IF || variant == TREE_WHILE ||
variant == TREE_DOWHILE || variant == TREE_FUN;
}
int libab_tree_has_type(libab_tree_variant variant) { int libab_tree_has_type(libab_tree_variant variant) {
return variant == TREE_FUN_PARAM || variant == TREE_FUN; return variant == TREE_FUN_PARAM || variant == TREE_FUN;
} }