Class: Idl::Var
- Inherits:
-
Object
- Object
- Idl::Var
- Defined in:
- lib/idl/symbol_table.rb
Overview
Objects to represent variables in the ISA def
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #clone ⇒ Object
- #const? ⇒ Boolean
- #decode_var? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name, type, value = nil, decode_var: false, template_index: nil, function_name: nil) ⇒ Var
constructor
A new instance of Var.
-
#template_index ⇒ Integer
The template value position.
- #template_val? ⇒ Boolean
-
#template_value_for?(function_name) ⇒ Boolean
Whether or not this variable is a function template argument from a call site for the function ‘function_name’.
- #to_cxx ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, type, value = nil, decode_var: false, template_index: nil, function_name: nil) ⇒ Var
Returns a new instance of Var.
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/idl/symbol_table.rb', line 8 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/idl/symbol_table.rb', line 8 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
8 9 10 |
# File 'lib/idl/symbol_table.rb', line 8 def value @value end |
Instance Method Details
#clone ⇒ Object
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
41 42 43 |
# File 'lib/idl/symbol_table.rb', line 41 def const? @type.const? end |
#decode_var? ⇒ Boolean
45 46 47 |
# File 'lib/idl/symbol_table.rb', line 45 def decode_var? @decode_var end |
#hash ⇒ Object
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_index ⇒ Integer
Returns the template value position.
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
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’.
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_cxx ⇒ Object
67 68 69 |
# File 'lib/idl/symbol_table.rb', line 67 def to_cxx @name end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/idl/symbol_table.rb', line 28 def to_s "VAR: #{type} #{name} #{value.nil? ? 'NO VALUE' : value}" end |