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 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 19 | ///Constructs a new multiplexing external sema source and appends the |
Axel Naumann | dd433f0 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 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 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 31 | ///Appends new source to the source list. |
Axel Naumann | dd433f0 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 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 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame^] | 124 | void MultiplexExternalSemaSource::FindFileRegionDecls(FileID File, |
Axel Naumann | dd433f0 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 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 | |
Hans Wennborg | 08c5a7b | 2018-06-25 13:23:49 +0000 | [diff] [blame] | 174 | bool MultiplexExternalSemaSource::DeclIsFromPCHWithObjectFile(const Decl *D) { |
| 175 | for (auto *S : Sources) |
| 176 | if (S->DeclIsFromPCHWithObjectFile(D)) |
| 177 | return true; |
| 178 | return false; |
| 179 | } |
| 180 | |
Axel Naumann | dd433f0 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 181 | bool MultiplexExternalSemaSource::layoutRecordType(const RecordDecl *Record, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame^] | 182 | uint64_t &Size, |
Axel Naumann | dd433f0 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 183 | uint64_t &Alignment, |
| 184 | llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets, |
| 185 | llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets, |
| 186 | llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets){ |
| 187 | for(size_t i = 0; i < Sources.size(); ++i) |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame^] | 188 | if (Sources[i]->layoutRecordType(Record, Size, Alignment, FieldOffsets, |
Axel Naumann | dd433f0 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 189 | BaseOffsets, VirtualBaseOffsets)) |
| 190 | return true; |
| 191 | return false; |
| 192 | } |
| 193 | |
| 194 | void MultiplexExternalSemaSource:: |
| 195 | getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
| 196 | for(size_t i = 0; i < Sources.size(); ++i) |
| 197 | Sources[i]->getMemoryBufferSizes(sizes); |
| 198 | |
| 199 | } |
| 200 | |
| 201 | //===----------------------------------------------------------------------===// |
| 202 | // ExternalSemaSource. |
| 203 | //===----------------------------------------------------------------------===// |
| 204 | |
| 205 | |
| 206 | void MultiplexExternalSemaSource::InitializeSema(Sema &S) { |
| 207 | for(size_t i = 0; i < Sources.size(); ++i) |
| 208 | Sources[i]->InitializeSema(S); |
| 209 | } |
| 210 | |
| 211 | void MultiplexExternalSemaSource::ForgetSema() { |
| 212 | for(size_t i = 0; i < Sources.size(); ++i) |
| 213 | Sources[i]->ForgetSema(); |
| 214 | } |
| 215 | |
| 216 | void MultiplexExternalSemaSource::ReadMethodPool(Selector Sel) { |
| 217 | for(size_t i = 0; i < Sources.size(); ++i) |
| 218 | Sources[i]->ReadMethodPool(Sel); |
| 219 | } |
| 220 | |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 221 | void MultiplexExternalSemaSource::updateOutOfDateSelector(Selector Sel) { |
| 222 | for(size_t i = 0; i < Sources.size(); ++i) |
| 223 | Sources[i]->updateOutOfDateSelector(Sel); |
| 224 | } |
| 225 | |
Axel Naumann | dd433f0 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 226 | void MultiplexExternalSemaSource::ReadKnownNamespaces( |
| 227 | SmallVectorImpl<NamespaceDecl*> &Namespaces){ |
| 228 | for(size_t i = 0; i < Sources.size(); ++i) |
| 229 | Sources[i]->ReadKnownNamespaces(Namespaces); |
| 230 | } |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 231 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 232 | void MultiplexExternalSemaSource::ReadUndefinedButUsed( |
Richard Smith | d6a04d7 | 2016-03-25 21:49:43 +0000 | [diff] [blame] | 233 | llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) { |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 234 | for(size_t i = 0; i < Sources.size(); ++i) |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 235 | Sources[i]->ReadUndefinedButUsed(Undefined); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 236 | } |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 237 | |
| 238 | void MultiplexExternalSemaSource::ReadMismatchingDeleteExpressions( |
| 239 | llvm::MapVector<FieldDecl *, |
| 240 | llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> & |
| 241 | Exprs) { |
| 242 | for (auto &Source : Sources) |
| 243 | Source->ReadMismatchingDeleteExpressions(Exprs); |
| 244 | } |
| 245 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame^] | 246 | bool MultiplexExternalSemaSource::LookupUnqualified(LookupResult &R, Scope *S){ |
Axel Naumann | dd433f0 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 247 | for(size_t i = 0; i < Sources.size(); ++i) |
| 248 | Sources[i]->LookupUnqualified(R, S); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame^] | 249 | |
Axel Naumann | dd433f0 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 250 | return !R.empty(); |
| 251 | } |
| 252 | |
| 253 | void MultiplexExternalSemaSource::ReadTentativeDefinitions( |
| 254 | SmallVectorImpl<VarDecl*> &TentativeDefs) { |
| 255 | for(size_t i = 0; i < Sources.size(); ++i) |
| 256 | Sources[i]->ReadTentativeDefinitions(TentativeDefs); |
| 257 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame^] | 258 | |
Axel Naumann | dd433f0 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 259 | void MultiplexExternalSemaSource::ReadUnusedFileScopedDecls( |
| 260 | SmallVectorImpl<const DeclaratorDecl*> &Decls) { |
| 261 | for(size_t i = 0; i < Sources.size(); ++i) |
| 262 | Sources[i]->ReadUnusedFileScopedDecls(Decls); |
| 263 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame^] | 264 | |
Axel Naumann | dd433f0 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 265 | void MultiplexExternalSemaSource::ReadDelegatingConstructors( |
| 266 | SmallVectorImpl<CXXConstructorDecl*> &Decls) { |
| 267 | for(size_t i = 0; i < Sources.size(); ++i) |
| 268 | Sources[i]->ReadDelegatingConstructors(Decls); |
| 269 | } |
| 270 | |
| 271 | void MultiplexExternalSemaSource::ReadExtVectorDecls( |
| 272 | SmallVectorImpl<TypedefNameDecl*> &Decls) { |
| 273 | for(size_t i = 0; i < Sources.size(); ++i) |
| 274 | Sources[i]->ReadExtVectorDecls(Decls); |
| 275 | } |
| 276 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 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 | |
Axel Naumann | dd433f0 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 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 | } |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 307 | |
| 308 | void MultiplexExternalSemaSource::ReadLateParsedTemplates( |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 309 | llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> |
| 310 | &LPTMap) { |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 311 | for (size_t i = 0; i < Sources.size(); ++i) |
| 312 | Sources[i]->ReadLateParsedTemplates(LPTMap); |
| 313 | } |
Kaelyn Uhrain | f0aabda | 2013-08-12 19:54:38 +0000 | [diff] [blame] | 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 | } |
Kaelyn Uhrain | 2c351bb | 2013-08-12 22:11:14 +0000 | [diff] [blame] | 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 | } |