1 //===- TemplateInstCallback.h - Template Instantiation Callback - C++ --===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===---------------------------------------------------------------------===//
10 // This file defines the TemplateInstantiationCallback class, which is the
11 // base class for callbacks that will be notified at template instantiations.
13 //===---------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_TEMPLATE_INST_CALLBACK_H
16 #define LLVM_CLANG_TEMPLATE_INST_CALLBACK_H
18 #include "clang/Sema/Sema.h"
22 /// This is a base class for callbacks that will be notified at every
23 /// template instantiation.
24 class TemplateInstantiationCallback {
26 virtual ~TemplateInstantiationCallback() = default;
28 /// Called before doing AST-parsing.
29 virtual void initialize(const Sema &TheSema) = 0;
31 /// Called after AST-parsing is completed.
32 virtual void finalize(const Sema &TheSema) = 0;
34 /// Called when instantiation of a template just began.
35 virtual void atTemplateBegin(const Sema &TheSema,
36 const Sema::CodeSynthesisContext &Inst) = 0;
38 /// Called when instantiation of a template is just about to end.
39 virtual void atTemplateEnd(const Sema &TheSema,
40 const Sema::CodeSynthesisContext &Inst) = 0;
43 template <class TemplateInstantiationCallbackPtrs>
44 void initialize(TemplateInstantiationCallbackPtrs &Callbacks,
45 const Sema &TheSema) {
46 for (auto &C : Callbacks) {
48 C->initialize(TheSema);
52 template <class TemplateInstantiationCallbackPtrs>
53 void finalize(TemplateInstantiationCallbackPtrs &Callbacks,
54 const Sema &TheSema) {
55 for (auto &C : Callbacks) {
61 template <class TemplateInstantiationCallbackPtrs>
62 void atTemplateBegin(TemplateInstantiationCallbackPtrs &Callbacks,
64 const Sema::CodeSynthesisContext &Inst) {
65 for (auto &C : Callbacks) {
67 C->atTemplateBegin(TheSema, Inst);
71 template <class TemplateInstantiationCallbackPtrs>
72 void atTemplateEnd(TemplateInstantiationCallbackPtrs &Callbacks,
74 const Sema::CodeSynthesisContext &Inst) {
75 for (auto &C : Callbacks) {
77 C->atTemplateEnd(TheSema, Inst);