[cfe-dev] Header Pasting and ASTMatchers
Farzad Sadeghi via cfe-dev
cfe-dev at lists.llvm.org
Mon Dec 12 18:31:22 PST 2016
ok, problem solved.
turns out it was happening because there is something wrong with the
compilation database.
i started using a compilation databse for the test codes and that was
the problem, not the PPCallbacks.
if i just call the tool with `--` instead of using my compilation
database, i wont see the headers twice.
the headers have inclusion guards so not sure why that's happening but
anyways, the problem was my CMake file.
thanks for your time.
On 12/12/16, Farzad Sadeghi <thabogre at gmail.com> wrote:
> also the same is true for PPCallbacks.
> what i mean is, if for example, i have a macro in a file that's
> included in another file, i see the macro twice. and the
> SourceLocation also tells me that the macro's are both in file A and
> the file that included File A.
> For ASTMatchers in MatchFinder::MatchCallback, the SourcLocation says
> that the two copies are in the same header file. My only proof for
> this one is that it is being matched twice. And I've tried my theory
> for other MatchFinderCallbacks as well. They all act like this now. as
> soon as there is a match in the header file, it is matched twice(it is
> matched twice since the header file is only included in one other
> file).
> The Code is from an open-source project on Github.
> Would you like me to provide a link?
>
> On 12/12/16, Farzad Sadeghi <thabogre at gmail.com> wrote:
>> 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
>>
>
>
> --
> Farzad Sadeghi
>
--
Farzad Sadeghi
More information about the cfe-dev
mailing list