Class: Idl::StringLiteralAst
- Includes:
- Rvalue
- Defined in:
- lib/idlc/ast.rb,
lib/idlc/passes/gen_adoc.rb
Overview
represents a string literal
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
- #const_eval?(symtab) ⇒ Boolean
- #gen_adoc(indent, indent_spaces: 2) ⇒ Object
-
#initialize(input, interval, text) ⇒ StringLiteralAst
constructor
A new instance of StringLiteralAst.
- #text_value ⇒ Object
- #to_h ⇒ Object
- #to_idl ⇒ Object
- #type(symtab) ⇒ Object
-
#type_check(_symtab, strict:) ⇒ void
type check this node and all children.
-
#value(_symtab) ⇒ Object
Return the compile-time-known value of the node.
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
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_value ⇒ Object
7334 |
# File 'lib/idlc/ast.rb', line 7334 def text_value = @text |
#to_h ⇒ Object
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_idl ⇒ Object
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
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 |