Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===--- ExternalSemaSource.h - External Sema Interface ---------*- 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 ExternalSemaSource interface.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 #ifndef LLVM_CLANG_SEMA_EXTERNALSEMASOURCE_H
0013 #define LLVM_CLANG_SEMA_EXTERNALSEMASOURCE_H
0014 
0015 #include "clang/AST/ExternalASTSource.h"
0016 #include "clang/AST/Type.h"
0017 #include "clang/Sema/TypoCorrection.h"
0018 #include "clang/Sema/Weak.h"
0019 #include "llvm/ADT/MapVector.h"
0020 #include <utility>
0021 
0022 namespace llvm {
0023 template <class T, unsigned n> class SmallSetVector;
0024 }
0025 
0026 namespace clang {
0027 
0028 class CXXConstructorDecl;
0029 class CXXRecordDecl;
0030 class DeclaratorDecl;
0031 class LookupResult;
0032 class Scope;
0033 class Sema;
0034 class TypedefNameDecl;
0035 class ValueDecl;
0036 class VarDecl;
0037 struct LateParsedTemplate;
0038 
0039 /// A simple structure that captures a vtable use for the purposes of
0040 /// the \c ExternalSemaSource.
0041 struct ExternalVTableUse {
0042   CXXRecordDecl *Record;
0043   SourceLocation Location;
0044   bool DefinitionRequired;
0045 };
0046 
0047 /// An abstract interface that should be implemented by
0048 /// external AST sources that also provide information for semantic
0049 /// analysis.
0050 class ExternalSemaSource : public ExternalASTSource {
0051   /// LLVM-style RTTI.
0052   static char ID;
0053 
0054 public:
0055   ExternalSemaSource() = default;
0056 
0057   ~ExternalSemaSource() override;
0058 
0059   /// Initialize the semantic source with the Sema instance
0060   /// being used to perform semantic analysis on the abstract syntax
0061   /// tree.
0062   virtual void InitializeSema(Sema &S) {}
0063 
0064   /// Inform the semantic consumer that Sema is no longer available.
0065   virtual void ForgetSema() {}
0066 
0067   /// Load the contents of the global method pool for a given
0068   /// selector.
0069   virtual void ReadMethodPool(Selector Sel);
0070 
0071   /// Load the contents of the global method pool for a given
0072   /// selector if necessary.
0073   virtual void updateOutOfDateSelector(Selector Sel);
0074 
0075   /// Load the set of namespaces that are known to the external source,
0076   /// which will be used during typo correction.
0077   virtual void ReadKnownNamespaces(
0078                            SmallVectorImpl<NamespaceDecl *> &Namespaces);
0079 
0080   /// Load the set of used but not defined functions or variables with
0081   /// internal linkage, or used but not defined internal functions.
0082   virtual void
0083   ReadUndefinedButUsed(llvm::MapVector<NamedDecl *, SourceLocation> &Undefined);
0084 
0085   virtual void ReadMismatchingDeleteExpressions(llvm::MapVector<
0086       FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &);
0087 
0088   /// Do last resort, unqualified lookup on a LookupResult that
0089   /// Sema cannot find.
0090   ///
0091   /// \param R a LookupResult that is being recovered.
0092   ///
0093   /// \param S the Scope of the identifier occurrence.
0094   ///
0095   /// \return true to tell Sema to recover using the LookupResult.
0096   virtual bool LookupUnqualified(LookupResult &R, Scope *S) { return false; }
0097 
0098   /// Read the set of tentative definitions known to the external Sema
0099   /// source.
0100   ///
0101   /// The external source should append its own tentative definitions to the
0102   /// given vector of tentative definitions. Note that this routine may be
0103   /// invoked multiple times; the external source should take care not to
0104   /// introduce the same declarations repeatedly.
0105   virtual void ReadTentativeDefinitions(
0106                                   SmallVectorImpl<VarDecl *> &TentativeDefs) {}
0107 
0108   /// Read the set of unused file-scope declarations known to the
0109   /// external Sema source.
0110   ///
0111   /// The external source should append its own unused, filed-scope to the
0112   /// given vector of declarations. Note that this routine may be
0113   /// invoked multiple times; the external source should take care not to
0114   /// introduce the same declarations repeatedly.
0115   virtual void ReadUnusedFileScopedDecls(
0116                  SmallVectorImpl<const DeclaratorDecl *> &Decls) {}
0117 
0118   /// Read the set of delegating constructors known to the
0119   /// external Sema source.
0120   ///
0121   /// The external source should append its own delegating constructors to the
0122   /// given vector of declarations. Note that this routine may be
0123   /// invoked multiple times; the external source should take care not to
0124   /// introduce the same declarations repeatedly.
0125   virtual void ReadDelegatingConstructors(
0126                  SmallVectorImpl<CXXConstructorDecl *> &Decls) {}
0127 
0128   /// Read the set of ext_vector type declarations known to the
0129   /// external Sema source.
0130   ///
0131   /// The external source should append its own ext_vector type declarations to
0132   /// the given vector of declarations. Note that this routine may be
0133   /// invoked multiple times; the external source should take care not to
0134   /// introduce the same declarations repeatedly.
0135   virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) {}
0136 
0137   /// Read the set of potentially unused typedefs known to the source.
0138   ///
0139   /// The external source should append its own potentially unused local
0140   /// typedefs to the given vector of declarations. Note that this routine may
0141   /// be invoked multiple times; the external source should take care not to
0142   /// introduce the same declarations repeatedly.
0143   virtual void ReadUnusedLocalTypedefNameCandidates(
0144       llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) {}
0145 
0146   /// Read the set of referenced selectors known to the
0147   /// external Sema source.
0148   ///
0149   /// The external source should append its own referenced selectors to the
0150   /// given vector of selectors. Note that this routine
0151   /// may be invoked multiple times; the external source should take care not
0152   /// to introduce the same selectors repeatedly.
0153   virtual void ReadReferencedSelectors(
0154                  SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {}
0155 
0156   /// Read the set of weak, undeclared identifiers known to the
0157   /// external Sema source.
0158   ///
0159   /// The external source should append its own weak, undeclared identifiers to
0160   /// the given vector. Note that this routine may be invoked multiple times;
0161   /// the external source should take care not to introduce the same identifiers
0162   /// repeatedly.
0163   virtual void ReadWeakUndeclaredIdentifiers(
0164                  SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) {}
0165 
0166   /// Read the set of used vtables known to the external Sema source.
0167   ///
0168   /// The external source should append its own used vtables to the given
0169   /// vector. Note that this routine may be invoked multiple times; the external
0170   /// source should take care not to introduce the same vtables repeatedly.
0171   virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) {}
0172 
0173   /// Read the set of pending instantiations known to the external
0174   /// Sema source.
0175   ///
0176   /// The external source should append its own pending instantiations to the
0177   /// given vector. Note that this routine may be invoked multiple times; the
0178   /// external source should take care not to introduce the same instantiations
0179   /// repeatedly.
0180   virtual void ReadPendingInstantiations(
0181                  SmallVectorImpl<std::pair<ValueDecl *,
0182                                            SourceLocation> > &Pending) {}
0183 
0184   /// Read the set of late parsed template functions for this source.
0185   ///
0186   /// The external source should insert its own late parsed template functions
0187   /// into the map. Note that this routine may be invoked multiple times; the
0188   /// external source should take care not to introduce the same map entries
0189   /// repeatedly.
0190   virtual void ReadLateParsedTemplates(
0191       llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
0192           &LPTMap) {}
0193 
0194   /// Read the set of decls to be checked for deferred diags.
0195   ///
0196   /// The external source should append its own potentially emitted function
0197   /// and variable decls which may cause deferred diags. Note that this routine
0198   /// may be invoked multiple times; the external source should take care not to
0199   /// introduce the same declarations repeatedly.
0200   virtual void
0201   ReadDeclsToCheckForDeferredDiags(llvm::SmallSetVector<Decl *, 4> &Decls) {}
0202 
0203   /// \copydoc Sema::CorrectTypo
0204   /// \note LookupKind must correspond to a valid Sema::LookupNameKind
0205   ///
0206   /// ExternalSemaSource::CorrectTypo is always given the first chance to
0207   /// correct a typo (really, to offer suggestions to repair a failed lookup).
0208   /// It will even be called when SpellChecking is turned off or after a
0209   /// fatal error has already been detected.
0210   virtual TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,
0211                                      int LookupKind, Scope *S, CXXScopeSpec *SS,
0212                                      CorrectionCandidateCallback &CCC,
0213                                      DeclContext *MemberContext,
0214                                      bool EnteringContext,
0215                                      const ObjCObjectPointerType *OPT) {
0216     return TypoCorrection();
0217   }
0218 
0219   /// Produces a diagnostic note if the external source contains a
0220   /// complete definition for \p T.
0221   ///
0222   /// \param Loc the location at which a complete type was required but not
0223   /// provided
0224   ///
0225   /// \param T the \c QualType that should have been complete at \p Loc
0226   ///
0227   /// \return true if a diagnostic was produced, false otherwise.
0228   virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc,
0229                                                 QualType T) {
0230     return false;
0231   }
0232 
0233   /// Notify the external source that a lambda was assigned a mangling number.
0234   /// This enables the external source to track the correspondence between
0235   /// lambdas and mangling numbers if necessary.
0236   virtual void AssignedLambdaNumbering(CXXRecordDecl *Lambda) {}
0237 
0238   /// LLVM-style RTTI.
0239   /// \{
0240   bool isA(const void *ClassID) const override {
0241     return ClassID == &ID || ExternalASTSource::isA(ClassID);
0242   }
0243   static bool classof(const ExternalASTSource *S) { return S->isA(&ID); }
0244   /// \}
0245 };
0246 
0247 } // end namespace clang
0248 
0249 #endif