Sha256: 2f1c24560d8306dd09ad23754406a88019c7c1b84e5e0b0f19e95836358ef96e

Contents?: true

Size: 919 Bytes

Versions: 7

Compression:

Stored size: 919 Bytes

Contents

# frozen_string_literal: true

require_relative 'branch'

module DeepCover
  class Node
    class ShortCircuit < Node
      include Branch
      has_tracker :conditional
      has_child lhs: Node
      has_child conditional: Node, flow_entry_count: :conditional_tracker_hits,
                rewrite: '(%{conditional_tracker};%{node})'

      def branches
        [
          conditional,
          TrivialBranch.new(condition: lhs, other_branch: conditional),
        ]
      end

      def branches_summary(of_branches = branches)
        of_branches.map do |jump|
          if jump == conditional
            'left-hand side'
          else
            "#{type == :and ? 'falsy' : 'truthy'} shortcut"
          end
        end.join(' and ')
      end

      def operator
        loc_hash[:operator].source.to_sym
      end
    end

    class And < ShortCircuit
    end

    class Or < ShortCircuit
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
deep-cover-0.6.1 lib/deep_cover/node/short_circuit.rb
deep-cover-0.6.0 lib/deep_cover/node/short_circuit.rb
deep-cover-0.5.7 lib/deep_cover/node/short_circuit.rb
deep-cover-0.5.6 lib/deep_cover/node/short_circuit.rb
deep-cover-0.5.5 lib/deep_cover/node/short_circuit.rb
deep-cover-0.5.4 lib/deep_cover/node/short_circuit.rb
deep-cover-0.5.3 lib/deep_cover/node/short_circuit.rb