Sha256: c4bea9dcaa73cc220b91bec13298c96691a0f3a37adacffa8fbb6984c7429279

Contents?: true

Size: 1.62 KB

Versions: 4

Compression:

Stored size: 1.62 KB

Contents

require_relative 'send'
require_relative 'keywords'

module DeepCover
  class Node
    module WithBlock
      def flow_completion_count
        parent.flow_completion_count
      end

      def execution_count
        last = children_nodes.last
        return last.flow_completion_count if last
        super
      end
    end

    class SendWithBlock < Node
      include WithBlock
      has_child receiver: [Node, nil]
      has_child method_name: Symbol
      has_extra_children arguments: Node

      def rewriting_rules # TODO: test more with foo[42]. Factorize with Send.
        rules = super
        unless arguments.empty? || loc_hash[:begin]
          range = arguments.last.expression.with(begin_pos: loc_hash[:selector].end_pos)
          rules.unshift [range, '(%{node})']
        end
        rules
      end
    end

    class SuperWithBlock < Node
      include WithBlock
      has_extra_children arguments: Node
    end

    class Block < Node
      check_completion
      has_tracker :body
      has_child call: {send: SendWithBlock, zsuper: SuperWithBlock, super: SuperWithBlock}
      has_child args: Args
      has_child body: Node,
                can_be_empty: -> { base_node.loc.end.begin },
                rewrite: '%{body_tracker};%{local}=nil;%{node}',
                flow_entry_count: :body_tracker_hits,
                is_statement: true
      executed_loc_keys # none

      def children_nodes_in_flow_order
        [call, args] # Similarly to a def, the body is actually not part of the flow of this node...
      end
    end

    # &foo
    class BlockPass < Node
      has_child block: Node
      # TODO
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
deep-cover-0.1.12 lib/deep_cover/node/block.rb
deep-cover-0.1.11 lib/deep_cover/node/block.rb
deep-cover-0.1.10 lib/deep_cover/node/block.rb
deep-cover-0.1.9 lib/deep_cover/node/block.rb