Class: Idl::IdAst
Overview
an identifier
Used for variables
Instance Method Summary collapse
-
#const? ⇒ Boolean
Whether or not the Id represents a const.
-
#initialize(input, interval) ⇒ IdAst
constructor
A new instance of IdAst.
-
#name ⇒ String
The ID name.
-
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree).
- #type(symtab) ⇒ Object
-
#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) ⇒ IdAst
Returns a new instance of IdAst.
556 557 558 559 560 |
# File 'lib/idl/ast.rb', line 556 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.
585 |
# File 'lib/idl/ast.rb', line 585 def const? = @const |
#name ⇒ String
Returns The ID name.
554 |
# File 'lib/idl/ast.rb', line 554 def name = text_value |
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree)
616 |
# File 'lib/idl/ast.rb', line 616 def to_idl = name |
#type(symtab) ⇒ Object
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
# File 'lib/idl/ast.rb', line 568 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
563 564 565 |
# File 'lib/idl/ast.rb', line 563 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
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 |
# File 'lib/idl/ast.rb', line 588 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 cfg_arch # var = @vars[symtab.cfg_arch] # if var.nil? # var = symtab.get(name) # @vars[symtab.cfg_arch] = 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