Class: Mirah::AST::Body
- Inherits:
-
Node
- Object
- Node
- Mirah::AST::Body
show all
- Defined in:
- lib/mirah/ast/structure.rb,
lib/mirah/compiler/structure.rb,
lib/mirah/jvm/source_generator/precompile.rb
Instance Attribute Summary
Attributes inherited from Node
#children, #inferred_type, #newline, #parent, #position
Instance Method Summary
collapse
Methods inherited from Node
===, #[], #[]=, #_dump, _load, #_set_parent, child, child_name, #child_nodes, #each, #empty?, #inferred_type!, #initialize_copy, #insert, #inspect, #inspect_children, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #temp, #to_s, #top_level?, #validate_child, #validate_children
Constructor Details
#initialize(parent, line_number, &block) ⇒ Body
Returns a new instance of Body.
20
21
22
|
# File 'lib/mirah/ast/structure.rb', line 20
def initialize(parent, line_number, &block)
super(parent, line_number, &block)
end
|
Instance Method Details
#<<(node) ⇒ Object
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/mirah/ast/structure.rb', line 57
def <<(node)
super
if @typer
orig_self = @typer.self_type
@typer.known_types['self'] = @self_type
@typer.infer(node, true)
@typer.known_types['self'] = orig_self
end
self
end
|
#add_node(node) ⇒ Object
68
69
70
|
# File 'lib/mirah/ast/structure.rb', line 68
def add_node(node)
self << node
end
|
#compile(compiler, expression) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/mirah/compiler/structure.rb', line 19
def compile(compiler, expression)
compiler.line(line_number)
compiler.body(self, expression)
rescue Exception => ex
raise Mirah::InternalCompilerError.wrap(ex, self)
end
|
#expr?(compiler) ⇒ Boolean
59
60
61
|
# File 'lib/mirah/jvm/source_generator/precompile.rb', line 59
def expr?(compiler)
false
end
|
#infer(typer, expression) ⇒ Object
Type of a block is the type of its final element
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/mirah/ast/structure.rb', line 25
def infer(typer, expression)
unless @inferred_type
@typer ||= typer
@self_type ||= typer.self_type
if children.empty?
@inferred_type = typer.no_type
else
children[0..-2].each do |child|
typer.infer(child, false)
end
@inferred_type = typer.infer(children.last, expression)
end
if @inferred_type
resolved!
else
typer.defer(self)
end
end
@inferred_type
end
|
#string_value ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/mirah/ast/structure.rb', line 49
def string_value
if children.size == 1
children[0].string_value
else
super
end
end
|