Skip to content

Commit

Permalink
[ruby/prism] Add methods for setting/unsetting and macros for testing…
Browse files Browse the repository at this point in the history
  • Loading branch information
paracycle authored and matzbot committed Dec 12, 2023
1 parent 67940b1 commit bdb38dd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions prism/prism.c
Expand Up @@ -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 */
/******************************************************************************/
Expand Down
5 changes: 5 additions & 0 deletions prism/templates/include/prism/ast.h.erb
Expand Up @@ -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.
Expand Down

0 comments on commit bdb38dd

Please sign in to comment.