Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:37:05

0001 //===- TemplateInstCallback.h - Template Instantiation Callback - C++ --===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===---------------------------------------------------------------------===//
0008 //
0009 // This file defines the TemplateInstantiationCallback class, which is the
0010 // base class for callbacks that will be notified at template instantiations.
0011 //
0012 //===---------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_CLANG_SEMA_TEMPLATEINSTCALLBACK_H
0015 #define LLVM_CLANG_SEMA_TEMPLATEINSTCALLBACK_H
0016 
0017 #include "clang/Sema/Sema.h"
0018 
0019 namespace clang {
0020 
0021 /// This is a base class for callbacks that will be notified at every
0022 /// template instantiation.
0023 class TemplateInstantiationCallback {
0024 public:
0025   virtual ~TemplateInstantiationCallback() = default;
0026 
0027   /// Called before doing AST-parsing.
0028   virtual void initialize(const Sema &TheSema) = 0;
0029 
0030   /// Called after AST-parsing is completed.
0031   virtual void finalize(const Sema &TheSema) = 0;
0032 
0033   /// Called when instantiation of a template just began.
0034   virtual void atTemplateBegin(const Sema &TheSema,
0035                                const Sema::CodeSynthesisContext &Inst) = 0;
0036 
0037   /// Called when instantiation of a template is just about to end.
0038   virtual void atTemplateEnd(const Sema &TheSema,
0039                              const Sema::CodeSynthesisContext &Inst) = 0;
0040 };
0041 
0042 template <class TemplateInstantiationCallbackPtrs>
0043 void initialize(TemplateInstantiationCallbackPtrs &Callbacks,
0044                 const Sema &TheSema) {
0045   for (auto &C : Callbacks) {
0046     if (C)
0047       C->initialize(TheSema);
0048   }
0049 }
0050 
0051 template <class TemplateInstantiationCallbackPtrs>
0052 void finalize(TemplateInstantiationCallbackPtrs &Callbacks,
0053               const Sema &TheSema) {
0054   for (auto &C : Callbacks) {
0055     if (C)
0056       C->finalize(TheSema);
0057   }
0058 }
0059 
0060 template <class TemplateInstantiationCallbackPtrs>
0061 void atTemplateBegin(TemplateInstantiationCallbackPtrs &Callbacks,
0062                      const Sema &TheSema,
0063                      const Sema::CodeSynthesisContext &Inst) {
0064   for (auto &C : Callbacks) {
0065     if (C)
0066       C->atTemplateBegin(TheSema, Inst);
0067   }
0068 }
0069 
0070 template <class TemplateInstantiationCallbackPtrs>
0071 void atTemplateEnd(TemplateInstantiationCallbackPtrs &Callbacks,
0072                    const Sema &TheSema,
0073                    const Sema::CodeSynthesisContext &Inst) {
0074   for (auto &C : Callbacks) {
0075     if (C)
0076       C->atTemplateEnd(TheSema, Inst);
0077   }
0078 }
0079 
0080 } // namespace clang
0081 
0082 #endif