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::DeclIsFromPCHWithObjectFile(const Decl *D) { 176 for (auto *S : Sources) 177 if (S->DeclIsFromPCHWithObjectFile(D)) 178 return true; 179 return false; 180 } 181 182 bool MultiplexExternalSemaSource::layoutRecordType(const RecordDecl *Record, 183 uint64_t &Size, 184 uint64_t &Alignment, 185 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets, 186 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets, 187 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets){ 188 for(size_t i = 0; i < Sources.size(); ++i) 189 if (Sources[i]->layoutRecordType(Record, Size, Alignment, FieldOffsets, 190 BaseOffsets, VirtualBaseOffsets)) 191 return true; 192 return false; 193 } 194 195 void MultiplexExternalSemaSource:: 196 getMemoryBufferSizes(MemoryBufferSizes &sizes) const { 197 for(size_t i = 0; i < Sources.size(); ++i) 198 Sources[i]->getMemoryBufferSizes(sizes); 199 200 } 201 202 //===----------------------------------------------------------------------===// 203 // ExternalSemaSource. 204 //===----------------------------------------------------------------------===// 205 206 207 void MultiplexExternalSemaSource::InitializeSema(Sema &S) { 208 for(size_t i = 0; i < Sources.size(); ++i) 209 Sources[i]->InitializeSema(S); 210 } 211 212 void MultiplexExternalSemaSource::ForgetSema() { 213 for(size_t i = 0; i < Sources.size(); ++i) 214 Sources[i]->ForgetSema(); 215 } 216 217 void MultiplexExternalSemaSource::ReadMethodPool(Selector Sel) { 218 for(size_t i = 0; i < Sources.size(); ++i) 219 Sources[i]->ReadMethodPool(Sel); 220 } 221 222 void MultiplexExternalSemaSource::updateOutOfDateSelector(Selector Sel) { 223 for(size_t i = 0; i < Sources.size(); ++i) 224 Sources[i]->updateOutOfDateSelector(Sel); 225 } 226 227 void MultiplexExternalSemaSource::ReadKnownNamespaces( 228 SmallVectorImpl<NamespaceDecl*> &Namespaces){ 229 for(size_t i = 0; i < Sources.size(); ++i) 230 Sources[i]->ReadKnownNamespaces(Namespaces); 231 } 232 233 void MultiplexExternalSemaSource::ReadUndefinedButUsed( 234 llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) { 235 for(size_t i = 0; i < Sources.size(); ++i) 236 Sources[i]->ReadUndefinedButUsed(Undefined); 237 } 238 239 void MultiplexExternalSemaSource::ReadMismatchingDeleteExpressions( 240 llvm::MapVector<FieldDecl *, 241 llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> & 242 Exprs) { 243 for (auto &Source : Sources) 244 Source->ReadMismatchingDeleteExpressions(Exprs); 245 } 246 247 bool MultiplexExternalSemaSource::LookupUnqualified(LookupResult &R, Scope *S){ 248 for(size_t i = 0; i < Sources.size(); ++i) 249 Sources[i]->LookupUnqualified(R, S); 250 251 return !R.empty(); 252 } 253 254 void MultiplexExternalSemaSource::ReadTentativeDefinitions( 255 SmallVectorImpl<VarDecl*> &TentativeDefs) { 256 for(size_t i = 0; i < Sources.size(); ++i) 257 Sources[i]->ReadTentativeDefinitions(TentativeDefs); 258 } 259 260 void MultiplexExternalSemaSource::ReadUnusedFileScopedDecls( 261 SmallVectorImpl<const DeclaratorDecl*> &Decls) { 262 for(size_t i = 0; i < Sources.size(); ++i) 263 Sources[i]->ReadUnusedFileScopedDecls(Decls); 264 } 265 266 void MultiplexExternalSemaSource::ReadDelegatingConstructors( 267 SmallVectorImpl<CXXConstructorDecl*> &Decls) { 268 for(size_t i = 0; i < Sources.size(); ++i) 269 Sources[i]->ReadDelegatingConstructors(Decls); 270 } 271 272 void MultiplexExternalSemaSource::ReadExtVectorDecls( 273 SmallVectorImpl<TypedefNameDecl*> &Decls) { 274 for(size_t i = 0; i < Sources.size(); ++i) 275 Sources[i]->ReadExtVectorDecls(Decls); 276 } 277 278 void MultiplexExternalSemaSource::ReadUnusedLocalTypedefNameCandidates( 279 llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) { 280 for(size_t i = 0; i < Sources.size(); ++i) 281 Sources[i]->ReadUnusedLocalTypedefNameCandidates(Decls); 282 } 283 284 void MultiplexExternalSemaSource::ReadReferencedSelectors( 285 SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { 286 for(size_t i = 0; i < Sources.size(); ++i) 287 Sources[i]->ReadReferencedSelectors(Sels); 288 } 289 290 void MultiplexExternalSemaSource::ReadWeakUndeclaredIdentifiers( 291 SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) { 292 for(size_t i = 0; i < Sources.size(); ++i) 293 Sources[i]->ReadWeakUndeclaredIdentifiers(WI); 294 } 295 296 void MultiplexExternalSemaSource::ReadUsedVTables( 297 SmallVectorImpl<ExternalVTableUse> &VTables) { 298 for(size_t i = 0; i < Sources.size(); ++i) 299 Sources[i]->ReadUsedVTables(VTables); 300 } 301 302 void MultiplexExternalSemaSource::ReadPendingInstantiations( 303 SmallVectorImpl<std::pair<ValueDecl*, 304 SourceLocation> > &Pending) { 305 for(size_t i = 0; i < Sources.size(); ++i) 306 Sources[i]->ReadPendingInstantiations(Pending); 307 } 308 309 void MultiplexExternalSemaSource::ReadLateParsedTemplates( 310 llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> 311 &LPTMap) { 312 for (size_t i = 0; i < Sources.size(); ++i) 313 Sources[i]->ReadLateParsedTemplates(LPTMap); 314 } 315 316 TypoCorrection MultiplexExternalSemaSource::CorrectTypo( 317 const DeclarationNameInfo &Typo, 318 int LookupKind, Scope *S, CXXScopeSpec *SS, 319 CorrectionCandidateCallback &CCC, 320 DeclContext *MemberContext, 321 bool EnteringContext, 322 const ObjCObjectPointerType *OPT) { 323 for (size_t I = 0, E = Sources.size(); I < E; ++I) { 324 if (TypoCorrection C = Sources[I]->CorrectTypo(Typo, LookupKind, S, SS, CCC, 325 MemberContext, 326 EnteringContext, OPT)) 327 return C; 328 } 329 return TypoCorrection(); 330 } 331 332 bool MultiplexExternalSemaSource::MaybeDiagnoseMissingCompleteType( 333 SourceLocation Loc, QualType T) { 334 for (size_t I = 0, E = Sources.size(); I < E; ++I) { 335 if (Sources[I]->MaybeDiagnoseMissingCompleteType(Loc, T)) 336 return true; 337 } 338 return false; 339 } 340