summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-02-01 15:16:15 -0500
committerKevin Newton <kddnewton@gmail.com>2024-02-01 15:52:19 -0500
commit332d2c92d8fd7827690e9be8ab76e4f999713b51 (patch)
tree0131c015a5b8a6e634bdc85c2847743e49ea6ed2
parentb47d43fa9bd48d14f871f71c2dfa18e241f0f051 (diff)
[PRISM] Emit parse warnings
-rw-r--r--prism/parser.h2
-rw-r--r--prism/prism.c8
-rw-r--r--prism_compile.c15
3 files changed, 19 insertions, 6 deletions
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.