Class: AdLint::Cpp::PPTokens
- Inherits:
-
SyntaxNode
- Object
- SyntaxNode
- AdLint::Cpp::PPTokens
- Defined in:
- lib/adlint/cpp/syntax.rb
Instance Attribute Summary collapse
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
-
#initialize ⇒ PPTokens
constructor
A new instance of PPTokens.
- #inspect(indent = 0) ⇒ Object
- #location ⇒ Object
- #may_represent_block? ⇒ Boolean
- #may_represent_controlling_keyword? ⇒ Boolean
- #may_represent_declaration_specifiers_head? ⇒ Boolean
- #may_represent_do_while_zero_idiom? ⇒ Boolean
- #may_represent_expression? ⇒ Boolean
- #may_represent_initializer? ⇒ Boolean
- #may_represent_punctuator? ⇒ Boolean
- #may_represent_specifier_qualifier_list? ⇒ Boolean
- #push(tok) ⇒ Object
- #to_s ⇒ Object
Methods inherited from SyntaxNode
Methods included from LocationHolder
Methods included from Visitable
Constructor Details
#initialize ⇒ PPTokens
Returns a new instance of PPTokens.
572 573 574 575 |
# File 'lib/adlint/cpp/syntax.rb', line 572 def initialize super @tokens = [] end |
Instance Attribute Details
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
577 578 579 |
# File 'lib/adlint/cpp/syntax.rb', line 577 def tokens @tokens end |
Instance Method Details
#inspect(indent = 0) ⇒ Object
704 705 706 |
# File 'lib/adlint/cpp/syntax.rb', line 704 def inspect(indent = 0) " " * indent + self.to_s end |
#location ⇒ Object
584 585 586 |
# File 'lib/adlint/cpp/syntax.rb', line 584 def location @tokens.first.location end |
#may_represent_block? ⇒ Boolean
628 629 630 631 632 633 634 635 636 |
# File 'lib/adlint/cpp/syntax.rb', line 628 def may_represent_block? return false if @tokens.size < 2 if @tokens.first.value == "{" && @tokens.last.value == "}" @tokens.any? { |pp_tok| pp_tok.value == ";" } else false end end |
#may_represent_controlling_keyword? ⇒ Boolean
688 689 690 691 692 693 694 695 696 697 698 |
# File 'lib/adlint/cpp/syntax.rb', line 688 def may_represent_controlling_keyword? return false if @tokens.size > 1 case @tokens.first.value when "while", "do", "for", "if", "else", "switch", "case", "default", "goto", "return", "break", "continue" true else false end end |
#may_represent_declaration_specifiers_head? ⇒ Boolean
662 663 664 665 666 667 668 669 670 671 672 673 |
# File 'lib/adlint/cpp/syntax.rb', line 662 def may_represent_declaration_specifiers_head? @tokens.all? do |pp_tok| case pp_tok.value when "typedef", "extern", "static", "auto", "register" true when "const", "volatile", "restrict" true else false end end end |
#may_represent_do_while_zero_idiom? ⇒ Boolean
638 639 640 641 642 643 644 |
# File 'lib/adlint/cpp/syntax.rb', line 638 def may_represent_do_while_zero_idiom? return false if @tokens.size < 4 @tokens[0].value == "do" && @tokens[-4].value == "while" && @tokens[-3].value == "(" && @tokens[-2].value == "0" && @tokens[-1].value == ")" end |
#may_represent_expression? ⇒ Boolean
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
# File 'lib/adlint/cpp/syntax.rb', line 588 def may_represent_expression? return false if @tokens.size < 2 @tokens.all? do |pp_tok| case pp_tok.value when "{", "}" false when ";" false when "while", "do", "for", "if", "else", "switch", "case", "default", "goto", "return", "break", "continue" false when "typedef", "extern", "static", "auto", "regisiter" false else true end end end |
#may_represent_initializer? ⇒ Boolean
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 |
# File 'lib/adlint/cpp/syntax.rb', line 608 def may_represent_initializer? return false if @tokens.size < 2 if @tokens.first.value == "{" && @tokens.last.value == "}" @tokens.all? do |pp_tok| case pp_tok.value when "while", "do", "for", "if", "else", "switch", "case", "default", "goto", "return", "break", "continue" false when ";" false else true end end else false end end |
#may_represent_punctuator? ⇒ Boolean
684 685 686 |
# File 'lib/adlint/cpp/syntax.rb', line 684 def may_represent_punctuator? @tokens.size == 1 && PUNCTUATORS.include?(@tokens.first.value) end |
#may_represent_specifier_qualifier_list? ⇒ Boolean
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 |
# File 'lib/adlint/cpp/syntax.rb', line 646 def may_represent_specifier_qualifier_list? @tokens.select { |pp_tok| case pp_tok.value when "const", "volatile", "restrict" true when "*" true when "void", "signed", "unsigned", "char", "short", "int", "long", "float", "double" true else false end }.size > 1 end |
#push(tok) ⇒ Object
579 580 581 582 |
# File 'lib/adlint/cpp/syntax.rb', line 579 def push(tok) @tokens.push(tok) self end |
#to_s ⇒ Object
700 701 702 |
# File 'lib/adlint/cpp/syntax.rb', line 700 def to_s @tokens.map { |tok| tok.value }.join(" ") end |