Axel Naumann | 0ec56b7 | 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 | 0ec56b7 | 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 | /// |
| 22 | ///\param[in] source - An ExternalSemaSource. |
| 23 | /// |
| 24 | MultiplexExternalSemaSource::MultiplexExternalSemaSource(ExternalSemaSource &s1, |
| 25 | ExternalSemaSource &s2){ |
| 26 | Sources.push_back(&s1); |
| 27 | Sources.push_back(&s2); |
| 28 | } |
| 29 | |
| 30 | // pin the vtable here. |
| 31 | MultiplexExternalSemaSource::~MultiplexExternalSemaSource() {} |
| 32 | |
| 33 | ///\brief Appends new source to the source list. |
| 34 | /// |
| 35 | ///\param[in] source - An ExternalSemaSource. |
| 36 | /// |
| 37 | void MultiplexExternalSemaSource::addSource(ExternalSemaSource &source) { |
| 38 | Sources.push_back(&source); |
| 39 | } |
| 40 | |
| 41 | //===----------------------------------------------------------------------===// |
| 42 | // ExternalASTSource. |
| 43 | //===----------------------------------------------------------------------===// |
| 44 | |
| 45 | Decl *MultiplexExternalSemaSource::GetExternalDecl(uint32_t ID) { |
| 46 | for(size_t i = 0; i < Sources.size(); ++i) |
| 47 | if (Decl *Result = Sources[i]->GetExternalDecl(ID)) |
| 48 | return Result; |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | Selector MultiplexExternalSemaSource::GetExternalSelector(uint32_t ID) { |
| 53 | Selector Sel; |
| 54 | for(size_t i = 0; i < Sources.size(); ++i) { |
| 55 | Sel = Sources[i]->GetExternalSelector(ID); |
| 56 | if (!Sel.isNull()) |
| 57 | return Sel; |
| 58 | } |
| 59 | return Sel; |
| 60 | } |
| 61 | |
| 62 | uint32_t MultiplexExternalSemaSource::GetNumExternalSelectors() { |
| 63 | uint32_t total = 0; |
| 64 | for(size_t i = 0; i < Sources.size(); ++i) |
| 65 | total += Sources[i]->GetNumExternalSelectors(); |
| 66 | return total; |
| 67 | } |
| 68 | |
| 69 | Stmt *MultiplexExternalSemaSource::GetExternalDeclStmt(uint64_t Offset) { |
| 70 | for(size_t i = 0; i < Sources.size(); ++i) |
| 71 | if (Stmt *Result = Sources[i]->GetExternalDeclStmt(Offset)) |
| 72 | return Result; |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | CXXBaseSpecifier *MultiplexExternalSemaSource::GetExternalCXXBaseSpecifiers( |
| 77 | uint64_t Offset){ |
| 78 | for(size_t i = 0; i < Sources.size(); ++i) |
| 79 | if (CXXBaseSpecifier *R = Sources[i]->GetExternalCXXBaseSpecifiers(Offset)) |
| 80 | return R; |
| 81 | return 0; |
| 82 | } |
| 83 | |
Richard Smith | 3646c68 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 84 | bool MultiplexExternalSemaSource:: |
Axel Naumann | 0ec56b7 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 85 | FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) { |
Richard Smith | 3646c68 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 86 | bool AnyDeclsFound = false; |
| 87 | for (size_t i = 0; i < Sources.size(); ++i) |
| 88 | AnyDeclsFound |= Sources[i]->FindExternalVisibleDeclsByName(DC, Name); |
| 89 | return AnyDeclsFound; |
Axel Naumann | 0ec56b7 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void MultiplexExternalSemaSource::completeVisibleDeclsMap(const DeclContext *DC){ |
| 93 | for(size_t i = 0; i < Sources.size(); ++i) |
| 94 | Sources[i]->completeVisibleDeclsMap(DC); |
| 95 | } |
| 96 | |
| 97 | ExternalLoadResult MultiplexExternalSemaSource:: |
| 98 | FindExternalLexicalDecls(const DeclContext *DC, |
| 99 | bool (*isKindWeWant)(Decl::Kind), |
| 100 | SmallVectorImpl<Decl*> &Result) { |
| 101 | for(size_t i = 0; i < Sources.size(); ++i) |
| 102 | // FIXME: The semantics of the return result is unclear to me... |
| 103 | Sources[i]->FindExternalLexicalDecls(DC, isKindWeWant, Result); |
| 104 | |
| 105 | return ELR_Success; |
| 106 | } |
| 107 | |
| 108 | void MultiplexExternalSemaSource::FindFileRegionDecls(FileID File, |
| 109 | unsigned Offset, |
| 110 | unsigned Length, |
| 111 | SmallVectorImpl<Decl *> &Decls){ |
| 112 | for(size_t i = 0; i < Sources.size(); ++i) |
| 113 | Sources[i]->FindFileRegionDecls(File, Offset, Length, Decls); |
| 114 | } |
| 115 | |
| 116 | void MultiplexExternalSemaSource::CompleteType(TagDecl *Tag) { |
| 117 | for(size_t i = 0; i < Sources.size(); ++i) |
| 118 | Sources[i]->CompleteType(Tag); |
| 119 | } |
| 120 | |
| 121 | void MultiplexExternalSemaSource::CompleteType(ObjCInterfaceDecl *Class) { |
| 122 | for(size_t i = 0; i < Sources.size(); ++i) |
| 123 | Sources[i]->CompleteType(Class); |
| 124 | } |
| 125 | |
| 126 | void MultiplexExternalSemaSource::ReadComments() { |
| 127 | for(size_t i = 0; i < Sources.size(); ++i) |
| 128 | Sources[i]->ReadComments(); |
| 129 | } |
| 130 | |
| 131 | void MultiplexExternalSemaSource::StartedDeserializing() { |
| 132 | for(size_t i = 0; i < Sources.size(); ++i) |
| 133 | Sources[i]->StartedDeserializing(); |
| 134 | } |
| 135 | |
| 136 | void MultiplexExternalSemaSource::FinishedDeserializing() { |
| 137 | for(size_t i = 0; i < Sources.size(); ++i) |
| 138 | Sources[i]->FinishedDeserializing(); |
| 139 | } |
| 140 | |
| 141 | void MultiplexExternalSemaSource::StartTranslationUnit(ASTConsumer *Consumer) { |
| 142 | for(size_t i = 0; i < Sources.size(); ++i) |
| 143 | Sources[i]->StartTranslationUnit(Consumer); |
| 144 | } |
| 145 | |
| 146 | void MultiplexExternalSemaSource::PrintStats() { |
| 147 | for(size_t i = 0; i < Sources.size(); ++i) |
| 148 | Sources[i]->PrintStats(); |
| 149 | } |
| 150 | |
| 151 | bool MultiplexExternalSemaSource::layoutRecordType(const RecordDecl *Record, |
| 152 | uint64_t &Size, |
| 153 | uint64_t &Alignment, |
| 154 | llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets, |
| 155 | llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets, |
| 156 | llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets){ |
| 157 | for(size_t i = 0; i < Sources.size(); ++i) |
| 158 | if (Sources[i]->layoutRecordType(Record, Size, Alignment, FieldOffsets, |
| 159 | BaseOffsets, VirtualBaseOffsets)) |
| 160 | return true; |
| 161 | return false; |
| 162 | } |
| 163 | |
| 164 | void MultiplexExternalSemaSource:: |
| 165 | getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
| 166 | for(size_t i = 0; i < Sources.size(); ++i) |
| 167 | Sources[i]->getMemoryBufferSizes(sizes); |
| 168 | |
| 169 | } |
| 170 | |
| 171 | //===----------------------------------------------------------------------===// |
| 172 | // ExternalSemaSource. |
| 173 | //===----------------------------------------------------------------------===// |
| 174 | |
| 175 | |
| 176 | void MultiplexExternalSemaSource::InitializeSema(Sema &S) { |
| 177 | for(size_t i = 0; i < Sources.size(); ++i) |
| 178 | Sources[i]->InitializeSema(S); |
| 179 | } |
| 180 | |
| 181 | void MultiplexExternalSemaSource::ForgetSema() { |
| 182 | for(size_t i = 0; i < Sources.size(); ++i) |
| 183 | Sources[i]->ForgetSema(); |
| 184 | } |
| 185 | |
| 186 | void MultiplexExternalSemaSource::ReadMethodPool(Selector Sel) { |
| 187 | for(size_t i = 0; i < Sources.size(); ++i) |
| 188 | Sources[i]->ReadMethodPool(Sel); |
| 189 | } |
| 190 | |
| 191 | void MultiplexExternalSemaSource::ReadKnownNamespaces( |
| 192 | SmallVectorImpl<NamespaceDecl*> &Namespaces){ |
| 193 | for(size_t i = 0; i < Sources.size(); ++i) |
| 194 | Sources[i]->ReadKnownNamespaces(Namespaces); |
| 195 | } |
Nick Lewycky | 01a4114 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 196 | |
Nick Lewycky | cd0655b | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 197 | void MultiplexExternalSemaSource::ReadUndefinedButUsed( |
Nick Lewycky | 995e26b | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 198 | llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined){ |
Nick Lewycky | 01a4114 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 199 | for(size_t i = 0; i < Sources.size(); ++i) |
Nick Lewycky | cd0655b | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 200 | Sources[i]->ReadUndefinedButUsed(Undefined); |
Nick Lewycky | 01a4114 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 201 | } |
Axel Naumann | 0ec56b7 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 202 | |
| 203 | bool MultiplexExternalSemaSource::LookupUnqualified(LookupResult &R, Scope *S){ |
| 204 | for(size_t i = 0; i < Sources.size(); ++i) |
| 205 | Sources[i]->LookupUnqualified(R, S); |
| 206 | |
| 207 | return !R.empty(); |
| 208 | } |
| 209 | |
| 210 | void MultiplexExternalSemaSource::ReadTentativeDefinitions( |
| 211 | SmallVectorImpl<VarDecl*> &TentativeDefs) { |
| 212 | for(size_t i = 0; i < Sources.size(); ++i) |
| 213 | Sources[i]->ReadTentativeDefinitions(TentativeDefs); |
| 214 | } |
| 215 | |
| 216 | void MultiplexExternalSemaSource::ReadUnusedFileScopedDecls( |
| 217 | SmallVectorImpl<const DeclaratorDecl*> &Decls) { |
| 218 | for(size_t i = 0; i < Sources.size(); ++i) |
| 219 | Sources[i]->ReadUnusedFileScopedDecls(Decls); |
| 220 | } |
| 221 | |
| 222 | void MultiplexExternalSemaSource::ReadDelegatingConstructors( |
| 223 | SmallVectorImpl<CXXConstructorDecl*> &Decls) { |
| 224 | for(size_t i = 0; i < Sources.size(); ++i) |
| 225 | Sources[i]->ReadDelegatingConstructors(Decls); |
| 226 | } |
| 227 | |
| 228 | void MultiplexExternalSemaSource::ReadExtVectorDecls( |
| 229 | SmallVectorImpl<TypedefNameDecl*> &Decls) { |
| 230 | for(size_t i = 0; i < Sources.size(); ++i) |
| 231 | Sources[i]->ReadExtVectorDecls(Decls); |
| 232 | } |
| 233 | |
| 234 | void MultiplexExternalSemaSource::ReadDynamicClasses( |
| 235 | SmallVectorImpl<CXXRecordDecl*> &Decls) { |
| 236 | for(size_t i = 0; i < Sources.size(); ++i) |
| 237 | Sources[i]->ReadDynamicClasses(Decls); |
| 238 | } |
| 239 | |
Richard Smith | 5ea6ef4 | 2013-01-10 23:43:47 +0000 | [diff] [blame] | 240 | void MultiplexExternalSemaSource::ReadLocallyScopedExternCDecls( |
Axel Naumann | 0ec56b7 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 241 | SmallVectorImpl<NamedDecl*> &Decls) { |
| 242 | for(size_t i = 0; i < Sources.size(); ++i) |
Richard Smith | 5ea6ef4 | 2013-01-10 23:43:47 +0000 | [diff] [blame] | 243 | Sources[i]->ReadLocallyScopedExternCDecls(Decls); |
Axel Naumann | 0ec56b7 | 2012-10-18 19:05:02 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | void MultiplexExternalSemaSource::ReadReferencedSelectors( |
| 247 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 248 | for(size_t i = 0; i < Sources.size(); ++i) |
| 249 | Sources[i]->ReadReferencedSelectors(Sels); |
| 250 | } |
| 251 | |
| 252 | void MultiplexExternalSemaSource::ReadWeakUndeclaredIdentifiers( |
| 253 | SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) { |
| 254 | for(size_t i = 0; i < Sources.size(); ++i) |
| 255 | Sources[i]->ReadWeakUndeclaredIdentifiers(WI); |
| 256 | } |
| 257 | |
| 258 | void MultiplexExternalSemaSource::ReadUsedVTables( |
| 259 | SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 260 | for(size_t i = 0; i < Sources.size(); ++i) |
| 261 | Sources[i]->ReadUsedVTables(VTables); |
| 262 | } |
| 263 | |
| 264 | void MultiplexExternalSemaSource::ReadPendingInstantiations( |
| 265 | SmallVectorImpl<std::pair<ValueDecl*, |
| 266 | SourceLocation> > &Pending) { |
| 267 | for(size_t i = 0; i < Sources.size(); ++i) |
| 268 | Sources[i]->ReadPendingInstantiations(Pending); |
| 269 | } |
Richard Smith | ac32d90 | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 270 | |
| 271 | void MultiplexExternalSemaSource::ReadLateParsedTemplates( |
| 272 | llvm::DenseMap<const FunctionDecl *, LateParsedTemplate *> &LPTMap) { |
| 273 | for (size_t i = 0; i < Sources.size(); ++i) |
| 274 | Sources[i]->ReadLateParsedTemplates(LPTMap); |
| 275 | } |
Kaelyn Uhrain | 70571f4 | 2013-08-12 19:54:38 +0000 | [diff] [blame] | 276 | |
| 277 | TypoCorrection MultiplexExternalSemaSource::CorrectTypo( |
| 278 | const DeclarationNameInfo &Typo, |
| 279 | int LookupKind, Scope *S, CXXScopeSpec *SS, |
| 280 | CorrectionCandidateCallback &CCC, |
| 281 | DeclContext *MemberContext, |
| 282 | bool EnteringContext, |
| 283 | const ObjCObjectPointerType *OPT) { |
| 284 | for (size_t I = 0, E = Sources.size(); I < E; ++I) { |
| 285 | if (TypoCorrection C = Sources[I]->CorrectTypo(Typo, LookupKind, S, SS, CCC, |
| 286 | MemberContext, |
| 287 | EnteringContext, OPT)) |
| 288 | return C; |
| 289 | } |
| 290 | return TypoCorrection(); |
| 291 | } |
Kaelyn Uhrain | 5d937b3 | 2013-08-12 22:11:14 +0000 | [diff] [blame] | 292 | |
| 293 | bool MultiplexExternalSemaSource::MaybeDiagnoseMissingCompleteType( |
| 294 | SourceLocation Loc, QualType T) { |
| 295 | for (size_t I = 0, E = Sources.size(); I < E; ++I) { |
| 296 | if (Sources[I]->MaybeDiagnoseMissingCompleteType(Loc, T)) |
| 297 | return true; |
| 298 | } |
| 299 | return false; |
| 300 | } |