• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
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 ///
MultiplexExternalSemaSource(ExternalSemaSource & s1,ExternalSemaSource & s2)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.
~MultiplexExternalSemaSource()31 MultiplexExternalSemaSource::~MultiplexExternalSemaSource() {}
32 
33 ///\brief Appends new source to the source list.
34 ///
35 ///\param[in] source - An ExternalSemaSource.
36 ///
addSource(ExternalSemaSource & source)37 void MultiplexExternalSemaSource::addSource(ExternalSemaSource &source) {
38   Sources.push_back(&source);
39 }
40 
41 //===----------------------------------------------------------------------===//
42 // ExternalASTSource.
43 //===----------------------------------------------------------------------===//
44 
GetExternalDecl(uint32_t ID)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 
GetExternalSelector(uint32_t ID)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 
GetNumExternalSelectors()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 
GetExternalDeclStmt(uint64_t Offset)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 
GetExternalCXXBaseSpecifiers(uint64_t Offset)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 
84 bool MultiplexExternalSemaSource::
FindExternalVisibleDeclsByName(const DeclContext * DC,DeclarationName Name)85 FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) {
86   bool AnyDeclsFound = false;
87   for (size_t i = 0; i < Sources.size(); ++i)
88     AnyDeclsFound |= Sources[i]->FindExternalVisibleDeclsByName(DC, Name);
89   return AnyDeclsFound;
90 }
91 
completeVisibleDeclsMap(const DeclContext * DC)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::
FindExternalLexicalDecls(const DeclContext * DC,bool (* isKindWeWant)(Decl::Kind),SmallVectorImpl<Decl * > & Result)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 
FindFileRegionDecls(FileID File,unsigned Offset,unsigned Length,SmallVectorImpl<Decl * > & Decls)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 
CompleteType(TagDecl * Tag)116 void MultiplexExternalSemaSource::CompleteType(TagDecl *Tag) {
117   for(size_t i = 0; i < Sources.size(); ++i)
118     Sources[i]->CompleteType(Tag);
119 }
120 
CompleteType(ObjCInterfaceDecl * Class)121 void MultiplexExternalSemaSource::CompleteType(ObjCInterfaceDecl *Class) {
122   for(size_t i = 0; i < Sources.size(); ++i)
123     Sources[i]->CompleteType(Class);
124 }
125 
ReadComments()126 void MultiplexExternalSemaSource::ReadComments() {
127   for(size_t i = 0; i < Sources.size(); ++i)
128     Sources[i]->ReadComments();
129 }
130 
StartedDeserializing()131 void MultiplexExternalSemaSource::StartedDeserializing() {
132   for(size_t i = 0; i < Sources.size(); ++i)
133     Sources[i]->StartedDeserializing();
134 }
135 
FinishedDeserializing()136 void MultiplexExternalSemaSource::FinishedDeserializing() {
137   for(size_t i = 0; i < Sources.size(); ++i)
138     Sources[i]->FinishedDeserializing();
139 }
140 
StartTranslationUnit(ASTConsumer * Consumer)141 void MultiplexExternalSemaSource::StartTranslationUnit(ASTConsumer *Consumer) {
142   for(size_t i = 0; i < Sources.size(); ++i)
143     Sources[i]->StartTranslationUnit(Consumer);
144 }
145 
PrintStats()146 void MultiplexExternalSemaSource::PrintStats() {
147   for(size_t i = 0; i < Sources.size(); ++i)
148     Sources[i]->PrintStats();
149 }
150 
layoutRecordType(const RecordDecl * Record,uint64_t & Size,uint64_t & Alignment,llvm::DenseMap<const FieldDecl *,uint64_t> & FieldOffsets,llvm::DenseMap<const CXXRecordDecl *,CharUnits> & BaseOffsets,llvm::DenseMap<const CXXRecordDecl *,CharUnits> & VirtualBaseOffsets)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::
getMemoryBufferSizes(MemoryBufferSizes & sizes) const165 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 
InitializeSema(Sema & S)176 void MultiplexExternalSemaSource::InitializeSema(Sema &S) {
177   for(size_t i = 0; i < Sources.size(); ++i)
178     Sources[i]->InitializeSema(S);
179 }
180 
ForgetSema()181 void MultiplexExternalSemaSource::ForgetSema() {
182   for(size_t i = 0; i < Sources.size(); ++i)
183     Sources[i]->ForgetSema();
184 }
185 
ReadMethodPool(Selector Sel)186 void MultiplexExternalSemaSource::ReadMethodPool(Selector Sel) {
187   for(size_t i = 0; i < Sources.size(); ++i)
188     Sources[i]->ReadMethodPool(Sel);
189 }
190 
ReadKnownNamespaces(SmallVectorImpl<NamespaceDecl * > & Namespaces)191 void MultiplexExternalSemaSource::ReadKnownNamespaces(
192                                    SmallVectorImpl<NamespaceDecl*> &Namespaces){
193   for(size_t i = 0; i < Sources.size(); ++i)
194     Sources[i]->ReadKnownNamespaces(Namespaces);
195 }
196 
ReadUndefinedButUsed(llvm::DenseMap<NamedDecl *,SourceLocation> & Undefined)197 void MultiplexExternalSemaSource::ReadUndefinedButUsed(
198                          llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined){
199   for(size_t i = 0; i < Sources.size(); ++i)
200     Sources[i]->ReadUndefinedButUsed(Undefined);
201 }
202 
LookupUnqualified(LookupResult & R,Scope * S)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 
ReadTentativeDefinitions(SmallVectorImpl<VarDecl * > & TentativeDefs)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 
ReadUnusedFileScopedDecls(SmallVectorImpl<const DeclaratorDecl * > & Decls)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 
ReadDelegatingConstructors(SmallVectorImpl<CXXConstructorDecl * > & Decls)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 
ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl * > & Decls)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 
ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl * > & Decls)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 
ReadLocallyScopedExternCDecls(SmallVectorImpl<NamedDecl * > & Decls)240 void MultiplexExternalSemaSource::ReadLocallyScopedExternCDecls(
241                                            SmallVectorImpl<NamedDecl*> &Decls) {
242   for(size_t i = 0; i < Sources.size(); ++i)
243     Sources[i]->ReadLocallyScopedExternCDecls(Decls);
244 }
245 
ReadReferencedSelectors(SmallVectorImpl<std::pair<Selector,SourceLocation>> & Sels)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 
ReadWeakUndeclaredIdentifiers(SmallVectorImpl<std::pair<IdentifierInfo *,WeakInfo>> & WI)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 
ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> & VTables)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 
ReadPendingInstantiations(SmallVectorImpl<std::pair<ValueDecl *,SourceLocation>> & Pending)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 }
270