-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Templight] Template Instantiation Observer
This patch adds a base-class called TemplateInstantiationObserver which gets notified whenever a template instantiation is entered or exited during semantic analysis. This is a base class used to implement the template profiling and debugging tool called Templight (https://github.com/mikael-s-persson/templight). The patch also makes a few more changes: * ActiveTemplateInstantiation class is moved out of the Sema class (so it can be used with inclusion of Sema.h). * CreateFrontendAction function in front-end utilities is given external linkage (not longer a hidden static function). * TemplateInstObserverChain data member added to Sema class to hold the list of template-inst observers. * Notifications to the template-inst observer are added at the key places where templates are instantiated. Patch by: Abel Sinkovics! Differential Revision: https://reviews.llvm.org/D5767 llvm-svn: 324808
- Loading branch information
Showing
25 changed files
with
1,113 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| //===- TemplateInstCallback.h - Template Instantiation Callback - C++ --===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===---------------------------------------------------------------------===// | ||
| // | ||
| // This file defines the TemplateInstantiationCallback class, which is the | ||
| // base class for callbacks that will be notified at template instantiations. | ||
| // | ||
| //===---------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_CLANG_TEMPLATE_INST_CALLBACK_H | ||
| #define LLVM_CLANG_TEMPLATE_INST_CALLBACK_H | ||
|
|
||
| #include "clang/Sema/Sema.h" | ||
|
|
||
| namespace clang { | ||
|
|
||
| /// \brief This is a base class for callbacks that will be notified at every | ||
| /// template instantiation. | ||
| class TemplateInstantiationCallback { | ||
| public: | ||
| virtual ~TemplateInstantiationCallback() = default; | ||
|
|
||
| /// \brief Called before doing AST-parsing. | ||
| virtual void initialize(const Sema &TheSema) = 0; | ||
|
|
||
| /// \brief Called after AST-parsing is completed. | ||
| virtual void finalize(const Sema &TheSema) = 0; | ||
|
|
||
| /// \brief Called when instantiation of a template just began. | ||
| virtual void atTemplateBegin(const Sema &TheSema, | ||
| const Sema::CodeSynthesisContext &Inst) = 0; | ||
|
|
||
| /// \brief Called when instantiation of a template is just about to end. | ||
| virtual void atTemplateEnd(const Sema &TheSema, | ||
| const Sema::CodeSynthesisContext &Inst) = 0; | ||
| }; | ||
|
|
||
| template <class TemplateInstantiationCallbackPtrs> | ||
| void initialize(TemplateInstantiationCallbackPtrs &Callbacks, | ||
| const Sema &TheSema) { | ||
| for (auto &C : Callbacks) { | ||
| if (C) | ||
| C->initialize(TheSema); | ||
| } | ||
| } | ||
|
|
||
| template <class TemplateInstantiationCallbackPtrs> | ||
| void finalize(TemplateInstantiationCallbackPtrs &Callbacks, | ||
| const Sema &TheSema) { | ||
| for (auto &C : Callbacks) { | ||
| if (C) | ||
| C->finalize(TheSema); | ||
| } | ||
| } | ||
|
|
||
| template <class TemplateInstantiationCallbackPtrs> | ||
| void atTemplateBegin(TemplateInstantiationCallbackPtrs &Callbacks, | ||
| const Sema &TheSema, | ||
| const Sema::CodeSynthesisContext &Inst) { | ||
| for (auto &C : Callbacks) { | ||
| if (C) | ||
| C->atTemplateBegin(TheSema, Inst); | ||
| } | ||
| } | ||
|
|
||
| template <class TemplateInstantiationCallbackPtrs> | ||
| void atTemplateEnd(TemplateInstantiationCallbackPtrs &Callbacks, | ||
| const Sema &TheSema, | ||
| const Sema::CodeSynthesisContext &Inst) { | ||
| for (auto &C : Callbacks) { | ||
| if (C) | ||
| C->atTemplateEnd(TheSema, Inst); | ||
| } | ||
| } | ||
|
|
||
| } // namespace clang | ||
|
|
||
| #endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.