This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

semantic of used_define cpp callback?


Hi,

libcpp/cpplib.h defines:

  /* Callbacks for when a macro is expanded, or tested (whether
     defined or not at the time) in #ifdef, #ifndef or "defined".  */
  void (*used_define) (cpp_reader *, unsigned int, cpp_hashnode *);
  void (*used_undef) (cpp_reader *, unsigned int, cpp_hashnode *);

now, consider the following simple code:

1: #define FOO foo1
2: 
3: int main()
4: {
5:    FOO(1);
6:    foo1(2);
7:    FOO(3);
8: }

The used_define callback is called at line 5, but not at line 7.
So it seems there's an inconsistency.

Is the intent that used_define should only be called when used in an #ifdef
as explained by the documented, or also when expanded in the source code?

Assuming the former (as per the comments), there's apparently a bug at line 5
where the callback should not trigger, or the comment should be updated to
reflect the implementation (e.g. callback triggered on first expansion if the
macro hasn't be previousely tested).

If the above is correct, what I'm interested in is a callback that will be
called each time a macro is expanded or tested *anywhere* in the source
code (for the purpose of generating cross-reference info for macros),
so would the addition of a new callback (e.g.
  void (*used) (cpp_reader *, unsigned int, cpp_hashnode *);
) be acceptable in principle? If so, I'll post a formal patch on gcc-patches@

Arno


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]