Skip to content

Commit 1725295

Browse files
tenderlovematzbot
authored andcommitted
[ruby/prism] Add a "LAST" enum field to all flags enums
This allows us to use the "last" of the enums in order to make masks, etc. This particular commit uses the call flag's last enum field as an offset so that we can define "private" flags but not accidentally clobber any newly added call node flags. ruby/prism@e71aa980d8
1 parent 8cefb70 commit 1725295

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

prism/prism.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,10 +2622,11 @@ pm_break_node_create(pm_parser_t *parser, const pm_token_t *keyword, pm_argument
26222622
// There are certain flags that we want to use internally but don't want to
26232623
// expose because they are not relevant beyond parsing. Therefore we'll define
26242624
// them here and not define them in config.yml/a header file.
2625-
static const pm_node_flags_t PM_WRITE_NODE_FLAGS_IMPLICIT_ARRAY = 0x4;
2626-
static const pm_node_flags_t PM_CALL_NODE_FLAGS_IMPLICIT_ARRAY = 0x40;
2627-
static const pm_node_flags_t PM_CALL_NODE_FLAGS_COMPARISON = 0x80;
2628-
static const pm_node_flags_t PM_CALL_NODE_FLAGS_INDEX = 0x100;
2625+
static const pm_node_flags_t PM_WRITE_NODE_FLAGS_IMPLICIT_ARRAY = (1 << 2);
2626+
2627+
static const pm_node_flags_t PM_CALL_NODE_FLAGS_IMPLICIT_ARRAY = ((PM_CALL_NODE_FLAGS_LAST - 1) << 1);
2628+
static const pm_node_flags_t PM_CALL_NODE_FLAGS_COMPARISON = ((PM_CALL_NODE_FLAGS_LAST - 1) << 2);
2629+
static const pm_node_flags_t PM_CALL_NODE_FLAGS_INDEX = ((PM_CALL_NODE_FLAGS_LAST - 1) << 3);
26292630

26302631
/**
26312632
* Allocate and initialize a new CallNode node. This sets everything to NULL or

prism/templates/include/prism/ast.h.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ typedef enum pm_<%= flag.human %> {
212212
/** <%= value.comment %> */
213213
PM_<%= flag.human.upcase %>_<%= value.name %> = <%= 1 << (index + Prism::Template::COMMON_FLAGS_COUNT) %>,
214214
<%- end -%>
215+
216+
PM_<%= flag.human.upcase %>_LAST,
215217
} pm_<%= flag.human %>_t;
216218
<%- end -%>
217219

0 commit comments

Comments
 (0)