Clang::preprocessor handle include directives

Hi,

would anybody help me to handle directives file parsing AST.

I have tried the following, but it does not help:

llvm_include_handler* h = new llvm_include_handler;
m_preprocessor->addPPCallbacks(h); // m_preprocessor is type of clang::Preprocessor*

where llvm_include_handler is defined as:

class llvm_include_handler :
public clang::PPCallbacks
{
public:
virtual void InclusionDirective(clang::SourceLocation,
const clang::Token& ,
llvm::StringRef FileName,
bool IsAngled,
const clang::FileEntry*,
clang::SourceLocation,
llvm::StringRef SearchPath,
llvm::StringRef RelativePath)
{
std::cout << "include "<< std::endl;
std::cout << FileName.str() << std::endl;
std::cout << "IsAngled " << IsAngled << std::endl;
std::cout << SearchPath.str() << std::endl;
std::cout << RelativePath.str() << std::endl;
}

virtual ~llvm_include_handler() throw()
{}
};

than I call clang::ParseAST() to parse the AST nodes with my ASTConsumer. The InclusionDirective is not called.
What have I missed.

Thanks,
Anna.

Seems right to me. Are you sure that m_preprocessor is the preprocessor
used by clang?

2011/4/29 Anna Lu <annaruben85@gmail.com>

It seems:
clang::ParseAST(m_preprocessor, m_ast_handler, a); // a is clang::ASTContext.
I add the main source file to m_preprocessor and it works.

Regards,
Anna.