2012-12-06 15:30:28 -05:00
|
|
|
module Mutant
|
|
|
|
class Mutator
|
|
|
|
class Node
|
2013-01-04 16:16:03 -05:00
|
|
|
|
|
|
|
# Namespace for send mutators
|
2012-12-06 15:30:28 -05:00
|
|
|
class Send < self
|
|
|
|
|
|
|
|
handle(Rubinius::AST::Send)
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2012-12-10 11:11:08 -05:00
|
|
|
# Emit mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def dispatch
|
2013-04-17 23:31:21 -04:00
|
|
|
emit_receiver
|
2012-12-10 11:11:08 -05:00
|
|
|
emit_implicit_self_receiver
|
2012-12-29 10:00:27 -05:00
|
|
|
emit_receiver_mutations
|
|
|
|
emit_block_mutations
|
2012-12-10 11:11:08 -05:00
|
|
|
emit_block_absence_mutation
|
|
|
|
end
|
|
|
|
|
2013-04-17 23:31:21 -04:00
|
|
|
# Emit receiver
|
2012-12-29 10:00:27 -05:00
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
2012-12-29 14:12:48 -05:00
|
|
|
# @api private
|
2012-12-29 10:00:27 -05:00
|
|
|
#
|
|
|
|
def emit_receiver
|
2012-12-29 16:51:42 -05:00
|
|
|
unless to_self?
|
2012-12-29 10:00:27 -05:00
|
|
|
emit(receiver)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Emit block mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def emit_block_mutations
|
2013-01-04 16:16:03 -05:00
|
|
|
emit_attribute_mutations(:block) if node.block
|
2012-12-29 10:00:27 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Emit receiver mutations
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def emit_receiver_mutations
|
2013-04-17 23:31:21 -04:00
|
|
|
emit_attribute_mutations(:receiver)
|
2012-12-29 10:00:27 -05:00
|
|
|
end
|
|
|
|
|
2012-12-10 11:11:08 -05:00
|
|
|
# Emit block absence mutation
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def emit_block_absence_mutation
|
|
|
|
dup = dup_node
|
|
|
|
dup.block = nil
|
|
|
|
emit(dup)
|
|
|
|
end
|
|
|
|
|
2012-12-06 15:30:28 -05:00
|
|
|
# Return receiver AST node
|
|
|
|
#
|
|
|
|
# @return [Rubinius::AST::Node]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def receiver
|
|
|
|
node.receiver
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return name of call
|
|
|
|
#
|
|
|
|
# @return [Symbol]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def name
|
|
|
|
node.name
|
|
|
|
end
|
|
|
|
|
|
|
|
# Check if receiver is self
|
|
|
|
#
|
|
|
|
# @return [true]
|
2012-12-29 16:51:42 -05:00
|
|
|
# if receiver is a Rubinius::AST::Self node
|
2012-12-06 15:30:28 -05:00
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# return false otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2012-12-29 16:51:42 -05:00
|
|
|
def to_self?
|
2012-12-06 15:30:28 -05:00
|
|
|
receiver.kind_of?(Rubinius::AST::Self)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Emit mutation that replaces explicit send to self with implicit send to self
|
2013-04-17 23:31:21 -04:00
|
|
|
#
|
2012-12-06 15:30:28 -05:00
|
|
|
# @example:
|
|
|
|
#
|
|
|
|
# # This class does use Foo#a with explicitly specifing the receiver self.
|
2013-04-17 23:31:21 -04:00
|
|
|
# # But an implicit (privately) call should be used as there is no need for
|
2012-12-06 15:30:28 -05:00
|
|
|
# # specifing en explicit receiver.
|
|
|
|
#
|
|
|
|
# class Foo # Mutation
|
|
|
|
# def print_a # def print_a
|
|
|
|
# puts self.a # puts a
|
|
|
|
# end # end
|
|
|
|
#
|
|
|
|
# def a
|
|
|
|
# :bar
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# There will not be any exception so the mutant is not killed and such calls where
|
|
|
|
# implicit receiver should be used will be spotted.
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def emit_implicit_self_receiver
|
2013-01-09 14:43:06 -05:00
|
|
|
unless to_self? and !Mutant::KEYWORDS.include?(node.name)
|
2013-01-04 16:16:03 -05:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-12-06 15:30:28 -05:00
|
|
|
mutant = dup_node
|
|
|
|
mutant.privately = true
|
|
|
|
emit(mutant)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|