[cfe-dev] Header Pasting and ASTMatchers

Farzad Sadeghi via cfe-dev cfe-dev at lists.llvm.org
Mon Dec 12 04:57:47 PST 2016


this is the ASTConsumer:
class MyFrontendAction : public ASTFrontendAction
{
public:
  MyFrontendAction() {}

  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef file) override
  {
    CI.getPreprocessor().addPPCallbacks(llvm::make_unique<PPInclusion>(&CI.getSourceManager()));

    TheRewriter.setSourceMgr(CI.getSourceManager(), CI.getLangOpts());
    return llvm::make_unique<MyASTConsumer>(TheRewriter);
  }

private:
  Rewriter TheRewriter;
};

here's the class containing the callbacks:
class PPInclusion : public PPCallbacks
{
public:
  explicit PPInclusion (SourceManager *SM) : SM(*SM) {}

  /*bunch of callbacks here*/

private:
  const SourceManager &SM;
};

On 12/12/16, Benjamin Kramer <benny.kra at gmail.com> wrote:
> You shouldn't be seeing the AST twice. Can you show the code where you
> set up PPCallbacks?
>
> On Sun, Dec 11, 2016 at 10:23 PM, Farzad Sadeghi via cfe-dev
> <cfe-dev at lists.llvm.org> wrote:
>> I have an ASTFronendAction that runs some matchers and has some
>> PPCallbacks.
>> Ever since i added the PPCallbacks, I'm getting the AST of a source
>> file that has the headers actually pasted at the top of it, so if
>> something's in an included file, i'm matching it twice.
>> is there a way to check for that when a MatchFinder::Callback is
>> called or is there a way to tell the Preprocessor to not paste the
>> headers at the top of the source files that included them?
>>
>> --
>> Farzad Sadeghi
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>


-- 
Farzad Sadeghi



More information about the cfe-dev mailing list