Class: Mirah::AST::FieldDeclaration
- Includes:
- Annotated, ClassScoped, Named, Typed
- Defined in:
- lib/mirah/ast/class.rb,
lib/mirah/compiler/class.rb
Instance Attribute Summary collapse
-
#static ⇒ Object
Returns the value of attribute static.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes included from Named
Attributes included from Annotated
Attributes inherited from Node
#children, #inferred_type, #newline, #parent, #position
Instance Method Summary collapse
- #compile(compiler, expression) ⇒ Object
- #infer(typer, expression) ⇒ Object
-
#initialize(parent, position, name, annotations = [], static = false, &block) ⇒ FieldDeclaration
constructor
A new instance of FieldDeclaration.
- #resolved!(typer) ⇒ Object
Methods included from ClassScoped
Methods included from Named
#string_value, #to_s, #validate_name
Methods included from Annotated
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?, #simple_name, #string_value, #temp, #to_s, #top_level?, #validate_child, #validate_children
Constructor Details
#initialize(parent, position, name, annotations = [], static = false, &block) ⇒ FieldDeclaration
Returns a new instance of FieldDeclaration.
215 216 217 218 219 220 |
# File 'lib/mirah/ast/class.rb', line 215 def initialize(parent, position, name, annotations=[], static = false, &block) @annotations = annotations super(parent, position, &block) self.name = name @static = static end |
Instance Attribute Details
#static ⇒ Object
Returns the value of attribute static.
213 214 215 |
# File 'lib/mirah/ast/class.rb', line 213 def static @static end |
#type ⇒ Object
Returns the value of attribute type.
212 213 214 |
# File 'lib/mirah/ast/class.rb', line 212 def type @type end |
Instance Method Details
#compile(compiler, expression) ⇒ Object
39 40 41 42 43 |
# File 'lib/mirah/compiler/class.rb', line 39 def compile(compiler, expression) compiler.field_declare(name, inferred_type, annotations, static) rescue Exception => ex raise Mirah::InternalCompilerError.wrap(ex, self) end |
#infer(typer, expression) ⇒ Object
222 223 224 225 226 227 |
# File 'lib/mirah/ast/class.rb', line 222 def infer(typer, expression) resolve_if(typer) do @annotations.each {|a| a.infer(typer, true)} if @annotations @type = type_node.type_reference(typer) end end |
#resolved!(typer) ⇒ Object
229 230 231 232 233 234 235 236 |
# File 'lib/mirah/ast/class.rb', line 229 def resolved!(typer) if static typer.learn_static_field_type(class_scope, name, @inferred_type) else typer.learn_field_type(class_scope, name, @inferred_type) end super end |