Class: Duby::AST::String

Inherits:
Node
  • Object
show all
Includes:
Literal
Defined in:
lib/duby/compiler.rb,
lib/duby/ast/literal.rb

Instance Attribute Summary

Attributes included from Literal

#literal

Attributes included from Typed

#type

Attributes inherited from Node

#children, #inferred_type, #newline, #parent, #position

Instance Method Summary collapse

Methods included from Literal

#to_s

Methods inherited from Node

#<<, ===, #[], #_set_parent, child, child_name, #each, #empty?, #expr?, #initialize_copy, #insert, #inspect, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #temp, #to_s

Constructor Details

#initialize(parent, line_number, literal) ⇒ String

Returns a new instance of String.



73
74
75
76
# File 'lib/duby/ast/literal.rb', line 73

def initialize(parent, line_number, literal)
  super(parent, line_number)
  @literal = literal
end

Instance Method Details

#compile(compiler, expression) ⇒ Object



24
25
26
27
28
29
# File 'lib/duby/compiler.rb', line 24

def compile(compiler, expression)
  if expression
    compiler.line(line_number)
    compiler.string(literal)
  end
end

#infer(typer) ⇒ Object



78
79
80
81
82
# File 'lib/duby/ast/literal.rb', line 78

def infer(typer)
  return @inferred_type if resolved?
  resolved!
  @inferred_type ||= typer.string_type
end