Class: Idl::ParenExpressionAst

Inherits:
AstNode
  • Object
show all
Includes:
Rvalue
Defined in:
lib/idlc/ast.rb,
lib/idlc/passes/prune.rb,
lib/idlc/passes/gen_adoc.rb

Overview

represents a parenthesized expression

for example:

(a + b)

Constant Summary

Constants inherited from AstNode

AstNode::Bits1Type, AstNode::Bits32Type, AstNode::Bits64Type, AstNode::BoolType, AstNode::ConstBoolType, AstNode::PossiblyUnknownBits1Type, AstNode::PossiblyUnknownBits32Type, AstNode::PossiblyUnknownBits64Type, AstNode::ReachableFunctionCacheType, AstNode::StringType, AstNode::VoidType

Instance Attribute Summary

Attributes inherited from AstNode

#children, #input, #interval, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rvalue

#truncate, #values

Methods inherited from AstNode

#always_terminates?, #declaration?, #executable?, extract_base_var_name, #find_ancestor, #find_dst_registers, #find_referenced_csrs, #find_src_registers, #freeze_tree, #gen_option_adoc, #input_file, input_from_source_yaml, #inspect, #internal_error, interval_from_source_yaml, #lineno, #lines_around, #nullify_assignments, #pass_find_return_values, #path, #print_ast, #reachable_exceptions, #reachable_functions, #set_input_file, #set_input_file_unless_already_set, #source_line_file_offsets, #source_starting_offset, #source_yaml, #starting_line, #text_value, #truncation_warn, #type_error, #unindent, value_else, #value_else, value_error, #value_error, value_try, #value_try, write_back_nested

Constructor Details

#initialize(input, interval, exp) ⇒ ParenExpressionAst

Returns a new instance of ParenExpressionAst.



5358
# File 'lib/idlc/ast.rb', line 5358

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

Class Method Details

.from_h(yaml, source_mapper) ⇒ Object



5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
# File 'lib/idlc/ast.rb', line 5389

def self.from_h(yaml, source_mapper)
  raise "Bad YAML" unless yaml.key?("kind") && yaml.fetch("kind") == "paren_expr"

  input = input_from_source_yaml(yaml.fetch("source"), source_mapper)
  interval = interval_from_source_yaml(yaml.fetch("source"))
  ParenExpressionAst.new(
    input, interval,
    T.cast(AstNode.from_h(yaml.fetch("expr"), source_mapper), RvalueAst)
  )
end

Instance Method Details

#const_eval?(symtab) ⇒ Boolean

Returns:

  • (Boolean)


5356
# File 'lib/idlc/ast.rb', line 5356

def const_eval?(symtab) = expression.const_eval?(symtab)

#expressionObject



5360
# File 'lib/idlc/ast.rb', line 5360

def expression = @children[0]

#gen_adoc(indent = 0, indent_spaces: 2) ⇒ Object



142
143
144
# File 'lib/idlc/passes/gen_adoc.rb', line 142

def gen_adoc(indent = 0, indent_spaces: 2)
  "#{' ' * indent}(#{expression.gen_adoc(indent, indent_spaces:)})"
end

#invert(symtab) ⇒ Object



5362
# File 'lib/idlc/ast.rb', line 5362

def invert(symtab) = expression.invert(symtab)

#max_value(symtab) ⇒ Object



5373
# File 'lib/idlc/ast.rb', line 5373

def max_value(symtab) = expression.max_value(symtab)

#min_value(symtab) ⇒ Object



5375
# File 'lib/idlc/ast.rb', line 5375

def min_value(symtab) = expression.min_value(symtab)

#prune(symtab, forced_type: nil) ⇒ Object



302
303
304
305
306
307
308
309
310
311
# File 'lib/idlc/passes/prune.rb', line 302

def prune(symtab, forced_type: nil)
  e = expression.prune(symtab, forced_type:)
  if e.is_a?(ParenExpressionAst)
    e
  elsif e.is_a?(IntLiteralAst) || e.is_a?(TrueExpressionAst) || e.is_a?(FalseExpressionAst) || e.is_a?(IdAst)
    e
  else
    ParenExpressionAst.new(input, interval, e)
  end
end

#to_hObject



5382
5383
5384
5385
5386
# File 'lib/idlc/ast.rb', line 5382

def to_h = {
  "kind" => "paren_expr",
  "expr" => expression.to_h,
  "source" => source_yaml
}

#to_idlObject



5379
# File 'lib/idlc/ast.rb', line 5379

def to_idl = "(#{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:



5368
# File 'lib/idlc/ast.rb', line 5368

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

#type_check(symtab, strict:) ⇒ 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:



5365
# File 'lib/idlc/ast.rb', line 5365

def type_check(symtab, strict:) = expression.type_check(symtab, strict:)

#value(symtab) ⇒ Object

Return the compile-time-known value of the node



5371
# File 'lib/idlc/ast.rb', line 5371

def value(symtab) = expression.value(symtab)