Class: DeepCover::Node::Csend

Inherits:
DeepCover::Node show all
Extended by:
Forwardable
Includes:
Branch
Defined in:
lib/deep_cover/node/send.rb

Constant Summary collapse

REWRITE_SUFFIX =
'%{node};%{local};else;nil;end)'

Constants inherited from DeepCover::Node

CLASSES, Complex, Cvasgn, Dsym, Erange, Float, Int, Ivar, Kwarg, Kwoptarg, Kwrestarg, OrAsgn, Rational, Sym, True, Zsuper

Instance Attribute Summary

Attributes inherited from DeepCover::Node

#base_node, #children, #index, #next_sibling, #parent, #previous_sibling

Instance Method Summary collapse

Methods included from Branch

#flow_completion_count

Methods inherited from DeepCover::Node

#[], [], atom, #children_nodes, #covered_code, define_module_class, #each_node, #fancy_type, #find_all, has_evaluated_segments, inherited, #simple_literal?, #to_s, #type

Methods included from Memoize

#freeze, included

Constructor Details

#initialize(base_node, base_children: base_node.children) ⇒ Csend

rubocop:disable Naming/UncommunicativeMethodParamName [#5436]



117
118
119
120
121
# File 'lib/deep_cover/node/send.rb', line 117

def initialize(base_node, base_children: base_node.children, **) # rubocop:disable Naming/UncommunicativeMethodParamName [#5436]
  send_without_receiver = base_node.updated(:safe_send, [nil, *base_node.children.drop(1)])
  base_children = [base_children.first, send_without_receiver]
  super
end

Instance Method Details

#branchesObject



140
141
142
143
144
# File 'lib/deep_cover/node/send.rb', line 140

def branches
  [TrivialBranch.new(condition: receiver, other_branch: actual_send),
   actual_send,
  ]
end

#branches_summary(of_branches) ⇒ Object



146
147
148
149
150
# File 'lib/deep_cover/node/send.rb', line 146

def branches_summary(of_branches)
  of_branches.map do |jump|
    jump == actual_send ? 'safe send' : 'nil shortcut'
  end.join(' and ')
end

#execution_countObject



136
137
138
# File 'lib/deep_cover/node/send.rb', line 136

def execution_count
  receiver.flow_completion_count
end

#has_block?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/deep_cover/node/send.rb', line 128

def has_block?
  parent.is_a?(Block) && parent.child_index_to_name(index) == :call
end

#rewriteObject



132
133
134
# File 'lib/deep_cover/node/send.rb', line 132

def rewrite
  REWRITE_SUFFIX unless has_block?
end