Class: Duby::AST::FieldAssignment

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

Instance Attribute Summary

Attributes included from Valued

#value

Attributes included from Typed

#type

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?, #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) ⇒ FieldAssignment

Returns a new instance of FieldAssignment.



200
201
202
203
204
# File 'lib/duby/ast/class.rb', line 200

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

Instance Method Details

#compile(compiler, expression) ⇒ Object



237
238
239
240
# File 'lib/duby/compiler.rb', line 237

def compile(compiler, expression)
  compiler.line(line_number)
  compiler.field_assign(name, inferred_type, expression, value, annotations)
end

#expr?(compiler) ⇒ Boolean

Returns:



176
177
178
# File 'lib/duby/jvm/source_generator/precompile.rb', line 176

def expr?(compiler)
  false
end

#infer(typer) ⇒ Object



206
207
208
209
210
211
212
213
214
# File 'lib/duby/ast/class.rb', line 206

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

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

  @inferred_type
end