class SyntaxTree::Index::ISeqBackend
def find_constant_path(insns, index)
def find_constant_path(insns, index) index -= 1 while index >= 0 && ( insns[index].is_a?(Integer) || ( insns[index].is_a?(Array) && %i[swap topn].include?(insns[index][0]) ) ) insn = insns[index] if insn.is_a?(Array) && insn[0] == :opt_getconstant_path # In this case we're on Ruby 3.2+ and we have an opt_getconstant_path # instruction, so we already know all of the symbols in the nesting. [index - 1, insn[1]] elsif insn.is_a?(Symbol) && insn.match?(/\Alabel_\d+/) # Otherwise, if we have a label then this is very likely the # destination of an opt_getinlinecache instruction, in which case # we'll walk backwards to grab up all of the constants. names = [] index -= 1 until insns[index].is_a?(Array) && insns[index][0] == :opt_getinlinecache if insns[index].is_a?(Array) && insns[index][0] == :getconstant names.unshift(insns[index][1]) end index -= 1 end [index - 1, names] else [index, []] end end