Class: Duby::AST::TypeReference

Inherits:
Node
  • Object
show all
Includes:
Named
Defined in:
lib/duby/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

Instance Method Summary collapse

Methods inherited from Node

#<<, ===, #[], #_set_parent, child, child_name, #each, #empty?, #expr?, #initialize_copy, #insert, #inspect, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #temp

Constructor Details

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

Returns a new instance of TypeReference.



408
409
410
411
412
413
# File 'lib/duby/ast.rb', line 408

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

Instance Attribute Details

#arrayObject Also known as: array?

Returns the value of attribute array.



403
404
405
# File 'lib/duby/ast.rb', line 403

def array
  @array
end

#metaObject

Returns the value of attribute meta.



405
406
407
# File 'lib/duby/ast.rb', line 405

def meta
  @meta
end

Instance Method Details

#==(other) ⇒ Object



419
420
421
# File 'lib/duby/ast.rb', line 419

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

#block?Boolean

Returns:



480
481
482
# File 'lib/duby/ast.rb', line 480

def block?
  name == :block
end

#compatible?(other) ⇒ Boolean

Returns:



436
437
438
439
440
441
# File 'lib/duby/ast.rb', line 436

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

#component_typeObject



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

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

#eql?(other) ⇒ Boolean

Returns:



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

def eql?(other)
  self == other
end

#error?Boolean

Returns:



468
469
470
# File 'lib/duby/ast.rb', line 468

def error?
  name == :error
end

#hashObject



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

def hash
  to_s.hash
end

#is_parent(other) ⇒ Object



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

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

#iterable?Boolean

Returns:



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

def iterable?
  array?
end

#meta?Object

Returns the value of attribute meta.



406
407
408
# File 'lib/duby/ast.rb', line 406

def meta
  @meta
end

#narrow(other) ⇒ Object



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

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:



472
473
474
# File 'lib/duby/ast.rb', line 472

def null?
  name == :null
end

#primitive?Boolean

Returns:



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

def primitive?
  true
end

#to_sObject



415
416
417
# File 'lib/duby/ast.rb', line 415

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

#unmetaObject



460
461
462
# File 'lib/duby/ast.rb', line 460

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

#unreachable?Boolean

Returns:



476
477
478
# File 'lib/duby/ast.rb', line 476

def unreachable?
  name == :unreachable
end