clang API Documentation

MultiplexExternalSemaSource.cpp
Go to the documentation of this file.
00001 //===--- MultiplexExternalSemaSource.cpp  ---------------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the event dispatching to the subscribed clients.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 #include "clang/Sema/MultiplexExternalSemaSource.h"
00014 #include "clang/AST/DeclContextInternals.h"
00015 #include "clang/Sema/Lookup.h"
00016 
00017 using namespace clang;
00018 
00019 ///\brief Constructs a new multiplexing external sema source and appends the
00020 /// given element to it.
00021 ///
00022 ///\param[in] source - An ExternalSemaSource.
00023 ///
00024 MultiplexExternalSemaSource::MultiplexExternalSemaSource(ExternalSemaSource &s1,
00025                                                         ExternalSemaSource &s2){
00026   Sources.push_back(&s1);
00027   Sources.push_back(&s2);
00028 }
00029 
00030 // pin the vtable here.
00031 MultiplexExternalSemaSource::~MultiplexExternalSemaSource() {}
00032 
00033 ///\brief Appends new source to the source list.
00034 ///
00035 ///\param[in] source - An ExternalSemaSource.
00036 ///
00037 void MultiplexExternalSemaSource::addSource(ExternalSemaSource &source) {
00038   Sources.push_back(&source);
00039 }
00040 
00041 //===----------------------------------------------------------------------===//
00042 // ExternalASTSource.
00043 //===----------------------------------------------------------------------===//
00044 
00045 Decl *MultiplexExternalSemaSource::GetExternalDecl(uint32_t ID) {
00046   for(size_t i = 0; i < Sources.size(); ++i)
00047     if (Decl *Result = Sources[i]->GetExternalDecl(ID))
00048       return Result;
00049   return nullptr;
00050 }
00051 
00052 void MultiplexExternalSemaSource::CompleteRedeclChain(const Decl *D) {
00053   for (size_t i = 0; i < Sources.size(); ++i)
00054     Sources[i]->CompleteRedeclChain(D);
00055 }
00056 
00057 Selector MultiplexExternalSemaSource::GetExternalSelector(uint32_t ID) {
00058   Selector Sel;
00059   for(size_t i = 0; i < Sources.size(); ++i) {
00060     Sel = Sources[i]->GetExternalSelector(ID);
00061     if (!Sel.isNull())
00062       return Sel;
00063   }
00064   return Sel;
00065 }
00066 
00067 uint32_t MultiplexExternalSemaSource::GetNumExternalSelectors() {
00068   uint32_t total = 0;
00069   for(size_t i = 0; i < Sources.size(); ++i)
00070     total += Sources[i]->GetNumExternalSelectors();
00071   return total;
00072 }
00073 
00074 Stmt *MultiplexExternalSemaSource::GetExternalDeclStmt(uint64_t Offset) {
00075   for(size_t i = 0; i < Sources.size(); ++i)
00076     if (Stmt *Result = Sources[i]->GetExternalDeclStmt(Offset))
00077       return Result;
00078   return nullptr;
00079 }
00080 
00081 CXXBaseSpecifier *MultiplexExternalSemaSource::GetExternalCXXBaseSpecifiers(
00082                                                                uint64_t Offset){
00083   for(size_t i = 0; i < Sources.size(); ++i)
00084     if (CXXBaseSpecifier *R = Sources[i]->GetExternalCXXBaseSpecifiers(Offset))
00085       return R;
00086   return nullptr;
00087 }
00088 
00089 bool MultiplexExternalSemaSource::
00090 FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) {
00091   bool AnyDeclsFound = false;
00092   for (size_t i = 0; i < Sources.size(); ++i)
00093     AnyDeclsFound |= Sources[i]->FindExternalVisibleDeclsByName(DC, Name);
00094   return AnyDeclsFound;
00095 }
00096 
00097 void MultiplexExternalSemaSource::completeVisibleDeclsMap(const DeclContext *DC){
00098   for(size_t i = 0; i < Sources.size(); ++i)
00099     Sources[i]->completeVisibleDeclsMap(DC);
00100 }
00101 
00102 ExternalLoadResult MultiplexExternalSemaSource::
00103 FindExternalLexicalDecls(const DeclContext *DC,
00104                          bool (*isKindWeWant)(Decl::Kind),
00105                          SmallVectorImpl<Decl*> &Result) {
00106   for(size_t i = 0; i < Sources.size(); ++i)
00107     // FIXME: The semantics of the return result is unclear to me...
00108     Sources[i]->FindExternalLexicalDecls(DC, isKindWeWant, Result);
00109 
00110   return ELR_Success;
00111 }
00112 
00113 void MultiplexExternalSemaSource::FindFileRegionDecls(FileID File, 
00114                                                       unsigned Offset,
00115                                                       unsigned Length,
00116                                                 SmallVectorImpl<Decl *> &Decls){
00117   for(size_t i = 0; i < Sources.size(); ++i)
00118     Sources[i]->FindFileRegionDecls(File, Offset, Length, Decls);
00119 }
00120 
00121 void MultiplexExternalSemaSource::CompleteType(TagDecl *Tag) {
00122   for(size_t i = 0; i < Sources.size(); ++i)
00123     Sources[i]->CompleteType(Tag);
00124 }
00125 
00126 void MultiplexExternalSemaSource::CompleteType(ObjCInterfaceDecl *Class) {
00127   for(size_t i = 0; i < Sources.size(); ++i)
00128     Sources[i]->CompleteType(Class);
00129 }
00130 
00131 void MultiplexExternalSemaSource::ReadComments() {
00132   for(size_t i = 0; i < Sources.size(); ++i)
00133     Sources[i]->ReadComments();
00134 }
00135 
00136 void MultiplexExternalSemaSource::StartedDeserializing() {
00137   for(size_t i = 0; i < Sources.size(); ++i)
00138     Sources[i]->StartedDeserializing();
00139 }
00140 
00141 void MultiplexExternalSemaSource::FinishedDeserializing() {
00142   for(size_t i = 0; i < Sources.size(); ++i)
00143     Sources[i]->FinishedDeserializing();
00144 }
00145 
00146 void MultiplexExternalSemaSource::StartTranslationUnit(ASTConsumer *Consumer) {
00147   for(size_t i = 0; i < Sources.size(); ++i)
00148     Sources[i]->StartTranslationUnit(Consumer);
00149 }
00150 
00151 void MultiplexExternalSemaSource::PrintStats() {
00152   for(size_t i = 0; i < Sources.size(); ++i)
00153     Sources[i]->PrintStats();
00154 }
00155 
00156 bool MultiplexExternalSemaSource::layoutRecordType(const RecordDecl *Record,
00157                                                    uint64_t &Size, 
00158                                                    uint64_t &Alignment,
00159                       llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
00160                   llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
00161           llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets){
00162   for(size_t i = 0; i < Sources.size(); ++i)
00163     if (Sources[i]->layoutRecordType(Record, Size, Alignment, FieldOffsets, 
00164                                      BaseOffsets, VirtualBaseOffsets))
00165       return true;
00166   return false;
00167 }
00168 
00169 void MultiplexExternalSemaSource::
00170 getMemoryBufferSizes(MemoryBufferSizes &sizes) const {
00171   for(size_t i = 0; i < Sources.size(); ++i)
00172     Sources[i]->getMemoryBufferSizes(sizes);
00173 
00174 }
00175 
00176 //===----------------------------------------------------------------------===//
00177 // ExternalSemaSource.
00178 //===----------------------------------------------------------------------===//
00179 
00180 
00181 void MultiplexExternalSemaSource::InitializeSema(Sema &S) {
00182   for(size_t i = 0; i < Sources.size(); ++i)
00183     Sources[i]->InitializeSema(S);
00184 }
00185 
00186 void MultiplexExternalSemaSource::ForgetSema() {
00187   for(size_t i = 0; i < Sources.size(); ++i)
00188     Sources[i]->ForgetSema();
00189 }
00190 
00191 void MultiplexExternalSemaSource::ReadMethodPool(Selector Sel) {
00192   for(size_t i = 0; i < Sources.size(); ++i)
00193     Sources[i]->ReadMethodPool(Sel);
00194 }
00195 
00196 void MultiplexExternalSemaSource::ReadKnownNamespaces(
00197                                    SmallVectorImpl<NamespaceDecl*> &Namespaces){
00198   for(size_t i = 0; i < Sources.size(); ++i)
00199     Sources[i]->ReadKnownNamespaces(Namespaces);
00200 }
00201 
00202 void MultiplexExternalSemaSource::ReadUndefinedButUsed(
00203                          llvm::DenseMap<NamedDecl*, SourceLocation> &Undefined){
00204   for(size_t i = 0; i < Sources.size(); ++i)
00205     Sources[i]->ReadUndefinedButUsed(Undefined);
00206 }
00207   
00208 bool MultiplexExternalSemaSource::LookupUnqualified(LookupResult &R, Scope *S){ 
00209   for(size_t i = 0; i < Sources.size(); ++i)
00210     Sources[i]->LookupUnqualified(R, S);
00211   
00212   return !R.empty();
00213 }
00214 
00215 void MultiplexExternalSemaSource::ReadTentativeDefinitions(
00216                                      SmallVectorImpl<VarDecl*> &TentativeDefs) {
00217   for(size_t i = 0; i < Sources.size(); ++i)
00218     Sources[i]->ReadTentativeDefinitions(TentativeDefs);
00219 }
00220   
00221 void MultiplexExternalSemaSource::ReadUnusedFileScopedDecls(
00222                                 SmallVectorImpl<const DeclaratorDecl*> &Decls) {
00223   for(size_t i = 0; i < Sources.size(); ++i)
00224     Sources[i]->ReadUnusedFileScopedDecls(Decls);
00225 }
00226   
00227 void MultiplexExternalSemaSource::ReadDelegatingConstructors(
00228                                   SmallVectorImpl<CXXConstructorDecl*> &Decls) {
00229   for(size_t i = 0; i < Sources.size(); ++i)
00230     Sources[i]->ReadDelegatingConstructors(Decls);
00231 }
00232 
00233 void MultiplexExternalSemaSource::ReadExtVectorDecls(
00234                                      SmallVectorImpl<TypedefNameDecl*> &Decls) {
00235   for(size_t i = 0; i < Sources.size(); ++i)
00236     Sources[i]->ReadExtVectorDecls(Decls);
00237 }
00238 
00239 void MultiplexExternalSemaSource::ReadDynamicClasses(
00240                                        SmallVectorImpl<CXXRecordDecl*> &Decls) {
00241   for(size_t i = 0; i < Sources.size(); ++i)
00242     Sources[i]->ReadDynamicClasses(Decls);
00243 }
00244 
00245 void MultiplexExternalSemaSource::ReadUnusedLocalTypedefNameCandidates(
00246     llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) {
00247   for(size_t i = 0; i < Sources.size(); ++i)
00248     Sources[i]->ReadUnusedLocalTypedefNameCandidates(Decls);
00249 }
00250 
00251 void MultiplexExternalSemaSource::ReadLocallyScopedExternCDecls(
00252                                            SmallVectorImpl<NamedDecl*> &Decls) {
00253   for(size_t i = 0; i < Sources.size(); ++i)
00254     Sources[i]->ReadLocallyScopedExternCDecls(Decls);
00255 }
00256 
00257 void MultiplexExternalSemaSource::ReadReferencedSelectors(
00258                   SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {
00259   for(size_t i = 0; i < Sources.size(); ++i)
00260     Sources[i]->ReadReferencedSelectors(Sels);
00261 }
00262 
00263 void MultiplexExternalSemaSource::ReadWeakUndeclaredIdentifiers(
00264                    SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) {
00265   for(size_t i = 0; i < Sources.size(); ++i)
00266     Sources[i]->ReadWeakUndeclaredIdentifiers(WI);
00267 }
00268 
00269 void MultiplexExternalSemaSource::ReadUsedVTables(
00270                                   SmallVectorImpl<ExternalVTableUse> &VTables) {
00271   for(size_t i = 0; i < Sources.size(); ++i)
00272     Sources[i]->ReadUsedVTables(VTables);
00273 }
00274 
00275 void MultiplexExternalSemaSource::ReadPendingInstantiations(
00276                                            SmallVectorImpl<std::pair<ValueDecl*,
00277                                                    SourceLocation> > &Pending) {
00278   for(size_t i = 0; i < Sources.size(); ++i)
00279     Sources[i]->ReadPendingInstantiations(Pending);
00280 }
00281 
00282 void MultiplexExternalSemaSource::ReadLateParsedTemplates(
00283     llvm::DenseMap<const FunctionDecl *, LateParsedTemplate *> &LPTMap) {
00284   for (size_t i = 0; i < Sources.size(); ++i)
00285     Sources[i]->ReadLateParsedTemplates(LPTMap);
00286 }
00287 
00288 TypoCorrection MultiplexExternalSemaSource::CorrectTypo(
00289                                      const DeclarationNameInfo &Typo,
00290                                      int LookupKind, Scope *S, CXXScopeSpec *SS,
00291                                      CorrectionCandidateCallback &CCC,
00292                                      DeclContext *MemberContext,
00293                                      bool EnteringContext,
00294                                      const ObjCObjectPointerType *OPT) {
00295   for (size_t I = 0, E = Sources.size(); I < E; ++I) {
00296     if (TypoCorrection C = Sources[I]->CorrectTypo(Typo, LookupKind, S, SS, CCC,
00297                                                    MemberContext,
00298                                                    EnteringContext, OPT))
00299       return C;
00300   }
00301   return TypoCorrection();
00302 }
00303 
00304 bool MultiplexExternalSemaSource::MaybeDiagnoseMissingCompleteType(
00305     SourceLocation Loc, QualType T) {
00306   for (size_t I = 0, E = Sources.size(); I < E; ++I) {
00307     if (Sources[I]->MaybeDiagnoseMissingCompleteType(Loc, T))
00308       return true;
00309   }
00310   return false;
00311 }