|
|
|||
File indexing completed on 2026-05-10 08:37:00
0001 //===--- MultiplexExternalSemaSource.h - External Sema Interface-*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 // 0009 // This file defines ExternalSemaSource interface, dispatching to all clients 0010 // 0011 //===----------------------------------------------------------------------===// 0012 #ifndef LLVM_CLANG_SEMA_MULTIPLEXEXTERNALSEMASOURCE_H 0013 #define LLVM_CLANG_SEMA_MULTIPLEXEXTERNALSEMASOURCE_H 0014 0015 #include "clang/Sema/ExternalSemaSource.h" 0016 #include "clang/Sema/Weak.h" 0017 #include "llvm/ADT/SmallVector.h" 0018 #include <utility> 0019 0020 namespace clang { 0021 0022 class CXXConstructorDecl; 0023 class CXXRecordDecl; 0024 class DeclaratorDecl; 0025 struct ExternalVTableUse; 0026 class LookupResult; 0027 class NamespaceDecl; 0028 class Scope; 0029 class Sema; 0030 class TypedefNameDecl; 0031 class ValueDecl; 0032 class VarDecl; 0033 0034 0035 /// An abstract interface that should be implemented by 0036 /// external AST sources that also provide information for semantic 0037 /// analysis. 0038 class MultiplexExternalSemaSource : public ExternalSemaSource { 0039 /// LLVM-style RTTI. 0040 static char ID; 0041 0042 private: 0043 SmallVector<ExternalSemaSource *, 2> Sources; 0044 0045 public: 0046 /// Constructs a new multiplexing external sema source and appends the 0047 /// given element to it. 0048 /// 0049 ///\param[in] S1 - A non-null (old) ExternalSemaSource. 0050 ///\param[in] S2 - A non-null (new) ExternalSemaSource. 0051 /// 0052 MultiplexExternalSemaSource(ExternalSemaSource *S1, ExternalSemaSource *S2); 0053 0054 ~MultiplexExternalSemaSource() override; 0055 0056 /// Appends new source to the source list. 0057 /// 0058 ///\param[in] Source - An ExternalSemaSource. 0059 /// 0060 void AddSource(ExternalSemaSource *Source); 0061 0062 //===--------------------------------------------------------------------===// 0063 // ExternalASTSource. 0064 //===--------------------------------------------------------------------===// 0065 0066 /// Resolve a declaration ID into a declaration, potentially 0067 /// building a new declaration. 0068 Decl *GetExternalDecl(GlobalDeclID ID) override; 0069 0070 /// Complete the redeclaration chain if it's been extended since the 0071 /// previous generation of the AST source. 0072 void CompleteRedeclChain(const Decl *D) override; 0073 0074 /// Resolve a selector ID into a selector. 0075 Selector GetExternalSelector(uint32_t ID) override; 0076 0077 /// Returns the number of selectors known to the external AST 0078 /// source. 0079 uint32_t GetNumExternalSelectors() override; 0080 0081 /// Resolve the offset of a statement in the decl stream into 0082 /// a statement. 0083 Stmt *GetExternalDeclStmt(uint64_t Offset) override; 0084 0085 /// Resolve the offset of a set of C++ base specifiers in the decl 0086 /// stream into an array of specifiers. 0087 CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override; 0088 0089 /// Resolve a handle to a list of ctor initializers into the list of 0090 /// initializers themselves. 0091 CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override; 0092 0093 ExtKind hasExternalDefinitions(const Decl *D) override; 0094 0095 /// Find all declarations with the given name in the 0096 /// given context. 0097 bool FindExternalVisibleDeclsByName(const DeclContext *DC, 0098 DeclarationName Name, 0099 const DeclContext *OriginalDC) override; 0100 0101 bool LoadExternalSpecializations(const Decl *D, bool OnlyPartial) override; 0102 0103 bool 0104 LoadExternalSpecializations(const Decl *D, 0105 ArrayRef<TemplateArgument> TemplateArgs) override; 0106 0107 /// Ensures that the table of all visible declarations inside this 0108 /// context is up to date. 0109 void completeVisibleDeclsMap(const DeclContext *DC) override; 0110 0111 /// Finds all declarations lexically contained within the given 0112 /// DeclContext, after applying an optional filter predicate. 0113 /// 0114 /// \param IsKindWeWant a predicate function that returns true if the passed 0115 /// declaration kind is one we are looking for. 0116 void 0117 FindExternalLexicalDecls(const DeclContext *DC, 0118 llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, 0119 SmallVectorImpl<Decl *> &Result) override; 0120 0121 /// Get the decls that are contained in a file in the Offset/Length 0122 /// range. \p Length can be 0 to indicate a point at \p Offset instead of 0123 /// a range. 0124 void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length, 0125 SmallVectorImpl<Decl *> &Decls) override; 0126 0127 /// Gives the external AST source an opportunity to complete 0128 /// an incomplete type. 0129 void CompleteType(TagDecl *Tag) override; 0130 0131 /// Gives the external AST source an opportunity to complete an 0132 /// incomplete Objective-C class. 0133 /// 0134 /// This routine will only be invoked if the "externally completed" bit is 0135 /// set on the ObjCInterfaceDecl via the function 0136 /// \c ObjCInterfaceDecl::setExternallyCompleted(). 0137 void CompleteType(ObjCInterfaceDecl *Class) override; 0138 0139 /// Loads comment ranges. 0140 void ReadComments() override; 0141 0142 /// Notify ExternalASTSource that we started deserialization of 0143 /// a decl or type so until FinishedDeserializing is called there may be 0144 /// decls that are initializing. Must be paired with FinishedDeserializing. 0145 void StartedDeserializing() override; 0146 0147 /// Notify ExternalASTSource that we finished the deserialization of 0148 /// a decl or type. Must be paired with StartedDeserializing. 0149 void FinishedDeserializing() override; 0150 0151 /// Function that will be invoked when we begin parsing a new 0152 /// translation unit involving this external AST source. 0153 void StartTranslationUnit(ASTConsumer *Consumer) override; 0154 0155 /// Print any statistics that have been gathered regarding 0156 /// the external AST source. 0157 void PrintStats() override; 0158 0159 /// Retrieve the module that corresponds to the given module ID. 0160 Module *getModule(unsigned ID) override; 0161 0162 /// Perform layout on the given record. 0163 /// 0164 /// This routine allows the external AST source to provide an specific 0165 /// layout for a record, overriding the layout that would normally be 0166 /// constructed. It is intended for clients who receive specific layout 0167 /// details rather than source code (such as LLDB). The client is expected 0168 /// to fill in the field offsets, base offsets, virtual base offsets, and 0169 /// complete object size. 0170 /// 0171 /// \param Record The record whose layout is being requested. 0172 /// 0173 /// \param Size The final size of the record, in bits. 0174 /// 0175 /// \param Alignment The final alignment of the record, in bits. 0176 /// 0177 /// \param FieldOffsets The offset of each of the fields within the record, 0178 /// expressed in bits. All of the fields must be provided with offsets. 0179 /// 0180 /// \param BaseOffsets The offset of each of the direct, non-virtual base 0181 /// classes. If any bases are not given offsets, the bases will be laid 0182 /// out according to the ABI. 0183 /// 0184 /// \param VirtualBaseOffsets The offset of each of the virtual base classes 0185 /// (either direct or not). If any bases are not given offsets, the bases will 0186 /// be laid out according to the ABI. 0187 /// 0188 /// \returns true if the record layout was provided, false otherwise. 0189 bool 0190 layoutRecordType(const RecordDecl *Record, 0191 uint64_t &Size, uint64_t &Alignment, 0192 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets, 0193 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets, 0194 llvm::DenseMap<const CXXRecordDecl *, 0195 CharUnits> &VirtualBaseOffsets) override; 0196 0197 /// Return the amount of memory used by memory buffers, breaking down 0198 /// by heap-backed versus mmap'ed memory. 0199 void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override; 0200 0201 //===--------------------------------------------------------------------===// 0202 // ExternalSemaSource. 0203 //===--------------------------------------------------------------------===// 0204 0205 /// Initialize the semantic source with the Sema instance 0206 /// being used to perform semantic analysis on the abstract syntax 0207 /// tree. 0208 void InitializeSema(Sema &S) override; 0209 0210 /// Inform the semantic consumer that Sema is no longer available. 0211 void ForgetSema() override; 0212 0213 /// Load the contents of the global method pool for a given 0214 /// selector. 0215 void ReadMethodPool(Selector Sel) override; 0216 0217 /// Load the contents of the global method pool for a given 0218 /// selector if necessary. 0219 void updateOutOfDateSelector(Selector Sel) override; 0220 0221 /// Load the set of namespaces that are known to the external source, 0222 /// which will be used during typo correction. 0223 void 0224 ReadKnownNamespaces(SmallVectorImpl<NamespaceDecl*> &Namespaces) override; 0225 0226 /// Load the set of used but not defined functions or variables with 0227 /// internal linkage, or used but not defined inline functions. 0228 void ReadUndefinedButUsed( 0229 llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override; 0230 0231 void ReadMismatchingDeleteExpressions(llvm::MapVector< 0232 FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> & 0233 Exprs) override; 0234 0235 /// Do last resort, unqualified lookup on a LookupResult that 0236 /// Sema cannot find. 0237 /// 0238 /// \param R a LookupResult that is being recovered. 0239 /// 0240 /// \param S the Scope of the identifier occurrence. 0241 /// 0242 /// \return true to tell Sema to recover using the LookupResult. 0243 bool LookupUnqualified(LookupResult &R, Scope *S) override; 0244 0245 /// Read the set of tentative definitions known to the external Sema 0246 /// source. 0247 /// 0248 /// The external source should append its own tentative definitions to the 0249 /// given vector of tentative definitions. Note that this routine may be 0250 /// invoked multiple times; the external source should take care not to 0251 /// introduce the same declarations repeatedly. 0252 void ReadTentativeDefinitions(SmallVectorImpl<VarDecl*> &Defs) override; 0253 0254 /// Read the set of unused file-scope declarations known to the 0255 /// external Sema source. 0256 /// 0257 /// The external source should append its own unused, filed-scope to the 0258 /// given vector of declarations. Note that this routine may be 0259 /// invoked multiple times; the external source should take care not to 0260 /// introduce the same declarations repeatedly. 0261 void ReadUnusedFileScopedDecls( 0262 SmallVectorImpl<const DeclaratorDecl*> &Decls) override; 0263 0264 /// Read the set of delegating constructors known to the 0265 /// external Sema source. 0266 /// 0267 /// The external source should append its own delegating constructors to the 0268 /// given vector of declarations. Note that this routine may be 0269 /// invoked multiple times; the external source should take care not to 0270 /// introduce the same declarations repeatedly. 0271 void ReadDelegatingConstructors( 0272 SmallVectorImpl<CXXConstructorDecl*> &Decls) override; 0273 0274 /// Read the set of ext_vector type declarations known to the 0275 /// external Sema source. 0276 /// 0277 /// The external source should append its own ext_vector type declarations to 0278 /// the given vector of declarations. Note that this routine may be 0279 /// invoked multiple times; the external source should take care not to 0280 /// introduce the same declarations repeatedly. 0281 void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl*> &Decls) override; 0282 0283 /// Read the set of potentially unused typedefs known to the source. 0284 /// 0285 /// The external source should append its own potentially unused local 0286 /// typedefs to the given vector of declarations. Note that this routine may 0287 /// be invoked multiple times; the external source should take care not to 0288 /// introduce the same declarations repeatedly. 0289 void ReadUnusedLocalTypedefNameCandidates( 0290 llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override; 0291 0292 /// Read the set of referenced selectors known to the 0293 /// external Sema source. 0294 /// 0295 /// The external source should append its own referenced selectors to the 0296 /// given vector of selectors. Note that this routine 0297 /// may be invoked multiple times; the external source should take care not 0298 /// to introduce the same selectors repeatedly. 0299 void ReadReferencedSelectors(SmallVectorImpl<std::pair<Selector, 0300 SourceLocation> > &Sels) override; 0301 0302 /// Read the set of weak, undeclared identifiers known to the 0303 /// external Sema source. 0304 /// 0305 /// The external source should append its own weak, undeclared identifiers to 0306 /// the given vector. Note that this routine may be invoked multiple times; 0307 /// the external source should take care not to introduce the same identifiers 0308 /// repeatedly. 0309 void ReadWeakUndeclaredIdentifiers( 0310 SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) override; 0311 0312 /// Read the set of used vtables known to the external Sema source. 0313 /// 0314 /// The external source should append its own used vtables to the given 0315 /// vector. Note that this routine may be invoked multiple times; the external 0316 /// source should take care not to introduce the same vtables repeatedly. 0317 void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override; 0318 0319 /// Read the set of pending instantiations known to the external 0320 /// Sema source. 0321 /// 0322 /// The external source should append its own pending instantiations to the 0323 /// given vector. Note that this routine may be invoked multiple times; the 0324 /// external source should take care not to introduce the same instantiations 0325 /// repeatedly. 0326 void ReadPendingInstantiations( 0327 SmallVectorImpl<std::pair<ValueDecl*, SourceLocation> >& Pending) override; 0328 0329 /// Read the set of late parsed template functions for this source. 0330 /// 0331 /// The external source should insert its own late parsed template functions 0332 /// into the map. Note that this routine may be invoked multiple times; the 0333 /// external source should take care not to introduce the same map entries 0334 /// repeatedly. 0335 void ReadLateParsedTemplates( 0336 llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> 0337 &LPTMap) override; 0338 0339 /// Read the set of decls to be checked for deferred diags. 0340 /// 0341 /// The external source should append its own potentially emitted function 0342 /// and variable decls which may cause deferred diags. Note that this routine 0343 /// may be invoked multiple times; the external source should take care not to 0344 /// introduce the same declarations repeatedly. 0345 void ReadDeclsToCheckForDeferredDiags( 0346 llvm::SmallSetVector<Decl *, 4> &Decls) override; 0347 0348 /// \copydoc ExternalSemaSource::CorrectTypo 0349 /// \note Returns the first nonempty correction. 0350 TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, 0351 int LookupKind, Scope *S, CXXScopeSpec *SS, 0352 CorrectionCandidateCallback &CCC, 0353 DeclContext *MemberContext, 0354 bool EnteringContext, 0355 const ObjCObjectPointerType *OPT) override; 0356 0357 /// Produces a diagnostic note if one of the attached sources 0358 /// contains a complete definition for \p T. Queries the sources in list 0359 /// order until the first one claims that a diagnostic was produced. 0360 /// 0361 /// \param Loc the location at which a complete type was required but not 0362 /// provided 0363 /// 0364 /// \param T the \c QualType that should have been complete at \p Loc 0365 /// 0366 /// \return true if a diagnostic was produced, false otherwise. 0367 bool MaybeDiagnoseMissingCompleteType(SourceLocation Loc, 0368 QualType T) override; 0369 0370 // Inform all attached sources that a mangling number was assigned. 0371 void AssignedLambdaNumbering(CXXRecordDecl *Lambda) override; 0372 0373 /// LLVM-style RTTI. 0374 /// \{ 0375 bool isA(const void *ClassID) const override { 0376 return ClassID == &ID || ExternalSemaSource::isA(ClassID); 0377 } 0378 static bool classof(const ExternalASTSource *S) { return S->isA(&ID); } 0379 /// \} 0380 }; 0381 0382 } // end namespace clang 0383 0384 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|