Class: CType::List
- Inherits:
-
Array
- Object
- Array
- CType::List
- Defined in:
- lib/caphir/ctype.rb
Overview
Type
Instance Method Summary collapse
- #ellipses? ⇒ Boolean
- #finalize ⇒ Object
-
#initialize(proto = false) ⇒ List
constructor
A new instance of List.
- #lookup(ident) ⇒ Object
-
#prototype? ⇒ Boolean
check if K & R style prototype: main();.
- #to_s ⇒ Object
- #with_ellipses ⇒ Object
Constructor Details
#initialize(proto = false) ⇒ List
Returns a new instance of List.
553 554 555 556 557 558 |
# File 'lib/caphir/ctype.rb', line 553 def initialize(proto=false) super() @ellipses = false @prototype = proto self.freeze if @prototype end |
Instance Method Details
#ellipses? ⇒ Boolean
576 577 578 |
# File 'lib/caphir/ctype.rb', line 576 def ellipses? @ellipses end |
#finalize ⇒ Object
580 581 582 583 584 585 586 587 588 |
# File 'lib/caphir/ctype.rb', line 580 def finalize if self.length == 1 and self[0].to_s == 'void' self.pop # get rid of (void) end # self.freeze causes problems with K & R function definitions, # since the list must be modified after it is "finalized" to # add the argument types. self end |
#lookup(ident) ⇒ Object
565 566 567 |
# File 'lib/caphir/ctype.rb', line 565 def lookup(ident) self.find { |p| p.identifier == ident } end |
#prototype? ⇒ Boolean
check if K & R style prototype: main();
561 562 563 |
# File 'lib/caphir/ctype.rb', line 561 def prototype? @prototype end |
#to_s ⇒ Object
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
# File 'lib/caphir/ctype.rb', line 590 def to_s if self.length == 0 if prototype? '' else 'void' end else if ellipses? [self, '...'] else self end.join(', ') end end |
#with_ellipses ⇒ Object
569 570 571 572 573 574 |
# File 'lib/caphir/ctype.rb', line 569 def with_ellipses() #raise "already has ellipses #{self}" if ellipses? #raise "prototype with ellipses?" if prototype? @ellipses = true self end |