[prism] Update to use new options APIs

This commit is contained in:
Kevin Newton 2023-11-03 08:42:48 -04:00
Родитель aab2a6a8a3
Коммит ec86b2eb39
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 0EAD74C79EC73F26
4 изменённых файлов: 59 добавлений и 37 удалений

Просмотреть файл

@ -97,6 +97,7 @@ PRISM_FILES = prism/api_node.$(OBJEXT) \
prism/enc/pm_windows_31j.$(OBJEXT) \
prism/extension.$(OBJEXT) \
prism/node.$(OBJEXT) \
prism/options.$(OBJEXT) \
prism/pack.$(OBJEXT) \
prism/prettyprint.$(OBJEXT) \
prism/regexp.$(OBJEXT) \
@ -3214,6 +3215,7 @@ compile.$(OBJEXT): $(top_srcdir)/prism/defines.h
compile.$(OBJEXT): $(top_srcdir)/prism/diagnostic.h
compile.$(OBJEXT): $(top_srcdir)/prism/enc/pm_encoding.h
compile.$(OBJEXT): $(top_srcdir)/prism/node.h
compile.$(OBJEXT): $(top_srcdir)/prism/options.h
compile.$(OBJEXT): $(top_srcdir)/prism/pack.h
compile.$(OBJEXT): $(top_srcdir)/prism/parser.h
compile.$(OBJEXT): $(top_srcdir)/prism/prettyprint.h
@ -8267,6 +8269,7 @@ iseq.$(OBJEXT): $(top_srcdir)/prism/defines.h
iseq.$(OBJEXT): $(top_srcdir)/prism/diagnostic.h
iseq.$(OBJEXT): $(top_srcdir)/prism/enc/pm_encoding.h
iseq.$(OBJEXT): $(top_srcdir)/prism/node.h
iseq.$(OBJEXT): $(top_srcdir)/prism/options.h
iseq.$(OBJEXT): $(top_srcdir)/prism/pack.h
iseq.$(OBJEXT): $(top_srcdir)/prism/parser.h
iseq.$(OBJEXT): $(top_srcdir)/prism/prettyprint.h
@ -11335,6 +11338,7 @@ prism/api_node.$(OBJEXT): $(top_srcdir)/prism/diagnostic.h
prism/api_node.$(OBJEXT): $(top_srcdir)/prism/enc/pm_encoding.h
prism/api_node.$(OBJEXT): $(top_srcdir)/prism/extension.h
prism/api_node.$(OBJEXT): $(top_srcdir)/prism/node.h
prism/api_node.$(OBJEXT): $(top_srcdir)/prism/options.h
prism/api_node.$(OBJEXT): $(top_srcdir)/prism/pack.h
prism/api_node.$(OBJEXT): $(top_srcdir)/prism/parser.h
prism/api_node.$(OBJEXT): $(top_srcdir)/prism/prettyprint.h
@ -11528,6 +11532,7 @@ prism/api_pack.$(OBJEXT): $(top_srcdir)/prism/diagnostic.h
prism/api_pack.$(OBJEXT): $(top_srcdir)/prism/enc/pm_encoding.h
prism/api_pack.$(OBJEXT): $(top_srcdir)/prism/extension.h
prism/api_pack.$(OBJEXT): $(top_srcdir)/prism/node.h
prism/api_pack.$(OBJEXT): $(top_srcdir)/prism/options.h
prism/api_pack.$(OBJEXT): $(top_srcdir)/prism/pack.h
prism/api_pack.$(OBJEXT): $(top_srcdir)/prism/parser.h
prism/api_pack.$(OBJEXT): $(top_srcdir)/prism/prettyprint.h
@ -11833,6 +11838,7 @@ prism/extension.$(OBJEXT): $(top_srcdir)/prism/enc/pm_encoding.h
prism/extension.$(OBJEXT): $(top_srcdir)/prism/extension.c
prism/extension.$(OBJEXT): $(top_srcdir)/prism/extension.h
prism/extension.$(OBJEXT): $(top_srcdir)/prism/node.h
prism/extension.$(OBJEXT): $(top_srcdir)/prism/options.h
prism/extension.$(OBJEXT): $(top_srcdir)/prism/pack.h
prism/extension.$(OBJEXT): $(top_srcdir)/prism/parser.h
prism/extension.$(OBJEXT): $(top_srcdir)/prism/prettyprint.h
@ -12021,6 +12027,7 @@ prism/node.$(OBJEXT): $(top_srcdir)/prism/defines.h
prism/node.$(OBJEXT): $(top_srcdir)/prism/diagnostic.h
prism/node.$(OBJEXT): $(top_srcdir)/prism/enc/pm_encoding.h
prism/node.$(OBJEXT): $(top_srcdir)/prism/node.h
prism/node.$(OBJEXT): $(top_srcdir)/prism/options.h
prism/node.$(OBJEXT): $(top_srcdir)/prism/pack.h
prism/node.$(OBJEXT): $(top_srcdir)/prism/parser.h
prism/node.$(OBJEXT): $(top_srcdir)/prism/prism.h
@ -12037,6 +12044,10 @@ prism/node.$(OBJEXT): $(top_srcdir)/prism/util/pm_strpbrk.h
prism/node.$(OBJEXT): {$(VPATH)}config.h
prism/node.$(OBJEXT): {$(VPATH)}prism/ast.h
prism/node.$(OBJEXT): {$(VPATH)}prism/node.c
prism/options.$(OBJEXT): $(top_srcdir)/prism/defines.h
prism/options.$(OBJEXT): $(top_srcdir)/prism/options.c
prism/options.$(OBJEXT): $(top_srcdir)/prism/options.h
prism/options.$(OBJEXT): $(top_srcdir)/prism/util/pm_string.h
prism/pack.$(OBJEXT): $(top_srcdir)/prism/defines.h
prism/pack.$(OBJEXT): $(top_srcdir)/prism/pack.c
prism/pack.$(OBJEXT): $(top_srcdir)/prism/pack.h
@ -12058,6 +12069,7 @@ prism/prism.$(OBJEXT): $(top_srcdir)/prism/defines.h
prism/prism.$(OBJEXT): $(top_srcdir)/prism/diagnostic.h
prism/prism.$(OBJEXT): $(top_srcdir)/prism/enc/pm_encoding.h
prism/prism.$(OBJEXT): $(top_srcdir)/prism/node.h
prism/prism.$(OBJEXT): $(top_srcdir)/prism/options.h
prism/prism.$(OBJEXT): $(top_srcdir)/prism/pack.h
prism/prism.$(OBJEXT): $(top_srcdir)/prism/parser.h
prism/prism.$(OBJEXT): $(top_srcdir)/prism/prettyprint.h
@ -12097,6 +12109,7 @@ prism/serialize.$(OBJEXT): $(top_srcdir)/prism/defines.h
prism/serialize.$(OBJEXT): $(top_srcdir)/prism/diagnostic.h
prism/serialize.$(OBJEXT): $(top_srcdir)/prism/enc/pm_encoding.h
prism/serialize.$(OBJEXT): $(top_srcdir)/prism/node.h
prism/serialize.$(OBJEXT): $(top_srcdir)/prism/options.h
prism/serialize.$(OBJEXT): $(top_srcdir)/prism/pack.h
prism/serialize.$(OBJEXT): $(top_srcdir)/prism/parser.h
prism/serialize.$(OBJEXT): $(top_srcdir)/prism/prettyprint.h
@ -12191,6 +12204,7 @@ prism_init.$(OBJEXT): $(top_srcdir)/prism/diagnostic.h
prism_init.$(OBJEXT): $(top_srcdir)/prism/enc/pm_encoding.h
prism_init.$(OBJEXT): $(top_srcdir)/prism/extension.h
prism_init.$(OBJEXT): $(top_srcdir)/prism/node.h
prism_init.$(OBJEXT): $(top_srcdir)/prism/options.h
prism_init.$(OBJEXT): $(top_srcdir)/prism/pack.h
prism_init.$(OBJEXT): $(top_srcdir)/prism/parser.h
prism_init.$(OBJEXT): $(top_srcdir)/prism/prettyprint.h
@ -15323,6 +15337,7 @@ ruby.$(OBJEXT): $(top_srcdir)/prism/defines.h
ruby.$(OBJEXT): $(top_srcdir)/prism/diagnostic.h
ruby.$(OBJEXT): $(top_srcdir)/prism/enc/pm_encoding.h
ruby.$(OBJEXT): $(top_srcdir)/prism/node.h
ruby.$(OBJEXT): $(top_srcdir)/prism/options.h
ruby.$(OBJEXT): $(top_srcdir)/prism/pack.h
ruby.$(OBJEXT): $(top_srcdir)/prism/parser.h
ruby.$(OBJEXT): $(top_srcdir)/prism/prettyprint.h

