Class: Idl::ArraySizeAst

Inherits:
AstNode show all
Defined in:
lib/idl/ast.rb

Instance Method Summary collapse

Constructor Details

#initialize(input, interval, expression) ⇒ ArraySizeAst

Returns a new instance of ArraySizeAst.



786
787
788
# File 'lib/idl/ast.rb', line 786

def initialize(input, interval, expression)
  super(input, interval, [expression])
end

Instance Method Details

#expressionAstNode

Returns Array expression.

Returns:



784
# File 'lib/idl/ast.rb', line 784

def expression = children[0]

#to_idlObject



813
# File 'lib/idl/ast.rb', line 813

def to_idl = "$array_size(#{expression.to_idl})"

#type(symtab) ⇒ Object



801
802
803
804
805
806
807
# File 'lib/idl/ast.rb', line 801

def type(symtab)
  if expression.type(symtab).width == :unknown
    Type.new(:bits, width: :unknown, qualifiers: [:const])
  else
    Type.new(:bits, width: expression.type(symtab).width.bit_length, qualifiers: [:const])
  end
end

#type_check(symtab) ⇒ Object



790
791
792
793
794
795
796
797
798
799
# File 'lib/idl/ast.rb', line 790

def type_check(symtab)
  expression.type_check(symtab)
  expression_type = expression.type(symtab)
  type_error "#{expression.text_value} is not an array" unless expression_type.kind == :array
  type_error "#{expression.text_value} must be a constant" unless expression_type.const?

  if symtab.cfg_arch.fully_configured? && (expression_type.width == :unknown)
    type_error "#{expression.text_value} must have a known value at compile time"
  end
end

#value(symtab) ⇒ Object



809
810
811
# File 'lib/idl/ast.rb', line 809

def value(symtab)
  expression.type(symtab).width
end