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.



426
427
428
429
430
431
# File 'lib/mirah/ast.rb', line 426

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.



421
422
423
# File 'lib/mirah/ast.rb', line 421

def array
  @array
end

#metaObject

Returns the value of attribute meta.



423
424
425
# File 'lib/mirah/ast.rb', line 423

def meta
  @meta
end

Class Method Details

._load(str) ⇒ Object



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

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

Instance Method Details

#==(other) ⇒ Object



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

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

#_dump(depth) ⇒ Object



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

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

#basic_typeObject



477
478
479
480
481
482
483
# File 'lib/mirah/ast.rb', line 477

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

#block?Boolean

Returns:



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

def block?
  name == :block
end

#compatible?(other) ⇒ Boolean

Returns:



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

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

#component_typeObject



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

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

#eql?(other) ⇒ Boolean

Returns:



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

def eql?(other)
  self == other
end

#error?Boolean

Returns:



506
507
508
# File 'lib/mirah/ast.rb', line 506

def error?
  name == :error
end

#full_nameObject



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

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

#hashObject



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

def hash
  to_s.hash
end

#is_parent(other) ⇒ Object



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

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

#iterable?Boolean

Returns:



469
470
471
# File 'lib/mirah/ast.rb', line 469

def iterable?
  array?
end

#meta?Object

Returns the value of attribute meta.



424
425
426
# File 'lib/mirah/ast.rb', line 424

def meta
  @meta
end

#narrow(other) ⇒ Object



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

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:



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

def null?
  name == :null
end

#primitive?Boolean

Returns:



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

def primitive?
  true
end

#to_sObject



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

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

#type_reference(typer) ⇒ Object



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

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

#unmetaObject



494
495
496
# File 'lib/mirah/ast.rb', line 494

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

#unreachable?Boolean

Returns:



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

def unreachable?
  name == :unreachable
end

#void?Boolean

Returns:



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

def void?
  name == :void
end