25
iseq.c
Просмотреть файл

@ -1414,34 +1414,34 @@ iseqw_s_compile_prism(int argc, VALUE *argv, VALUE self)
Check_Type(file, T_STRING);
rb_iseq_t *iseq = iseq_alloc();
int start_line = NUM2INT(line);
pm_options_t options = { 0 };
pm_options_filepath_set(&options, RSTRING_PTR(file));
pm_options_line_set(&options, start_line);
pm_parser_t parser;
size_t len = RSTRING_LEN(src);
VALUE name = rb_fstring_lit("<compiled>");
pm_parser_init(&parser, (const uint8_t *) RSTRING_PTR(src), len, "");
pm_parser_init(&parser, (const uint8_t *) RSTRING_PTR(src), RSTRING_LEN(src), &options);
pm_node_t *node = pm_parse(&parser);
int first_lineno = NUM2INT(line);
pm_line_column_t start_loc = pm_newline_list_line_column(&parser.newline_list, node->location.start);
pm_line_column_t end_loc = pm_newline_list_line_column(&parser.newline_list, node->location.end);
rb_code_location_t node_location;
node_location.beg_pos.lineno = (int)start_loc.line;
node_location.beg_pos.column = (int)start_loc.column;
node_location.end_pos.lineno = (int)end_loc.line;
node_location.end_pos.column = (int)end_loc.column;
node_location.beg_pos.lineno = (int) start_loc.line;
node_location.beg_pos.column = (int) start_loc.column;
node_location.end_pos.lineno = (int) end_loc.line;
node_location.end_pos.column = (int) end_loc.column;
int node_id = 0;
rb_iseq_t *parent = NULL;
enum rb_iseq_type iseq_type = ISEQ_TYPE_TOP;
rb_compile_option_t option;
make_compile_option(&option, opt);
prepare_iseq_build(iseq, name, file, path, first_lineno, &node_location, node_id,
VALUE name = rb_fstring_lit("<compiled>");
prepare_iseq_build(iseq, name, file, path, start_line, &node_location, node_id,
parent, 0, (enum rb_iseq_type)iseq_type, Qnil, &option);
pm_scope_node_t scope_node;
@ -1451,6 +1451,7 @@ iseqw_s_compile_prism(int argc, VALUE *argv, VALUE self)
finish_iseq_build(iseq);
pm_node_destroy(&parser, node);
pm_parser_free(&parser);
pm_options_free(&options);
return iseqw_new(iseq);
}

