Skip to content

Commit b850794

Browse files
committed
Remove dynamic Debug module methods
1 parent 53b2866 commit b850794

File tree

2 files changed

+2
-174
lines changed

2 files changed

+2
-174
lines changed

ext/prism/extension.c

Lines changed: 2 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ check_string(VALUE value) {
5252

5353
// Check if the value is a string. If it's not, then raise a type error.
5454
if (!RB_TYPE_P(value, T_STRING)) {
55-
rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE" (expected String)", rb_obj_class(value));
55+
rb_raise(rb_eTypeError, "wrong argument type %" PRIsVALUE " (expected String)", rb_obj_class(value));
5656
}
5757

5858
// Otherwise, return the value as a C string.
@@ -66,7 +66,7 @@ static void
6666
input_load_string(pm_string_t *input, VALUE string) {
6767
// Check if the string is a string. If it's not, then raise a type error.
6868
if (!RB_TYPE_P(string, T_STRING)) {
69-
rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE" (expected String)", rb_obj_class(string));
69+
rb_raise(rb_eTypeError, "wrong argument type %" PRIsVALUE " (expected String)", rb_obj_class(string));
7070
}
7171

7272
pm_string_constant_init(input, RSTRING_PTR(string), RSTRING_LEN(string));
@@ -1089,118 +1089,6 @@ parse_file_failure_p(int argc, VALUE *argv, VALUE self) {
10891089
return RTEST(parse_file_success_p(argc, argv, self)) ? Qfalse : Qtrue;
10901090
}
10911091

