Class: Mirah::AST::FieldAssignment

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

Instance Attribute Summary collapse

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

#class_scope

Methods included from Named

#string_value, #to_s, #validate_name

Methods included from Annotated

#annotation

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, #string_value, #temp, #to_s, #top_level?, #validate_child, #validate_children

Constructor Details

#initialize(parent, position, name, annotations = [], static = false, &block) ⇒ FieldAssignment

Returns a new instance of FieldAssignment.



248
249
250
251
252
253
# File 'lib/mirah/ast/class.rb', line 248

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

Instance Attribute Details

#staticObject

Returns the value of attribute static.



246
247
248
# File 'lib/mirah/ast/class.rb', line 246

def static
  @static
end

Instance Method Details

#compile(compiler, expression) ⇒ Object



47
48
49
50
51
52
# File 'lib/mirah/compiler/class.rb', line 47

def compile(compiler, expression)
  compiler.line(line_number)
  compiler.field_assign(name, inferred_type, expression, value, annotations, static)
rescue Exception => ex
  raise Mirah::InternalCompilerError.wrap(ex, self)
end

#expr?(compiler) ⇒ Boolean

Returns:



200
201
202
# File 'lib/mirah/jvm/source_generator/precompile.rb', line 200

def expr?(compiler)
  false
end

#infer(typer, expression) ⇒ Object



255
256
257
258
259
260
261
262
263
264
# File 'lib/mirah/ast/class.rb', line 255

def infer(typer, expression)
  resolve_if(typer) do
    @annotations.each {|a| a.infer(typer, true)} if @annotations
    if static
      typer.learn_static_field_type(class_scope, name, typer.infer(value, true))
    else
      typer.learn_field_type(class_scope, name, typer.infer(value, true))
    end
  end
end