Class: SourceRoute::TpResultChain

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/source_route/tp_result_chain.rb

Instance Method Summary collapse

Constructor Details

#initializeTpResultChain

Returns a new instance of TpResultChain.



9
10
11
# File 'lib/source_route/tp_result_chain.rb', line 9

def initialize
  @chain = []
end

Instance Method Details

#call_chainObject



13
14
15
# File 'lib/source_route/tp_result_chain.rb', line 13

def call_chain
  select { |tpr| tpr[:event] == :call }
end

#import_return_value_to_call_chainObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/source_route/tp_result_chain.rb', line 21

def import_return_value_to_call_chain
  call_chain.each do |ctp|
    matched_return_tp = return_chain.detect do |rtp|
      rtp[:tp_self] == ctp[:tp_self] and rtp[:method_id] == ctp[:method_id] and rtp[:defined_class] == ctp[:defined_class]
    end
    ctp[:return_value] = matched_return_tp[:return_value]
    ctp[:local_var] = matched_return_tp[:local_var] if matched_return_tp.key? :local_var
    ctp[:instance_var] = matched_return_tp[:instance_var] if matched_return_tp.key? :instance_var
  end
end

#parent_length_listObject



50
51
52
# File 'lib/source_route/tp_result_chain.rb', line 50

def parent_length_list
  call_chain.map { |tp| tp[:parent_length] }.uniq.sort
end

#return_chainObject



17
18
19
# File 'lib/source_route/tp_result_chain.rb', line 17

def return_chain
  select { |tpr| tpr[:event] == :return }
end

#treeize_call_chainObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/source_route/tp_result_chain.rb', line 32

def treeize_call_chain
  init_order_id_and_parent_ids
  call_chain.each do |tpr|
    return_tpr = return_chain.find do |rtpr|
      rtpr[:defined_class] == tpr[:defined_class] and rtpr[:method_id] == tpr[:method_id]
    end

    start_index, end_index = tpr[:order_id], return_tpr[:order_id]
    unless end_index == start_index + 1
      values_at(start_index+1 ... end_index).select { |tpr| tpr[:event] == :call }.each do |tpr|
        tpr[:parent_ids].push start_index
      end
    end
  end

  cal_parent_length
end