Class: Duby::AST::Field

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

Instance Attribute Summary

Attributes included from Named

#name

Attributes included from Annotated

#annotations

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 included from Annotated

#annotation

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, position, name, annotations = [], &block) ⇒ Field

Returns a new instance of Field.



222
223
224
225
226
# File 'lib/duby/ast/class.rb', line 222

def initialize(parent, position, name, annotations=[], &block)
  @annotations = annotations
  super(parent, position, &block)
  @name = name
end

Instance Method Details

#compile(compiler, expression) ⇒ Object



244
245
246
247
248
249
# File 'lib/duby/compiler.rb', line 244

def compile(compiler, expression)
  compiler.line(line_number)
  if expression
    compiler.field(name, inferred_type, annotations)
  end
end

#infer(typer) ⇒ Object



228
229
230
231
232
233
234
235
236
# File 'lib/duby/ast/class.rb', line 228

def infer(typer)
  unless resolved?
    @inferred_type = typer.field_type(scope, name)

    @inferred_type ? resolved! : typer.defer(self)
  end

  @inferred_type
end