summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2024-05-24 11:22:29 -0400
committergit <[email protected]>2024-05-24 17:19:33 +0000
commit870350253e1df70f56d33107b9ed3b9ebaaccdec (patch)
tree1cf7fa7104f7c8274956cc0ed313a667c4c5e133
parent47b723f8906ba24af13292c43e389b716e24cf17 (diff)
[ruby/prism] Remove Debug::static_inspect
https://github.com/ruby/prism/commit/486c71c426
-rw-r--r--prism/extension.c35
-rw-r--r--prism/static_literals.c2
-rw-r--r--prism/static_literals.h2
-rw-r--r--prism/util/pm_char.h3
-rw-r--r--test/prism/static_inspect_test.rb5
5 files changed, 5 insertions, 42 deletions
diff --git a/prism/extension.c b/prism/extension.c
index 84872914c4..9375273ac5 100644
--- a/prism/extension.c
+++ b/prism/extension.c
@@ -1224,40 +1224,6 @@ format_errors(VALUE self, VALUE source, VALUE colorize) {
}
/**
- * call-seq:
- * Debug::static_inspect(source) -> String
- *
- * Inspect the node as it would be inspected by the warnings used in static
- * literal sets.
- */
-static VALUE
-static_inspect(int argc, VALUE *argv, VALUE self) {
- pm_string_t input;
- pm_options_t options = { 0 };
- string_options(argc, argv, &input, &options);
-
- pm_parser_t parser;
- pm_parser_init(&parser, pm_string_source(&input), pm_string_length(&input), &options);
-
- pm_node_t *program = pm_parse(&parser);
- pm_node_t *node = ((pm_program_node_t *) program)->statements->body.nodes[0];
-
- pm_buffer_t buffer = { 0 };
- pm_static_literal_inspect(&buffer, &parser.newline_list, parser.start_line, parser.encoding->name, node);
-
- rb_encoding *encoding = rb_enc_find(parser.encoding->name);
- VALUE result = rb_enc_str_new(pm_buffer_value(&buffer), pm_buffer_length(&buffer), encoding);
-
- pm_buffer_free(&buffer);
- pm_node_destroy(&parser, program);
- pm_parser_free(&parser);
- pm_string_free(&input);
- pm_options_free(&options);
-
- return result;
-}
-
-/**
* call-seq: Debug::Encoding.all -> Array[Debug::Encoding]
*
* Return an array of all of the encodings that prism knows about.
@@ -1414,7 +1380,6 @@ Init_prism(void) {
rb_define_singleton_method(rb_cPrismDebug, "memsize", memsize, 1);
rb_define_singleton_method(rb_cPrismDebug, "profile_file", profile_file, 1);
rb_define_singleton_method(rb_cPrismDebug, "format_errors", format_errors, 2);
- rb_define_singleton_method(rb_cPrismDebug, "static_inspect", static_inspect, -1);
#ifndef PRISM_EXCLUDE_PRETTYPRINT
rb_define_singleton_method(rb_cPrismDebug, "inspect_node", inspect_node, 1);
diff --git a/prism/static_literals.c b/prism/static_literals.c
index 3b0cb13bf5..b8604321c9 100644
--- a/prism/static_literals.c
+++ b/prism/static_literals.c
@@ -603,7 +603,7 @@ pm_static_literal_inspect_node(pm_buffer_t *buffer, const pm_static_literals_met
/**
* Create a string-based representation of the given static literal.
*/
-PRISM_EXPORTED_FUNCTION void
+void
pm_static_literal_inspect(pm_buffer_t *buffer, const pm_newline_list_t *newline_list, int32_t start_line, const char *encoding_name, const pm_node_t *node) {
pm_static_literal_inspect_node(
buffer,
diff --git a/prism/static_literals.h b/prism/static_literals.h
index 9ef10afce0..bd29761899 100644
--- a/prism/static_literals.h
+++ b/prism/static_literals.h
@@ -116,6 +116,6 @@ void pm_static_literals_free(pm_static_literals_t *literals);
* @param encoding_name The name of the encoding of the source being parsed.
* @param node The node to create a string representation of.
*/
-PRISM_EXPORTED_FUNCTION void pm_static_literal_inspect(pm_buffer_t *buffer, const pm_newline_list_t *newline_list, int32_t start_line, const char *encoding_name, const pm_node_t *node);
+void pm_static_literal_inspect(pm_buffer_t *buffer, const pm_newline_list_t *newline_list, int32_t start_line, const char *encoding_name, const pm_node_t *node);
#endif
diff --git a/prism/util/pm_char.h b/prism/util/pm_char.h
index 32f698a42b..deeafd6321 100644
--- a/prism/util/pm_char.h
+++ b/prism/util/pm_char.h
@@ -34,8 +34,7 @@ size_t pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length);
* @return The number of characters at the start of the string that are
* whitespace.
*/
-size_t
-pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_newline_list_t *newline_list);
+size_t pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_newline_list_t *newline_list);
/**
* Returns the number of characters at the start of the string that are inline
diff --git a/test/prism/static_inspect_test.rb b/test/prism/static_inspect_test.rb
index 8df2fd241e..cc8ed28c95 100644
--- a/test/prism/static_inspect_test.rb
+++ b/test/prism/static_inspect_test.rb
@@ -2,8 +2,6 @@
require_relative "test_helper"
-return if Prism::BACKEND == :FFI
-
module Prism
class StaticInspectTest < TestCase
def test_false
@@ -84,7 +82,8 @@ module Prism
private
def static_inspect(source, **options)
- Debug.static_inspect(source, **options)
+ warnings = Prism.parse("{ #{source} => 1, #{source} => 1 }", **options).warnings
+ warnings.last.message[/^key (.+) is duplicated and overwritten on line \d/, 1]
end
end
end