Class: Idl::IdAst

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

Overview

an identifier

Used for variables

Instance Method Summary collapse

Constructor Details

#initialize(input, interval) ⇒ IdAst

Returns a new instance of IdAst.



554
555
556
557
558
# File 'lib/idl/ast.rb', line 554

def initialize(input, interval)
  super(input, interval, EMPTY_ARRAY)
  @const = (text_value[0] == text_value[0].upcase)
  @vars = {}
end

Instance Method Details

#const?Boolean

Returns whether or not the Id represents a const.

Returns:

  • (Boolean)

    whether or not the Id represents a const



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

def const? = @const

#nameString

Returns The ID name.

Returns:

  • (String)

    The ID name



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

def name = text_value

#to_idlString

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

Returns:

  • (String)

    IDL code for the node



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

def to_idl = name

#type(symtab) ⇒ Object



566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/idl/ast.rb', line 566

def type(symtab)
  return @type unless @type.nil?

  internal_error "Symbol '#{name}' not found" if symtab.get(name).nil?

  sym = symtab.get(name)
  # @type =
    if sym.is_a?(Type)
      sym
    elsif sym.is_a?(Var)
      sym.type
    else
      internal_error "Unexpected object on the symbol table"
    end
end

#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:



561
562
563
# File 'lib/idl/ast.rb', line 561

def type_check(symtab)
  type_error "no symbol named '#{name}' on line #{lineno}" if symtab.get(name).nil?
end

#value(symtab) ⇒ Object

Return the compile-time-known value of the node



586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
# File 'lib/idl/ast.rb', line 586

def value(symtab)
  # can't do this.... a const might be in a template function, with different values at call time
  # if @const
  #   # consts never change, so we can look them up by arch_def
  #   var = @vars[symtab.archdef]
  #   if var.nil?
  #     var = symtab.get(name)
  #     @vars[symtab.archdef] = var
  #   end
  #   type_error "Variable '#{name}' was not found" if var.nil?
  #   value_error "Value of '#{name}' not known" if var.value.nil?
  #   value_error "Value of #{name} is unknown" if var.value == :unknown

  #   return var.value
  # end

  var = symtab.get(name)

  type_error "Variable '#{name}' was not found" if var.nil?

  value_error "Value of '#{name}' not known" if var.value.nil?

  v = var.value
  value_error "Value of #{name} is unknown" if v == :unknown
  v
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