class Antlr4::Runtime::ArrayPredictionContext

Attributes

parents[RW]
return_states[RW]

Public Class Methods

new(parents, return_states = nil) click to toggle source
Calls superclass method
# File lib/antlr4/runtime/array_prediction_context.rb, line 7
def initialize(parents, return_states = nil)
  if parents.is_a? SingletonPredictionContext
    return_states = [parents.return_state]
    parents = [parents.parent]
  end

  super(PredictionContextUtils.calculate_hash_code2(parents, return_states))
  @parents = parents
  @return_states = return_states
end

Public Instance Methods

empty?() click to toggle source
# File lib/antlr4/runtime/array_prediction_context.rb, line 18
def empty? # since EMPTY_RETURN_STATE can only appear in the last position, we
  # don't need to verify that size==1
  @return_states[0] == EMPTY_RETURN_STATE
end
equals(o) click to toggle source
# File lib/antlr4/runtime/array_prediction_context.rb, line 35
def equals(o)
  if self == o
    return true
  elsif !(o.is_a? ArrayPredictionContext)
    return false
  end

  if hash != o.hash
    return false # can't be same if hash is different
  end

  (@return_states.eql? o.return_states) && (@parents.eql? o.parents)
end
get_parent(index) click to toggle source
# File lib/antlr4/runtime/array_prediction_context.rb, line 27
def get_parent(index)
  @parents[index]
end
get_return_state(index) click to toggle source
# File lib/antlr4/runtime/array_prediction_context.rb, line 31
def get_return_state(index)
  @return_states[index]
end
size() click to toggle source
# File lib/antlr4/runtime/array_prediction_context.rb, line 23
def size
  @return_states.length
end
to_s() click to toggle source
# File lib/antlr4/runtime/array_prediction_context.rb, line 49
def to_s
  return '[]' if empty?

  buf = ''
  buf << '['
  i = 0
  while i < @return_states.length
    buf << ', ' if i > 0
    if return_states[i] == EMPTY_RETURN_STATE
      buf << '$'
      i += 1
      next
    end
    buf << @return_states[i]
    if !@parents[i].nil?
      buf << ' '
      buf << @parents[i].to_s
    else
      buf << 'nil'
    end
    i += 1
  end

  buf << ']'
  buf.to_s
end