/* Part of CPP library. (Macro and #define handling.)
Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1998,
1999, 2000, 2001, 2002, 2003, 2004, 2005,
- 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+ 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
Written by Per Bothner, 1994.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
source_location **);
static size_t tokens_buff_count (_cpp_buff *);
static const cpp_token **tokens_buff_last_token_ptr (_cpp_buff *);
-static const cpp_token **tokens_buff_put_token_to (const cpp_token **,
- source_location *,
- const cpp_token *,
- source_location,
- source_location,
- const struct line_map *,
- unsigned int);
+static inline const cpp_token **tokens_buff_put_token_to (const cpp_token **,
+ source_location *,
+ const cpp_token *,
+ source_location,
+ source_location,
+ const struct line_map *,
+ unsigned int);
static const cpp_token **tokens_buff_add_token (_cpp_buff *,
source_location *,
source_location,
const struct line_map *,
unsigned int);
-static void tokens_buff_remove_last_token (_cpp_buff *);
+static inline void tokens_buff_remove_last_token (_cpp_buff *);
static void replace_args (cpp_reader *, cpp_hashnode *, cpp_macro *,
macro_arg *, source_location);
static _cpp_buff *funlike_invocation_p (cpp_reader *, cpp_hashnode *,
source_location *);
static const cpp_token* cpp_get_token_1 (cpp_reader *, source_location *);
+/* Statistical counter tracking the number of macros that got
+ expanded. */
+unsigned num_expanded_macros_counter = 0;
+/* Statistical counter tracking the total number tokens resulting
+ from macro expansion. */
+unsigned num_macro_tokens_counter = 0;
+
/* Emits a warning if NODE is a macro defined in the main file that
has not been used. */
int
pfile->line_table->highest_line);
else
{
- map = linemap_lookup (pfile->line_table, pfile->line_table->highest_line);
- while (! MAIN_FILE_P (map))
- map = INCLUDED_FROM (pfile->line_table, map);
- name = ORDINARY_MAP_FILE_NAME (map);
+ name = _cpp_get_file_name (pfile->main_file);
+ if (!name)
+ abort ();
}
len = strlen (name);
buf = _cpp_unaligned_alloc (pfile, len * 2 + 3);
(const cpp_token **)
macro_tokens->base,
count);
+ num_macro_tokens_counter += count;
}
else
- _cpp_push_token_context (pfile, node, macro->exp.tokens,
- macro_real_token_count (macro));
+ {
+ unsigned tokens_count = macro_real_token_count (macro);
+ _cpp_push_token_context (pfile, node, macro->exp.tokens,
+ tokens_count);
+ num_macro_tokens_counter += tokens_count;
+ }
}
if (pragma_buff)
padding_token (pfile, result), 1);
do
{
+ unsigned tokens_count;
_cpp_buff *tail = pragma_buff->next;
pragma_buff->next = NULL;
+ tokens_count = ((const cpp_token **) BUFF_FRONT (pragma_buff)
+ - (const cpp_token **) pragma_buff->base);
push_ptoken_context (pfile, NULL, pragma_buff,
(const cpp_token **) pragma_buff->base,
- ((const cpp_token **) BUFF_FRONT (pragma_buff)
- - (const cpp_token **) pragma_buff->base));
+ tokens_count);
pragma_buff = tail;
+ if (!CPP_OPTION (pfile, track_macro_expansion))
+ num_macro_tokens_counter += tokens_count;
+
}
while (pragma_buff != NULL);
return 2;
iter->track_macro_exp_p = track_macro_exp_p;
iter->kind = kind;
iter->token_ptr = token_ptr;
+ /* Unconditionally initialize this so that the compiler doesn't warn
+ about iter->location_ptr being possibly uninitialized later after
+ this code has been inlined somewhere. */
+ iter->location_ptr = NULL;
if (track_macro_exp_p)
iter->location_ptr = get_arg_token_location (arg, kind);
#ifdef ENABLE_CHECKING
else
push_ptoken_context (pfile, node, buff, first,
tokens_buff_count (buff));
+
+ num_macro_tokens_counter += tokens_buff_count (buff);
}
/* Return a special padding token, with padding inherited from SOURCE. */
}
else
{
+ if (pfile->context->c.macro)
+ ++num_expanded_macros_counter;
_cpp_pop_context (pfile);
if (pfile->state.in_directive)
continue;