MultiplexExternalSemaSource.h revision 651f13cea278ec967336033dd032faef0e9fc2ec
1//===--- MultiplexExternalSemaSource.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 ExternalSemaSource interface, dispatching to all clients 11// 12//===----------------------------------------------------------------------===// 13#ifndef LLVM_CLANG_SEMA_MULTIPLEX_EXTERNAL_SEMA_SOURCE_H 14#define LLVM_CLANG_SEMA_MULTIPLEX_EXTERNAL_SEMA_SOURCE_H 15 16#include "clang/Sema/ExternalSemaSource.h" 17#include "clang/Sema/Weak.h" 18#include "llvm/ADT/SmallVector.h" 19#include <utility> 20 21namespace clang { 22 23 class CXXConstructorDecl; 24 class CXXRecordDecl; 25 class DeclaratorDecl; 26 struct ExternalVTableUse; 27 class LookupResult; 28 class NamespaceDecl; 29 class Scope; 30 class Sema; 31 class TypedefNameDecl; 32 class ValueDecl; 33 class VarDecl; 34 35 36/// \brief An abstract interface that should be implemented by 37/// external AST sources that also provide information for semantic 38/// analysis. 39class MultiplexExternalSemaSource : public ExternalSemaSource { 40 41private: 42 SmallVector<ExternalSemaSource *, 2> Sources; // doesn't own them. 43 44public: 45 46 ///\brief Constructs a new multiplexing external sema source and appends the 47 /// given element to it. 48 /// 49 ///\param[in] s1 - A non-null (old) ExternalSemaSource. 50 ///\param[in] s2 - A non-null (new) ExternalSemaSource. 51 /// 52 MultiplexExternalSemaSource(ExternalSemaSource& s1, ExternalSemaSource& s2); 53 54 ~MultiplexExternalSemaSource(); 55 56 ///\brief Appends new source to the source list. 57 /// 58 ///\param[in] source - An ExternalSemaSource. 59 /// 60 void addSource(ExternalSemaSource &source); 61 62 //===--------------------------------------------------------------------===// 63 // ExternalASTSource. 64 //===--------------------------------------------------------------------===// 65 66 /// \brief Resolve a declaration ID into a declaration, potentially 67 /// building a new declaration. 68 Decl *GetExternalDecl(uint32_t ID) override; 69 70 /// \brief Resolve a selector ID into a selector. 71 Selector GetExternalSelector(uint32_t ID) override; 72 73 /// \brief Returns the number of selectors known to the external AST 74 /// source. 75 uint32_t GetNumExternalSelectors() override; 76 77 /// \brief Resolve the offset of a statement in the decl stream into 78 /// a statement. 79 Stmt *GetExternalDeclStmt(uint64_t Offset) override; 80 81 /// \brief Resolve the offset of a set of C++ base specifiers in the decl 82 /// stream into an array of specifiers. 83 CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override; 84 85 /// \brief Find all declarations with the given name in the 86 /// given context. 87 bool 88 FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) override; 89 90 /// \brief Ensures that the table of all visible declarations inside this 91 /// context is up to date. 92 void completeVisibleDeclsMap(const DeclContext *DC) override; 93 94 /// \brief Finds all declarations lexically contained within the given 95 /// DeclContext, after applying an optional filter predicate. 96 /// 97 /// \param isKindWeWant a predicate function that returns true if the passed 98 /// declaration kind is one we are looking for. If NULL, all declarations 99 /// are returned. 100 /// 101 /// \return an indication of whether the load succeeded or failed. 102 ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC, 103 bool (*isKindWeWant)(Decl::Kind), 104 SmallVectorImpl<Decl*> &Result) override; 105 106 /// \brief Finds all declarations lexically contained within the given 107 /// DeclContext. 108 /// 109 /// \return true if an error occurred 110 ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC, 111 SmallVectorImpl<Decl*> &Result) { 112 return FindExternalLexicalDecls(DC, 0, Result); 113 } 114 115 template <typename DeclTy> 116 ExternalLoadResult FindExternalLexicalDeclsBy(const DeclContext *DC, 117 SmallVectorImpl<Decl*> &Result) { 118 return FindExternalLexicalDecls(DC, DeclTy::classofKind, Result); 119 } 120 121 /// \brief Get the decls that are contained in a file in the Offset/Length 122 /// range. \p Length can be 0 to indicate a point at \p Offset instead of 123 /// a range. 124 void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length, 125 SmallVectorImpl<Decl *> &Decls) override; 126 127 /// \brief Gives the external AST source an opportunity to complete 128 /// an incomplete type. 129 void CompleteType(TagDecl *Tag) override; 130 131 /// \brief Gives the external AST source an opportunity to complete an 132 /// incomplete Objective-C class. 133 /// 134 /// This routine will only be invoked if the "externally completed" bit is 135 /// set on the ObjCInterfaceDecl via the function 136 /// \c ObjCInterfaceDecl::setExternallyCompleted(). 137 void CompleteType(ObjCInterfaceDecl *Class) override; 138 139 /// \brief Loads comment ranges. 140 void ReadComments() override; 141 142 /// \brief Notify ExternalASTSource that we started deserialization of 143 /// a decl or type so until FinishedDeserializing is called there may be 144 /// decls that are initializing. Must be paired with FinishedDeserializing. 145 void StartedDeserializing() override; 146 147 /// \brief Notify ExternalASTSource that we finished the deserialization of 148 /// a decl or type. Must be paired with StartedDeserializing. 149 void FinishedDeserializing() override; 150 151 /// \brief Function that will be invoked when we begin parsing a new 152 /// translation unit involving this external AST source. 153 void StartTranslationUnit(ASTConsumer *Consumer) override; 154 155 /// \brief Print any statistics that have been gathered regarding 156 /// the external AST source. 157 void PrintStats() override; 158 159 160 /// \brief Perform layout on the given record. 161 /// 162 /// This routine allows the external AST source to provide an specific 163 /// layout for a record, overriding the layout that would normally be 164 /// constructed. It is intended for clients who receive specific layout 165 /// details rather than source code (such as LLDB). The client is expected 166 /// to fill in the field offsets, base offsets, virtual base offsets, and 167 /// complete object size. 168 /// 169 /// \param Record The record whose layout is being requested. 170 /// 171 /// \param Size The final size of the record, in bits. 172 /// 173 /// \param Alignment The final alignment of the record, in bits. 174 /// 175 /// \param FieldOffsets The offset of each of the fields within the record, 176 /// expressed in bits. All of the fields must be provided with offsets. 177 /// 178 /// \param BaseOffsets The offset of each of the direct, non-virtual base 179 /// classes. If any bases are not given offsets, the bases will be laid 180 /// out according to the ABI. 181 /// 182 /// \param VirtualBaseOffsets The offset of each of the virtual base classes 183 /// (either direct or not). If any bases are not given offsets, the bases will 184 /// be laid out according to the ABI. 185 /// 186 /// \returns true if the record layout was provided, false otherwise. 187 bool 188 layoutRecordType(const RecordDecl *Record, 189 uint64_t &Size, uint64_t &Alignment, 190 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets, 191 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets, 192 llvm::DenseMap<const CXXRecordDecl *, 193 CharUnits> &VirtualBaseOffsets) override; 194 195 /// Return the amount of memory used by memory buffers, breaking down 196 /// by heap-backed versus mmap'ed memory. 197 void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override; 198 199 //===--------------------------------------------------------------------===// 200 // ExternalSemaSource. 201 //===--------------------------------------------------------------------===// 202 203 /// \brief Initialize the semantic source with the Sema instance 204 /// being used to perform semantic analysis on the abstract syntax 205 /// tree. 206 void InitializeSema(Sema &S) override; 207 208 /// \brief Inform the semantic consumer that Sema is no longer available. 209 void ForgetSema() override; 210 211 /// \brief Load the contents of the global method pool for a given 212 /// selector. 213 void ReadMethodPool(Selector Sel) override; 214 215 /// \brief Load the set of namespaces that are known to the external source, 216 /// which will be used during typo correction. 217 void 218 ReadKnownNamespaces(SmallVectorImpl<NamespaceDecl*> &Namespaces) override; 219 220 /// \brief Load the set of used but not defined functions or variables with 221 /// internal linkage, or used but not defined inline functions. 222 void ReadUndefinedButUsed( 223 llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined) override; 224 225 /// \brief Do last resort, unqualified lookup on a LookupResult that 226 /// Sema cannot find. 227 /// 228 /// \param R a LookupResult that is being recovered. 229 /// 230 /// \param S the Scope of the identifier occurrence. 231 /// 232 /// \return true to tell Sema to recover using the LookupResult. 233 bool LookupUnqualified(LookupResult &R, Scope *S) override; 234 235 /// \brief Read the set of tentative definitions known to the external Sema 236 /// source. 237 /// 238 /// The external source should append its own tentative definitions to the 239 /// given vector of tentative definitions. Note that this routine may be 240 /// invoked multiple times; the external source should take care not to 241 /// introduce the same declarations repeatedly. 242 void ReadTentativeDefinitions(SmallVectorImpl<VarDecl*> &Defs) override; 243 244 /// \brief Read the set of unused file-scope declarations known to the 245 /// external Sema source. 246 /// 247 /// The external source should append its own unused, filed-scope to the 248 /// given vector of declarations. Note that this routine may be 249 /// invoked multiple times; the external source should take care not to 250 /// introduce the same declarations repeatedly. 251 void ReadUnusedFileScopedDecls( 252 SmallVectorImpl<const DeclaratorDecl*> &Decls) override; 253 254 /// \brief Read the set of delegating constructors known to the 255 /// external Sema source. 256 /// 257 /// The external source should append its own delegating constructors to the 258 /// given vector of declarations. Note that this routine may be 259 /// invoked multiple times; the external source should take care not to 260 /// introduce the same declarations repeatedly. 261 void ReadDelegatingConstructors( 262 SmallVectorImpl<CXXConstructorDecl*> &Decls) override; 263 264 /// \brief Read the set of ext_vector type declarations known to the 265 /// external Sema source. 266 /// 267 /// The external source should append its own ext_vector type declarations to 268 /// the given vector of declarations. Note that this routine may be 269 /// invoked multiple times; the external source should take care not to 270 /// introduce the same declarations repeatedly. 271 void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl*> &Decls) override; 272 273 /// \brief Read the set of dynamic classes known to the external Sema source. 274 /// 275 /// The external source should append its own dynamic classes to 276 /// the given vector of declarations. Note that this routine may be 277 /// invoked multiple times; the external source should take care not to 278 /// introduce the same declarations repeatedly. 279 void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl*> &Decls) override; 280 281 /// \brief Read the set of locally-scoped extern "C" declarations known to the 282 /// external Sema source. 283 /// 284 /// The external source should append its own locally-scoped external 285 /// declarations to the given vector of declarations. Note that this routine 286 /// may be invoked multiple times; the external source should take care not 287 /// to introduce the same declarations repeatedly. 288 void ReadLocallyScopedExternCDecls( 289 SmallVectorImpl<NamedDecl*> &Decls) override; 290 291 /// \brief Read the set of referenced selectors known to the 292 /// external Sema source. 293 /// 294 /// The external source should append its own referenced selectors to the 295 /// given vector of selectors. Note that this routine 296 /// may be invoked multiple times; the external source should take care not 297 /// to introduce the same selectors repeatedly. 298 void ReadReferencedSelectors(SmallVectorImpl<std::pair<Selector, 299 SourceLocation> > &Sels) override; 300 301 /// \brief Read the set of weak, undeclared identifiers known to the 302 /// external Sema source. 303 /// 304 /// The external source should append its own weak, undeclared identifiers to 305 /// the given vector. Note that this routine may be invoked multiple times; 306 /// the external source should take care not to introduce the same identifiers 307 /// repeatedly. 308 void ReadWeakUndeclaredIdentifiers( 309 SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) override; 310 311 /// \brief Read the set of used vtables known to the external Sema source. 312 /// 313 /// The external source should append its own used vtables to the given 314 /// vector. Note that this routine may be invoked multiple times; the external 315 /// source should take care not to introduce the same vtables repeatedly. 316 void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override; 317 318 /// \brief Read the set of pending instantiations known to the external 319 /// Sema source. 320 /// 321 /// The external source should append its own pending instantiations to the 322 /// given vector. Note that this routine may be invoked multiple times; the 323 /// external source should take care not to introduce the same instantiations 324 /// repeatedly. 325 void ReadPendingInstantiations( 326 SmallVectorImpl<std::pair<ValueDecl*, SourceLocation> >& Pending) override; 327 328 /// \brief Read the set of late parsed template functions for this source. 329 /// 330 /// The external source should insert its own late parsed template functions 331 /// into the map. Note that this routine may be invoked multiple times; the 332 /// external source should take care not to introduce the same map entries 333 /// repeatedly. 334 void ReadLateParsedTemplates( 335 llvm::DenseMap<const FunctionDecl *, 336 LateParsedTemplate *> &LPTMap) override; 337 338 /// \copydoc ExternalSemaSource::CorrectTypo 339 /// \note Returns the first nonempty correction. 340 TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, 341 int LookupKind, Scope *S, CXXScopeSpec *SS, 342 CorrectionCandidateCallback &CCC, 343 DeclContext *MemberContext, 344 bool EnteringContext, 345 const ObjCObjectPointerType *OPT) override; 346 347 /// \brief Produces a diagnostic note if one of the attached sources 348 /// contains a complete definition for \p T. Queries the sources in list 349 /// order until the first one claims that a diagnostic was produced. 350 /// 351 /// \param Loc the location at which a complete type was required but not 352 /// provided 353 /// 354 /// \param T the \c QualType that should have been complete at \p Loc 355 /// 356 /// \return true if a diagnostic was produced, false otherwise. 357 bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc, 358 QualType T) override; 359 360 // isa/cast/dyn_cast support 361 static bool classof(const MultiplexExternalSemaSource*) { return true; } 362 //static bool classof(const ExternalSemaSource*) { return true; } 363}; 364 365} // end namespace clang 366 367#endif // LLVM_CLANG_SEMA_MULTIPLEX_EXTERNAL_SEMA_SOURCE_H 368