@@ -171,6 +171,11 @@ def index_file(filepath)
171171
172172 private
173173
174+ def location_for ( iseq )
175+ code_location = iseq [ 4 ] [ :code_location ]
176+ Location . new ( code_location [ 0 ] , code_location [ 1 ] )
177+ end
178+
174179 def index_iseq ( iseq , file_comments )
175180 results = [ ]
176181 queue = [ [ iseq , [ ] ] ]
@@ -192,19 +197,15 @@ def index_iseq(iseq, file_comments)
192197 "singleton class with non-self receiver"
193198 end
194199 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 )
198201 results << ModuleDefinition . new (
199202 current_nesting ,
200203 name ,
201204 location ,
202205 EntryComments . new ( file_comments , location )
203206 )
204207 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 )
208209 results << ClassDefinition . new (
209210 current_nesting ,
210211 name ,
@@ -215,25 +216,23 @@ def index_iseq(iseq, file_comments)
215216
216217 queue << [ class_iseq , current_nesting + [ name ] ]
217218 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 (
223221 current_nesting ,
224- name ,
222+ insn [ 1 ] ,
225223 location ,
226224 EntryComments . new ( file_comments , location )
227225 )
228226 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
233231
234- results << MethodDefinition . new (
232+ location = location_for ( insn [ 2 ] )
233+ results << SingletonMethodDefinition . new (
235234 current_nesting ,
236- name ,
235+ insn [ 1 ] ,
237236 location ,
238237 EntryComments . new ( file_comments , location )
239238 )
@@ -363,13 +362,13 @@ def index_file(filepath)
363362 defined? ( RubyVM ::InstructionSequence ) ? ISeqBackend : ParserBackend
364363
365364 # 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 )
368367 end
369368
370369 # 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 )
373372 end
374373 end
375374end
0 commit comments