diff --git a/prism/parser.h b/prism/parser.h index 9a7ff53cd1..0aa2c2f917 100644 --- a/prism/parser.h +++ b/prism/parser.h @@ -626,7 +626,7 @@ struct pm_parser { * This is the path of the file being parsed. We use the filepath when * constructing SourceFileNodes. */ - pm_string_t filepath_string; + pm_string_t filepath; /** * This constant pool keeps all of the constants defined throughout the file diff --git a/prism/prism.c b/prism/prism.c index 43aafeb8dd..87fc43105d 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -5430,7 +5430,7 @@ pm_source_file_node_create(pm_parser_t *parser, const pm_token_t *file_keyword) .flags = PM_NODE_FLAG_STATIC_LITERAL, .location = PM_LOCATION_TOKEN_VALUE(file_keyword), }, - .filepath = parser->filepath_string, + .filepath = parser->filepath, }; return node; @@ -17752,7 +17752,7 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm .encoding_changed_callback = NULL, .encoding_comment_start = source, .lex_callback = NULL, - .filepath_string = { 0 }, + .filepath = { 0 }, .constant_pool = { 0 }, .newline_list = { 0 }, .integer_base = 0, @@ -17795,7 +17795,7 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm // If options were provided to this parse, establish them here. if (options != NULL) { // filepath option - parser->filepath_string = options->filepath; + parser->filepath = options->filepath; // line option parser->start_line = options->line; @@ -17897,7 +17897,7 @@ pm_magic_comment_list_free(pm_list_t *list) { */ PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser) { - pm_string_free(&parser->filepath_string); + pm_string_free(&parser->filepath); pm_diagnostic_list_free(&parser->error_list); pm_diagnostic_list_free(&parser->warning_list); pm_comment_list_free(&parser->comment_list); diff --git a/prism_compile.c b/prism_compile.c index a54f2a71a9..ae56b99519 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -7620,7 +7620,20 @@ pm_parse_input(pm_parse_result_t *result, VALUE filepath) return error; } - // TODO: we should be emitting warnings here as well. + // Emit all of the various warnings from the parse. + const pm_diagnostic_t *warning; + const char *warning_filepath = (const char *) pm_string_source(&result->parser.filepath); + + for (warning = (pm_diagnostic_t *) result->parser.warning_list.head; warning != NULL; warning = (pm_diagnostic_t *) warning->node.next) { + int line = (int) pm_newline_list_line_column(&result->parser.newline_list, warning->location.start).line; + + if (warning->level == PM_WARNING_LEVEL_VERBOSE) { + rb_compile_warning(warning_filepath, line, "%s", warning->message); + } + else { + rb_compile_warn(warning_filepath, line, "%s", warning->message); + } + } // Now set up the constant pool and intern all of the various constants into // their corresponding IDs.