Class: SystemRDL::Evaluator::InstanceRef

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/systemrdl/evaluator/reference.rb

Instance Attribute Summary collapse

Attributes included from Common

#component, #parent, #token_range

Instance Method Summary collapse

Methods included from Common

#connect

Constructor Details

#initialize(elements, token_range) ⇒ InstanceRef

Returns a new instance of InstanceRef.



65
66
67
68
# File 'lib/systemrdl/evaluator/reference.rb', line 65

def initialize(elements, token_range)
  super(token_range)
  @elements = elements
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



70
71
72
# File 'lib/systemrdl/evaluator/reference.rb', line 70

def elements
  @elements
end

Instance Method Details

#array_select?Boolean

Returns:



87
88
89
# File 'lib/systemrdl/evaluator/reference.rb', line 87

def array_select?
  elements.any?(&:array_select?)
end

#evaluate(instance, **_optargs) ⇒ Object



72
73
74
# File 'lib/systemrdl/evaluator/reference.rb', line 72

def evaluate(instance, **_optargs)
  find(instance, allow_array_ref: false)[0].to_value(token_range)
end

#find(instance, allow_array_ref: false) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/systemrdl/evaluator/reference.rb', line 76

def find(instance, allow_array_ref: false)
  result = @elements.inject([instance]) do |instances, element|
    process_instance_ref_element(instances, element)
  end

  return result if allow_array_ref || result.size <= 1

  message = 'reference to array instance not allowed'
  raise_evaluation_error message, token_range
end