Class: Mirah::AST::Field

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

Instance Attribute Summary collapse

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

Returns a new instance of Field.



274
275
276
277
278
279
# File 'lib/mirah/ast/class.rb', line 274

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.



272
273
274
# File 'lib/mirah/ast/class.rb', line 272

def static
  @static
end

Instance Method Details

#compile(compiler, expression) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/mirah/compiler/class.rb', line 56

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

#infer(typer, expression) ⇒ Object



281
282
283
284
285
286
287
288
289
290
# File 'lib/mirah/ast/class.rb', line 281

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