Sha256: 6babe5ec671a4e49dd8d51907b06fff1ce6d937c89543de29893452cbfd42374

Contents?: true

Size: 920 Bytes

Versions: 4

Compression:

Stored size: 920 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
            'right-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

4 entries across 4 versions & 2 rubygems

Version Path
deep-cover-core-0.6.4 lib/deep_cover/node/short_circuit.rb
deep-cover-core-0.6.3 lib/deep_cover/node/short_circuit.rb
deep-cover-core-0.6.3.pre lib/deep_cover/node/short_circuit.rb
deep-cover-0.6.2 lib/deep_cover/node/short_circuit.rb