MultiplexExternalSemaSource.cpp 12 KB

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