Просмотреть файл

@ -15,12 +15,12 @@ VALUE rb_cPrismParseError;
VALUE rb_cPrismParseWarning;
VALUE rb_cPrismParseResult;
ID id_filepath;
ID id_encoding;
ID id_line;
ID id_frozen_string_literal;
ID id_suppress_warnings;
ID id_scopes;
ID rb_option_id_filepath;
ID rb_option_id_encoding;
ID rb_option_id_line;
ID rb_option_id_frozen_string_literal;
ID rb_option_id_suppress_warnings;
ID rb_option_id_scopes;
/******************************************************************************/
/* IO of Ruby code */
@ -119,17 +119,17 @@ build_options_i(VALUE key, VALUE value, VALUE argument) {
pm_options_t *options = (pm_options_t *) argument;
ID key_id = SYM2ID(key);
if (key_id == id_filepath) {
if (key_id == rb_option_id_filepath) {
if (!NIL_P(value)) pm_options_filepath_set(options, check_string(value));
} else if (key_id == id_encoding) {
} else if (key_id == rb_option_id_encoding) {
if (!NIL_P(value)) pm_options_encoding_set(options, rb_enc_name(rb_to_encoding(value)));
} else if (key_id == id_line) {
} else if (key_id == rb_option_id_line) {
if (!NIL_P(value)) pm_options_line_set(options, NUM2UINT(value));
} else if (key_id == id_frozen_string_literal) {
} else if (key_id == rb_option_id_frozen_string_literal) {
if (!NIL_P(value)) pm_options_frozen_string_literal_set(options, value == Qtrue);
} else if (key_id == id_suppress_warnings) {
} else if (key_id == rb_option_id_suppress_warnings) {
if (!NIL_P(value)) pm_options_suppress_warnings_set(options, value == Qtrue);
} else if (key_id == id_scopes) {
} else if (key_id == rb_option_id_scopes) {
if (!NIL_P(value)) build_options_scopes(options, value);
} else {
rb_raise(rb_eArgError, "unknown keyword: %"PRIsVALUE, key);
@ -940,12 +940,12 @@ Init_prism(void) {
// Intern all of the options that we support so that we don't have to do it
// every time we parse.
id_filepath = rb_intern_const("filepath");
id_encoding = rb_intern_const("encoding");
id_line = rb_intern_const("line");
id_frozen_string_literal = rb_intern_const("frozen_string_literal");
id_suppress_warnings = rb_intern_const("suppress_warnings");
id_scopes = rb_intern_const("scopes");
rb_option_id_filepath = rb_intern_const("filepath");
rb_option_id_encoding = rb_intern_const("encoding");
rb_option_id_line = rb_intern_const("line");
rb_option_id_frozen_string_literal = rb_intern_const("frozen_string_literal");
rb_option_id_suppress_warnings = rb_intern_const("suppress_warnings");
rb_option_id_scopes = rb_intern_const("scopes");
/**
* The version of the prism library.

20
ruby.c
Просмотреть файл

@ -2335,17 +2335,20 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
}
if (dump & (DUMP_BIT(prism_parsetree))) {
pm_parser_t parser;
pm_string_t input;
pm_options_t options = { 0 };
if (opt->e_script) {
size_t len = RSTRING_LEN(opt->e_script);
pm_parser_init(&parser, (const uint8_t *) RSTRING_PTR(opt->e_script), len, "-e");
pm_string_constant_init(&input, RSTRING_PTR(opt->e_script), RSTRING_LEN(opt->e_script));
pm_options_filepath_set(&options, "-e");
} else {
pm_string_t input;
char *filepath = RSTRING_PTR(opt->script_name);
pm_string_mapped_init(&input, filepath);
pm_parser_init(&parser, pm_string_source(&input), pm_string_length(&input), filepath);
pm_string_mapped_init(&input, RSTRING_PTR(opt->script_name));
pm_options_filepath_set(&options, RSTRING_PTR(opt->script_name));
}
pm_parser_t parser;
pm_parser_init(&parser, pm_string_source(&input), pm_string_length(&input), &options);
pm_node_t *node = pm_parse(&parser);
pm_buffer_t output_buffer = { 0 };
@ -2356,6 +2359,9 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
pm_buffer_free(&output_buffer);
pm_node_destroy(&parser, node);
pm_parser_free(&parser);
pm_string_free(&input);
pm_options_free(&options);
}
if (dump & (DUMP_BIT(parsetree)|DUMP_BIT(parsetree_with_comment))) {