[cfe-dev] A Question regarding Macros

Farzad Sadeghi via cfe-dev cfe-dev at lists.llvm.org
Sat Dec 10 13:43:55 PST 2016


Is there a way to find out that a macro definition that I'm seeing
because of a PPCallbacks::MacroDefined is from the mainfile itself or
from an included file?

I'm trying to see whether a macro has been defined within a block or
not. my idea was first i store the sourcelocation of the macro
definition i get and then i check them against the begin and end
sourcelocaitons that i get from a matcher matching functiondecl that
are definitions.
the problem i have is that when a file includes another file that has
macro defs, they get pasted at the top of that file and so i see that
definition twice, once inside the original file and once inside the
file that includes it(my frontend action is a ASTfrontendAction and i
add PPCallbacks inside CreateASTConsumer using CompilerInstance). and
the sourcelocation for that will not be the same as the ones I'll get
from when matching an AST so my check is useless for those macros.

-- 
Farzad Sadeghi



More information about the cfe-dev mailing list