class Covered::Source

The source map, loads the source file, parses the AST to generate which lines contain executable code.

def disable

def disable
	Eval::disable(self)
	
	super
end

def each(&block)

def each(&block)
	@output.each do |coverage|
		if top = parse(coverage.path)
			self.expand(top, coverage)
		end
		
		yield coverage.freeze
	end
end

def enable

def enable
	super
	
	Eval::enable(self)
end

def executable?(node)

def executable?(node)
	node.type == :send
end

def expand(node, coverage, level = 0)

def expand(node, coverage, level = 0)
	if node.is_a? Parser::AST::Node
		if ignore?(node)
			coverage.annotate(node.location.line, "ignoring #{node.type}")
		else
			if executable?(node)
				# coverage.annotate(node.first_lineno, "executable #{node.type}")
				coverage.counts[node.location.line] ||= 0
			else
				# coverage.annotate(node.first_lineno, "not executable #{node.type}")
			end
			
			expand(node.children, coverage, level + 1)
		end
	elsif node.is_a? Array
		node.each do |child|
			expand(child, coverage, level)
		end
	else
		return false
	end
end

def ignore?(node)

def ignore?(node)
	node.nil? or node.type == :arg
end

def initialize(output)

def initialize(output)
	super(output)
	
	@paths = {}
	@mutex = Mutex.new
	
	@annotations = {}
end

def intercept_eval(string, binding = nil, filename = nil, lineno = 1)

def intercept_eval(string, binding = nil, filename = nil, lineno = 1)
	return unless filename
	
	@mutex.synchronize do
		@paths[filename] = string
	end
end

def parse(path)

def parse(path)
	if source = @paths[path]
		Parser::CurrentRuby.parse(source)
	elsif File.exist?(path)
		Parser::CurrentRuby.parse_file(path)
	else
		warn "Couldn't parse #{path}, file doesn't exist?"
	end
rescue
	warn "Couldn't parse #{path}: #{$!}"
end