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