mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Support shareable_constant_value pragma
This commit is contained in:
parent
7060d6b721
commit
b1bd223085
Notes:
git
2020-12-14 19:19:48 +09:00
2 changed files with 19 additions and 0 deletions
13
parse.y
13
parse.y
|
@ -31,6 +31,7 @@ struct lex_context {
|
||||||
unsigned int in_kwarg: 1;
|
unsigned int in_kwarg: 1;
|
||||||
unsigned int in_def: 1;
|
unsigned int in_def: 1;
|
||||||
unsigned int in_class: 1;
|
unsigned int in_class: 1;
|
||||||
|
unsigned int shareable_constant_value: 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
@ -959,6 +960,7 @@ restore_defun(struct parser_params *p, NODE *name)
|
||||||
YYSTYPE c = {.val = name->nd_cval};
|
YYSTYPE c = {.val = name->nd_cval};
|
||||||
p->cur_arg = name->nd_vid;
|
p->cur_arg = name->nd_vid;
|
||||||
p->ctxt.in_def = c.ctxt.in_def;
|
p->ctxt.in_def = c.ctxt.in_def;
|
||||||
|
p->ctxt.shareable_constant_value = c.ctxt.shareable_constant_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -3087,6 +3089,7 @@ primary : literal
|
||||||
/*% ripper: class!($2, $3, $5) %*/
|
/*% ripper: class!($2, $3, $5) %*/
|
||||||
local_pop(p);
|
local_pop(p);
|
||||||
p->ctxt.in_class = $<ctxt>1.in_class;
|
p->ctxt.in_class = $<ctxt>1.in_class;
|
||||||
|
p->ctxt.shareable_constant_value = $<ctxt>1.shareable_constant_value;
|
||||||
}
|
}
|
||||||
| k_class tLSHFT expr
|
| k_class tLSHFT expr
|
||||||
{
|
{
|
||||||
|
@ -3108,6 +3111,7 @@ primary : literal
|
||||||
local_pop(p);
|
local_pop(p);
|
||||||
p->ctxt.in_def = $<ctxt>1.in_def;
|
p->ctxt.in_def = $<ctxt>1.in_def;
|
||||||
p->ctxt.in_class = $<ctxt>1.in_class;
|
p->ctxt.in_class = $<ctxt>1.in_class;
|
||||||
|
p->ctxt.shareable_constant_value = $<ctxt>1.shareable_constant_value;
|
||||||
}
|
}
|
||||||
| k_module cpath
|
| k_module cpath
|
||||||
{
|
{
|
||||||
|
@ -3130,6 +3134,7 @@ primary : literal
|
||||||
/*% ripper: module!($2, $4) %*/
|
/*% ripper: module!($2, $4) %*/
|
||||||
local_pop(p);
|
local_pop(p);
|
||||||
p->ctxt.in_class = $<ctxt>1.in_class;
|
p->ctxt.in_class = $<ctxt>1.in_class;
|
||||||
|
p->ctxt.shareable_constant_value = $<ctxt>1.shareable_constant_value;
|
||||||
}
|
}
|
||||||
| defn_head
|
| defn_head
|
||||||
f_arglist
|
f_arglist
|
||||||
|
@ -7978,6 +7983,13 @@ parser_set_compile_option_flag(struct parser_params *p, const char *name, const
|
||||||
(b ? Qtrue : Qfalse));
|
(b ? Qtrue : Qfalse));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
parser_set_shareable_constant_value(struct parser_params *p, const char *name, const char *val)
|
||||||
|
{
|
||||||
|
int b = parser_get_bool(p, name, val);
|
||||||
|
if (b >= 0) p->ctxt.shareable_constant_value = b;
|
||||||
|
}
|
||||||
|
|
||||||
# if WARN_PAST_SCOPE
|
# if WARN_PAST_SCOPE
|
||||||
static void
|
static void
|
||||||
parser_set_past_scope(struct parser_params *p, const char *name, const char *val)
|
parser_set_past_scope(struct parser_params *p, const char *name, const char *val)
|
||||||
|
@ -7997,6 +8009,7 @@ static const struct magic_comment magic_comments[] = {
|
||||||
{"coding", magic_comment_encoding, parser_encode_length},
|
{"coding", magic_comment_encoding, parser_encode_length},
|
||||||
{"encoding", magic_comment_encoding, parser_encode_length},
|
{"encoding", magic_comment_encoding, parser_encode_length},
|
||||||
{"frozen_string_literal", parser_set_compile_option_flag},
|
{"frozen_string_literal", parser_set_compile_option_flag},
|
||||||
|
{"shareable_constant_value", parser_set_shareable_constant_value},
|
||||||
{"warn_indent", parser_set_token_info},
|
{"warn_indent", parser_set_token_info},
|
||||||
# if WARN_PAST_SCOPE
|
# if WARN_PAST_SCOPE
|
||||||
{"warn_past_scope", parser_set_past_scope},
|
{"warn_past_scope", parser_set_past_scope},
|
||||||
|
|
|
@ -1174,6 +1174,12 @@ x = __ENCODING__
|
||||||
assert_equal(1, ex.message.scan(w).size, "same #{w.inspect} warning should be just once")
|
assert_equal(1, ex.message.scan(w).size, "same #{w.inspect} warning should be just once")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_shareable_constant_value
|
||||||
|
assert_warning(/invalid value/) do
|
||||||
|
assert_valid_syntax("# shareable_constant_value: invalid-option", verbose: true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
def test_past_scope_variable
|
def test_past_scope_variable
|
||||||
assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}
|
assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue