Class: Mirah::AST::TypeReference
- Inherits:
-
Node
- Object
- Node
- Mirah::AST::TypeReference
show all
- Includes:
- Named
- Defined in:
- lib/mirah/ast.rb
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
#array ⇒ Object
Also known as:
array?
Returns the value of attribute array.
430
431
432
|
# File 'lib/mirah/ast.rb', line 430
def array
@array
end
|
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_type ⇒ Object
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
|
527
528
529
|
# File 'lib/mirah/ast.rb', line 527
def block?
name == :block
end
|
#compatible?(other) ⇒ Boolean
471
472
473
474
475
476
|
# File 'lib/mirah/ast.rb', line 471
def compatible?(other)
self == other ||
error? || other.error? ||
unreachable? || other.unreachable?
end
|
#component_type ⇒ Object
482
483
484
|
# File 'lib/mirah/ast.rb', line 482
def component_type
AST.type(nil, name) if array?
end
|
#eql?(other) ⇒ Boolean
458
459
460
|
# File 'lib/mirah/ast.rb', line 458
def eql?(other)
self == other
end
|
515
516
517
|
# File 'lib/mirah/ast.rb', line 515
def error?
name == :error
end
|
#full_name ⇒ Object
450
451
452
|
# File 'lib/mirah/ast.rb', line 450
def full_name
"#{name}#{array ? '[]' : ''}"
end
|
#hash ⇒ Object
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)
self == other
end
|
478
479
480
|
# File 'lib/mirah/ast.rb', line 478
def iterable?
array?
end
|
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)
if error? || unreachable?
other
else
self
end
end
|
519
520
521
|
# File 'lib/mirah/ast.rb', line 519
def null?
name == :null
end
|
531
532
533
|
# File 'lib/mirah/ast.rb', line 531
def primitive?
true
end
|
#to_s ⇒ Object
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
|
503
504
505
|
# File 'lib/mirah/ast.rb', line 503
def unmeta
TypeReference.new(name, array, false)
end
|
#unreachable? ⇒ Boolean
523
524
525
|
# File 'lib/mirah/ast.rb', line 523
def unreachable?
name == :unreachable
end
|
511
512
513
|
# File 'lib/mirah/ast.rb', line 511
def void?
name == :void
end
|