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.



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

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

Instance Method Details

#expressionAstNode

Returns Array expression.

Returns:



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

def expression = children[0]

#to_idlObject



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

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

#type(symtab) ⇒ Object



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

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



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

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.archdef.fully_configured? && (expression_type.width == :unknown)
    type_error "#{expression.text_value} must have a known value at compile time"
  end
end

#value(symtab) ⇒ Object



807
808
809
# File 'lib/idl/ast.rb', line 807

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