<div dir="ltr">On Mon, Jun 3, 2013 at 5:27 PM, Vane, Edwin <span dir="ltr"><<a href="mailto:edwin.vane@intel.com" target="_blank">edwin.vane@intel.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
<br>
> -----Original Message-----<br>
> From: Manuel Klimek [mailto:<a href="mailto:klimek@google.com">klimek@google.com</a>]<br>
</div><div class="im">> Sent: Monday, June 03, 2013 11:17 AM<br>
> To: Vane, Edwin<br>
> Cc: <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> Subject: Re: r182864 - Tooling: Call back for both begin and end of sources<br>
><br>
</div><div class="im">> On Mon, Jun 3, 2013 at 5:06 PM, Vane, Edwin <<a href="mailto:edwin.vane@intel.com">edwin.vane@intel.com</a>> wrote:<br>
><br>
><br>
> This was the sort of question I had originally: is a begin callback useful<br>
> enough to be put in Tooling code? Then I thought: if an end callback is available<br>
> it only makes sense to have a begin callback for symmetry. Otherwise, one day<br>
> someone will come along and, like me, say: "Here's an end callback but no begin<br>
> callback but it's the begin callback I really want. Why is it missing?"<br>
><br>
><br>
><br>
> Well, "why is it missing" is easy to answer: the minimal needed solution to run a<br>
> clang tool is to hook into the end callback.<br>
<br>
</div>What do you mean? Before making the interface change I went searching for usages of the end callback and found none. I presumed there must be some third-party code somewhere that needed it.<br></blockquote><div><br>
</div><div style>Ah, right, /me got confused.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
> If the callback is a problem I'll remove it and add a custom<br>
> FrontendAction where it's needed in the migrator.<br>
><br>
><br>
> I don't think it's harmful (as it's usually not in the "visible" interface space<br>
> anyway).<br>
><br>
> One question is whether we need the CompilerInstance in the callback, as that is<br>
> a kind of coupling that goes beyond interface symmetry ...<br>
<br>
</div>I'm not sure how CompilerInstance figures with symmetry. It's there because it's provided by the </blockquote><div><br></div><div style>Well, it doesn't figure with symmetry :)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
FrontendAction and why would we hide that information? The argument already has one user: the add-override transform in the migrator to get access to the Preprocessor object. From what I've read on the lifetime of CompilerInstance this method of access seemed in-line with design philosophy.<br>
</blockquote><div style><br>Well, in general, I'd try to keep interfaces as small as possible, and only hand through more dependencies when needed. It's not that lifetime is a problem, but that as a user of that interface I would ask myself "why do I get the compiler instance here?", which means a user has to understand that, possibly look into the interface, etc. If you already have a place where it's used, that's fine...</div>
<div style> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
> Thoughts?<br>
> /Manuel<br>
><br>
><br>
><br>
> > -----Original Message-----<br>
> > From: Manuel Klimek [mailto:<a href="mailto:klimek@google.com">klimek@google.com</a>]<br>
> > Sent: Monday, June 03, 2013 8:59 AM<br>
> > To: Vane, Edwin<br>
> > Cc: <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> > Subject: Re: r182864 - Tooling: Call back for both begin and end of<br>
> sources<br>
> ><br>
> > Hmm... My main concern is whether this is really common enough that<br>
> we don't<br>
> > want to just write FrontendActions for where we need it (it's not hard<br>
> to write<br>
> > your own FrontendAction - the methods in tooling are mainly there to<br>
> make the<br>
> > very common use cases less code to write).<br>
> ><br>
> ><br>
> > On Wed, May 29, 2013 at 6:01 PM, Edwin Vane<br>
> <<a href="mailto:edwin.vane@intel.com">edwin.vane@intel.com</a>> wrote:<br>
> ><br>
> ><br>
> > Author: revane<br>
> > Date: Wed May 29 11:01:10 2013<br>
> > New Revision: 182864<br>
> ><br>
> > URL: <a href="http://llvm.org/viewvc/llvm-project?rev=182864&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=182864&view=rev</a><br>
> > Log:<br>
> > Tooling: Call back for both begin and end of sources<br>
> ><br>
> > newFrontendActionFactory() took a pointer to a callback to call<br>
> when a<br>
> > source<br>
> > file was done being processed by an action. This revision updates<br>
> the<br>
> > callback<br>
> > to include an ante-processing callback as well.<br>
> ><br>
> > Callback-providing class renamed and callback functions<br>
> themselves<br>
> > renamed.<br>
> > Functions are no longer pure-virtual so users aren't forced to<br>
> implement<br>
> > both<br>
> > callbacks if one isn't needed.<br>
> ><br>
> ><br>
> > Modified:<br>
> > cfe/trunk/include/clang/Tooling/Tooling.h<br>
> > cfe/trunk/unittests/Tooling/ToolingTest.cpp<br>
> ><br>
> > Modified: cfe/trunk/include/clang/Tooling/Tooling.h<br>
> > URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> ><br>
> project/cfe/trunk/include/clang/Tooling/Tooling.h?rev=182864&r1=182863&r2<br>
> > =182864&view=diff<br>
> ><br>
> ==========================================================<br>
> > ====================<br>
> > --- cfe/trunk/include/clang/Tooling/Tooling.h (original)<br>
> > +++ cfe/trunk/include/clang/Tooling/Tooling.h Wed May 29<br>
> 11:01:10<br>
> > 2013<br>
> > @@ -74,12 +74,22 @@ public:<br>
> > template <typename T><br>
> > FrontendActionFactory *newFrontendActionFactory();<br>
> ><br>
> > -/// \brief Called at the end of each source file when used with<br>
> > -/// \c newFrontendActionFactory.<br>
> > -class EndOfSourceFileCallback {<br>
> > +/// \brief Callbacks called before and after each source file<br>
> processed<br>
> > by a<br>
> > +/// FrontendAction created by the FrontedActionFactory returned<br>
> by \c<br>
> > +/// newFrontendActionFactory.<br>
> > +class SourceFileCallbacks {<br>
> > public:<br>
> > - virtual ~EndOfSourceFileCallback() {}<br>
> > - virtual void run() = 0;<br>
> > + virtual ~SourceFileCallbacks() {}<br>
> > +<br>
> > + /// \brief Called before a source file is processed by a<br>
> FrontEndAction.<br>
> ><br>
> ><br>
> ><br>
> > FrontendAction.<br>
> ><br>
> ><br>
> > + /// \see clang::FrontendAction::BeginSourceFileAction<br>
> > + virtual bool BeginSource(CompilerInstance &CI, StringRef<br>
> Filename) {<br>
> > + return true;<br>
> > + }<br>
> > +<br>
> > + /// \brief Called after a source file is processed by a<br>
> FrontendAction.<br>
> > + /// \see clang::FrontendAction::EndSourceFileAction<br>
> > + virtual void EndSource() {}<br>
> > };<br>
> ><br>
> > /// \brief Returns a new FrontendActionFactory for any type that<br>
> > provides an<br>
> > @@ -95,7 +105,7 @@ public:<br>
> > /// newFrontendActionFactory(&Factory);<br>
> > template <typename FactoryT><br>
> > inline FrontendActionFactory *newFrontendActionFactory(<br>
> > - FactoryT *ConsumerFactory, EndOfSourceFileCallback<br>
> *EndCallback<br>
> > = NULL);<br>
> > + FactoryT *ConsumerFactory, SourceFileCallbacks *Callbacks =<br>
> > NULL);<br>
> ><br>
> > /// \brief Runs (and deletes) the tool on 'Code' with the -fsyntax-<br>
> only<br>
> > flag.<br>
> > ///<br>
> > @@ -226,23 +236,23 @@ FrontendActionFactory<br>
> *newFrontendAction<br>
> ><br>
> > template <typename FactoryT><br>
> > inline FrontendActionFactory *newFrontendActionFactory(<br>
> > - FactoryT *ConsumerFactory, EndOfSourceFileCallback<br>
> *EndCallback)<br>
> > {<br>
> > + FactoryT *ConsumerFactory, SourceFileCallbacks *Callbacks) {<br>
> > class FrontendActionFactoryAdapter : public<br>
> FrontendActionFactory {<br>
> > public:<br>
> > explicit FrontendActionFactoryAdapter(FactoryT<br>
> *ConsumerFactory,<br>
> > - EndOfSourceFileCallback *EndCallback)<br>
> > - : ConsumerFactory(ConsumerFactory),<br>
> EndCallback(EndCallback) {}<br>
> > + SourceFileCallbacks *Callbacks)<br>
> > + : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}<br>
> ><br>
> > virtual clang::FrontendAction *create() {<br>
> > - return new ConsumerFactoryAdaptor(ConsumerFactory,<br>
> > EndCallback);<br>
> > + return new ConsumerFactoryAdaptor(ConsumerFactory,<br>
> Callbacks);<br>
> > }<br>
> ><br>
> > private:<br>
> > class ConsumerFactoryAdaptor : public<br>
> clang::ASTFrontendAction {<br>
> > public:<br>
> > ConsumerFactoryAdaptor(FactoryT *ConsumerFactory,<br>
> > - EndOfSourceFileCallback *EndCallback)<br>
> > - : ConsumerFactory(ConsumerFactory),<br>
> EndCallback(EndCallback) {}<br>
> > + SourceFileCallbacks *Callbacks)<br>
> > + : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}<br>
> ><br>
> > clang::ASTConsumer<br>
> *CreateASTConsumer(clang::CompilerInstance<br>
> > &,<br>
> > StringRef) {<br>
> > @@ -250,21 +260,29 @@ inline FrontendActionFactory<br>
> *newFronten<br>
> > }<br>
> ><br>
> > protected:<br>
> > - virtual void EndSourceFileAction() {<br>
> > - if (EndCallback != NULL)<br>
> > - EndCallback->run();<br>
> > + virtual bool BeginSourceFileAction(CompilerInstance &CI,<br>
> > + StringRef Filename) LLVM_OVERRIDE {<br>
> > + if (!clang::ASTFrontendAction::BeginSourceFileAction(CI,<br>
> > Filename))<br>
> > + return false;<br>
> > + if (Callbacks != NULL)<br>
> > + return Callbacks->BeginSource(CI, Filename);<br>
> > + return true;<br>
> > + }<br>
> > + virtual void EndSourceFileAction() LLVM_OVERRIDE {<br>
> > + if (Callbacks != NULL)<br>
> > + Callbacks->EndSource();<br>
> > clang::ASTFrontendAction::EndSourceFileAction();<br>
> > }<br>
> ><br>
> > private:<br>
> > FactoryT *ConsumerFactory;<br>
> > - EndOfSourceFileCallback *EndCallback;<br>
> > + SourceFileCallbacks *Callbacks;<br>
> > };<br>
> > FactoryT *ConsumerFactory;<br>
> > - EndOfSourceFileCallback *EndCallback;<br>
> > + SourceFileCallbacks *Callbacks;<br>
> > };<br>
> ><br>
> > - return new FrontendActionFactoryAdapter(ConsumerFactory,<br>
> > EndCallback);<br>
> > + return new FrontendActionFactoryAdapter(ConsumerFactory,<br>
> > Callbacks);<br>
> > }<br>
> ><br>
> > /// \brief Returns the absolute path of \c File, by prepending it<br>
> with<br>
> ><br>
> > Modified: cfe/trunk/unittests/Tooling/ToolingTest.cpp<br>
> > URL: <a href="http://llvm.org/viewvc/llvm-" target="_blank">http://llvm.org/viewvc/llvm-</a><br>
> ><br>
> project/cfe/trunk/unittests/Tooling/ToolingTest.cpp?rev=182864&r1=182863&r<br>
> > 2=182864&view=diff<br>
> ><br>
> ==========================================================<br>
> > ====================<br>
> > --- cfe/trunk/unittests/Tooling/ToolingTest.cpp (original)<br>
> > +++ cfe/trunk/unittests/Tooling/ToolingTest.cpp Wed May 29<br>
> 11:01:10<br>
> > 2013<br>
> > @@ -131,20 +131,26 @@ TEST(ToolInvocation,<br>
> TestMapVirtualFile)<br>
> > EXPECT_TRUE(Invocation.run());<br>
> > }<br>
> ><br>
> > -struct VerifyEndCallback : public EndOfSourceFileCallback {<br>
> > - VerifyEndCallback() : Called(0), Matched(false) {}<br>
> > - virtual void run() {<br>
> > - ++Called;<br>
> > +struct VerifyEndCallback : public SourceFileCallbacks {<br>
> > + VerifyEndCallback() : BeginCalled(0), EndCalled(0),<br>
> Matched(false) {}<br>
> > + virtual bool BeginSource(CompilerInstance &CI,<br>
> > + StringRef Filename) LLVM_OVERRIDE {<br>
> > + ++BeginCalled;<br>
> > + return true;<br>
> > + }<br>
> > + virtual void EndSource() {<br>
> > + ++EndCalled;<br>
> > }<br>
> > ASTConsumer *newASTConsumer() {<br>
> > return new FindTopLevelDeclConsumer(&Matched);<br>
> > }<br>
> > - unsigned Called;<br>
> > + unsigned BeginCalled;<br>
> > + unsigned EndCalled;<br>
> > bool Matched;<br>
> > };<br>
> ><br>
> > #if !defined(_WIN32)<br>
> > -TEST(newFrontendActionFactory, InjectsEndOfSourceFileCallback)<br>
> {<br>
> > +TEST(newFrontendActionFactory, InjectsSourceFileCallbacks) {<br>
> > VerifyEndCallback EndCallback;<br>
> ><br>
> > FixedCompilationDatabase Compilations("/",<br>
> > std::vector<std::string>());<br>
> > @@ -159,7 +165,8 @@ TEST(newFrontendActionFactory, InjectsEn<br>
> > Tool.run(newFrontendActionFactory(&EndCallback,<br>
> &EndCallback));<br>
> ><br>
> > EXPECT_TRUE(EndCallback.Matched);<br>
> > - EXPECT_EQ(2u, EndCallback.Called);<br>
> > + EXPECT_EQ(2u, EndCallback.BeginCalled);<br>
> > + EXPECT_EQ(2u, EndCallback.EndCalled);<br>
> > }<br>
> > #endif<br>
> ><br>
> ><br>
> ><br>
> > _______________________________________________<br>
> > cfe-commits mailing list<br>
> > <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
> ><br>
> ><br>
><br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div></div>