class Roby::EventConstraints::Explanation

An explanation for a given predicate value. predicate is the predicate, elements the explanations for predicate having reached the value.

elements is an array of Event and EventGenerator instances.

If an Event is stored there, the explanation is that this event has been emitted.

If an EventGenerator is stored there, the reason depends on value. If value is nil (static), the reason is that the generator is unreachable. If value is false (not emitted), it is that the generator did not emit.

Attributes

elements[R]

The elements of explanation

predicate[R]

The predicate that we are providing an explanation for

value[RW]

Representation of what is being explained. It is true if it is explaining why a predicate is true, false if it is explaining why it is false and nil for static.

Public Class Methods

new(value, predicate, elements) click to toggle source
# File lib/roby/event_constraints.rb, line 296
def initialize(value, predicate, elements)
    @value, @predicate, @elements = value, predicate, elements
end

Public Instance Methods

pretty_print(pp) click to toggle source
# File lib/roby/event_constraints.rb, line 319
def pretty_print(pp)
    if value == false
        predicate.pretty_print(pp)
        pp.text " is false"
    elsif value == true
        predicate.pretty_print(pp)
        pp.text " is true"
    elsif value == nil
        pp.text "the value of "
        predicate.pretty_print(pp)
        pp.text " will not change anymore"
    end

    pp.nest(2) do
        elements.each do |explanation|
            pp.breakable
            case explanation
            when Event
                pp.text "the following event has been emitted "
            when EventGenerator
                if value == nil
                    pp.text "the following event is unreachable "
                elsif value == true
                    pp.text "the following event is reachable, but has not been emitted "
                else
                    pp.text "the following event has been emitted "
                end
            end

            explanation.pretty_print(pp)
            case explanation
            when Event
                sources = explanation.all_sources
                if !sources.empty?
                    pp.breakable
                    pp.text "The emission was caused by the following events"
                    sources.each do |ev|
                        pp.breakable
                        pp.text "< "
                        ev.pretty_print(pp, false)
                    end
                end

            when EventGenerator
                if value == nil && explanation.unreachability_reason
                    pp.breakable
                    pp.text "The unreachability was caused by "
                    pp.nest(2) do
                        pp.breakable
                        explanation.unreachability_reason.pretty_print(pp)
                    end
                end
            else
                explanation.pretty_print(pp)
            end
            pp.breakable
        end
    end
end
report_exceptions_on(e) click to toggle source
# File lib/roby/event_constraints.rb, line 300
def report_exceptions_on(e)
    elements.each do |el|
        case el
        when Explanation
            el.report_exceptions_on(e)
        when Exception
            e.report_exceptions_from(el)
        when Event
            el.all_sources.each do |ev|
                e.report_exceptions_from(ev)
            end
        when EventGenerator
            if value == nil
                e.report_exceptions_from(el.unreachability_reason)
            end
        end
    end
end
simple?() click to toggle source
# File lib/roby/event_constraints.rb, line 292
def simple?
    elements.size == 1 && !elements.first.kind_of?(Explanation)
end