blob: ad7627a457156e021cd969e1b6f69b890dc588f3 [file] [log] [blame]
Axel Naumann0ec56b72012-10-18 19:05:02 +00001//===--- 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 Naumann0ec56b72012-10-18 19:05:02 +000014#include "clang/AST/DeclContextInternals.h"
15#include "clang/Sema/Lookup.h"
16
17using 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///
24MultiplexExternalSemaSource::MultiplexExternalSemaSource(ExternalSemaSource &s1,
25 ExternalSemaSource &s2){
26 Sources.push_back(&s1);
27 Sources.push_back(&s2);
28}
29
30// pin the vtable here.
31MultiplexExternalSemaSource::~MultiplexExternalSemaSource() {}
32
33///\brief Appends new source to the source list.
34///
35///\param[in] source - An ExternalSemaSource.
36///
37void MultiplexExternalSemaSource::addSource(ExternalSemaSource &source) {
38 Sources.push_back(&source);
39}
40
41//===----------------------------------------------------------------------===//
42// ExternalASTSource.
43//===----------------------------------------------------------------------===//
44
45Decl *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
52Selector 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
62uint32_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
69Stmt *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
76CXXBaseSpecifier *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 Smith3646c682013-02-07 03:30:24 +000084bool MultiplexExternalSemaSource::
Axel Naumann0ec56b72012-10-18 19:05:02 +000085FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) {
Richard Smith3646c682013-02-07 03:30:24 +000086 bool AnyDeclsFound = false;
87 for (size_t i = 0; i < Sources.size(); ++i)
88 AnyDeclsFound |= Sources[i]->FindExternalVisibleDeclsByName(DC, Name);
89 return AnyDeclsFound;
Axel Naumann0ec56b72012-10-18 19:05:02 +000090}
91
92void MultiplexExternalSemaSource::completeVisibleDeclsMap(const DeclContext *DC){
93 for(size_t i = 0; i < Sources.size(); ++i)
94 Sources[i]->completeVisibleDeclsMap(DC);
95}
96
97ExternalLoadResult MultiplexExternalSemaSource::
98FindExternalLexicalDecls(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
108void 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
116void MultiplexExternalSemaSource::CompleteType(TagDecl *Tag) {
117 for(size_t i = 0; i < Sources.size(); ++i)
118 Sources[i]->CompleteType(Tag);
119}
120
121void MultiplexExternalSemaSource::CompleteType(ObjCInterfaceDecl *Class) {
122 for(size_t i = 0; i < Sources.size(); ++i)
123 Sources[i]->CompleteType(Class);
124}
125
126void MultiplexExternalSemaSource::ReadComments() {
127 for(size_t i = 0; i < Sources.size(); ++i)
128 Sources[i]->ReadComments();
129}
130
131void MultiplexExternalSemaSource::StartedDeserializing() {
132 for(size_t i = 0; i < Sources.size(); ++i)
133 Sources[i]->StartedDeserializing();
134}
135
136void MultiplexExternalSemaSource::FinishedDeserializing() {
137 for(size_t i = 0; i < Sources.size(); ++i)
138 Sources[i]->FinishedDeserializing();
139}
140
141void MultiplexExternalSemaSource::StartTranslationUnit(ASTConsumer *Consumer) {
142 for(size_t i = 0; i < Sources.size(); ++i)
143 Sources[i]->StartTranslationUnit(Consumer);
144}
145
146void MultiplexExternalSemaSource::PrintStats() {
147 for(size_t i = 0; i < Sources.size(); ++i)
148 Sources[i]->PrintStats();
149}
150
151bool 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
164void MultiplexExternalSemaSource::
165getMemoryBufferSizes(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
176void MultiplexExternalSemaSource::InitializeSema(Sema &S) {
177 for(size_t i = 0; i < Sources.size(); ++i)
178 Sources[i]->InitializeSema(S);
179}
180
181void MultiplexExternalSemaSource::ForgetSema() {
182 for(size_t i = 0; i < Sources.size(); ++i)
183 Sources[i]->ForgetSema();
184}
185
186void MultiplexExternalSemaSource::ReadMethodPool(Selector Sel) {
187 for(size_t i = 0; i < Sources.size(); ++i)
188 Sources[i]->ReadMethodPool(Sel);
189}
190
191void MultiplexExternalSemaSource::ReadKnownNamespaces(
192 SmallVectorImpl<NamespaceDecl*> &Namespaces){
193 for(size_t i = 0; i < Sources.size(); ++i)
194 Sources[i]->ReadKnownNamespaces(Namespaces);
195}
Nick Lewycky01a41142013-01-26 00:35:08 +0000196
Nick Lewyckycd0655b2013-02-01 08:13:20 +0000197void MultiplexExternalSemaSource::ReadUndefinedButUsed(
Nick Lewycky995e26b2013-01-31 03:23:57 +0000198 llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined){
Nick Lewycky01a41142013-01-26 00:35:08 +0000199 for(size_t i = 0; i < Sources.size(); ++i)
Nick Lewyckycd0655b2013-02-01 08:13:20 +0000200 Sources[i]->ReadUndefinedButUsed(Undefined);
Nick Lewycky01a41142013-01-26 00:35:08 +0000201}
Axel Naumann0ec56b72012-10-18 19:05:02 +0000202
203bool 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
210void MultiplexExternalSemaSource::ReadTentativeDefinitions(
211 SmallVectorImpl<VarDecl*> &TentativeDefs) {
212 for(size_t i = 0; i < Sources.size(); ++i)
213 Sources[i]->ReadTentativeDefinitions(TentativeDefs);
214}
215
216void MultiplexExternalSemaSource::ReadUnusedFileScopedDecls(
217 SmallVectorImpl<const DeclaratorDecl*> &Decls) {
218 for(size_t i = 0; i < Sources.size(); ++i)
219 Sources[i]->ReadUnusedFileScopedDecls(Decls);
220}
221
222void MultiplexExternalSemaSource::ReadDelegatingConstructors(
223 SmallVectorImpl<CXXConstructorDecl*> &Decls) {
224 for(size_t i = 0; i < Sources.size(); ++i)
225 Sources[i]->ReadDelegatingConstructors(Decls);
226}
227
228void MultiplexExternalSemaSource::ReadExtVectorDecls(
229 SmallVectorImpl<TypedefNameDecl*> &Decls) {
230 for(size_t i = 0; i < Sources.size(); ++i)
231 Sources[i]->ReadExtVectorDecls(Decls);
232}
233
234void MultiplexExternalSemaSource::ReadDynamicClasses(
235 SmallVectorImpl<CXXRecordDecl*> &Decls) {
236 for(size_t i = 0; i < Sources.size(); ++i)
237 Sources[i]->ReadDynamicClasses(Decls);
238}
239
Richard Smith5ea6ef42013-01-10 23:43:47 +0000240void MultiplexExternalSemaSource::ReadLocallyScopedExternCDecls(
Axel Naumann0ec56b72012-10-18 19:05:02 +0000241 SmallVectorImpl<NamedDecl*> &Decls) {
242 for(size_t i = 0; i < Sources.size(); ++i)
Richard Smith5ea6ef42013-01-10 23:43:47 +0000243 Sources[i]->ReadLocallyScopedExternCDecls(Decls);
Axel Naumann0ec56b72012-10-18 19:05:02 +0000244}
245
246void 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
252void 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
258void MultiplexExternalSemaSource::ReadUsedVTables(
259 SmallVectorImpl<ExternalVTableUse> &VTables) {
260 for(size_t i = 0; i < Sources.size(); ++i)
261 Sources[i]->ReadUsedVTables(VTables);
262}
263
264void 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 Smithac32d902013-08-07 21:41:30 +0000270
271void 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 Uhrain70571f42013-08-12 19:54:38 +0000276
277TypoCorrection 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 Uhrain5d937b32013-08-12 22:11:14 +0000292
293bool 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}