[ruby/prism] Move common flags to top bits
Moves the common flag bits to the top. This lets us eliminate the `COMMON` constant, and also allows us to group encoding flags on a nibble so we can more easily mask them. https://github.com/ruby/prism/commit/895508659e
This commit is contained in:
parent
17697c968e
commit
42484d1281
@ -361,6 +361,8 @@ flags:
|
|||||||
comment: "x - ignores whitespace and allows comments in regular expressions"
|
comment: "x - ignores whitespace and allows comments in regular expressions"
|
||||||
- name: MULTI_LINE
|
- name: MULTI_LINE
|
||||||
comment: "m - allows $ to match the end of lines within strings"
|
comment: "m - allows $ to match the end of lines within strings"
|
||||||
|
- name: ONCE
|
||||||
|
comment: "o - only interpolates values into the regular expression once"
|
||||||
- name: EUC_JP
|
- name: EUC_JP
|
||||||
comment: "e - forces the EUC-JP encoding"
|
comment: "e - forces the EUC-JP encoding"
|
||||||
- name: ASCII_8BIT
|
- name: ASCII_8BIT
|
||||||
@ -369,8 +371,6 @@ flags:
|
|||||||
comment: "s - forces the Windows-31J encoding"
|
comment: "s - forces the Windows-31J encoding"
|
||||||
- name: UTF_8
|
- name: UTF_8
|
||||||
comment: "u - forces the UTF-8 encoding"
|
comment: "u - forces the UTF-8 encoding"
|
||||||
- name: ONCE
|
|
||||||
comment: "o - only interpolates values into the regular expression once"
|
|
||||||
- name: StringFlags
|
- name: StringFlags
|
||||||
values:
|
values:
|
||||||
- name: FROZEN
|
- name: FROZEN
|
||||||
|
@ -176,7 +176,7 @@ pm_ast_new(pm_parser_t *parser, pm_node_t *node, rb_encoding *encoding) {
|
|||||||
argv[<%= index %>] = ULONG2NUM(cast-><%= field.name %>);
|
argv[<%= index %>] = ULONG2NUM(cast-><%= field.name %>);
|
||||||
<%- when Prism::FlagsField -%>
|
<%- when Prism::FlagsField -%>
|
||||||
#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>"
|
#line <%= __LINE__ + 1 %> "<%= File.basename(__FILE__) %>"
|
||||||
argv[<%= index %>] = ULONG2NUM(node->flags >> <%= Prism::COMMON_FLAGS %>);
|
argv[<%= index %>] = ULONG2NUM(node->flags & ~PM_NODE_FLAG_COMMON_MASK);
|
||||||
<%- else -%>
|
<%- else -%>
|
||||||
<%- raise -%>
|
<%- raise -%>
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
|
@ -52,8 +52,10 @@ typedef uint16_t pm_node_flags_t;
|
|||||||
|
|
||||||
// We store the flags enum in every node in the tree. Some flags are common to
|
// We store the flags enum in every node in the tree. Some flags are common to
|
||||||
// all nodes (the ones listed below). Others are specific to certain node types.
|
// all nodes (the ones listed below). Others are specific to certain node types.
|
||||||
static const pm_node_flags_t PM_NODE_FLAG_NEWLINE = 0x1;
|
#define PM_NODE_FLAG_BITS (sizeof(pm_node_flags_t) * 8)
|
||||||
static const pm_node_flags_t PM_NODE_FLAG_STATIC_LITERAL = 0x2;
|
static const pm_node_flags_t PM_NODE_FLAG_NEWLINE = (1 << (PM_NODE_FLAG_BITS - 1));
|
||||||
|
static const pm_node_flags_t PM_NODE_FLAG_STATIC_LITERAL = (1 << (PM_NODE_FLAG_BITS - 2));
|
||||||
|
static const pm_node_flags_t PM_NODE_FLAG_COMMON_MASK = PM_NODE_FLAG_NEWLINE | PM_NODE_FLAG_STATIC_LITERAL;
|
||||||
|
|
||||||
// For easy access, we define some macros to check node type
|
// For easy access, we define some macros to check node type
|
||||||
#define PM_NODE_TYPE(node) ((enum pm_node_type)node->type)
|
#define PM_NODE_TYPE(node) ((enum pm_node_type)node->type)
|
||||||
@ -105,7 +107,7 @@ typedef struct pm_<%= node.human %> {
|
|||||||
|
|
||||||
// <%= flag.name %>
|
// <%= flag.name %>
|
||||||
typedef enum pm_<%= flag.human %> {
|
typedef enum pm_<%= flag.human %> {
|
||||||
<%- flag.values.each.with_index(Prism::COMMON_FLAGS) do |value, index| -%>
|
<%- flag.values.each_with_index do |value, index| -%>
|
||||||
PM_<%= flag.human.upcase %>_<%= value.name %> = 1 << <%= index %>,
|
PM_<%= flag.human.upcase %>_<%= value.name %> = 1 << <%= index %>,
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
} pm_<%= flag.human %>_t;
|
} pm_<%= flag.human %>_t;
|
||||||
|
@ -80,7 +80,7 @@ prettyprint_node(pm_buffer_t *buffer, pm_parser_t *parser, pm_node_t *node) {
|
|||||||
pm_buffer_append_str(buffer, <%= field.name %>_buffer, strlen(<%= field.name %>_buffer));
|
pm_buffer_append_str(buffer, <%= field.name %>_buffer, strlen(<%= field.name %>_buffer));
|
||||||
<%- when Prism::FlagsField -%>
|
<%- when Prism::FlagsField -%>
|
||||||
char <%= field.name %>_buffer[12];
|
char <%= field.name %>_buffer[12];
|
||||||
snprintf(<%= field.name %>_buffer, sizeof(<%= field.name %>_buffer), "+%d", node->flags >> <%= Prism::COMMON_FLAGS %>);
|
snprintf(<%= field.name %>_buffer, sizeof(<%= field.name %>_buffer), "+%d", (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
|
||||||
pm_buffer_append_str(buffer, <%= field.name %>_buffer, strlen(<%= field.name %>_buffer));
|
pm_buffer_append_str(buffer, <%= field.name %>_buffer, strlen(<%= field.name %>_buffer));
|
||||||
<%- else -%>
|
<%- else -%>
|
||||||
<%- raise -%>
|
<%- raise -%>
|
||||||
|
@ -110,7 +110,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
|
|||||||
<%- when Prism::UInt32Field -%>
|
<%- when Prism::UInt32Field -%>
|
||||||
pm_buffer_append_u32(buffer, ((pm_<%= node.human %>_t *)node)-><%= field.name %>);
|
pm_buffer_append_u32(buffer, ((pm_<%= node.human %>_t *)node)-><%= field.name %>);
|
||||||
<%- when Prism::FlagsField -%>
|
<%- when Prism::FlagsField -%>
|
||||||
pm_buffer_append_u32(buffer, node->flags >> <%= Prism::COMMON_FLAGS %>);
|
pm_buffer_append_u32(buffer, (uint32_t)(node->flags & ~PM_NODE_FLAG_COMMON_MASK));
|
||||||
<%- else -%>
|
<%- else -%>
|
||||||
<%- raise -%>
|
<%- raise -%>
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
|
@ -5,8 +5,6 @@ require "fileutils"
|
|||||||
require "yaml"
|
require "yaml"
|
||||||
|
|
||||||
module Prism
|
module Prism
|
||||||
COMMON_FLAGS = 2
|
|
||||||
|
|
||||||
SERIALIZE_ONLY_SEMANTICS_FIELDS = ENV.fetch("PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS", false)
|
SERIALIZE_ONLY_SEMANTICS_FIELDS = ENV.fetch("PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS", false)
|
||||||
|
|
||||||
JAVA_BACKEND = ENV["PRISM_JAVA_BACKEND"] || "truffleruby"
|
JAVA_BACKEND = ENV["PRISM_JAVA_BACKEND"] || "truffleruby"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user