1 //===--- MultiplexExternalSemaSource.cpp ---------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements the event dispatching to the subscribed clients. 10 // 11 //===----------------------------------------------------------------------===// 12 #include "clang/Sema/MultiplexExternalSemaSource.h" 13 #include "clang/AST/DeclContextInternals.h" 14 #include "clang/Sema/Lookup.h" 15 16 using namespace clang; 17 18 char MultiplexExternalSemaSource::ID; 19 20 ///Constructs a new multiplexing external sema source and appends the 21 /// given element to it. 22 /// 23 MultiplexExternalSemaSource::MultiplexExternalSemaSource(ExternalSemaSource &s1, 24 ExternalSemaSource &s2){ 25 Sources.push_back(&s1); 26 Sources.push_back(&s2); 27 } 28 29 // pin the vtable here. 30 MultiplexExternalSemaSource::~MultiplexExternalSemaSource() {} 31 32 ///Appends new source to the source list. 33 /// 34 ///\param[in] source - An ExternalSemaSource. 35 /// 36 void MultiplexExternalSemaSource::addSource(ExternalSemaSource &source) { 37 Sources.push_back(&source); 38 } 39 40 //===----------------------------------------------------------------------===// 41 // ExternalASTSource. 42 //===----------------------------------------------------------------------===// 43 44 Decl *MultiplexExternalSemaSource::GetExternalDecl(uint32_t ID) { 45 for(size_t i = 0; i < Sources.size(); ++i) 46 if (Decl *Result = Sources[i]->GetExternalDecl(ID)) 47 return Result; 48 return nullptr; 49 } 50 51 void MultiplexExternalSemaSource::CompleteRedeclChain(const Decl *D) { 52 for (size_t i = 0; i < Sources.size(); ++i) 53 Sources[i]->CompleteRedeclChain(D); 54 } 55 56 Selector MultiplexExternalSemaSource::GetExternalSelector(uint32_t ID) { 57 Selector Sel; 58 for(size_t i = 0; i < Sources.size(); ++i) { 59 Sel = Sources[i]->GetExternalSelector(ID); 60 if (!Sel.isNull()) 61 return Sel; 62 } 63 return Sel; 64 } 65 66 uint32_t MultiplexExternalSemaSource::GetNumExternalSelectors() { 67 uint32_t total = 0; 68 for(size_t i = 0; i < Sources.size(); ++i) 69 total += Sources[i]->GetNumExternalSelectors(); 70 return total; 71 } 72 73 Stmt *MultiplexExternalSemaSource::GetExternalDeclStmt(uint64_t Offset) { 74 for(size_t i = 0; i < Sources.size(); ++i) 75 if (Stmt *Result = Sources[i]->GetExternalDeclStmt(Offset)) 76 return Result; 77 return nullptr; 78 } 79 80 CXXBaseSpecifier *MultiplexExternalSemaSource::GetExternalCXXBaseSpecifiers( 81 uint64_t Offset){ 82 for(size_t i = 0; i < Sources.size(); ++i) 83 if (CXXBaseSpecifier *R = Sources[i]->GetExternalCXXBaseSpecifiers(Offset)) 84 return R; 85 return nullptr; 86 } 87 88 CXXCtorInitializer ** 89 MultiplexExternalSemaSource::GetExternalCXXCtorInitializers(uint64_t Offset) { 90 for (auto *S : Sources) 91 if (auto *R = S->GetExternalCXXCtorInitializers(Offset)) 92 return R; 93 return nullptr; 94 } 95 96 ExternalASTSource::ExtKind 97 MultiplexExternalSemaSource::hasExternalDefinitions(const Decl *D) { 98 for (const auto &S : Sources) 99 if (auto EK = S->hasExternalDefinitions(D)) 100 if (EK != EK_ReplyHazy) 101 return EK; 102 return EK_ReplyHazy; 103 } 104 105 bool MultiplexExternalSemaSource:: 106 FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) { 107 bool AnyDeclsFound = false; 108 for (size_t i = 0; i < Sources.size(); ++i) 109 AnyDeclsFound |= Sources[i]->FindExternalVisibleDeclsByName(DC, Name); 110 return AnyDeclsFound; 111 } 112 113 void MultiplexExternalSemaSource::completeVisibleDeclsMap(const DeclContext *DC){ 114 for(size_t i = 0; i < Sources.size(); ++i) 115 Sources[i]->completeVisibleDeclsMap(DC); 116 } 117 118 void MultiplexExternalSemaSource::FindExternalLexicalDecls( 119 const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, 120 SmallVectorImpl<Decl *> &Result) { 121 for(size_t i = 0; i < Sources.size(); ++i) 122 Sources[i]->FindExternalLexicalDecls(DC, IsKindWeWant, Result); 123 } 124 125 void MultiplexExternalSemaSource::FindFileRegionDecls(FileID File, 126 unsigned Offset, 127 unsigned Length, 128 SmallVectorImpl<Decl *> &Decls){ 129 for(size_t i = 0; i < Sources.size(); ++i) 130 Sources[i]->FindFileRegionDecls(File, Offset, Length, Decls); 131 } 132 133 void MultiplexExternalSemaSource::CompleteType(TagDecl *Tag) { 134 for(size_t i = 0; i < Sources.size(); ++i) 135 Sources[i]->CompleteType(Tag); 136 } 137 138 void MultiplexExternalSemaSource::CompleteType(ObjCInterfaceDecl *Class) { 139 for(size_t i = 0; i < Sources.size(); ++i) 140 Sources[i]->CompleteType(Class); 141 } 142 143 void MultiplexExternalSemaSource::ReadComments() { 144 for(size_t i = 0; i < Sources.size(); ++i) 145 Sources[i]->ReadComments(); 146 } 147 148 void MultiplexExternalSemaSource::StartedDeserializing() { 149 for(size_t i = 0; i < Sources.size(); ++i) 150 Sources[i]->StartedDeserializing(); 151 } 152 153 void MultiplexExternalSemaSource::FinishedDeserializing() { 154 for(size_t i = 0; i < Sources.size(); ++i) 155 Sources[i]->FinishedDeserializing(); 156 } 157 158 void MultiplexExternalSemaSource::StartTranslationUnit(ASTConsumer *Consumer) { 159 for(size_t i = 0; i < Sources.size(); ++i) 160 Sources[i]->StartTranslationUnit(Consumer); 161 } 162 163 void MultiplexExternalSemaSource::PrintStats() { 164 for(size_t i = 0; i < Sources.size(); ++i) 165 Sources[i]->PrintStats(); 166 } 167 168 Module *MultiplexExternalSemaSource::getModule(unsigned ID) { 169 for (size_t i = 0; i < Sources.size(); ++i) 170 if (auto M = Sources[i]->getModule(ID)) 171 return M; 172 return nullptr; 173 } 174 175 bool MultiplexExternalSemaSource::layoutRecordType(const RecordDecl *Record, 176 uint64_t &Size, 177 uint64_t &Alignment, 178 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets, 179 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets, 180 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets){ 181 for(size_t i = 0; i < Sources.size(); ++i) 182 if (Sources[i]->layoutRecordType(Record, Size, Alignment, FieldOffsets, 183 BaseOffsets, VirtualBaseOffsets)) 184 return true; 185 return false; 186 } 187 188 void MultiplexExternalSemaSource:: 189 getMemoryBufferSizes(MemoryBufferSizes &sizes) const { 190 for(size_t i = 0; i < Sources.size(); ++i) 191 Sources[i]->getMemoryBufferSizes(sizes); 192 193 } 194 195 //===----------------------------------------------------------------------===// 196 // ExternalSemaSource. 197 //===----------------------------------------------------------------------===// 198 199 200 void MultiplexExternalSemaSource::InitializeSema(Sema &S) { 201 for(size_t i = 0; i < Sources.size(); ++i) 202 Sources[i]->InitializeSema(S); 203 } 204 205 void MultiplexExternalSemaSource::ForgetSema() { 206 for(size_t i = 0; i < Sources.size(); ++i) 207 Sources[i]->ForgetSema(); 208 } 209 210 void MultiplexExternalSemaSource::ReadMethodPool(Selector Sel) { 211 for(size_t i = 0; i < Sources.size(); ++i) 212 Sources[i]->ReadMethodPool(Sel); 213 } 214 215 void MultiplexExternalSemaSource::updateOutOfDateSelector(Selector Sel) { 216 for(size_t i = 0; i < Sources.size(); ++i) 217 Sources[i]->updateOutOfDateSelector(Sel); 218 } 219 220 void MultiplexExternalSemaSource::ReadKnownNamespaces( 221 SmallVectorImpl<NamespaceDecl*> &Namespaces){ 222 for(size_t i = 0; i < Sources.size(); ++i) 223 Sources[i]->ReadKnownNamespaces(Namespaces); 224 } 225 226 void MultiplexExternalSemaSource::ReadUndefinedButUsed( 227 llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) { 228 for(size_t i = 0; i < Sources.size(); ++i) 229 Sources[i]->ReadUndefinedButUsed(Undefined); 230 } 231 232 void MultiplexExternalSemaSource::ReadMismatchingDeleteExpressions( 233 llvm::MapVector<FieldDecl *, 234 llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> & 235 Exprs) { 236 for (auto &Source : Sources) 237 Source->ReadMismatchingDeleteExpressions(Exprs); 238 } 239 240 bool MultiplexExternalSemaSource::LookupUnqualified(LookupResult &R, Scope *S){ 241 for(size_t i = 0; i < Sources.size(); ++i) 242 Sources[i]->LookupUnqualified(R, S); 243 244 return !R.empty(); 245 } 246 247 void MultiplexExternalSemaSource::ReadTentativeDefinitions( 248 SmallVectorImpl<VarDecl*> &TentativeDefs) { 249 for(size_t i = 0; i < Sources.size(); ++i) 250 Sources[i]->ReadTentativeDefinitions(TentativeDefs); 251 } 252 253 void MultiplexExternalSemaSource::ReadUnusedFileScopedDecls( 254 SmallVectorImpl<const DeclaratorDecl*> &Decls) { 255 for(size_t i = 0; i < Sources.size(); ++i) 256 Sources[i]->ReadUnusedFileScopedDecls(Decls); 257 } 258 259 void MultiplexExternalSemaSource::ReadDelegatingConstructors( 260 SmallVectorImpl<CXXConstructorDecl*> &Decls) { 261 for(size_t i = 0; i < Sources.size(); ++i) 262 Sources[i]->ReadDelegatingConstructors(Decls); 263 } 264 265 void MultiplexExternalSemaSource::ReadExtVectorDecls( 266 SmallVectorImpl<TypedefNameDecl*> &Decls) { 267 for(size_t i = 0; i < Sources.size(); ++i) 268 Sources[i]->ReadExtVectorDecls(Decls); 269 } 270 271 void MultiplexExternalSemaSource::ReadDeclsToCheckForDeferredDiags( 272 llvm::SmallVector<Decl *, 4> &Decls) { 273 for(size_t i = 0; i < Sources.size(); ++i) 274 Sources[i]->ReadDeclsToCheckForDeferredDiags(Decls); 275 } 276 277 void MultiplexExternalSemaSource::ReadUnusedLocalTypedefNameCandidates( 278 llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) { 279 for(size_t i = 0; i < Sources.size(); ++i) 280 Sources[i]->ReadUnusedLocalTypedefNameCandidates(Decls); 281 } 282 283 void MultiplexExternalSemaSource::ReadReferencedSelectors( 284 SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { 285 for(size_t i = 0; i < Sources.size(); ++i) 286 Sources[i]->ReadReferencedSelectors(Sels); 287 } 288 289 void MultiplexExternalSemaSource::ReadWeakUndeclaredIdentifiers( 290 SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) { 291 for(size_t i = 0; i < Sources.size(); ++i) 292 Sources[i]->ReadWeakUndeclaredIdentifiers(WI); 293 } 294 295 void MultiplexExternalSemaSource::ReadUsedVTables( 296 SmallVectorImpl<ExternalVTableUse> &VTables) { 297 for(size_t i = 0; i < Sources.size(); ++i) 298 Sources[i]->ReadUsedVTables(VTables); 299 } 300 301 void MultiplexExternalSemaSource::ReadPendingInstantiations( 302 SmallVectorImpl<std::pair<ValueDecl*, 303 SourceLocation> > &Pending) { 304 for(size_t i = 0; i < Sources.size(); ++i) 305 Sources[i]->ReadPendingInstantiations(Pending); 306 } 307 308 void MultiplexExternalSemaSource::ReadLateParsedTemplates( 309 llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> 310 &LPTMap) { 311 for (size_t i = 0; i < Sources.size(); ++i) 312 Sources[i]->ReadLateParsedTemplates(LPTMap); 313 } 314 315 TypoCorrection MultiplexExternalSemaSource::CorrectTypo( 316 const DeclarationNameInfo &Typo, 317 int LookupKind, Scope *S, CXXScopeSpec *SS, 318 CorrectionCandidateCallback &CCC, 319 DeclContext *MemberContext, 320 bool EnteringContext, 321 const ObjCObjectPointerType *OPT) { 322 for (size_t I = 0, E = Sources.size(); I < E; ++I) { 323 if (TypoCorrection C = Sources[I]->CorrectTypo(Typo, LookupKind, S, SS, CCC, 324 MemberContext, 325 EnteringContext, OPT)) 326 return C; 327 } 328 return TypoCorrection(); 329 } 330 331 bool MultiplexExternalSemaSource::MaybeDiagnoseMissingCompleteType( 332 SourceLocation Loc, QualType T) { 333 for (size_t I = 0, E = Sources.size(); I < E; ++I) { 334 if (Sources[I]->MaybeDiagnoseMissingCompleteType(Loc, T)) 335 return true; 336 } 337 return false; 338 } 339