diff options
| author | Aaron Patterson <tenderlove@ruby-lang.org> | 2025-09-29 16:12:44 -0700 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2025-10-01 00:37:42 +0000 |
| commit | 17252958c9ce094c583616257452cfb1695dc7ef (patch) | |
| tree | 8beae22191480c05cbbe9b254896346c1094592d | |
| parent | 8cefb70e210348f509648df943eebe61ef708c3d (diff) | |
[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.
https://github.com/ruby/prism/commit/e71aa980d8
| -rw-r--r-- | prism/prism.c | 9 | ||||
| -rw-r--r-- | prism/templates/include/prism/ast.h.erb | 2 |
2 files changed, 7 insertions, 4 deletions
diff --git a/prism/prism.c b/prism/prism.c index 6dd0b2ae73..875968f06b 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -2622,10 +2622,11 @@ pm_break_node_create(pm_parser_t *parser, const pm_token_t *keyword, pm_argument // There are certain flags that we want to use internally but don't want to // expose because they are not relevant beyond parsing. Therefore we'll define // them here and not define them in config.yml/a header file. -static const pm_node_flags_t PM_WRITE_NODE_FLAGS_IMPLICIT_ARRAY = 0x4; -static const pm_node_flags_t PM_CALL_NODE_FLAGS_IMPLICIT_ARRAY = 0x40; -static const pm_node_flags_t PM_CALL_NODE_FLAGS_COMPARISON = 0x80; -static const pm_node_flags_t PM_CALL_NODE_FLAGS_INDEX = 0x100; +static const pm_node_flags_t PM_WRITE_NODE_FLAGS_IMPLICIT_ARRAY = (1 << 2); + +static const pm_node_flags_t PM_CALL_NODE_FLAGS_IMPLICIT_ARRAY = ((PM_CALL_NODE_FLAGS_LAST - 1) << 1); +static const pm_node_flags_t PM_CALL_NODE_FLAGS_COMPARISON = ((PM_CALL_NODE_FLAGS_LAST - 1) << 2); +static const pm_node_flags_t PM_CALL_NODE_FLAGS_INDEX = ((PM_CALL_NODE_FLAGS_LAST - 1) << 3); /** * Allocate and initialize a new CallNode node. This sets everything to NULL or diff --git a/prism/templates/include/prism/ast.h.erb b/prism/templates/include/prism/ast.h.erb index 087eb81890..e82cb78fe3 100644 --- a/prism/templates/include/prism/ast.h.erb +++ b/prism/templates/include/prism/ast.h.erb @@ -212,6 +212,8 @@ typedef enum pm_<%= flag.human %> { /** <%= value.comment %> */ PM_<%= flag.human.upcase %>_<%= value.name %> = <%= 1 << (index + Prism::Template::COMMON_FLAGS_COUNT) %>, <%- end -%> + + PM_<%= flag.human.upcase %>_LAST, } pm_<%= flag.human %>_t; <%- end -%> |
