Class: Duby::AST::Import

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

Instance Attribute Summary collapse

Attributes inherited from Node

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

Instance Method Summary collapse

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

Constructor Details

#initialize(parent, line_number, short, long) ⇒ Import

Returns a new instance of Import.



5
6
7
8
9
10
# File 'lib/duby/ast/type.rb', line 5

def initialize(parent, line_number, short, long)
  @short = short
  @long = long
  super(parent, line_number, [])
  Duby::AST.type_factory.alias(short, long) if Duby::AST.type_factory
end

Instance Attribute Details

#longObject

Returns the value of attribute long.



4
5
6
# File 'lib/duby/ast/type.rb', line 4

def long
  @long
end

#shortObject

Returns the value of attribute short.



3
4
5
# File 'lib/duby/ast/type.rb', line 3

def short
  @short
end

Instance Method Details

#compile(compiler, expression) ⇒ Object



83
84
85
86
# File 'lib/duby/compiler.rb', line 83

def compile(compiler, expression)
  # TODO: what does it mean for import to be an expression?
  compiler.import(short, long)
end

#infer(typer) ⇒ Object



16
17
18
19
20
# File 'lib/duby/ast/type.rb', line 16

def infer(typer)
  # add both the meta and non-meta imports
  typer.alias_types(short, long)
  typer.no_type
end

#to_sObject



12
13
14
# File 'lib/duby/ast/type.rb', line 12

def to_s
  "Import(#{short} = #{long})"
end