Class: Idl::Var

Inherits:
Object
  • Object
show all
Defined in:
lib/idl/symbol_table.rb

Overview

Objects to represent variables in the ISA def

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, value = nil, decode_var: false, template_index: nil, function_name: nil) ⇒ Var

Returns a new instance of Var.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/idl/symbol_table.rb', line 10

def initialize(name, type, value = nil, decode_var: false, template_index: nil, function_name: nil)
  @name = name
  raise ArgumentError, "Expecting a Type, got #{type.class.name}" unless type.is_a?(Type)

  @type = type
  @type.freeze
  @value = value
  raise 'unexpected' unless decode_var.is_a?(TrueClass) || decode_var.is_a?(FalseClass)

  @decode_var = decode_var
  @template_index = template_index
  @function_name = function_name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/idl/symbol_table.rb', line 8

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/idl/symbol_table.rb', line 8

def type
  @type
end

#valueObject

Returns the value of attribute value.



8
9
10
# File 'lib/idl/symbol_table.rb', line 8

def value
  @value
end

Instance Method Details

#cloneObject



32
33
34
35
36
37
38
39
# File 'lib/idl/symbol_table.rb', line 32

def clone
  Var.new(
    name,
    type.clone,
    value&.clone,
    decode_var: @decode_var
  )
end

#const?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/idl/symbol_table.rb', line 41

def const?
  @type.const?
end

#decode_var?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/idl/symbol_table.rb', line 45

def decode_var?
  @decode_var
end

#hashObject



24
25
26
# File 'lib/idl/symbol_table.rb', line 24

def hash
  [@name, @type, @value, @decode_var, @template_index, @function_name].hash
end

#template_indexInteger

Returns the template value position.

Returns:

  • (Integer)

    the template value position

Raises:

  • if Var is not a template value



57
58
59
60
61
# File 'lib/idl/symbol_table.rb', line 57

def template_index
  raise "Not a template value" if @template_index.nil?

  @template_index
end

#template_val?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/idl/symbol_table.rb', line 63

def template_val?
  !@template_index.nil?
end

#template_value_for?(function_name) ⇒ Boolean

Returns whether or not this variable is a function template argument from a call site for the function ‘function_name’.

Parameters:

  • function_name (#to_s)

    A function name

Returns:

  • (Boolean)

    whether or not this variable is a function template argument from a call site for the function ‘function_name’



51
52
53
# File 'lib/idl/symbol_table.rb', line 51

def template_value_for?(function_name)
  !@template_index.nil? && (function_name.to_s == @function_name)
end

#to_cxxObject



67
68
69
# File 'lib/idl/symbol_table.rb', line 67

def to_cxx
  @name
end

#to_sObject



28
29
30
# File 'lib/idl/symbol_table.rb', line 28

def to_s
  "VAR: #{type} #{name} #{value.nil? ? 'NO VALUE' : value}"
end