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