Class: Idl::WidthRevealAst

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

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

#max_value, #min_value, #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_adoc, #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, #prune, #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, e) ⇒ WidthRevealAst

Returns a new instance of WidthRevealAst.



4293
4294
4295
# File 'lib/idlc/ast.rb', line 4293

def initialize(input, interval, e)
  super(input, interval, [e])
end

Class Method Details

.from_h(yaml, source_mapper) ⇒ Object



4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
# File 'lib/idlc/ast.rb', line 4332

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

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

Instance Method Details

#const_eval?(symtab) ⇒ Boolean

Returns:

  • (Boolean)


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

def const_eval?(symtab) = true

#expressionObject



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

def expression = T.cast(@children.fetch(0), RvalueAst)

#to_hObject



4325
4326
4327
4328
4329
# File 'lib/idlc/ast.rb', line 4325

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

#to_idlObject



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

def to_idl = "$width(#{expression.to_idl})"

#type(symtab) ⇒ Object



4306
4307
4308
4309
4310
4311
4312
# File 'lib/idlc/ast.rb', line 4306

def type(symtab)
  if (expression.type(symtab).width == :unknown)
    BitsUnknownType
  else
    Type.new(:bits, width: T.cast(expression.type(symtab).width, Integer).bit_length)
  end
end

#type_check(symtab, strict:) ⇒ Object



4298
4299
4300
4301
4302
4303
# File 'lib/idlc/ast.rb', line 4298

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

  e_type = expression.type(symtab)
  type_error "#{expression.text_value} is not a Bits<N> type" unless e_type.kind == :bits
end

#value(symtab) ⇒ Object



4315
4316
4317
4318
4319
# File 'lib/idlc/ast.rb', line 4315

def value(symtab)
  v = expression.type(symtab).width
  value_error "Width is not known" if v == :unknown
  T.cast(v, Integer)
end