MultiplexExternalSemaSource.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. //===--- MultiplexExternalSemaSource.cpp ---------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements the event dispatching to the subscribed clients.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "clang/Sema/MultiplexExternalSemaSource.h"
  13. #include "clang/Sema/Lookup.h"
  14. using namespace clang;
  15. char MultiplexExternalSemaSource::ID;
  16. /// Constructs a new multiplexing external sema source and appends the
  17. /// given element to it.
  18. ///
  19. MultiplexExternalSemaSource::MultiplexExternalSemaSource(
  20. ExternalSemaSource *S1, ExternalSemaSource *S2) {
  21. S1->Retain();
  22. S2->Retain();
  23. Sources.push_back(S1);
  24. Sources.push_back(S2);
  25. }
  26. // pin the vtable here.
  27. MultiplexExternalSemaSource::~MultiplexExternalSemaSource() {
  28. for (auto *S : Sources)
  29. S->Release();
  30. }
  31. /// Appends new source to the source list.
  32. ///
  33. ///\param[in] source - An ExternalSemaSource.
  34. ///
  35. void MultiplexExternalSemaSource::AddSource(ExternalSemaSource *Source) {
  36. Source->Retain();
  37. Sources.push_back(Source);
  38. }
  39. //===----------------------------------------------------------------------===//
  40. // ExternalASTSource.
  41. //===----------------------------------------------------------------------===//
  42. Decl *MultiplexExternalSemaSource::GetExternalDecl(uint32_t ID) {
  43. for(size_t i = 0; i < Sources.size(); ++i)
  44. if (Decl *Result = Sources[i]->GetExternalDecl(ID))
  45. return Result;
  46. return nullptr;
  47. }
  48. void MultiplexExternalSemaSource::CompleteRedeclChain(const Decl *D) {
  49. for (size_t i = 0; i < Sources.size(); ++i)
  50. Sources[i]->CompleteRedeclChain(D);
  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. uint32_t MultiplexExternalSemaSource::GetNumExternalSelectors() {
  62. uint32_t total = 0;
  63. for(size_t i = 0; i < Sources.size(); ++i)
  64. total += Sources[i]->GetNumExternalSelectors();
  65. return total;
  66. }
  67. Stmt *MultiplexExternalSemaSource::GetExternalDeclStmt(uint64_t Offset) {
  68. for(size_t i = 0; i < Sources.size(); ++i)
  69. if (Stmt *Result = Sources[i]->GetExternalDeclStmt(Offset))
  70. return Result;
  71. return nullptr;
  72. }
  73. CXXBaseSpecifier *MultiplexExternalSemaSource::GetExternalCXXBaseSpecifiers(
  74. uint64_t Offset){
  75. for(size_t i = 0; i < Sources.size(); ++i)
  76. if (CXXBaseSpecifier *R = Sources[i]->GetExternalCXXBaseSpecifiers(Offset))
  77. return R;
  78. return nullptr;
  79. }
  80. CXXCtorInitializer **
  81. MultiplexExternalSemaSource::GetExternalCXXCtorInitializers(uint64_t Offset) {
  82. for (auto *S : Sources)
  83. if (auto *R = S->GetExternalCXXCtorInitializers(Offset))
  84. return R;
  85. return nullptr;
  86. }
  87. ExternalASTSource::ExtKind
  88. MultiplexExternalSemaSource::hasExternalDefinitions(const Decl *D) {
  89. for (const auto &S : Sources)
  90. if (auto EK = S->hasExternalDefinitions(D))
  91. if (EK != EK_ReplyHazy)
  92. return EK;
  93. return EK_ReplyHazy;
  94. }
  95. bool MultiplexExternalSemaSource::
  96. FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name) {
  97. bool AnyDeclsFound = false;
  98. for (size_t i = 0; i < Sources.size(); ++i)
  99. AnyDeclsFound |= Sources[i]->FindExternalVisibleDeclsByName(DC, Name);
  100. return AnyDeclsFound;
  101. }
  102. void MultiplexExternalSemaSource::completeVisibleDeclsMap(const DeclContext *DC){
  103. for(size_t i = 0; i < Sources.size(); ++i)
  104. Sources[i]->completeVisibleDeclsMap(DC);
  105. }
  106. void MultiplexExternalSemaSource::FindExternalLexicalDecls(
  107. const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
  108. SmallVectorImpl<Decl *> &Result) {
  109. for(size_t i = 0; i < Sources.size(); ++i)
  110. Sources[i]->FindExternalLexicalDecls(DC, IsKindWeWant, Result);
  111. }
  112. void MultiplexExternalSemaSource::FindFileRegionDecls(FileID File,
  113. unsigned Offset,
  114. unsigned Length,
  115. SmallVectorImpl<Decl *> &Decls){
  116. for(size_t i = 0; i < Sources.size(); ++i)
  117. Sources[i]->FindFileRegionDecls(File, Offset, Length, Decls);
  118. }
  119. void MultiplexExternalSemaSource::CompleteType(TagDecl *Tag) {
  120. for(size_t i = 0; i < Sources.size(); ++i)
  121. Sources[i]->CompleteType(Tag);
  122. }
  123. void MultiplexExternalSemaSource::CompleteType(ObjCInterfaceDecl *Class) {
  124. for(size_t i = 0; i < Sources.size(); ++i)
  125. Sources[i]->CompleteType(Class);
  126. }
  127. void MultiplexExternalSemaSource::ReadComments() {
  128. for(size_t i = 0; i < Sources.size(); ++i)
  129. Sources[i]->ReadComments();
  130. }
  131. void MultiplexExternalSemaSource::StartedDeserializing() {
  132. for(size_t i = 0; i < Sources.size(); ++i)
  133. Sources[i]->StartedDeserializing();
  134. }
  135. void MultiplexExternalSemaSource::FinishedDeserializing() {
  136. for(size_t i = 0; i < Sources.size(); ++i)
  137. Sources[i]->FinishedDeserializing();
  138. }
  139. void MultiplexExternalSemaSource::StartTranslationUnit(ASTConsumer *Consumer) {
  140. for(size_t i = 0; i < Sources.size(); ++i)
  141. Sources[i]->StartTranslationUnit(Consumer);
  142. }
  143. void MultiplexExternalSemaSource::PrintStats() {
  144. for(size_t i = 0; i < Sources.size(); ++i)
  145. Sources[i]->PrintStats();
  146. }
  147. Module *MultiplexExternalSemaSource::getModule(unsigned ID) {
  148. for (size_t i = 0; i < Sources.size(); ++i)
  149. if (auto M = Sources[i]->getModule(ID))
  150. return M;
  151. return nullptr;
  152. }
  153. bool MultiplexExternalSemaSource::layoutRecordType(const RecordDecl *Record,
  154. uint64_t &Size,
  155. uint64_t &Alignment,
  156. llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
  157. llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
  158. llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets){
  159. for(size_t i = 0; i < Sources.size(); ++i)
  160. if (Sources[i]->layoutRecordType(Record, Size, Alignment, FieldOffsets,
  161. BaseOffsets, VirtualBaseOffsets))
  162. return true;
  163. return false;
  164. }
  165. void MultiplexExternalSemaSource::
  166. getMemoryBufferSizes(MemoryBufferSizes &sizes) const {
  167. for(size_t i = 0; i < Sources.size(); ++i)
  168. Sources[i]->getMemoryBufferSizes(sizes);
  169. }
  170. //===----------------------------------------------------------------------===//
  171. // ExternalSemaSource.
  172. //===----------------------------------------------------------------------===//
  173. void MultiplexExternalSemaSource::InitializeSema(Sema &S) {
  174. for(size_t i = 0; i < Sources.size(); ++i)
  175. Sources[i]->InitializeSema(S);
  176. }
  177. void MultiplexExternalSemaSource::ForgetSema() {
  178. for(size_t i = 0; i < Sources.size(); ++i)
  179. Sources[i]->ForgetSema();
  180. }
  181. void MultiplexExternalSemaSource::ReadMethodPool(Selector Sel) {
  182. for(size_t i = 0; i < Sources.size(); ++i)
  183. Sources[i]->ReadMethodPool(Sel);
  184. }
  185. void MultiplexExternalSemaSource::updateOutOfDateSelector(Selector Sel) {
  186. for(size_t i = 0; i < Sources.size(); ++i)
  187. Sources[i]->updateOutOfDateSelector(Sel);
  188. }
  189. void MultiplexExternalSemaSource::ReadKnownNamespaces(
  190. SmallVectorImpl<NamespaceDecl*> &Namespaces){
  191. for(size_t i = 0; i < Sources.size(); ++i)
  192. Sources[i]->ReadKnownNamespaces(Namespaces);
  193. }
  194. void MultiplexExternalSemaSource::ReadUndefinedButUsed(
  195. llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) {
  196. for(size_t i = 0; i < Sources.size(); ++i)
  197. Sources[i]->ReadUndefinedButUsed(Undefined);
  198. }
  199. void MultiplexExternalSemaSource::ReadMismatchingDeleteExpressions(
  200. llvm::MapVector<FieldDecl *,
  201. llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
  202. Exprs) {
  203. for (auto &Source : Sources)
  204. Source->ReadMismatchingDeleteExpressions(Exprs);
  205. }
  206. bool MultiplexExternalSemaSource::LookupUnqualified(LookupResult &R, Scope *S){
  207. for(size_t i = 0; i < Sources.size(); ++i)
  208. Sources[i]->LookupUnqualified(R, S);
  209. return !R.empty();
  210. }
  211. void MultiplexExternalSemaSource::ReadTentativeDefinitions(
  212. SmallVectorImpl<VarDecl*> &TentativeDefs) {
  213. for(size_t i = 0; i < Sources.size(); ++i)
  214. Sources[i]->ReadTentativeDefinitions(TentativeDefs);
  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. void MultiplexExternalSemaSource::ReadDelegatingConstructors(
  222. SmallVectorImpl<CXXConstructorDecl*> &Decls) {
  223. for(size_t i = 0; i < Sources.size(); ++i)
  224. Sources[i]->ReadDelegatingConstructors(Decls);
  225. }
  226. void MultiplexExternalSemaSource::ReadExtVectorDecls(
  227. SmallVectorImpl<TypedefNameDecl*> &Decls) {
  228. for(size_t i = 0; i < Sources.size(); ++i)
  229. Sources[i]->ReadExtVectorDecls(Decls);
  230. }
  231. void MultiplexExternalSemaSource::ReadDeclsToCheckForDeferredDiags(
  232. llvm::SmallSetVector<Decl *, 4> &Decls) {
  233. for(size_t i = 0; i < Sources.size(); ++i)
  234. Sources[i]->ReadDeclsToCheckForDeferredDiags(Decls);
  235. }
  236. void MultiplexExternalSemaSource::ReadUnusedLocalTypedefNameCandidates(
  237. llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) {
  238. for(size_t i = 0; i < Sources.size(); ++i)
  239. Sources[i]->ReadUnusedLocalTypedefNameCandidates(Decls);
  240. }
  241. void MultiplexExternalSemaSource::ReadReferencedSelectors(
  242. SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) {
  243. for(size_t i = 0; i < Sources.size(); ++i)
  244. Sources[i]->ReadReferencedSelectors(Sels);
  245. }
  246. void MultiplexExternalSemaSource::ReadWeakUndeclaredIdentifiers(
  247. SmallVectorImpl<std::pair<IdentifierInfo*, WeakInfo> > &WI) {
  248. for(size_t i = 0; i < Sources.size(); ++i)
  249. Sources[i]->ReadWeakUndeclaredIdentifiers(WI);
  250. }
  251. void MultiplexExternalSemaSource::ReadUsedVTables(
  252. SmallVectorImpl<ExternalVTableUse> &VTables) {
  253. for(size_t i = 0; i < Sources.size(); ++i)
  254. Sources[i]->ReadUsedVTables(VTables);
  255. }
  256. void MultiplexExternalSemaSource::ReadPendingInstantiations(
  257. SmallVectorImpl<std::pair<ValueDecl*,
  258. SourceLocation> > &Pending) {
  259. for(size_t i = 0; i < Sources.size(); ++i)
  260. Sources[i]->ReadPendingInstantiations(Pending);
  261. }
  262. void MultiplexExternalSemaSource::ReadLateParsedTemplates(
  263. llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
  264. &LPTMap) {
  265. for (size_t i = 0; i < Sources.size(); ++i)
  266. Sources[i]->ReadLateParsedTemplates(LPTMap);
  267. }
  268. TypoCorrection MultiplexExternalSemaSource::CorrectTypo(
  269. const DeclarationNameInfo &Typo,
  270. int LookupKind, Scope *S, CXXScopeSpec *SS,
  271. CorrectionCandidateCallback &CCC,
  272. DeclContext *MemberContext,
  273. bool EnteringContext,
  274. const ObjCObjectPointerType *OPT) {
  275. for (size_t I = 0, E = Sources.size(); I < E; ++I) {
  276. if (TypoCorrection C = Sources[I]->CorrectTypo(Typo, LookupKind, S, SS, CCC,
  277. MemberContext,
  278. EnteringContext, OPT))
  279. return C;
  280. }
  281. return TypoCorrection();
  282. }
  283. bool MultiplexExternalSemaSource::MaybeDiagnoseMissingCompleteType(
  284. SourceLocation Loc, QualType T) {
  285. for (size_t I = 0, E = Sources.size(); I < E; ++I) {
  286. if (Sources[I]->MaybeDiagnoseMissingCompleteType(Loc, T))
  287. return true;
  288. }
  289. return false;
  290. }