1092-
/******************************************************************************/
1093-
/* Utility functions exposed to make testing easier */
1094-
/******************************************************************************/
1095-
1096-
#ifndef PRISM_EXCLUDE_PRETTYPRINT
1097-
1098-
/**
1099-
* call-seq:
1100-
* Debug::inspect_node(source) -> inspected
1101-
*
1102-
* Inspect the AST that represents the given source using the prism pretty print
1103-
* as opposed to the Ruby implementation.
1104-
*/
1105-
static VALUE
1106-
inspect_node(VALUE self, VALUE source) {
1107-
pm_string_t input;
1108-
input_load_string(&input, source);
1109-
1110-
pm_parser_t parser;
1111-
pm_parser_init(&parser, pm_string_source(&input), pm_string_length(&input), NULL);
1112-
1113-
pm_node_t *node = pm_parse(&parser);
1114-
pm_buffer_t buffer = { 0 };
1115-
1116-
pm_prettyprint(&buffer, &parser, node);
1117-
1118-
rb_encoding *encoding = rb_enc_find(parser.encoding->name);
1119-
VALUE string = rb_enc_str_new(pm_buffer_value(&buffer), pm_buffer_length(&buffer), encoding);
1120-
1121-
pm_buffer_free(&buffer);
1122-
pm_node_destroy(&parser, node);
1123-
pm_parser_free(&parser);
1124-
1125-
return string;
1126-
}
1127-
1128-
#endif
1129-
1130-
/**
1131-
* call-seq: Debug::Encoding.all -> Array[Debug::Encoding]
1132-
*
1133-
* Return an array of all of the encodings that prism knows about.
1134-
*/
1135-
static VALUE
1136-
encoding_all(VALUE self) {
1137-
VALUE encodings = rb_ary_new();
1138-
1139-
for (size_t index = 0; index < PM_ENCODING_MAXIMUM; index++) {
1140-
const pm_encoding_t *encoding = &pm_encodings[index];
1141-
1142-
VALUE encoding_argv[] = { rb_str_new_cstr(encoding->name), encoding->multibyte ? Qtrue : Qfalse };
1143-
rb_ary_push(encodings, rb_class_new_instance(2, encoding_argv, rb_cPrismDebugEncoding));
1144-
}
1145-
1146-
return encodings;
1147-
}
1148-
1149-
static const pm_encoding_t *
1150-
encoding_find(VALUE name) {
1151-
const uint8_t *source = (const uint8_t *) RSTRING_PTR(name);
1152-
size_t length = RSTRING_LEN(name);
1153-
1154-
const pm_encoding_t *encoding = pm_encoding_find(source, source + length);
1155-
if (encoding == NULL) { rb_raise(rb_eArgError, "Unknown encoding: %s", source); }
1156-
1157-
return encoding;
1158-
}
1159-
1160-
/**
1161-
* call-seq: Debug::Encoding.width(source) -> Integer
1162-
*
1163-
* Returns the width of the first character in the given string if it is valid
1164-
* in the encoding. If it is not, this function returns 0.
1165-
*/
1166-
static VALUE
1167-
encoding_char_width(VALUE self, VALUE name, VALUE value) {
1168-
return ULONG2NUM(encoding_find(name)->char_width((const uint8_t *) RSTRING_PTR(value), RSTRING_LEN(value)));
1169-
}
1170-
1171-
/**
1172-
* call-seq: Debug::Encoding.alnum?(source) -> true | false
1173-
*
1174-
* Returns true if the first character in the given string is an alphanumeric
1175-
* character in the encoding.
1176-
*/
1177-
static VALUE
1178-
encoding_alnum_char(VALUE self, VALUE name, VALUE value) {
1179-
return encoding_find(name)->alnum_char((const uint8_t *) RSTRING_PTR(value), RSTRING_LEN(value)) > 0 ? Qtrue : Qfalse;
1180-
}
1181-
1182-
/**
1183-
* call-seq: Debug::Encoding.alpha?(source) -> true | false
1184-
*
1185-
* Returns true if the first character in the given string is an alphabetic
1186-
* character in the encoding.
1187-
*/
1188-
static VALUE
1189-
encoding_alpha_char(VALUE self, VALUE name, VALUE value) {
1190-
return encoding_find(name)->alpha_char((const uint8_t *) RSTRING_PTR(value), RSTRING_LEN(value)) > 0 ? Qtrue : Qfalse;
1191-
}
1192-
1193-
/**
1194-
* call-seq: Debug::Encoding.upper?(source) -> true | false
1195-
*
1196-
* Returns true if the first character in the given string is an uppercase
1197-
* character in the encoding.
1198-
*/
1199-
static VALUE
1200-
encoding_isupper_char(VALUE self, VALUE name, VALUE value) {
1201-
return encoding_find(name)->isupper_char((const uint8_t *) RSTRING_PTR(value), RSTRING_LEN(value)) ? Qtrue : Qfalse;
1202-
}
1203-
12041092
/******************************************************************************/
12051093
/* Initialization of the extension */
12061094
/******************************************************************************/
@@ -1276,23 +1164,6 @@ Init_prism(void) {
12761164
rb_define_singleton_method(rb_cPrism, "dump_file", dump_file, -1);
12771165
#endif
12781166

1279-
// Next, the functions that will be called by the parser to perform various
1280-
// internal tasks. We expose these to make them easier to test.
1281-
VALUE rb_cPrismDebug = rb_define_module_under(rb_cPrism, "Debug");
1282-
1283-
#ifndef PRISM_EXCLUDE_PRETTYPRINT
1284-
rb_define_singleton_method(rb_cPrismDebug, "inspect_node", inspect_node, 1);
1285-
#endif
1286-
1287-
// Next, define the functions that are exposed through the private
1288-
// Debug::Encoding class.
1289-
rb_cPrismDebugEncoding = rb_define_class_under(rb_cPrismDebug, "Encoding", rb_cObject);
1290-
rb_define_singleton_method(rb_cPrismDebugEncoding, "all", encoding_all, 0);
1291-
rb_define_singleton_method(rb_cPrismDebugEncoding, "_width", encoding_char_width, 2);
1292-
rb_define_singleton_method(rb_cPrismDebugEncoding, "_alnum?", encoding_alnum_char, 2);
1293-
rb_define_singleton_method(rb_cPrismDebugEncoding, "_alpha?", encoding_alpha_char, 2);
1294-
rb_define_singleton_method(rb_cPrismDebugEncoding, "_upper?", encoding_isupper_char, 2);
1295-
12961167
// Next, initialize the other APIs.
12971168
Init_prism_api_node();
12981169
Init_prism_pack();

lib/prism/debug.rb

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -202,48 +202,5 @@ def self.prism_locals(source)
202202
def self.newlines(source)
203203
Prism.parse(source).source.offsets
204204
end
205-
206-
# A wrapping around prism's internal encoding data structures. This is used
207-
# for reflection and debugging purposes.
208-
class Encoding
209-
# The name of the encoding, that can be passed to Encoding.find.
210-
attr_reader :name
211-
212-
# Initialize a new encoding with the given name and whether or not it is
213-
# a multibyte encoding.
214-
def initialize(name, multibyte)
215-
@name = name
216-
@multibyte = multibyte
217-
end
218-
219-
# Whether or not the encoding is a multibyte encoding.
220-
def multibyte?
221-
@multibyte
222-
end
223-
224-
# Returns the number of bytes of the first character in the source string,
225-
# if it is valid for the encoding. Otherwise, returns 0.
226-
def width(source)
227-
Encoding._width(name, source)
228-
end
229-
230-
# Returns true if the first character in the source string is a valid
231-
# alphanumeric character for the encoding.
232-
def alnum?(source)
233-
Encoding._alnum?(name, source)
234-
end
235-
236-
# Returns true if the first character in the source string is a valid
237-
# alphabetic character for the encoding.
238-
def alpha?(source)
239-
Encoding._alpha?(name, source)
240-
end
241-
242-
# Returns true if the first character in the source string is a valid
243-
# uppercase character for the encoding.
244-
def upper?(source)
245-
Encoding._upper?(name, source)
246-
end
247-
end
248205
end
249206
end

0 commit comments

Comments
 (0)