This is an archive of the discontinued LLVM Phabricator instance.

[clang] Add PPCallbacks list to preprocessor when building a preacompiled preamble.
ClosedPublic

Authored by Nebiroth on Oct 27 2017, 8:38 AM.

Details

Summary

Revision D38639 needs this commit in order to properly make open definition calls on include statements work.
Since this modifies clang and not clangd, I decided to include it in a different patch.

Diff Detail

Repository
rL LLVM

Event Timeline

Nebiroth created this revision.Oct 27 2017, 8:38 AM
malaperle edited edge metadata.Oct 27 2017, 9:38 AM

Can you revert the formatting changes in places you haven’t touched (mainly astunit.cpp)? I think you should be able to do that with git checkout -p HEAD~1

ilya-biryukov requested changes to this revision.Nov 8 2017, 4:24 AM

Could you please take a different approach and add the callbacks you need into PreambleCallbacks class?
It already has this one:

virtual void HandleMacroDefined(const Token &MacroNameTok,
                               const MacroDirective *MD);

Otherwise we'll be creating too many ways to do the same thing.

We should also definitely get rid of all the unrelated formatting changes.

This revision now requires changes to proceed.Nov 8 2017, 4:24 AM
Nebiroth updated this revision to Diff 125815.Dec 6 2017, 2:19 PM
Nebiroth edited edge metadata.

Reverted formatting changes to ASTUnit

ilya-biryukov requested changes to this revision.Dec 7 2017, 5:42 AM
ilya-biryukov added inline comments.
lib/Frontend/PrecompiledPreamble.cpp
242 ↗(On Diff #125815)

Could we add a method to PreambleCallbacks to create PPCallbacks instead?
Otherwise we have both MacroDefined in PreambleCallbacks and a separate set of PPCallbacks, so we have two ways of doing the same thing.

class PreambleCallbacks {
public:
// ...

  /// Remove this.
  virtual void HandleMacroDefined(...);

  // Add this instead.
  virtual std::unique_ptr<PPCallbacks> createPPCallbacks();

}

Alternatively, follow the current pattern in PreambleCallbacks and add some extra functions from the PPCallbacks interface to it. This would not require changes to the existing usages of PrecompiledPreamble in ASTUnit. Albeit, I'd prefer the first option.

class PreambleCallbacks {
public:
// ...

  // Keep this
  virtual void HandleMacroDefined(...);
  // Add the ones you need, e.g.
  virtual void InclusionDirective(...);
  virtual void FileChanged(...);
};
This revision now requires changes to proceed.Dec 7 2017, 5:42 AM
Nebiroth added inline comments.Dec 7 2017, 11:32 AM
lib/Frontend/PrecompiledPreamble.cpp
242 ↗(On Diff #125815)

If we were to do that, one would then be required to define a wrapper class for PPCallbacks and create an instance of it inside createPPCallbacks() for the purpose of creating a unique_ptr? Then that unique_ptr would be sent from within the PreambleCallbacks parameter in the Build function?

ilya-biryukov added inline comments.Dec 8 2017, 2:26 AM
lib/Frontend/PrecompiledPreamble.cpp
242 ↗(On Diff #125815)

We're already passing our own wrapper around PreambleCallbacks anyway (see PreambleMacroCallbacks), we'll pass the unique_ptr<PPCallbacks> instead.
But, yes, the clients will have to write their own implementation of PPCallbacks and pass it as unique_ptr. Is there something wrong with that?

Or, have I misunderstood the question entirely?

Nebiroth added inline comments.Dec 8 2017, 6:42 AM
lib/Frontend/PrecompiledPreamble.cpp
242 ↗(On Diff #125815)

No this is fine. I was just making sure I understood correctly.

Nebiroth updated this revision to Diff 126430.Dec 11 2017, 12:58 PM
Nebiroth edited edge metadata.

Removed unique_ptr parameter in PrecompiledPreamble::Build
Added method createPPCallbacks() in PreambleCallback to be overriden

malaperle requested changes to this revision.Dec 14 2017, 7:12 AM
malaperle added inline comments.
include/clang/Frontend/PrecompiledPreamble.h
263 ↗(On Diff #126430)

It doesn't add, it creates.It's also not a "list". Is it true that it will process includes outside the preamble? I would think building the preamble stopped at the end of the preamble.

lib/Frontend/PrecompiledPreamble.cpp
354 ↗(On Diff #126430)

extract this to a local variable

This revision now requires changes to proceed.Dec 14 2017, 7:12 AM
Nebiroth updated this revision to Diff 126984.Dec 14 2017, 9:43 AM
Nebiroth marked an inline comment as done.

Minor code cleanup

malaperle accepted this revision.Dec 14 2017, 9:04 PM

Looks good to me. But this is not really my area :)

ilya-biryukov accepted this revision.Dec 15 2017, 3:28 AM

LGTM modulo a few comments.
AFAIK, @Nebiroth does not have a commit access, so I'll land this with minor tweaks to unblock the other patch.

include/clang/Frontend/PrecompiledPreamble.h
261 ↗(On Diff #126984)

This method can now be removed as its use-case is now covered by createPPCallbacks

lib/Frontend/PrecompiledPreamble.cpp
716 ↗(On Diff #126984)

Please clang-format the code when submitting patches.

This revision is now accepted and ready to land.Dec 15 2017, 3:28 AM
This revision was automatically updated to reflect the committed changes.