Class: Idl::ArraySizeAst
Instance Method Summary collapse
-
#expression ⇒ AstNode
Array expression.
-
#initialize(input, interval, expression) ⇒ ArraySizeAst
constructor
A new instance of ArraySizeAst.
- #to_idl ⇒ Object
- #type(symtab) ⇒ Object
- #type_check(symtab) ⇒ Object
- #value(symtab) ⇒ Object
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
#expression ⇒ AstNode
Returns Array expression.
782 |
# File 'lib/idl/ast.rb', line 782 def expression = children[0] |
#to_idl ⇒ Object
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 |