Class: Mirah::AST::TypeReference

Inherits:
Node
  • Object
show all
Includes:
Named
Defined in:
lib/mirah/ast.rb

Direct Known Subclasses

TypeDefinition, JVM::Types::Type

Constant Summary collapse

NoType =
TypeReference.new(:notype)
NullType =
TypeReference.new(:null)
ErrorType =
TypeReference.new(:error)
UnreachableType =
TypeReference.new(:unreachable)
BlockType =
TypeReference.new(:block)

Instance Attribute Summary collapse

Attributes included from Named

#name

Attributes inherited from Node

#children, #inferred_type, #newline, #parent, #position

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Named

#string_value, #validate_name

Methods inherited from Node

#<<, ===, #[], #[]=, #_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, #top_level?, #validate_child, #validate_children

Constructor Details

#initialize(name, array = false, meta = false, position = nil) ⇒ TypeReference

Returns a new instance of TypeReference.



435
436
437
438
439
440
# File 'lib/mirah/ast.rb', line 435

def initialize(name, array = false, meta = false, position=nil)
  super(nil, position)
  self.name = name
  @array = array
  @meta = meta
end

Instance Attribute Details

#arrayObject Also known as: array?

Returns the value of attribute array.



430
431
432
# File 'lib/mirah/ast.rb', line 430

def array
  @array
end

#metaObject

Returns the value of attribute meta.



432
433
434
# File 'lib/mirah/ast.rb', line 432

def meta
  @meta
end

Class Method Details

._load(str) ⇒ Object



539
540
541
# File 'lib/mirah/ast.rb', line 539

def self._load(str)
  AST::Type(*Marshal.load(str))
end

Instance Method Details

#==(other) ⇒ Object



454
455
456
# File 'lib/mirah/ast.rb', line 454

def ==(other)
  to_s == other.to_s
end

#_dump(depth) ⇒ Object



535
536
537
# File 'lib/mirah/ast.rb', line 535

def _dump(depth)
  Marshal.dump([name, array?, meta?])
end

#basic_typeObject



486
487
488
489
490
491
492
# File 'lib/mirah/ast.rb', line 486

def basic_type
  if array? || meta?
    TypeReference.new(name, false, false)
  else
    self
  end
end

#block?Boolean

Returns:



527
528
529
# File 'lib/mirah/ast.rb', line 527

def block?
  name == :block
end

#compatible?(other) ⇒ Boolean

Returns:



471
472
473
474
475
476
# File 'lib/mirah/ast.rb', line 471

def compatible?(other)
  # default behavior is only exact match right now
  self == other ||
      error? || other.error? ||
      unreachable? || other.unreachable?
end

#component_typeObject



482
483
484
# File 'lib/mirah/ast.rb', line 482

def component_type
  AST.type(nil, name) if array?
end

#eql?(other) ⇒ Boolean

Returns:



458
459
460
# File 'lib/mirah/ast.rb', line 458

def eql?(other)
  self == other
end

#error?Boolean

Returns:



515
516
517
# File 'lib/mirah/ast.rb', line 515

def error?
  name == :error
end

#full_nameObject



450
451
452
# File 'lib/mirah/ast.rb', line 450

def full_name
  "#{name}#{array ? '[]' : ''}"
end

#hashObject



462
463
464
# File 'lib/mirah/ast.rb', line 462

def hash
  to_s.hash
end

#is_parent(other) ⇒ Object



466
467
468
469
# File 'lib/mirah/ast.rb', line 466

def is_parent(other)
  # default behavior now is to disallow any polymorphic types
  self == other
end

#iterable?Boolean

Returns:



478
479
480
# File 'lib/mirah/ast.rb', line 478

def iterable?
  array?
end

#meta?Object

Returns the value of attribute meta.



433
434
435
# File 'lib/mirah/ast.rb', line 433

def meta
  @meta
end

#narrow(other) ⇒ Object



494
495
496
497
498
499
500
501
# File 'lib/mirah/ast.rb', line 494

def narrow(other)
  # only exact match allowed for now, so narrowing is a noop
  if error? || unreachable?
    other
  else
    self
  end
end

#null?Boolean

Returns:



519
520
521
# File 'lib/mirah/ast.rb', line 519

def null?
  name == :null
end

#primitive?Boolean

Returns:



531
532
533
# File 'lib/mirah/ast.rb', line 531

def primitive?
  true
end

#to_sObject



446
447
448
# File 'lib/mirah/ast.rb', line 446

def to_s
  "Type(#{name}#{array? ? ' array' : ''}#{meta? ? ' meta' : ''})"
end

#type_reference(typer) ⇒ Object



442
443
444
# File 'lib/mirah/ast.rb', line 442

def type_reference(typer)
  typer.type_reference(nil, name, array, meta)
end

#unmetaObject



503
504
505
# File 'lib/mirah/ast.rb', line 503

def unmeta
  TypeReference.new(name, array, false)
end

#unreachable?Boolean

Returns:



523
524
525
# File 'lib/mirah/ast.rb', line 523

def unreachable?
  name == :unreachable
end

#void?Boolean

Returns:



511
512
513
# File 'lib/mirah/ast.rb', line 511

def void?
  name == :void
end