diff options
Diffstat (limited to 'MoonParser/ast.hpp')
-rw-r--r-- | MoonParser/ast.hpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/MoonParser/ast.hpp b/MoonParser/ast.hpp index 1b40e1b..955cdc0 100644 --- a/MoonParser/ast.hpp +++ b/MoonParser/ast.hpp | |||
@@ -80,11 +80,20 @@ private: | |||
80 | }; | 80 | }; |
81 | 81 | ||
82 | template<class T> | 82 | template<class T> |
83 | T* ast_cast(ast_node *node) | 83 | T* ast_cast(ast_node *node) { |
84 | { | ||
85 | return node && ast_type<T>() == node->get_type() ? static_cast<T*>(node) : nullptr; | 84 | return node && ast_type<T>() == node->get_type() ? static_cast<T*>(node) : nullptr; |
86 | } | 85 | } |
87 | 86 | ||
87 | template <class ...Args> | ||
88 | bool ast_is(ast_node* node) { | ||
89 | if (!node) return false; | ||
90 | bool result = false; | ||
91 | int type = node->get_type(); | ||
92 | using swallow = bool[]; | ||
93 | (void)swallow{result || (result = ast_type<Args>() == type)...}; | ||
94 | return result; | ||
95 | } | ||
96 | |||
88 | class ast_member; | 97 | class ast_member; |
89 | 98 | ||
90 | 99 | ||