Class: AdLint::Cpp::VaFunctionLikeMacro

Inherits:
FunctionLikeMacro show all
Defined in:
lib/adlint/cpp/macro.rb

Instance Attribute Summary

Attributes inherited from FunctionLikeMacro

#parameter_names

Attributes inherited from Macro

#define_line

Instance Method Summary collapse

Methods inherited from FunctionLikeMacro

#function_like?, #initialize

Methods inherited from Macro

#function_like?, #initialize, #location, #name, #replacement_list

Methods included from LocationHolder

#analysis_target?

Constructor Details

This class inherits a constructor from AdLint::Cpp::FunctionLikeMacro

Instance Method Details

#expand(toks, macro_tbl, repl_ctxt) ⇒ Object



407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/adlint/cpp/macro.rb', line 407

def expand(toks, macro_tbl, repl_ctxt)
  super

  all_args, * = parse_arguments(toks, 1)
  args = all_args.shift(@parameter_names.size)
  rest_args = all_args

  args_hash =
    @parameter_names.zip(args).each_with_object({}) { |(param, arg), hash|
      hash[param] = arg
    }

  va_args = args_hash["__VA_ARGS__"] = []
  unless rest_args.empty?
    va_args.concat(rest_args.shift)
    rest_args.each do |arg|
      va_args.push(ReplacedToken.new(:PP_TOKEN, ",", Location.new))
      va_args.concat(arg)
    end
  end

  rslt_toks = expand_replacement_list(args_hash, toks.first.location,
                                      macro_tbl, repl_ctxt)
  macro_tbl.notify_function_like_macro_replacement(self, toks, args,
                                                   rslt_toks)
  rslt_toks
end

#replaceable_size(toks) ⇒ Object



398
399
400
401
402
403
404
405
# File 'lib/adlint/cpp/macro.rb', line 398

def replaceable_size(toks)
  if name.value == toks.first.value
    args, idx = parse_arguments(toks, 1)
    args ? idx + 1 : 0
  else
    0
  end
end