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(); 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 dynamic classes known to the external Sema source. 132 /// 133 /// The external source should append its own dynamic classes to 134 /// the given vector of declarations. Note that this routine may be 135 /// invoked multiple times; the external source should take care not to 136 /// introduce the same declarations repeatedly. ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl * > & Decls)137 virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) {} 138 139 /// \brief Read the set of potentially unused typedefs known to the source. 140 /// 141 /// The external source should append its own potentially unused local 142 /// typedefs to the given vector of declarations. Note that this routine may 143 /// be invoked multiple times; the external source should take care not to 144 /// introduce the same declarations repeatedly. ReadUnusedLocalTypedefNameCandidates(llvm::SmallSetVector<const TypedefNameDecl *,4> & Decls)145 virtual void ReadUnusedLocalTypedefNameCandidates( 146 llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) {}; 147 148 /// \brief Read the set of locally-scoped external declarations known to the 149 /// external Sema source. 150 /// 151 /// The external source should append its own locally-scoped external 152 /// declarations to the given vector of declarations. Note that this routine 153 /// may be invoked multiple times; the external source should take care not 154 /// to introduce the same declarations repeatedly. ReadLocallyScopedExternCDecls(SmallVectorImpl<NamedDecl * > & Decls)155 virtual void ReadLocallyScopedExternCDecls( 156 SmallVectorImpl<NamedDecl *> &Decls) {} 157 158 /// \brief Read the set of referenced selectors known to the 159 /// external Sema source. 160 /// 161 /// The external source should append its own referenced selectors to the 162 /// given vector of selectors. Note that this routine 163 /// may be invoked multiple times; the external source should take care not 164 /// to introduce the same selectors repeatedly. ReadReferencedSelectors(SmallVectorImpl<std::pair<Selector,SourceLocation>> & Sels)165 virtual void ReadReferencedSelectors( 166 SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {} 167 168 /// \brief Read the set of weak, undeclared identifiers known to the 169 /// external Sema source. 170 /// 171 /// The external source should append its own weak, undeclared identifiers to 172 /// the given vector. Note that this routine may be invoked multiple times; 173 /// the external source should take care not to introduce the same identifiers 174 /// repeatedly. ReadWeakUndeclaredIdentifiers(SmallVectorImpl<std::pair<IdentifierInfo *,WeakInfo>> & WI)175 virtual void ReadWeakUndeclaredIdentifiers( 176 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) {} 177 178 /// \brief Read the set of used vtables known to the external Sema source. 179 /// 180 /// The external source should append its own used vtables to the given 181 /// vector. Note that this routine may be invoked multiple times; the external 182 /// source should take care not to introduce the same vtables repeatedly. ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> & VTables)183 virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) {} 184 185 /// \brief Read the set of pending instantiations known to the external 186 /// Sema source. 187 /// 188 /// The external source should append its own pending instantiations to the 189 /// given vector. Note that this routine may be invoked multiple times; the 190 /// external source should take care not to introduce the same instantiations 191 /// repeatedly. ReadPendingInstantiations(SmallVectorImpl<std::pair<ValueDecl *,SourceLocation>> & Pending)192 virtual void ReadPendingInstantiations( 193 SmallVectorImpl<std::pair<ValueDecl *, 194 SourceLocation> > &Pending) {} 195 196 /// \brief Read the set of late parsed template functions for this source. 197 /// 198 /// The external source should insert its own late parsed template functions 199 /// into the map. Note that this routine may be invoked multiple times; the 200 /// external source should take care not to introduce the same map entries 201 /// repeatedly. ReadLateParsedTemplates(llvm::DenseMap<const FunctionDecl *,LateParsedTemplate * > & LPTMap)202 virtual void ReadLateParsedTemplates( 203 llvm::DenseMap<const FunctionDecl *, LateParsedTemplate *> &LPTMap) {} 204 205 /// \copydoc Sema::CorrectTypo 206 /// \note LookupKind must correspond to a valid Sema::LookupNameKind 207 /// 208 /// ExternalSemaSource::CorrectTypo is always given the first chance to 209 /// correct a typo (really, to offer suggestions to repair a failed lookup). 210 /// It will even be called when SpellChecking is turned off or after a 211 /// 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)212 virtual TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, 213 int LookupKind, Scope *S, CXXScopeSpec *SS, 214 CorrectionCandidateCallback &CCC, 215 DeclContext *MemberContext, 216 bool EnteringContext, 217 const ObjCObjectPointerType *OPT) { 218 return TypoCorrection(); 219 } 220 221 /// \brief Produces a diagnostic note if the external source contains a 222 /// complete definition for \p T. 223 /// 224 /// \param Loc the location at which a complete type was required but not 225 /// provided 226 /// 227 /// \param T the \c QualType that should have been complete at \p Loc 228 /// 229 /// \return true if a diagnostic was produced, false otherwise. MaybeDiagnoseMissingCompleteType(SourceLocation Loc,QualType T)230 virtual bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc, 231 QualType T) { 232 return false; 233 } 234 235 // isa/cast/dyn_cast support classof(const ExternalASTSource * Source)236 static bool classof(const ExternalASTSource *Source) { 237 return Source->SemaSource; 238 } 239 }; 240 241 } // end namespace clang 242 243 #endif 244