Class: AdLint::Cpp::FunctionLikeMacro
- Defined in:
- lib/adlint/cpp/macro.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#parameter_names ⇒ Object
readonly
Returns the value of attribute parameter_names.
Attributes inherited from Macro
Instance Method Summary collapse
- #expand(toks, macro_tbl, repl_ctxt) ⇒ Object
- #function_like? ⇒ Boolean
-
#initialize(define_line) ⇒ FunctionLikeMacro
constructor
A new instance of FunctionLikeMacro.
- #replaceable_size(toks) ⇒ Object
Methods inherited from Macro
#location, #name, #replacement_list
Methods included from LocationHolder
Constructor Details
#initialize(define_line) ⇒ FunctionLikeMacro
Returns a new instance of FunctionLikeMacro.
100 101 102 103 104 105 106 107 |
# File 'lib/adlint/cpp/macro.rb', line 100 def initialize(define_line) super if params = define_line.identifier_list @parameter_names = params.identifiers.map { |tok| tok.value } else @parameter_names = [] end end |
Instance Attribute Details
#parameter_names ⇒ Object (readonly)
Returns the value of attribute parameter_names.
109 110 111 |
# File 'lib/adlint/cpp/macro.rb', line 109 def parameter_names @parameter_names end |
Instance Method Details
#expand(toks, macro_tbl, repl_ctxt) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/adlint/cpp/macro.rb', line 124 def (toks, macro_tbl, repl_ctxt) super args, * = parse_arguments(toks, 1) args = [] if @parameter_names.empty? args_hash = @parameter_names.zip(args).each_with_object({}) { |(param, arg), hash| hash[param] = arg } rslt_toks = (args_hash, toks.first.location, macro_tbl, repl_ctxt) macro_tbl.notify_function_like_macro_replacement(self, toks, args, rslt_toks) rslt_toks end |
#function_like? ⇒ Boolean
141 |
# File 'lib/adlint/cpp/macro.rb', line 141 def function_like?; true end |
#replaceable_size(toks) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/adlint/cpp/macro.rb', line 111 def replaceable_size(toks) return 0 unless name.value == toks.first.value args, idx = parse_arguments(toks, 1) case when args && @parameter_names.empty? idx + 1 when args && @parameter_names.size >= args.size idx + 1 else 0 end end |