Class: Mirah::AST::Import

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

Instance Attribute Summary collapse

Attributes inherited from Node

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

Instance Method Summary collapse

Methods included from Scoped

#containing_scope, #scope

Methods inherited from Node

#<<, ===, #[], #[]=, #_dump, _load, #_set_parent, child, child_name, #child_nodes, #each, #empty?, #expr?, #inferred_type!, #initialize_copy, #insert, #inspect, #inspect_children, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #string_value, #temp, #validate_child, #validate_children

Constructor Details

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

Returns a new instance of Import.



21
22
23
24
25
# File 'lib/mirah/ast/type.rb', line 21

def initialize(parent, line_number, short, long)
  @short = short
  @long = long
  super(parent, line_number, [])
end

Instance Attribute Details

#longObject

Returns the value of attribute long.



20
21
22
# File 'lib/mirah/ast/type.rb', line 20

def long
  @long
end

#shortObject

Returns the value of attribute short.



19
20
21
# File 'lib/mirah/ast/type.rb', line 19

def short
  @short
end

Instance Method Details

#compile(compiler, expression) ⇒ Object



19
20
21
22
23
24
# File 'lib/mirah/compiler/type.rb', line 19

def compile(compiler, expression)
  # TODO: what does it mean for import to be an expression?
  compiler.import(short, long)
rescue Exception => ex
  raise Mirah::InternalCompilerError.wrap(ex, self)
end

#infer(typer, expression) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/mirah/ast/type.rb', line 31

def infer(typer, expression)
  resolve_if(typer) do
    scope.static_scope.import(long, short)
    typer.type_reference(scope, @long) if short != '*'
    typer.no_type
  end
end

#to_sObject



27
28
29
# File 'lib/mirah/ast/type.rb', line 27

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

#top_level?Boolean

Returns:



39
40
41
# File 'lib/mirah/ast/type.rb', line 39

def top_level?
  true
end