Class: Duby::AST::FieldDeclaration

Inherits:
Node show all
Includes:
ClassScoped, Named, Typed
Defined in:
lib/duby/compiler.rb,
lib/duby/ast/class.rb

Instance Attribute Summary

Attributes included from Typed

#type

Attributes included from Named

#name

Attributes inherited from Node

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

Instance Method Summary collapse

Methods included from ClassScoped

#scope

Methods included from Named

#to_s

Methods inherited from Node

#[], #each, #expr?, #inspect, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #temp, #to_s

Constructor Details

#initialize(parent, line_number, name, &block) ⇒ FieldDeclaration

Returns a new instance of FieldDeclaration.



83
84
85
86
87
# File 'lib/duby/ast/class.rb', line 83

def initialize(parent, line_number, name, &block)
  super(parent, line_number, &block)
  @name = name
  @type = children[0]
end

Instance Method Details

#compile(compiler, expression) ⇒ Object



173
174
175
# File 'lib/duby/compiler.rb', line 173

def compile(compiler, expression)
  compiler.field_declare(name, inferred_type)
end

#infer(typer) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/duby/ast/class.rb', line 89

def infer(typer)
  unless resolved?
    resolved!
    @inferred_type = typer.known_types[type]
    if @inferred_type
      resolved!
      typer.learn_field_type(scope, name, @inferred_type)
    else
      typer.defer(self)
    end
  end
  @inferred_type
end