1 //===--- ExternalSemaSource.h - External Sema Interface ---------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines the ExternalSemaSource interface. 11 // 12 //===----------------------------------------------------------------------===// 13 #ifndef LLVM_CLANG_SEMA_EXTERNALSEMASOURCE_H 14 #define LLVM_CLANG_SEMA_EXTERNALSEMASOURCE_H 15 16 #include "clang/AST/ExternalASTSource.h" 17 #include "clang/AST/Type.h" 18 #include "clang/Sema/TypoCorrection.h" 19 #include "clang/Sema/Weak.h" 20 #include "llvm/ADT/MapVector.h" 21 #include <utility> 22 23 namespace llvm { 24 template <class T, unsigned n> class SmallSetVector; 25 } 26 27 namespace clang { 28 29 class CXXConstructorDecl; 30 class CXXRecordDecl; 31 class DeclaratorDecl; 32 class LookupResult; 33 struct ObjCMethodList; 34 class Scope; 35 class Sema; 36 class TypedefNameDecl; 37 class ValueDecl; 38 class VarDecl; 39 struct LateParsedTemplate; 40 41 /// \brief A simple structure that captures a vtable use for the purposes of 42 /// the \c ExternalSemaSource. 43 struct ExternalVTableUse { 44 CXXRecordDecl *Record; 45 SourceLocation Location; 46 bool DefinitionRequired; 47 }; 48 49 /// \brief An abstract interface that should be implemented by 50 /// external AST sources that also provide information for semantic 51 /// analysis. 52 class ExternalSemaSource : public ExternalASTSource { 53 public: ExternalSemaSource()54 ExternalSemaSource() { 55 ExternalASTSource::SemaSource = true; 56 } 57 58 ~ExternalSemaSource() override; 59 60 /// \brief Initialize the semantic source with the Sema instance 61 /// being used to perform semantic analysis on the abstract syntax 62 /// tree. InitializeSema(Sema & S)63 virtual void InitializeSema(Sema &S) {} 64 65 /// \brief Inform the semantic consumer that Sema is no longer available. ForgetSema()66 virtual void ForgetSema() {} 67 68 /// \brief Load the contents of the global method pool for a given 69 /// selector. 70 virtual void ReadMethodPool(Selector Sel); 71 72 /// \brief Load the set of namespaces that are known to the external source, 73 /// which will be used during typo correction. 74 virtual void ReadKnownNamespaces( 75 SmallVectorImpl<NamespaceDecl *> &Namespaces); 76 77 /// \brief Load the set of used but not defined functions or variables with 78 /// internal linkage, or used but not defined internal functions. 79 virtual void ReadUndefinedButUsed( 80 llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined); 81 82 /// \brief Do last resort, unqualified lookup on a LookupResult that 83 /// Sema cannot find. 84 /// 85 /// \param R a LookupResult that is being recovered. 86 /// 87 /// \param S the Scope of the identifier occurrence. 88 /// 89 /// \return true to tell Sema to recover using the LookupResult. LookupUnqualified(LookupResult & R,Scope * S)90 virtual bool LookupUnqualified(LookupResult &R, Scope *S) { return false; } 91 92 /// \brief Read the set of tentative definitions known to the external Sema 93 /// source. 94 /// 95 /// The external source should append its own tentative definitions to the 96 /// given vector of tentative definitions. Note that this routine may be 97 /// invoked multiple times; the external source should take care not to 98 /// introduce the same declarations repeatedly. ReadTentativeDefinitions(SmallVectorImpl<VarDecl * > & TentativeDefs)99 virtual void ReadTentativeDefinitions( 100 SmallVectorImpl<VarDecl *> &TentativeDefs) {} 101 102 /// \brief Read the set of unused file-scope declarations known to the 103 /// external Sema source. 104 /// 105 /// The external source should append its own unused, filed-scope to the 106 /// given vector of declarations. Note that this routine may be 107 /// invoked multiple times; the external source should take care not to 108 /// introduce the same declarations repeatedly. ReadUnusedFileScopedDecls(SmallVectorImpl<const DeclaratorDecl * > & Decls)109 virtual void ReadUnusedFileScopedDecls( 110 SmallVectorImpl<const DeclaratorDecl *> &Decls) {} 111 112 /// \brief Read the set of delegating constructors known to the 113 /// external Sema source. 114 /// 115 /// The external source should append its own delegating constructors to the 116 /// given vector of declarations. Note that this routine may be 117 /// invoked multiple times; the external source should take care not to 118 /// introduce the same declarations repeatedly. ReadDelegatingConstructors(SmallVectorImpl<CXXConstructorDecl * > & Decls)119 virtual void ReadDelegatingConstructors( 120 SmallVectorImpl<CXXConstructorDecl *> &Decls) {} 121 122 /// \brief Read the set of ext_vector type declarations known to the 123 /// external Sema source. 124 /// 125 /// The external source should append its own ext_vector type declarations to 126 /// the given vector of declarations. Note that this routine may be 127 /// invoked multiple times; the external source should take care not to 128 /// introduce the same declarations repeatedly. ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl * > & Decls)129 virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) {} 130 131 /// \brief Read the set of potentially unused typedefs known to the source. 132 /// 133 /// The external source should append its own potentially unused local 134 /// typedefs to the given vector of declarations. Note that this routine may 135 /// be invoked multiple times; the external source should take care not to 136 /// introduce the same declarations repeatedly. ReadUnusedLocalTypedefNameCandidates(llvm::SmallSetVector<const TypedefNameDecl *,4> & Decls)137 virtual void ReadUnusedLocalTypedefNameCandidates( 138 llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) {}; 139 140 /// \brief Read the set of referenced selectors known to the 141 /// external Sema source. 142 /// 143 /// The external source should append its own referenced selectors to the 144 /// given vector of selectors. Note that this routine 145 /// may be invoked multiple times; the external source should take care not 146 /// to introduce the same selectors repeatedly. ReadReferencedSelectors(SmallVectorImpl<std::pair<Selector,SourceLocation>> & Sels)147 virtual void ReadReferencedSelectors( 148 SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {} 149 150 /// \brief Read the set of weak, undeclared identifiers known to the 151 /// external Sema source. 152 /// 153 /// The external source should append its own weak, undeclared identifiers to 154 /// the given vector. Note that this routine may be invoked multiple times; 155 /// the external source should take care not to introduce the same identifiers 156 /// repeatedly. ReadWeakUndeclaredIdentifiers(SmallVectorImpl<std::pair<IdentifierInfo *,WeakInfo>> & WI)157 virtual void ReadWeakUndeclaredIdentifiers( 158 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) {} 159 160 /// \brief Read the set of used vtables known to the external Sema source. 161 /// 162 /// The external source should append its own used vtables to the given 163 /// vector. Note that this routine may be invoked multiple times; the external 164 /// source should take care not to introduce the same vtables repeatedly. ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> & VTables)165 virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) {} 166 167 /// \brief Read the set of pending instantiations known to the external 168 /// Sema source. 169 /// 170 /// The external source should append its own pending instantiations to the 171 /// given vector. Note that this routine may be invoked multiple times; the 172 /// external source should take care not to introduce the same instantiations 173 /// repeatedly. ReadPendingInstantiations(SmallVectorImpl<std::pair<ValueDecl *,SourceLocation>> & Pending)174 virtual void ReadPendingInstantiations( 175 SmallVectorImpl<std::pair<ValueDecl *, 176 SourceLocation> > &Pending) {} 177 178 /// \brief Read the set of late parsed template functions for this source. 179 /// 180 /// The external source should insert its own late parsed template functions 181 /// into the map. Note that this routine may be invoked multiple times; the 182 /// external source should take care not to introduce the same map entries 183 /// repeatedly. ReadLateParsedTemplates(llvm::MapVector<const FunctionDecl *,LateParsedTemplate * > & LPTMap)184 virtual void ReadLateParsedTemplates( 185 llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap) {} 186 187 /// \copydoc Sema::CorrectTypo 188 /// \note LookupKind must correspond to a valid Sema::LookupNameKind 189 /// 190 /// ExternalSemaSource::CorrectTypo is always given the first chance to 191 /// correct a typo (really, to offer suggestions to repair a failed lookup). 192 /// It will even be called when SpellChecking is turned off or after a 193 /// fatal error has already been detected. CorrectTypo(const DeclarationNameInfo & Typo,int LookupKind,Scope * S,CXXScopeSpec * SS,CorrectionCandidateCallback & CCC,DeclContext * MemberContext,bool EnteringContext,const ObjCObjectPointerType * OPT)194 virtual TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, 195 int LookupKind, Scope *S, CXXScopeSpec *SS, 196 CorrectionCandidateCallback &CCC, 197 DeclContext *MemberContext, 198 bool EnteringContext, 199 const ObjCObjectPointerType *OPT) { 200 return TypoCorrection(); 201 } 202 203 /// \brief Produces a diagnostic note if the external source contains a 204 /// complete definition for \p T. 205 /// 206 /// \param Loc the location at which a complete type was required but not 207 /// provided 208 /// 209 /// \param T the \c QualType that should have been complete at \p Loc 210 /// 211 /// \return true if a diagnostic was produced, false otherwise. MaybeDiagnoseMissingCompleteType(SourceLocation Loc,QualType T)212 virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc, 213 QualType T) { 214 return false; 215 } 216 217 // isa/cast/dyn_cast support classof(const ExternalASTSource * Source)218 static bool classof(const ExternalASTSource *Source) { 219 return Source->SemaSource; 220 } 221 }; 222 223 } // end namespace clang 224 225 #endif 226