Class: Idl::SignCastAst

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

Instance Method Summary collapse

Constructor Details

#initialize(input, interval, exp) ⇒ SignCastAst

Returns a new instance of SignCastAst.



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

def initialize(input, interval, exp) = super(input, interval, [exp])

Instance Method Details

#expressionObject



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

def expression = @children[0]

#to_idlString

Return valid IDL representation of the node (and its subtree)

Returns:

  • (String)

    IDL code for the node



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

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

Parameters:

Returns:

  • (Type)

    The type of the node

Raises:



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

def type(symtab) = expression.type(symtab).clone.make_signed

#type_check(symtab) ⇒ void

This method returns an undefined value.

type check this node and all children

Calls to #type and/or #value may depend on type_check being called first with the same symtab. If not, those functions may raise an AstNode::InternalError

Parameters:

Raises:



2527
2528
2529
# File 'lib/idl/ast.rb', line 2527

def type_check(symtab)
  expression.type_check(symtab)
end

#value(symtab) ⇒ Object

Return the compile-time-known value of the node



2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
# File 'lib/idl/ast.rb', line 2535

def value(symtab)
  t = expression.type(symtab)
  internal_error "Expecting a bits type" unless t.kind == :bits
  v = expression.value(symtab)

  if ((v >> (t.width - 1)) & 1) == 1
    # twos compliment negate the value
    -(2**t.width - v)
  else
    v
  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

Parameters:

  • symtab (SymbolTable)

    The context for the evaulation

Returns:

  • (Array<Integer>)

    The complete list of compile-time-known values, when they are integral

  • (Array<Boolean>)

    The complete list of compile-time-known values, when they are booleans

  • (AstNode::ValueError)

    if the list of values is not knowable at compile time