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