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.
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.
583 |
# File 'lib/idl/ast.rb', line 583 def const? = @const |
#name ⇒ String
Returns The ID name.
552 |
# File 'lib/idl/ast.rb', line 552 def name = text_value |
#to_idl ⇒ String
Return valid IDL representation of the node (and its subtree)
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
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