зеркало из https://github.com/github/ruby.git
[PRISM] Pass --enable-frozen-string-literal through to evals
This commit is contained in:
Родитель
a1ae29e87d
Коммит
42d1cd8f7f
2
iseq.c
2
iseq.c
|
@ -1253,8 +1253,6 @@ pm_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, V
|
|||
pm_parse_result_t result = { 0 };
|
||||
pm_options_line_set(&result.options, NUM2INT(line));
|
||||
|
||||
pm_options_frozen_string_literal_init(&result, option.frozen_string_literal);
|
||||
|
||||
VALUE error;
|
||||
if (RB_TYPE_P(src, T_FILE)) {
|
||||
VALUE filepath = rb_io_path(src);
|
||||
|
|
|
@ -8479,6 +8479,30 @@ pm_parse_process(pm_parse_result_t *result, pm_node_t *node)
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the frozen_string_literal option based on the default value used by the
|
||||
* CRuby compiler.
|
||||
*/
|
||||
static void
|
||||
pm_options_frozen_string_literal_init(pm_options_t *options)
|
||||
{
|
||||
int frozen_string_literal = rb_iseq_opt_frozen_string_literal();
|
||||
|
||||
switch (frozen_string_literal) {
|
||||
case ISEQ_FROZEN_STRING_LITERAL_UNSET:
|
||||
break;
|
||||
case ISEQ_FROZEN_STRING_LITERAL_DISABLED:
|
||||
pm_options_frozen_string_literal_set(options, false);
|
||||
break;
|
||||
case ISEQ_FROZEN_STRING_LITERAL_ENABLED:
|
||||
pm_options_frozen_string_literal_set(options, true);
|
||||
break;
|
||||
default:
|
||||
rb_bug("pm_options_frozen_string_literal_init: invalid frozen_string_literal=%d", frozen_string_literal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of ruby String objects that represent the lines of the
|
||||
* source file that the given parser parsed.
|
||||
|
@ -8514,24 +8538,6 @@ pm_parse_file_script_lines(const pm_scope_node_t *scope_node, const pm_parser_t
|
|||
return lines;
|
||||
}
|
||||
|
||||
void
|
||||
pm_options_frozen_string_literal_init(pm_parse_result_t *result, int frozen_string_literal)
|
||||
{
|
||||
switch (frozen_string_literal) {
|
||||
case ISEQ_FROZEN_STRING_LITERAL_UNSET:
|
||||
break;
|
||||
case ISEQ_FROZEN_STRING_LITERAL_DISABLED:
|
||||
pm_options_frozen_string_literal_set(&result->options, false);
|
||||
break;
|
||||
case ISEQ_FROZEN_STRING_LITERAL_ENABLED:
|
||||
pm_options_frozen_string_literal_set(&result->options, true);
|
||||
break;
|
||||
default:
|
||||
rb_bug("pm_options_frozen_string_literal_init: invalid frozen_string_literal=%d", frozen_string_literal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to load the file into memory. Return a Ruby error if the file cannot
|
||||
* be read.
|
||||
|
@ -8551,6 +8557,7 @@ pm_load_file(pm_parse_result_t *result, VALUE filepath)
|
|||
return err;
|
||||
}
|
||||
|
||||
pm_options_frozen_string_literal_init(&result->options);
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
|
@ -8616,6 +8623,7 @@ pm_parse_string(pm_parse_result_t *result, VALUE source, VALUE filepath)
|
|||
return rb_exc_new_cstr(rb_eArgError, "invalid source encoding");
|
||||
}
|
||||
|
||||
pm_options_frozen_string_literal_init(&result->options);
|
||||
pm_string_constant_init(&result->input, RSTRING_PTR(source), RSTRING_LEN(source));
|
||||
pm_options_encoding_set(&result->options, rb_enc_name(encoding));
|
||||
|
||||
|
@ -8658,6 +8666,8 @@ pm_parse_stdin_fgets(char *string, int size, void *stream)
|
|||
VALUE
|
||||
pm_parse_stdin(pm_parse_result_t *result)
|
||||
{
|
||||
pm_options_frozen_string_literal_init(&result->options);
|
||||
|
||||
pm_buffer_t buffer;
|
||||
pm_node_t *node = pm_parse_stream(&result->parser, &buffer, (void *) rb_stdin, pm_parse_stdin_fgets, &result->options);
|
||||
|
||||
|
|
|
@ -47,7 +47,6 @@ typedef struct {
|
|||
bool parsed;
|
||||
} pm_parse_result_t;
|
||||
|
||||
void pm_options_frozen_string_literal_init(pm_parse_result_t *result, int frozen_string_literal);
|
||||
VALUE pm_load_file(pm_parse_result_t *result, VALUE filepath);
|
||||
VALUE pm_parse_file(pm_parse_result_t *result, VALUE filepath);
|
||||
VALUE pm_load_parse_file(pm_parse_result_t *result, VALUE filepath);
|
||||
|
|
2
ruby.c
2
ruby.c
|
@ -2116,8 +2116,6 @@ prism_script(ruby_cmdline_options_t *opt, pm_parse_result_t *result)
|
|||
pm_options_t *options = &result->options;
|
||||
pm_options_line_set(options, 1);
|
||||
|
||||
pm_options_frozen_string_literal_init(result, rb_iseq_opt_frozen_string_literal());
|
||||
|
||||
if (opt->ext.enc.name != 0) {
|
||||
pm_options_encoding_set(options, StringValueCStr(opt->ext.enc.name));
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ MSpec.register(:exclude, "The -S command line option runs launcher found in PATH
|
|||
MSpec.register(:exclude, "The -x command line option runs code after the first /#!.*ruby.*/-ish line in target file")
|
||||
MSpec.register(:exclude, "The -x command line option fails when /#!.*ruby.*/-ish line in target file is not found")
|
||||
MSpec.register(:exclude, "The -x command line option behaves as -x was set when non-ruby shebang is encountered on first line")
|
||||
MSpec.register(:exclude, "The --enable-frozen-string-literal flag causes string literals to produce the same object for literals with the same content in different files")
|
||||
MSpec.register(:exclude, "The --debug flag produces debugging info on attempted frozen string modification")
|
||||
|
||||
## Language
|
||||
|
|
|
@ -1663,8 +1663,6 @@ pm_eval_make_iseq(VALUE src, VALUE fname, int line,
|
|||
pm_parse_result_t result = { 0 };
|
||||
pm_options_line_set(&result.options, line);
|
||||
|
||||
pm_options_frozen_string_literal_init(&result, rb_iseq_opt_frozen_string_literal());
|
||||
|
||||
// Cout scopes, one for each parent iseq, plus one for our local scope
|
||||
int scopes_count = 0;
|
||||
do {
|
||||
|
|
Загрузка…
Ссылка в новой задаче