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.



416
417
418
419
420
421
# File 'lib/mirah/ast.rb', line 416

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.



411
412
413
# File 'lib/mirah/ast.rb', line 411

def array
  @array
end

#metaObject

Returns the value of attribute meta.



413
414
415
# File 'lib/mirah/ast.rb', line 413

def meta
  @meta
end

Class Method Details

._load(str) ⇒ Object



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

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

Instance Method Details

#==(other) ⇒ Object



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

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

#_dump(depth) ⇒ Object



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

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

#basic_typeObject



467
468
469
470
471
472
473
# File 'lib/mirah/ast.rb', line 467

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

#block?Boolean

Returns:



508
509
510
# File 'lib/mirah/ast.rb', line 508

def block?
  name == :block
end

#compatible?(other) ⇒ Boolean

Returns:



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

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

#component_typeObject



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

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

#eql?(other) ⇒ Boolean

Returns:



439
440
441
# File 'lib/mirah/ast.rb', line 439

def eql?(other)
  self == other
end

#error?Boolean

Returns:



496
497
498
# File 'lib/mirah/ast.rb', line 496

def error?
  name == :error
end

#full_nameObject



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

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

#hashObject



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

def hash
  to_s.hash
end

#is_parent(other) ⇒ Object



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

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

#iterable?Boolean

Returns:



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

def iterable?
  array?
end

#meta?Object

Returns the value of attribute meta.



414
415
416
# File 'lib/mirah/ast.rb', line 414

def meta
  @meta
end

#narrow(other) ⇒ Object



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

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:



500
501
502
# File 'lib/mirah/ast.rb', line 500

def null?
  name == :null
end

#primitive?Boolean

Returns:



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

def primitive?
  true
end

#to_sObject



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

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

#type_reference(typer) ⇒ Object



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

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

#unmetaObject



484
485
486
# File 'lib/mirah/ast.rb', line 484

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

#unreachable?Boolean

Returns:



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

def unreachable?
  name == :unreachable
end

#void?Boolean

Returns:



492
493
494
# File 'lib/mirah/ast.rb', line 492

def void?
  name == :void
end