Class: SystemRDL::Evaluator::PropRef

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(instance_ref, prop, token_range) ⇒ PropRef

Returns a new instance of PropRef.



101
102
103
104
105
# File 'lib/systemrdl/evaluator/reference.rb', line 101

def initialize(instance_ref, prop, token_range)
  super(token_range)
  @instance_ref = instance_ref
  @prop = prop
end

Instance Attribute Details

#instance_refObject (readonly)

Returns the value of attribute instance_ref.



107
108
109
# File 'lib/systemrdl/evaluator/reference.rb', line 107

def instance_ref
  @instance_ref
end

#propObject (readonly)

Returns the value of attribute prop.



108
109
110
# File 'lib/systemrdl/evaluator/reference.rb', line 108

def prop
  @prop
end

Instance Method Details

#array_select?Boolean

Returns:



130
131
132
# File 'lib/systemrdl/evaluator/reference.rb', line 130

def array_select?
  @instance_ref&.array_select? || false
end

#evaluate(instance, **_optargs) ⇒ Object



110
111
112
# File 'lib/systemrdl/evaluator/reference.rb', line 110

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

#find(instance, allow_array_ref: false) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/systemrdl/evaluator/reference.rb', line 114

def find(instance, allow_array_ref: false)
  insts =
    if @instance_ref
      @instance_ref.find(instance, allow_array_ref:)
    else
      [instance]
    end

  insts.map do |inst|
    prop = inst.property(@prop.value)
    next prop if prop

    raise_evaluation_error "undefined property: #{@prop.value}", token_range
  end
end