Class: AdLint::Cpp::MacroTable
- Inherits:
-
Object
- Object
- AdLint::Cpp::MacroTable
- Extended by:
- Pluggable
- Defined in:
- lib/adlint/cpp/macro.rb
Instance Method Summary collapse
- #define(macro) ⇒ Object
-
#initialize ⇒ MacroTable
constructor
A new instance of MacroTable.
- #lookup(name_str) ⇒ Object
- #notify_function_like_macro_replacement(macro, replacing_toks, args, rslt_toks) ⇒ Object
- #notify_last_backslash_ignored(tok) ⇒ Object
- #notify_object_like_macro_replacement(macro, replacing_toks, rslt_toks) ⇒ Object
- #notify_sharpsharp_operator_evaled(lhs_tok, rhs_tok, new_toks) ⇒ Object
- #replace(toks, repl_ctxt = nil) ⇒ Object
- #undef(name_str) ⇒ Object
Methods included from Pluggable
Constructor Details
#initialize ⇒ MacroTable
Returns a new instance of MacroTable.
664 665 666 667 |
# File 'lib/adlint/cpp/macro.rb', line 664 def initialize @macros = {} predefine_special_macros end |
Instance Method Details
#define(macro) ⇒ Object
676 677 678 679 |
# File 'lib/adlint/cpp/macro.rb', line 676 def define(macro) @macros[macro.name.value] = macro self end |
#lookup(name_str) ⇒ Object
686 687 688 |
# File 'lib/adlint/cpp/macro.rb', line 686 def lookup(name_str) @macros[name_str] end |
#notify_function_like_macro_replacement(macro, replacing_toks, args, rslt_toks) ⇒ Object
720 721 722 723 724 |
# File 'lib/adlint/cpp/macro.rb', line 720 def notify_function_like_macro_replacement(macro, replacing_toks, args, rslt_toks) on_function_like_macro_replacement.invoke(macro, replacing_toks, args, rslt_toks) end |
#notify_last_backslash_ignored(tok) ⇒ Object
730 731 732 |
# File 'lib/adlint/cpp/macro.rb', line 730 def notify_last_backslash_ignored(tok) on_last_backslash_ignored.invoke(tok) end |
#notify_object_like_macro_replacement(macro, replacing_toks, rslt_toks) ⇒ Object
716 717 718 |
# File 'lib/adlint/cpp/macro.rb', line 716 def notify_object_like_macro_replacement(macro, replacing_toks, rslt_toks) on_object_like_macro_replacement.invoke(macro, replacing_toks, rslt_toks) end |
#notify_sharpsharp_operator_evaled(lhs_tok, rhs_tok, new_toks) ⇒ Object
726 727 728 |
# File 'lib/adlint/cpp/macro.rb', line 726 def notify_sharpsharp_operator_evaled(lhs_tok, rhs_tok, new_toks) on_sharpsharp_operator_evaled.invoke(lhs_tok, rhs_tok, new_toks) end |
#replace(toks, repl_ctxt = nil) ⇒ Object
690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 |
# File 'lib/adlint/cpp/macro.rb', line 690 def replace(toks, repl_ctxt = nil) replaced = false idx = 0 while tok = toks[idx] case tok.value when "defined" in_defined = true when "(", ")" ; else if in_defined in_defined = false else if new_idx = do_replace(toks, idx, repl_ctxt) idx = new_idx replaced = true end end end idx += 1 end replaced end |
#undef(name_str) ⇒ Object
681 682 683 684 |
# File 'lib/adlint/cpp/macro.rb', line 681 def undef(name_str) @macros.delete(name_str) self end |