ruby-changes:64152
From: Nobuyoshi <ko1@a...>
Date: Mon, 14 Dec 2020 19:29:52 +0900 (JST)
Subject: [ruby-changes:64152] b1bd223085 (master): Support shareable_constant_value pragma
https://git.ruby-lang.org/ruby.git/commit/?id=b1bd223085 From b1bd223085d7b97d8de8679894a81b7993c26b28 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 9 Oct 2020 20:06:30 +0900 Subject: Support shareable_constant_value pragma diff --git a/parse.y b/parse.y index ff413d8..3c9b9e0 100644 --- a/parse.y +++ b/parse.y @@ -31,6 +31,7 @@ struct lex_context { https://github.com/ruby/ruby/blob/trunk/parse.y#L31 unsigned int in_kwarg: 1; unsigned int in_def: 1; unsigned int in_class: 1; + unsigned int shareable_constant_value: 1; }; #include "internal.h" @@ -959,6 +960,7 @@ restore_defun(struct parser_params *p, NODE *name) https://github.com/ruby/ruby/blob/trunk/parse.y#L960 YYSTYPE c = {.val = name->nd_cval}; p->cur_arg = name->nd_vid; p->ctxt.in_def = c.ctxt.in_def; + p->ctxt.shareable_constant_value = c.ctxt.shareable_constant_value; } static void @@ -3087,6 +3089,7 @@ primary : literal https://github.com/ruby/ruby/blob/trunk/parse.y#L3089 /*% ripper: class!($2, $3, $5) %*/ local_pop(p); p->ctxt.in_class = $<ctxt>1.in_class; + p->ctxt.shareable_constant_value = $<ctxt>1.shareable_constant_value; } | k_class tLSHFT expr { @@ -3108,6 +3111,7 @@ primary : literal https://github.com/ruby/ruby/blob/trunk/parse.y#L3111 local_pop(p); p->ctxt.in_def = $<ctxt>1.in_def; p->ctxt.in_class = $<ctxt>1.in_class; + p->ctxt.shareable_constant_value = $<ctxt>1.shareable_constant_value; } | k_module cpath { @@ -3130,6 +3134,7 @@ primary : literal https://github.com/ruby/ruby/blob/trunk/parse.y#L3134 /*% ripper: module!($2, $4) %*/ local_pop(p); p->ctxt.in_class = $<ctxt>1.in_class; + p->ctxt.shareable_constant_value = $<ctxt>1.shareable_constant_value; } | defn_head f_arglist @@ -7978,6 +7983,13 @@ parser_set_compile_option_flag(struct parser_params *p, const char *name, const https://github.com/ruby/ruby/blob/trunk/parse.y#L7983 (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 static void 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[] = { https://github.com/ruby/ruby/blob/trunk/parse.y#L8009 {"coding", magic_comment_encoding, parser_encode_length}, {"encoding", magic_comment_encoding, parser_encode_length}, {"frozen_string_literal", parser_set_compile_option_flag}, + {"shareable_constant_value", parser_set_shareable_constant_value}, {"warn_indent", parser_set_token_info}, # if WARN_PAST_SCOPE {"warn_past_scope", parser_set_past_scope}, diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index 422a7cb..1ed92d5 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -1174,6 +1174,12 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L1174 assert_equal(1, ex.message.scan(w).size, "same #{w.inspect} warning should be just once") end + def test_shareable_constant_value + assert_warning(/invalid value/) do + assert_valid_syntax("# shareable_constant_value: invalid-option", verbose: true) + end + end + =begin def test_past_scope_variable assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}} -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/