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]

Re: About trees and expanded code by macros


Alberto Lozano Alelu <alelus@gmail.com> a Ãcrit:

> Hello.

Hello Alberto,

> I'am developing an statement detector for c++ and I would like to
> detect if an statement is expanded from macro.

I guess you are doing this from a plugin?

> Can I detect in ast tree if an statement is expanded code from macro?

As Manuel has said in another thread, if you are using GCC 4.7, you need
to have the option -ftrack-macro-expansion turned on.

Then, in the code, you need to get a handle on a token (instance of
cp_token, defined in gcc/cp/parser.h) of your statement.  The information
you are looking for is basically encoded in the cp_token::location field.

The function you want to use on that cp_token::location field is
line_map_location_from_macro_expansion_p, declared and commented in
libcpp/include/line-map.h.  The argument for the first parameter of that
function is the global variable named "line_table".

If you are using the current development version of GCC from trunk (that
is going to be 4.8), then you don't even need to pass
-ftrack-macro-expansion to the compiler as it is turned on by default.

For versions earlier than 4.7, I am afraid you cannot have the
information you want without (at least) patching the interface between
the parser and the pre-processor.

I hope this helps.

-- 
		Dodji


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