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.
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
#array ⇒ Object
Also known as:
array?
Returns the value of attribute array.
421
422
423
|
# File 'lib/mirah/ast.rb', line 421
def array
@array
end
|
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_type ⇒ Object
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
|
518
519
520
|
# File 'lib/mirah/ast.rb', line 518
def block?
name == :block
end
|
#compatible?(other) ⇒ Boolean
462
463
464
465
466
467
|
# File 'lib/mirah/ast.rb', line 462
def compatible?(other)
self == other ||
error? || other.error? ||
unreachable? || other.unreachable?
end
|
#component_type ⇒ Object
473
474
475
|
# File 'lib/mirah/ast.rb', line 473
def component_type
AST.type(nil, name) if array?
end
|
#eql?(other) ⇒ Boolean
449
450
451
|
# File 'lib/mirah/ast.rb', line 449
def eql?(other)
self == other
end
|
506
507
508
|
# File 'lib/mirah/ast.rb', line 506
def error?
name == :error
end
|
#full_name ⇒ Object
441
442
443
|
# File 'lib/mirah/ast.rb', line 441
def full_name
"#{name}#{array ? '[]' : ''}"
end
|
#hash ⇒ Object
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)
self == other
end
|
469
470
471
|
# File 'lib/mirah/ast.rb', line 469
def iterable?
array?
end
|
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)
if error? || unreachable?
other
else
self
end
end
|
510
511
512
|
# File 'lib/mirah/ast.rb', line 510
def null?
name == :null
end
|
522
523
524
|
# File 'lib/mirah/ast.rb', line 522
def primitive?
true
end
|
#to_s ⇒ Object
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
|
494
495
496
|
# File 'lib/mirah/ast.rb', line 494
def unmeta
TypeReference.new(name, array, false)
end
|
#unreachable? ⇒ Boolean
514
515
516
|
# File 'lib/mirah/ast.rb', line 514
def unreachable?
name == :unreachable
end
|
502
503
504
|
# File 'lib/mirah/ast.rb', line 502
def void?
name == :void
end
|