[ruby/prism] Add methods for setting/unsetting and macros for testing a flags

https://github.com/ruby/prism/commit/e5f37d1407
This commit is contained in:
Ufuk Kayserilioglu 2023-12-12 00:28:03 +02:00 committed by git
parent 67940b135c
commit bdb38dd9f2
2 changed files with 26 additions and 0 deletions

View File

@ -864,6 +864,27 @@ pm_arguments_validate_block(pm_parser_t *parser, pm_arguments_t *arguments, pm_b
pm_parser_err_node(parser, (pm_node_t *) block, PM_ERR_ARGUMENT_UNEXPECTED_BLOCK);
}
/******************************************************************************/
/* 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 */
/******************************************************************************/

View File

@ -116,6 +116,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.