Class: Idl::StringLiteralAst

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

Overview

represents a string literal

Examples:

">= 1.0"
"sequential_bytes"

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_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, #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, text) ⇒ StringLiteralAst

Returns a new instance of StringLiteralAst.



7327
7328
7329
7330
7331
# File 'lib/idlc/ast.rb', line 7327

def initialize(input, interval, text)
  @text = text
  super(input, interval, EMPTY_ARRAY)
  @type = Type.new(:string, width: value(nil).length, qualifiers: [:const])
end

Class Method Details

.from_h(yaml, source_mapper) ⇒ Object



7359
7360
7361
7362
7363
7364
7365
7366
7367
# File 'lib/idlc/ast.rb', line 7359

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

  input = input_from_source_yaml(yaml.fetch("source"), source_mapper)
  interval = interval_from_source_yaml(yaml.fetch("source"))
  StringLiteralAst.new(
    input, interval, "\"#{yaml.fetch("text")}\""
  )
end

Instance Method Details

#const_eval?(symtab) ⇒ Boolean

Returns:

  • (Boolean)


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

def const_eval?(symtab) = true

#gen_adoc(indent, indent_spaces: 2) ⇒ Object



60
61
62
63
# File 'lib/idlc/passes/gen_adoc.rb', line 60

def gen_adoc(indent, indent_spaces: 2)
  # text_value will include leading and trailing quotes
  "#{' ' * indent}#{text_value}"
end

#text_valueObject



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

def text_value = @text

#to_hObject



7352
7353
7354
7355
7356
# File 'lib/idlc/ast.rb', line 7352

def to_h = {
  "kind" => "string_literal",
  "text" => text_value.gsub('"', ""),
  "source" => source_yaml
}

#to_idlObject



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

def to_idl = text_value

#type(symtab) ⇒ Object



7339
7340
7341
# File 'lib/idlc/ast.rb', line 7339

def type(symtab)
  @type
end

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



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

def type_check(_symtab, strict:); end

#value(_symtab) ⇒ Object

Return the compile-time-known value of the node



7344
7345
7346
# File 'lib/idlc/ast.rb', line 7344

def value(_symtab)
  text_value.gsub('"', "")
end