diff options
author | Ufuk Kayserilioglu <ufuk.kayserilioglu@shopify.com> | 2023-12-12 00:28:03 +0200 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-12-12 17:35:52 +0000 |
commit | bdb38dd9f22accfddc8d0a5e211c74b6a06faf51 (patch) | |
tree | e7dc3dcfa4a6ca6801c00cfca36e47964aa14124 /prism | |
parent | 67940b135cae091f0f13d2c531b2ef33660e82fc (diff) |
[ruby/prism] Add methods for setting/unsetting and macros for testing a flags
https://github.com/ruby/prism/commit/e5f37d1407
Diffstat (limited to 'prism')
-rw-r--r-- | prism/prism.c | 21 | ||||
-rw-r--r-- | prism/templates/include/prism/ast.h.erb | 5 |
2 files changed, 26 insertions, 0 deletions
diff --git a/prism/prism.c b/prism/prism.c index 2b74152cce..56056190e4 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -865,6 +865,27 @@ pm_arguments_validate_block(pm_parser_t *parser, pm_arguments_t *arguments, pm_b } /******************************************************************************/ +/* Node flag handling functions */ +/******************************************************************************/ + +/** + * Set the given flag on the given node. + */ +static inline void +pm_node_flag_set(pm_node_t *node, pm_node_flags_t flag) { + node->flags |= flag; +} + +/** + * Remove the given flag from the given node. + */ +static inline void +pm_node_flag_unset(pm_node_t *node, pm_node_flags_t flag) { + node->flags &= (pm_node_flags_t) ~flag; +} + + +/******************************************************************************/ /* Node creation functions */ /******************************************************************************/ diff --git a/prism/templates/include/prism/ast.h.erb b/prism/templates/include/prism/ast.h.erb index 8670dc3d2a..c169fedf0a 100644 --- a/prism/templates/include/prism/ast.h.erb +++ b/prism/templates/include/prism/ast.h.erb @@ -117,6 +117,11 @@ static const pm_node_flags_t PM_NODE_FLAG_COMMON_MASK = (1 << (PM_NODE_FLAG_BITS #define PM_NODE_TYPE_P(node, type) (PM_NODE_TYPE(node) == (type)) /** + * Return true if the given flag is set on the given node. + */ +#define PM_NODE_FLAG_P(node, flag) ((((pm_node_t *)(node))->flags & (flag)) != 0) + +/** * This is the base structure that represents a node in the syntax tree. It is * embedded into every node type. */ |