@@ -171,6 +171,11 @@ def index_file(filepath)
171
171
172
172
private
173
173
174
+ def location_for ( iseq )
175
+ code_location = iseq [ 4 ] [ :code_location ]
176
+ Location . new ( code_location [ 0 ] , code_location [ 1 ] )
177
+ end
178
+
174
179
def index_iseq ( iseq , file_comments )
175
180
results = [ ]
176
181
queue = [ [ iseq , [ ] ] ]
@@ -192,19 +197,15 @@ def index_iseq(iseq, file_comments)
192
197
"singleton class with non-self receiver"
193
198
end
194
199
elsif flags & VM_DEFINECLASS_TYPE_MODULE > 0
195
- code_location = class_iseq [ 4 ] [ :code_location ]
196
- location = Location . new ( code_location [ 0 ] , code_location [ 1 ] )
197
-
200
+ location = location_for ( class_iseq )
198
201
results << ModuleDefinition . new (
199
202
current_nesting ,
200
203
name ,
201
204
location ,
202
205
EntryComments . new ( file_comments , location )
203
206
)
204
207
else
205
- code_location = class_iseq [ 4 ] [ :code_location ]
206
- location = Location . new ( code_location [ 0 ] , code_location [ 1 ] )
207
-
208
+ location = location_for ( class_iseq )
208
209
results << ClassDefinition . new (
209
210
current_nesting ,
210
211
name ,
@@ -215,25 +216,23 @@ def index_iseq(iseq, file_comments)
215
216
216
217
queue << [ class_iseq , current_nesting + [ name ] ]
217
218
when :definemethod
218
- _ , name , method_iseq = insn
219
-
220
- code_location = method_iseq [ 4 ] [ :code_location ]
221
- location = Location . new ( code_location [ 0 ] , code_location [ 1 ] )
222
- results << SingletonMethodDefinition . new (
219
+ location = location_for ( insn [ 2 ] )
220
+ results << MethodDefinition . new (
223
221
current_nesting ,
224
- name ,
222
+ insn [ 1 ] ,
225
223
location ,
226
224
EntryComments . new ( file_comments , location )
227
225
)
228
226
when :definesmethod
229
- _ , name , method_iseq = insn
230
-
231
- code_location = method_iseq [ 4 ] [ :code_location ]
232
- location = Location . new ( code_location [ 0 ] , code_location [ 1 ] )
227
+ if current_iseq [ 13 ] [ index - 1 ] != [ :putself ]
228
+ raise NotImplementedError ,
229
+ "singleton method with non-self receiver"
230
+ end
233
231
234
- results << MethodDefinition . new (
232
+ location = location_for ( insn [ 2 ] )
233
+ results << SingletonMethodDefinition . new (
235
234
current_nesting ,
236
- name ,
235
+ insn [ 1 ] ,
237
236
location ,
238
237
EntryComments . new ( file_comments , location )
239
238
)
@@ -363,13 +362,13 @@ def index_file(filepath)
363
362
defined? ( RubyVM ::InstructionSequence ) ? ISeqBackend : ParserBackend
364
363
365
364
# This method accepts source code and then indexes it.
366
- def self . index ( source )
367
- INDEX_BACKEND . new . index ( source )
365
+ def self . index ( source , backend : INDEX_BACKEND . new )
366
+ backend . index ( source )
368
367
end
369
368
370
369
# This method accepts a filepath and then indexes it.
371
- def self . index_file ( filepath )
372
- INDEX_BACKEND . new . index_file ( filepath )
370
+ def self . index_file ( filepath , backend : INDEX_BACKEND . new )
371
+ backend . index_file ( filepath )
373
372
end
374
373
end
375
374
end
0 commit comments