Class: Idl::BitsCastAst
- Includes:
- Rvalue
- Defined in:
- lib/idl/ast.rb
Overview
Node for a cast to a Bits<N> type
This will result in a BitsCaseAst:
$bits(ExceptionCode::LoadAccessFault)
Instance Method Summary collapse
-
#expression ⇒ AstNode
The casted expression.
-
#initialize(input, interval, exp) ⇒ BitsCastAst
constructor
A new instance of BitsCastAst.
-
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree).
-
#type(symtab) ⇒ Type
Given a specific symbol table, return the type of this node.
-
#type_check(symtab) ⇒ void
type check this node and all children.
-
#value(symtab) ⇒ Object
Return the compile-time-known value of the node.
-
#values(symtab) ⇒ Array<Integer>, ...
included
from Rvalue
Return a complete list of possible compile-time-known values of the node, or raise a ValueError if the full list cannot be determined.
Constructor Details
#initialize(input, interval, exp) ⇒ BitsCastAst
Returns a new instance of BitsCastAst.
2569 |
# File 'lib/idl/ast.rb', line 2569 def initialize(input, interval, exp) = super(input, interval, [exp]) |
Instance Method Details
#expression ⇒ AstNode
Returns The casted expression.
2567 |
# File 'lib/idl/ast.rb', line 2567 def expression = @children[0] |
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree)
2621 |
# File 'lib/idl/ast.rb', line 2621 def to_idl = "$signed(#{expression.to_idl})" |
#type(symtab) ⇒ Type
Given a specific symbol table, return the type of this node.
Should not be called until #type_check is called with the same arguments
2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 |
# File 'lib/idl/ast.rb', line 2581 def type(symtab) etype = expression.type(symtab) case etype.kind when :bits etype when :enum_ref Type.new(:bits, width: etype.enum_class.width) when :csr if etype.csr.dynamic_length?(symtab.archdef) Type.new(:bits, width: :unknown) else Type.new(:bits, width: etype.csr.length(symtab.archdef)) end end end |
#type_check(symtab) ⇒ void
2572 2573 2574 2575 2576 2577 2578 |
# File 'lib/idl/ast.rb', line 2572 def type_check(symtab) expression.type_check(symtab) unless [:bits, :enum_ref, :csr].include?(expression.type(symtab).kind) type_error "#{expression.type(symtab)} Cannot be cast to bits" end end |
#value(symtab) ⇒ Object
Return the compile-time-known value of the node
2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 |
# File 'lib/idl/ast.rb', line 2599 def value(symtab) etype = expression.type(symtab) case etype.kind when :bits expression.value(symtab) when :enum_ref if expression.is_a?(EnumRefAst) element_name = expression.text_value.split(":")[2] etype.enum_class.value(element_name) else # this is an expression with an EnumRef type expression.value(symtab) end when :csr expression.value(symtab) else internal_error "TODO: Bits cast for #{etype.kind}" end end |
#values(symtab) ⇒ Array<Integer>, ... Originally defined in module Rvalue
Return a complete list of possible compile-time-known values of the node, or raise a ValueError if the full list cannot be determined
For most AstNodes, this will just be a single-entry array