1 //===- TemplateInstCallback.h - Template Instantiation Callback - C++ --===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===---------------------------------------------------------------------===//
9 // This file defines the TemplateInstantiationCallback class, which is the
10 // base class for callbacks that will be notified at template instantiations.
12 //===---------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_TEMPLATE_INST_CALLBACK_H
15 #define LLVM_CLANG_TEMPLATE_INST_CALLBACK_H
17 #include "clang/Sema/Sema.h"
21 /// This is a base class for callbacks that will be notified at every
22 /// template instantiation.
23 class TemplateInstantiationCallback {
25 virtual ~TemplateInstantiationCallback() = default;
27 /// Called before doing AST-parsing.
28 virtual void initialize(const Sema &TheSema) = 0;
30 /// Called after AST-parsing is completed.
31 virtual void finalize(const Sema &TheSema) = 0;
33 /// Called when instantiation of a template just began.
34 virtual void atTemplateBegin(const Sema &TheSema,
35 const Sema::CodeSynthesisContext &Inst) = 0;
37 /// Called when instantiation of a template is just about to end.
38 virtual void atTemplateEnd(const Sema &TheSema,
39 const Sema::CodeSynthesisContext &Inst) = 0;
42 template <class TemplateInstantiationCallbackPtrs>
43 void initialize(TemplateInstantiationCallbackPtrs &Callbacks,
44 const Sema &TheSema) {
45 for (auto &C : Callbacks) {
47 C->initialize(TheSema);
51 template <class TemplateInstantiationCallbackPtrs>
52 void finalize(TemplateInstantiationCallbackPtrs &Callbacks,
53 const Sema &TheSema) {
54 for (auto &C : Callbacks) {
60 template <class TemplateInstantiationCallbackPtrs>
61 void atTemplateBegin(TemplateInstantiationCallbackPtrs &Callbacks,
63 const Sema::CodeSynthesisContext &Inst) {
64 for (auto &C : Callbacks) {
66 C->atTemplateBegin(TheSema, Inst);
70 template <class TemplateInstantiationCallbackPtrs>
71 void atTemplateEnd(TemplateInstantiationCallbackPtrs &Callbacks,
73 const Sema::CodeSynthesisContext &Inst) {
74 for (auto &C : Callbacks) {
76 C->atTemplateEnd(TheSema, Inst);