From bdb38dd9f22accfddc8d0a5e211c74b6a06faf51 Mon Sep 17 00:00:00 2001 From: Ufuk Kayserilioglu Date: Tue, 12 Dec 2023 00:28:03 +0200 Subject: [PATCH] [ruby/prism] Add methods for setting/unsetting and macros for testing a flags https://github.com/ruby/prism/commit/e5f37d1407 --- prism/prism.c | 21 +++++++++++++++++++++ prism/templates/include/prism/ast.h.erb | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/prism/prism.c b/prism/prism.c index 2b74152cce..56056190e4 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -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 */ /******************************************************************************/ 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 @@ -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.