clang  13.0.0git
ASTUnit.cpp
Go to the documentation of this file.
1 //===- ASTUnit.cpp - ASTUnit utility --------------------------------------===//
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 // ASTUnit Implementation.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "clang/Frontend/ASTUnit.h"
14 #include "clang/AST/ASTConsumer.h"
15 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/Decl.h"
18 #include "clang/AST/DeclBase.h"
19 #include "clang/AST/DeclCXX.h"
20 #include "clang/AST/DeclGroup.h"
21 #include "clang/AST/DeclObjC.h"
22 #include "clang/AST/DeclTemplate.h"
26 #include "clang/AST/Type.h"
27 #include "clang/AST/TypeOrdering.h"
28 #include "clang/Basic/Diagnostic.h"
31 #include "clang/Basic/LLVM.h"
34 #include "clang/Basic/Module.h"
37 #include "clang/Basic/TargetInfo.h"
47 #include "clang/Frontend/Utils.h"
48 #include "clang/Lex/HeaderSearch.h"
50 #include "clang/Lex/Lexer.h"
51 #include "clang/Lex/PPCallbacks.h"
53 #include "clang/Lex/Preprocessor.h"
55 #include "clang/Lex/Token.h"
58 #include "clang/Sema/Sema.h"
66 #include "llvm/ADT/ArrayRef.h"
67 #include "llvm/ADT/DenseMap.h"
68 #include "llvm/ADT/IntrusiveRefCntPtr.h"
69 #include "llvm/ADT/None.h"
70 #include "llvm/ADT/Optional.h"
71 #include "llvm/ADT/STLExtras.h"
72 #include "llvm/ADT/ScopeExit.h"
73 #include "llvm/ADT/SmallString.h"
74 #include "llvm/ADT/SmallVector.h"
75 #include "llvm/ADT/StringMap.h"
76 #include "llvm/ADT/StringRef.h"
77 #include "llvm/ADT/StringSet.h"
78 #include "llvm/ADT/Twine.h"
79 #include "llvm/ADT/iterator_range.h"
80 #include "llvm/Bitstream/BitstreamWriter.h"
81 #include "llvm/Support/Allocator.h"
82 #include "llvm/Support/Casting.h"
83 #include "llvm/Support/CrashRecoveryContext.h"
84 #include "llvm/Support/DJB.h"
85 #include "llvm/Support/ErrorHandling.h"
86 #include "llvm/Support/ErrorOr.h"
87 #include "llvm/Support/FileSystem.h"
88 #include "llvm/Support/FileUtilities.h"
89 #include "llvm/Support/MemoryBuffer.h"
90 #include "llvm/Support/Timer.h"
91 #include "llvm/Support/VirtualFileSystem.h"
92 #include "llvm/Support/raw_ostream.h"
93 #include <algorithm>
94 #include <atomic>
95 #include <cassert>
96 #include <cstdint>
97 #include <cstdio>
98 #include <cstdlib>
99 #include <memory>
100 #include <mutex>
101 #include <string>
102 #include <tuple>
103 #include <utility>
104 #include <vector>
105 
106 using namespace clang;
107 
108 using llvm::TimeRecord;
109 
110 namespace {
111 
112  class SimpleTimer {
113  bool WantTiming;
114  TimeRecord Start;
115  std::string Output;
116 
117  public:
118  explicit SimpleTimer(bool WantTiming) : WantTiming(WantTiming) {
119  if (WantTiming)
120  Start = TimeRecord::getCurrentTime();
121  }
122 
123  ~SimpleTimer() {
124  if (WantTiming) {
125  TimeRecord Elapsed = TimeRecord::getCurrentTime();
126  Elapsed -= Start;
127  llvm::errs() << Output << ':';
128  Elapsed.print(Elapsed, llvm::errs());
129  llvm::errs() << '\n';
130  }
131  }
132 
133  void setOutput(const Twine &Output) {
134  if (WantTiming)
135  this->Output = Output.str();
136  }
137  };
138 
139 } // namespace
140 
141 template <class T>
142 static std::unique_ptr<T> valueOrNull(llvm::ErrorOr<std::unique_ptr<T>> Val) {
143  if (!Val)
144  return nullptr;
145  return std::move(*Val);
146 }
147 
148 template <class T>
149 static bool moveOnNoError(llvm::ErrorOr<T> Val, T &Output) {
150  if (!Val)
151  return false;
152  Output = std::move(*Val);
153  return true;
154 }
155 
156 /// Get a source buffer for \p MainFilePath, handling all file-to-file
157 /// and file-to-buffer remappings inside \p Invocation.
158 static std::unique_ptr<llvm::MemoryBuffer>
160  llvm::vfs::FileSystem *VFS,
161  StringRef FilePath, bool isVolatile) {
162  const auto &PreprocessorOpts = Invocation.getPreprocessorOpts();
163 
164  // Try to determine if the main file has been remapped, either from the
165  // command line (to another file) or directly through the compiler
166  // invocation (to a memory buffer).
167  llvm::MemoryBuffer *Buffer = nullptr;
168  std::unique_ptr<llvm::MemoryBuffer> BufferOwner;
169  auto FileStatus = VFS->status(FilePath);
170  if (FileStatus) {
171  llvm::sys::fs::UniqueID MainFileID = FileStatus->getUniqueID();
172 
173  // Check whether there is a file-file remapping of the main file
174  for (const auto &RF : PreprocessorOpts.RemappedFiles) {
175  std::string MPath(RF.first);
176  auto MPathStatus = VFS->status(MPath);
177  if (MPathStatus) {
178  llvm::sys::fs::UniqueID MID = MPathStatus->getUniqueID();
179  if (MainFileID == MID) {
180  // We found a remapping. Try to load the resulting, remapped source.
181  BufferOwner = valueOrNull(VFS->getBufferForFile(RF.second, -1, true, isVolatile));
182  if (!BufferOwner)
183  return nullptr;
184  }
185  }
186  }
187 
188  // Check whether there is a file-buffer remapping. It supercedes the
189  // file-file remapping.
190  for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) {
191  std::string MPath(RB.first);
192  auto MPathStatus = VFS->status(MPath);
193  if (MPathStatus) {
194  llvm::sys::fs::UniqueID MID = MPathStatus->getUniqueID();
195  if (MainFileID == MID) {
196  // We found a remapping.
197  BufferOwner.reset();
198  Buffer = const_cast<llvm::MemoryBuffer *>(RB.second);
199  }
200  }
201  }
202  }
203 
204  // If the main source file was not remapped, load it now.
205  if (!Buffer && !BufferOwner) {
206  BufferOwner = valueOrNull(VFS->getBufferForFile(FilePath, -1, true, isVolatile));
207  if (!BufferOwner)
208  return nullptr;
209  }
210 
211  if (BufferOwner)
212  return BufferOwner;
213  if (!Buffer)
214  return nullptr;
215  return llvm::MemoryBuffer::getMemBufferCopy(Buffer->getBuffer(), FilePath);
216 }
217 
220  llvm::BitstreamWriter Stream;
222 
224  : Stream(Buffer), Writer(Stream, Buffer, ModuleCache, {}) {}
225 };
226 
227 void ASTUnit::clearFileLevelDecls() {
228  FileDecls.clear();
229 }
230 
231 /// After failing to build a precompiled preamble (due to
232 /// errors in the source that occurs in the preamble), the number of
233 /// reparses during which we'll skip even trying to precompile the
234 /// preamble.
236 
237 /// Tracks the number of ASTUnit objects that are currently active.
238 ///
239 /// Used for debugging purposes only.
240 static std::atomic<unsigned> ActiveASTUnitObjects;
241 
242 ASTUnit::ASTUnit(bool _MainFileIsAST)
243  : MainFileIsAST(_MainFileIsAST), WantTiming(getenv("LIBCLANG_TIMING")),
244  ShouldCacheCodeCompletionResults(false),
245  IncludeBriefCommentsInCodeCompletion(false), UserFilesAreVolatile(false),
246  UnsafeToFree(false) {
247  if (getenv("LIBCLANG_OBJTRACKING"))
248  fprintf(stderr, "+++ %u translation units\n", ++ActiveASTUnitObjects);
249 }
250 
251 ASTUnit::~ASTUnit() {
252  // If we loaded from an AST file, balance out the BeginSourceFile call.
253  if (MainFileIsAST && getDiagnostics().getClient()) {
255  }
256 
257  clearFileLevelDecls();
258 
259  // Free the buffers associated with remapped files. We are required to
260  // perform this operation here because we explicitly request that the
261  // compiler instance *not* free these buffers for each invocation of the
262  // parser.
263  if (Invocation && OwnsRemappedFileBuffers) {
264  PreprocessorOptions &PPOpts = Invocation->getPreprocessorOpts();
265  for (const auto &RB : PPOpts.RemappedFileBuffers)
266  delete RB.second;
267  }
268 
269  ClearCachedCompletionResults();
270 
271  if (getenv("LIBCLANG_OBJTRACKING"))
272  fprintf(stderr, "--- %u translation units\n", --ActiveASTUnitObjects);
273 }
274 
275 void ASTUnit::setPreprocessor(std::shared_ptr<Preprocessor> PP) {
276  this->PP = std::move(PP);
277 }
278 
280  assert(getDiagnostics().getClient() && Ctx &&
281  "Bad context for source file");
282  getDiagnostics().getClient()->BeginSourceFile(Ctx->getLangOpts(), PP.get());
283 }
284 
285 /// Determine the set of code-completion contexts in which this
286 /// declaration should be shown.
287 static uint64_t getDeclShowContexts(const NamedDecl *ND,
288  const LangOptions &LangOpts,
289  bool &IsNestedNameSpecifier) {
290  IsNestedNameSpecifier = false;
291 
292  if (isa<UsingShadowDecl>(ND))
293  ND = ND->getUnderlyingDecl();
294  if (!ND)
295  return 0;
296 
297  uint64_t Contexts = 0;
298  if (isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND) ||
299  isa<ClassTemplateDecl>(ND) || isa<TemplateTemplateParmDecl>(ND) ||
300  isa<TypeAliasTemplateDecl>(ND)) {
301  // Types can appear in these contexts.
302  if (LangOpts.CPlusPlus || !isa<TagDecl>(ND))
303  Contexts |= (1LL << CodeCompletionContext::CCC_TopLevel)
309 
310  // In C++, types can appear in expressions contexts (for functional casts).
311  if (LangOpts.CPlusPlus)
312  Contexts |= (1LL << CodeCompletionContext::CCC_Expression);
313 
314  // In Objective-C, message sends can send interfaces. In Objective-C++,
315  // all types are available due to functional casts.
316  if (LangOpts.CPlusPlus || isa<ObjCInterfaceDecl>(ND))
318 
319  // In Objective-C, you can only be a subclass of another Objective-C class
320  if (const auto *ID = dyn_cast<ObjCInterfaceDecl>(ND)) {
321  // Objective-C interfaces can be used in a class property expression.
322  if (ID->getDefinition())
323  Contexts |= (1LL << CodeCompletionContext::CCC_Expression);
325  }
326 
327  // Deal with tag names.
328  if (isa<EnumDecl>(ND)) {
329  Contexts |= (1LL << CodeCompletionContext::CCC_EnumTag);
330 
331  // Part of the nested-name-specifier in C++0x.
332  if (LangOpts.CPlusPlus11)
333  IsNestedNameSpecifier = true;
334  } else if (const auto *Record = dyn_cast<RecordDecl>(ND)) {
335  if (Record->isUnion())
336  Contexts |= (1LL << CodeCompletionContext::CCC_UnionTag);
337  else
338  Contexts |= (1LL << CodeCompletionContext::CCC_ClassOrStructTag);
339 
340  if (LangOpts.CPlusPlus)
341  IsNestedNameSpecifier = true;
342  } else if (isa<ClassTemplateDecl>(ND))
343  IsNestedNameSpecifier = true;
344  } else if (isa<ValueDecl>(ND) || isa<FunctionTemplateDecl>(ND)) {
345  // Values can appear in these contexts.
346  Contexts = (1LL << CodeCompletionContext::CCC_Statement)
350  } else if (isa<ObjCProtocolDecl>(ND)) {
352  } else if (isa<ObjCCategoryDecl>(ND)) {
354  } else if (isa<NamespaceDecl>(ND) || isa<NamespaceAliasDecl>(ND)) {
355  Contexts = (1LL << CodeCompletionContext::CCC_Namespace);
356 
357  // Part of the nested-name-specifier.
358  IsNestedNameSpecifier = true;
359  }
360 
361  return Contexts;
362 }
363 
364 void ASTUnit::CacheCodeCompletionResults() {
365  if (!TheSema)
366  return;
367 
368  SimpleTimer Timer(WantTiming);
369  Timer.setOutput("Cache global code completions for " + getMainFileName());
370 
371  // Clear out the previous results.
372  ClearCachedCompletionResults();
373 
374  // Gather the set of global code completions.
375  using Result = CodeCompletionResult;
376  SmallVector<Result, 8> Results;
377  CachedCompletionAllocator = std::make_shared<GlobalCodeCompletionAllocator>();
378  CodeCompletionTUInfo CCTUInfo(CachedCompletionAllocator);
379  TheSema->GatherGlobalCodeCompletions(*CachedCompletionAllocator,
380  CCTUInfo, Results);
381 
382  // Translate global code completions into cached completions.
383  llvm::DenseMap<CanQualType, unsigned> CompletionTypes;
385 
386  for (auto &R : Results) {
387  switch (R.Kind) {
388  case Result::RK_Declaration: {
389  bool IsNestedNameSpecifier = false;
390  CachedCodeCompletionResult CachedResult;
391  CachedResult.Completion = R.CreateCodeCompletionString(
392  *TheSema, CCContext, *CachedCompletionAllocator, CCTUInfo,
393  IncludeBriefCommentsInCodeCompletion);
394  CachedResult.ShowInContexts = getDeclShowContexts(
395  R.Declaration, Ctx->getLangOpts(), IsNestedNameSpecifier);
396  CachedResult.Priority = R.Priority;
397  CachedResult.Kind = R.CursorKind;
398  CachedResult.Availability = R.Availability;
399 
400  // Keep track of the type of this completion in an ASTContext-agnostic
401  // way.
402  QualType UsageType = getDeclUsageType(*Ctx, R.Declaration);
403  if (UsageType.isNull()) {
404  CachedResult.TypeClass = STC_Void;
405  CachedResult.Type = 0;
406  } else {
407  CanQualType CanUsageType
408  = Ctx->getCanonicalType(UsageType.getUnqualifiedType());
409  CachedResult.TypeClass = getSimplifiedTypeClass(CanUsageType);
410 
411  // Determine whether we have already seen this type. If so, we save
412  // ourselves the work of formatting the type string by using the
413  // temporary, CanQualType-based hash table to find the associated value.
414  unsigned &TypeValue = CompletionTypes[CanUsageType];
415  if (TypeValue == 0) {
416  TypeValue = CompletionTypes.size();
417  CachedCompletionTypes[QualType(CanUsageType).getAsString()]
418  = TypeValue;
419  }
420 
421  CachedResult.Type = TypeValue;
422  }
423 
424  CachedCompletionResults.push_back(CachedResult);
425 
426  /// Handle nested-name-specifiers in C++.
427  if (TheSema->Context.getLangOpts().CPlusPlus && IsNestedNameSpecifier &&
428  !R.StartsNestedNameSpecifier) {
429  // The contexts in which a nested-name-specifier can appear in C++.
430  uint64_t NNSContexts
443 
444  if (isa<NamespaceDecl>(R.Declaration) ||
445  isa<NamespaceAliasDecl>(R.Declaration))
446  NNSContexts |= (1LL << CodeCompletionContext::CCC_Namespace);
447 
448  if (uint64_t RemainingContexts
449  = NNSContexts & ~CachedResult.ShowInContexts) {
450  // If there any contexts where this completion can be a
451  // nested-name-specifier but isn't already an option, create a
452  // nested-name-specifier completion.
453  R.StartsNestedNameSpecifier = true;
454  CachedResult.Completion = R.CreateCodeCompletionString(
455  *TheSema, CCContext, *CachedCompletionAllocator, CCTUInfo,
456  IncludeBriefCommentsInCodeCompletion);
457  CachedResult.ShowInContexts = RemainingContexts;
458  CachedResult.Priority = CCP_NestedNameSpecifier;
459  CachedResult.TypeClass = STC_Void;
460  CachedResult.Type = 0;
461  CachedCompletionResults.push_back(CachedResult);
462  }
463  }
464  break;
465  }
466 
467  case Result::RK_Keyword:
468  case Result::RK_Pattern:
469  // Ignore keywords and patterns; we don't care, since they are so
470  // easily regenerated.
471  break;
472 
473  case Result::RK_Macro: {
474  CachedCodeCompletionResult CachedResult;
475  CachedResult.Completion = R.CreateCodeCompletionString(
476  *TheSema, CCContext, *CachedCompletionAllocator, CCTUInfo,
477  IncludeBriefCommentsInCodeCompletion);
478  CachedResult.ShowInContexts
491 
492  CachedResult.Priority = R.Priority;
493  CachedResult.Kind = R.CursorKind;
494  CachedResult.Availability = R.Availability;
495  CachedResult.TypeClass = STC_Void;
496  CachedResult.Type = 0;
497  CachedCompletionResults.push_back(CachedResult);
498  break;
499  }
500  }
501  }
502 
503  // Save the current top-level hash value.
504  CompletionCacheTopLevelHashValue = CurrentTopLevelHashValue;
505 }
506 
507 void ASTUnit::ClearCachedCompletionResults() {
508  CachedCompletionResults.clear();
509  CachedCompletionTypes.clear();
510  CachedCompletionAllocator = nullptr;
511 }
512 
513 namespace {
514 
515 /// Gathers information from ASTReader that will be used to initialize
516 /// a Preprocessor.
517 class ASTInfoCollector : public ASTReaderListener {
518  Preprocessor &PP;
519  ASTContext *Context;
520  HeaderSearchOptions &HSOpts;
521  PreprocessorOptions &PPOpts;
522  LangOptions &LangOpt;
523  std::shared_ptr<TargetOptions> &TargetOpts;
525  unsigned &Counter;
526  bool InitializedLanguage = false;
527 
528 public:
529  ASTInfoCollector(Preprocessor &PP, ASTContext *Context,
530  HeaderSearchOptions &HSOpts, PreprocessorOptions &PPOpts,
531  LangOptions &LangOpt,
532  std::shared_ptr<TargetOptions> &TargetOpts,
533  IntrusiveRefCntPtr<TargetInfo> &Target, unsigned &Counter)
534  : PP(PP), Context(Context), HSOpts(HSOpts), PPOpts(PPOpts),
535  LangOpt(LangOpt), TargetOpts(TargetOpts), Target(Target),
536  Counter(Counter) {}
537 
538  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
539  bool AllowCompatibleDifferences) override {
540  if (InitializedLanguage)
541  return false;
542 
543  LangOpt = LangOpts;
544  InitializedLanguage = true;
545 
546  updated();
547  return false;
548  }
549 
550  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
551  StringRef SpecificModuleCachePath,
552  bool Complain) override {
553  this->HSOpts = HSOpts;
554  return false;
555  }
556 
557  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
558  std::string &SuggestedPredefines) override {
559  this->PPOpts = PPOpts;
560  return false;
561  }
562 
563  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
564  bool AllowCompatibleDifferences) override {
565  // If we've already initialized the target, don't do it again.
566  if (Target)
567  return false;
568 
569  this->TargetOpts = std::make_shared<TargetOptions>(TargetOpts);
570  Target =
571  TargetInfo::CreateTargetInfo(PP.getDiagnostics(), this->TargetOpts);
572 
573  updated();
574  return false;
575  }
576 
577  void ReadCounter(const serialization::ModuleFile &M,
578  unsigned Value) override {
579  Counter = Value;
580  }
581 
582 private:
583  void updated() {
584  if (!Target || !InitializedLanguage)
585  return;
586 
587  // Inform the target of the language options.
588  //
589  // FIXME: We shouldn't need to do this, the target should be immutable once
590  // created. This complexity should be lifted elsewhere.
591  Target->adjust(LangOpt);
592 
593  // Initialize the preprocessor.
594  PP.Initialize(*Target);
595 
596  if (!Context)
597  return;
598 
599  // Initialize the ASTContext
600  Context->InitBuiltinTypes(*Target);
601 
602  // Adjust printing policy based on language options.
603  Context->setPrintingPolicy(PrintingPolicy(LangOpt));
604 
605  // We didn't have access to the comment options when the ASTContext was
606  // constructed, so register them now.
608  LangOpt.CommentOpts);
609  }
610 };
611 
612 /// Diagnostic consumer that saves each diagnostic it is given.
613 class FilterAndStoreDiagnosticConsumer : public DiagnosticConsumer {
616  bool CaptureNonErrorsFromIncludes = true;
617  const LangOptions *LangOpts = nullptr;
618  SourceManager *SourceMgr = nullptr;
619 
620 public:
621  FilterAndStoreDiagnosticConsumer(
624  bool CaptureNonErrorsFromIncludes)
625  : StoredDiags(StoredDiags), StandaloneDiags(StandaloneDiags),
626  CaptureNonErrorsFromIncludes(CaptureNonErrorsFromIncludes) {
627  assert((StoredDiags || StandaloneDiags) &&
628  "No output collections were passed to StoredDiagnosticConsumer.");
629  }
630 
631  void BeginSourceFile(const LangOptions &LangOpts,
632  const Preprocessor *PP = nullptr) override {
633  this->LangOpts = &LangOpts;
634  if (PP)
635  SourceMgr = &PP->getSourceManager();
636  }
637 
638  void HandleDiagnostic(DiagnosticsEngine::Level Level,
639  const Diagnostic &Info) override;
640 };
641 
642 /// RAII object that optionally captures and filters diagnostics, if
643 /// there is no diagnostic client to capture them already.
644 class CaptureDroppedDiagnostics {
645  DiagnosticsEngine &Diags;
646  FilterAndStoreDiagnosticConsumer Client;
647  DiagnosticConsumer *PreviousClient = nullptr;
648  std::unique_ptr<DiagnosticConsumer> OwningPreviousClient;
649 
650 public:
651  CaptureDroppedDiagnostics(
652  CaptureDiagsKind CaptureDiagnostics, DiagnosticsEngine &Diags,
655  : Diags(Diags),
656  Client(StoredDiags, StandaloneDiags,
657  CaptureDiagnostics !=
659  if (CaptureDiagnostics != CaptureDiagsKind::None ||
660  Diags.getClient() == nullptr) {
661  OwningPreviousClient = Diags.takeClient();
662  PreviousClient = Diags.getClient();
663  Diags.setClient(&Client, false);
664  }
665  }
666 
667  ~CaptureDroppedDiagnostics() {
668  if (Diags.getClient() == &Client)
669  Diags.setClient(PreviousClient, !!OwningPreviousClient.release());
670  }
671 };
672 
673 } // namespace
674 
676 makeStandaloneDiagnostic(const LangOptions &LangOpts,
677  const StoredDiagnostic &InDiag);
678 
679 static bool isInMainFile(const clang::Diagnostic &D) {
680  if (!D.hasSourceManager() || !D.getLocation().isValid())
681  return false;
682 
683  auto &M = D.getSourceManager();
684  return M.isWrittenInMainFile(M.getExpansionLoc(D.getLocation()));
685 }
686 
687 void FilterAndStoreDiagnosticConsumer::HandleDiagnostic(
689  // Default implementation (Warnings/errors count).
691 
692  // Only record the diagnostic if it's part of the source manager we know
693  // about. This effectively drops diagnostics from modules we're building.
694  // FIXME: In the long run, ee don't want to drop source managers from modules.
695  if (!Info.hasSourceManager() || &Info.getSourceManager() == SourceMgr) {
696  if (!CaptureNonErrorsFromIncludes && Level <= DiagnosticsEngine::Warning &&
697  !isInMainFile(Info)) {
698  return;
699  }
700 
701  StoredDiagnostic *ResultDiag = nullptr;
702  if (StoredDiags) {
703  StoredDiags->emplace_back(Level, Info);
704  ResultDiag = &StoredDiags->back();
705  }
706 
707  if (StandaloneDiags) {
709  if (!ResultDiag) {
710  StoredDiag.emplace(Level, Info);
711  ResultDiag = StoredDiag.getPointer();
712  }
713  StandaloneDiags->push_back(
714  makeStandaloneDiagnostic(*LangOpts, *ResultDiag));
715  }
716  }
717 }
718 
720  return Reader;
721 }
722 
724  if (WriterData)
725  return &WriterData->Writer;
726  return nullptr;
727 }
728 
730  if (WriterData)
731  return &WriterData->Writer;
732  return nullptr;
733 }
734 
735 std::unique_ptr<llvm::MemoryBuffer>
736 ASTUnit::getBufferForFile(StringRef Filename, std::string *ErrorStr) {
737  assert(FileMgr);
738  auto Buffer = FileMgr->getBufferForFile(Filename, UserFilesAreVolatile);
739  if (Buffer)
740  return std::move(*Buffer);
741  if (ErrorStr)
742  *ErrorStr = Buffer.getError().message();
743  return nullptr;
744 }
745 
746 /// Configure the diagnostics object for use with ASTUnit.
747 void ASTUnit::ConfigureDiags(IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
748  ASTUnit &AST,
749  CaptureDiagsKind CaptureDiagnostics) {
750  assert(Diags.get() && "no DiagnosticsEngine was provided");
751  if (CaptureDiagnostics != CaptureDiagsKind::None)
752  Diags->setClient(new FilterAndStoreDiagnosticConsumer(
753  &AST.StoredDiagnostics, nullptr,
755 }
756 
757 std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
758  const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
760  const FileSystemOptions &FileSystemOpts, bool UseDebugInfo,
761  bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
762  bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
763  std::unique_ptr<ASTUnit> AST(new ASTUnit(true));
764 
765  // Recover resources if we crash before exiting this method.
766  llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
767  ASTUnitCleanup(AST.get());
768  llvm::CrashRecoveryContextCleanupRegistrar<DiagnosticsEngine,
769  llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine>>
770  DiagCleanup(Diags.get());
771 
772  ConfigureDiags(Diags, *AST, CaptureDiagnostics);
773 
774  AST->LangOpts = std::make_shared<LangOptions>();
775  AST->OnlyLocalDecls = OnlyLocalDecls;
776  AST->CaptureDiagnostics = CaptureDiagnostics;
777  AST->Diagnostics = Diags;
779  llvm::vfs::getRealFileSystem();
780  AST->FileMgr = new FileManager(FileSystemOpts, VFS);
781  AST->UserFilesAreVolatile = UserFilesAreVolatile;
782  AST->SourceMgr = new SourceManager(AST->getDiagnostics(),
783  AST->getFileManager(),
784  UserFilesAreVolatile);
785  AST->ModuleCache = new InMemoryModuleCache;
786  AST->HSOpts = std::make_shared<HeaderSearchOptions>();
787  AST->HSOpts->ModuleFormat = std::string(PCHContainerRdr.getFormat());
788  AST->HeaderInfo.reset(new HeaderSearch(AST->HSOpts,
789  AST->getSourceManager(),
790  AST->getDiagnostics(),
791  AST->getLangOpts(),
792  /*Target=*/nullptr));
793  AST->PPOpts = std::make_shared<PreprocessorOptions>();
794 
795  // Gather Info for preprocessor construction later on.
796 
797  HeaderSearch &HeaderInfo = *AST->HeaderInfo;
798  unsigned Counter;
799 
800  AST->PP = std::make_shared<Preprocessor>(
801  AST->PPOpts, AST->getDiagnostics(), *AST->LangOpts,
802  AST->getSourceManager(), HeaderInfo, AST->ModuleLoader,
803  /*IILookup=*/nullptr,
804  /*OwnsHeaderSearch=*/false);
805  Preprocessor &PP = *AST->PP;
806 
807  if (ToLoad >= LoadASTOnly)
808  AST->Ctx = new ASTContext(*AST->LangOpts, AST->getSourceManager(),
810  PP.getBuiltinInfo());
811 
812  DisableValidationForModuleKind disableValid =
814  if (::getenv("LIBCLANG_DISABLE_PCH_VALIDATION"))
816  AST->Reader = new ASTReader(
817  PP, *AST->ModuleCache, AST->Ctx.get(), PCHContainerRdr, {},
818  /*isysroot=*/"",
819  /*DisableValidation=*/disableValid, AllowASTWithCompilerErrors);
820 
821  AST->Reader->setListener(std::make_unique<ASTInfoCollector>(
822  *AST->PP, AST->Ctx.get(), *AST->HSOpts, *AST->PPOpts, *AST->LangOpts,
823  AST->TargetOpts, AST->Target, Counter));
824 
825  // Attach the AST reader to the AST context as an external AST
826  // source, so that declarations will be deserialized from the
827  // AST file as needed.
828  // We need the external source to be set up before we read the AST, because
829  // eagerly-deserialized declarations may use it.
830  if (AST->Ctx)
831  AST->Ctx->setExternalSource(AST->Reader);
832 
833  switch (AST->Reader->ReadAST(Filename, serialization::MK_MainFile,
835  case ASTReader::Success:
836  break;
837 
838  case ASTReader::Failure:
839  case ASTReader::Missing:
844  AST->getDiagnostics().Report(diag::err_fe_unable_to_load_pch);
845  return nullptr;
846  }
847 
848  AST->OriginalSourceFile = std::string(AST->Reader->getOriginalSourceFile());
849 
850  PP.setCounterValue(Counter);
851 
852  // Create an AST consumer, even though it isn't used.
853  if (ToLoad >= LoadASTOnly)
854  AST->Consumer.reset(new ASTConsumer);
855 
856  // Create a semantic analysis object and tell the AST reader about it.
857  if (ToLoad >= LoadEverything) {
858  AST->TheSema.reset(new Sema(PP, *AST->Ctx, *AST->Consumer));
859  AST->TheSema->Initialize();
860  AST->Reader->InitializeSema(*AST->TheSema);
861  }
862 
863  // Tell the diagnostic client that we have started a source file.
864  AST->getDiagnostics().getClient()->BeginSourceFile(PP.getLangOpts(), &PP);
865 
866  return AST;
867 }
868 
869 /// Add the given macro to the hash of all top-level entities.
870 static void AddDefinedMacroToHash(const Token &MacroNameTok, unsigned &Hash) {
871  Hash = llvm::djbHash(MacroNameTok.getIdentifierInfo()->getName(), Hash);
872 }
873 
874 namespace {
875 
876 /// Preprocessor callback class that updates a hash value with the names
877 /// of all macros that have been defined by the translation unit.
878 class MacroDefinitionTrackerPPCallbacks : public PPCallbacks {
879  unsigned &Hash;
880 
881 public:
882  explicit MacroDefinitionTrackerPPCallbacks(unsigned &Hash) : Hash(Hash) {}
883 
884  void MacroDefined(const Token &MacroNameTok,
885  const MacroDirective *MD) override {
886  AddDefinedMacroToHash(MacroNameTok, Hash);
887  }
888 };
889 
890 } // namespace
891 
892 /// Add the given declaration to the hash of all top-level entities.
893 static void AddTopLevelDeclarationToHash(Decl *D, unsigned &Hash) {
894  if (!D)
895  return;
896 
897  DeclContext *DC = D->getDeclContext();
898  if (!DC)
899  return;
900 
901  if (!(DC->isTranslationUnit() || DC->getLookupParent()->isTranslationUnit()))
902  return;
903 
904  if (const auto *ND = dyn_cast<NamedDecl>(D)) {
905  if (const auto *EnumD = dyn_cast<EnumDecl>(D)) {
906  // For an unscoped enum include the enumerators in the hash since they
907  // enter the top-level namespace.
908  if (!EnumD->isScoped()) {
909  for (const auto *EI : EnumD->enumerators()) {
910  if (EI->getIdentifier())
911  Hash = llvm::djbHash(EI->getIdentifier()->getName(), Hash);
912  }
913  }
914  }
915 
916  if (ND->getIdentifier())
917  Hash = llvm::djbHash(ND->getIdentifier()->getName(), Hash);
918  else if (DeclarationName Name = ND->getDeclName()) {
919  std::string NameStr = Name.getAsString();
920  Hash = llvm::djbHash(NameStr, Hash);
921  }
922  return;
923  }
924 
925  if (const auto *ImportD = dyn_cast<ImportDecl>(D)) {
926  if (const Module *Mod = ImportD->getImportedModule()) {
927  std::string ModName = Mod->getFullModuleName();
928  Hash = llvm::djbHash(ModName, Hash);
929  }
930  return;
931  }
932 }
933 
934 namespace {
935 
936 class TopLevelDeclTrackerConsumer : public ASTConsumer {
937  ASTUnit &Unit;
938  unsigned &Hash;
939 
940 public:
941  TopLevelDeclTrackerConsumer(ASTUnit &_Unit, unsigned &Hash)
942  : Unit(_Unit), Hash(Hash) {
943  Hash = 0;
944  }
945 
946  void handleTopLevelDecl(Decl *D) {
947  if (!D)
948  return;
949 
950  // FIXME: Currently ObjC method declarations are incorrectly being
951  // reported as top-level declarations, even though their DeclContext
952  // is the containing ObjC @interface/@implementation. This is a
953  // fundamental problem in the parser right now.
954  if (isa<ObjCMethodDecl>(D))
955  return;
956 
958  Unit.addTopLevelDecl(D);
959 
960  handleFileLevelDecl(D);
961  }
962 
963  void handleFileLevelDecl(Decl *D) {
964  Unit.addFileLevelDecl(D);
965  if (auto *NSD = dyn_cast<NamespaceDecl>(D)) {
966  for (auto *I : NSD->decls())
967  handleFileLevelDecl(I);
968  }
969  }
970 
971  bool HandleTopLevelDecl(DeclGroupRef D) override {
972  for (auto *TopLevelDecl : D)
973  handleTopLevelDecl(TopLevelDecl);
974  return true;
975  }
976 
977  // We're not interested in "interesting" decls.
978  void HandleInterestingDecl(DeclGroupRef) override {}
979 
980  void HandleTopLevelDeclInObjCContainer(DeclGroupRef D) override {
981  for (auto *TopLevelDecl : D)
982  handleTopLevelDecl(TopLevelDecl);
983  }
984 
985  ASTMutationListener *GetASTMutationListener() override {
986  return Unit.getASTMutationListener();
987  }
988 
989  ASTDeserializationListener *GetASTDeserializationListener() override {
990  return Unit.getDeserializationListener();
991  }
992 };
993 
994 class TopLevelDeclTrackerAction : public ASTFrontendAction {
995 public:
996  ASTUnit &Unit;
997 
998  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
999  StringRef InFile) override {
1001  std::make_unique<MacroDefinitionTrackerPPCallbacks>(
1002  Unit.getCurrentTopLevelHashValue()));
1003  return std::make_unique<TopLevelDeclTrackerConsumer>(
1004  Unit, Unit.getCurrentTopLevelHashValue());
1005  }
1006 
1007 public:
1008  TopLevelDeclTrackerAction(ASTUnit &_Unit) : Unit(_Unit) {}
1009 
1010  bool hasCodeCompletionSupport() const override { return false; }
1011 
1012  TranslationUnitKind getTranslationUnitKind() override {
1013  return Unit.getTranslationUnitKind();
1014  }
1015 };
1016 
1017 class ASTUnitPreambleCallbacks : public PreambleCallbacks {
1018 public:
1019  unsigned getHash() const { return Hash; }
1020 
1021  std::vector<Decl *> takeTopLevelDecls() { return std::move(TopLevelDecls); }
1022 
1023  std::vector<serialization::DeclID> takeTopLevelDeclIDs() {
1024  return std::move(TopLevelDeclIDs);
1025  }
1026 
1027  void AfterPCHEmitted(ASTWriter &Writer) override {
1028  TopLevelDeclIDs.reserve(TopLevelDecls.size());
1029  for (const auto *D : TopLevelDecls) {
1030  // Invalid top-level decls may not have been serialized.
1031  if (D->isInvalidDecl())
1032  continue;
1033  TopLevelDeclIDs.push_back(Writer.getDeclID(D));
1034  }
1035  }
1036 
1037  void HandleTopLevelDecl(DeclGroupRef DG) override {
1038  for (auto *D : DG) {
1039  // FIXME: Currently ObjC method declarations are incorrectly being
1040  // reported as top-level declarations, even though their DeclContext
1041  // is the containing ObjC @interface/@implementation. This is a
1042  // fundamental problem in the parser right now.
1043  if (isa<ObjCMethodDecl>(D))
1044  continue;
1046  TopLevelDecls.push_back(D);
1047  }
1048  }
1049 
1050  std::unique_ptr<PPCallbacks> createPPCallbacks() override {
1051  return std::make_unique<MacroDefinitionTrackerPPCallbacks>(Hash);
1052  }
1053 
1054 private:
1055  unsigned Hash = 0;
1056  std::vector<Decl *> TopLevelDecls;
1057  std::vector<serialization::DeclID> TopLevelDeclIDs;
1059 };
1060 
1061 } // namespace
1062 
1063 static bool isNonDriverDiag(const StoredDiagnostic &StoredDiag) {
1064  return StoredDiag.getLocation().isValid();
1065 }
1066 
1067 static void
1069  // Get rid of stored diagnostics except the ones from the driver which do not
1070  // have a source location.
1071  StoredDiags.erase(
1072  std::remove_if(StoredDiags.begin(), StoredDiags.end(), isNonDriverDiag),
1073  StoredDiags.end());
1074 }
1075 
1077  StoredDiagnostics,
1078  SourceManager &SM) {
1079  // The stored diagnostic has the old source manager in it; update
1080  // the locations to refer into the new source manager. Since we've
1081  // been careful to make sure that the source manager's state
1082  // before and after are identical, so that we can reuse the source
1083  // location itself.
1084  for (auto &SD : StoredDiagnostics) {
1085  if (SD.getLocation().isValid()) {
1086  FullSourceLoc Loc(SD.getLocation(), SM);
1087  SD.setLocation(Loc);
1088  }
1089  }
1090 }
1091 
1092 /// Parse the source file into a translation unit using the given compiler
1093 /// invocation, replacing the current translation unit.
1094 ///
1095 /// \returns True if a failure occurred that causes the ASTUnit not to
1096 /// contain any translation-unit information, false otherwise.
1097 bool ASTUnit::Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1098  std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer,
1100  if (!Invocation)
1101  return true;
1102 
1103  if (VFS && FileMgr)
1104  assert(VFS == &FileMgr->getVirtualFileSystem() &&
1105  "VFS passed to Parse and VFS in FileMgr are different");
1106 
1107  auto CCInvocation = std::make_shared<CompilerInvocation>(*Invocation);
1108  if (OverrideMainBuffer) {
1109  assert(Preamble &&
1110  "No preamble was built, but OverrideMainBuffer is not null");
1111  Preamble->AddImplicitPreamble(*CCInvocation, VFS, OverrideMainBuffer.get());
1112  // VFS may have changed...
1113  }
1114 
1115  // Create the compiler instance to use for building the AST.
1116  std::unique_ptr<CompilerInstance> Clang(
1117  new CompilerInstance(std::move(PCHContainerOps)));
1118 
1119  // Clean up on error, disengage it if the function returns successfully.
1120  auto CleanOnError = llvm::make_scope_exit([&]() {
1121  // Remove the overridden buffer we used for the preamble.
1122  SavedMainFileBuffer = nullptr;
1123 
1124  // Keep the ownership of the data in the ASTUnit because the client may
1125  // want to see the diagnostics.
1126  transferASTDataFromCompilerInstance(*Clang);
1127  FailedParseDiagnostics.swap(StoredDiagnostics);
1128  StoredDiagnostics.clear();
1129  NumStoredDiagnosticsFromDriver = 0;
1130  });
1131 
1132  // Ensure that Clang has a FileManager with the right VFS, which may have
1133  // changed above in AddImplicitPreamble. If VFS is nullptr, rely on
1134  // createFileManager to create one.
1135  if (VFS && FileMgr && &FileMgr->getVirtualFileSystem() == VFS)
1136  Clang->setFileManager(&*FileMgr);
1137  else
1138  FileMgr = Clang->createFileManager(std::move(VFS));
1139 
1140  // Recover resources if we crash before exiting this method.
1141  llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
1142  CICleanup(Clang.get());
1143 
1144  Clang->setInvocation(CCInvocation);
1145  OriginalSourceFile =
1146  std::string(Clang->getFrontendOpts().Inputs[0].getFile());
1147 
1148  // Set up diagnostics, capturing any diagnostics that would
1149  // otherwise be dropped.
1150  Clang->setDiagnostics(&getDiagnostics());
1151 
1152  // Create the target instance.
1153  Clang->setTarget(TargetInfo::CreateTargetInfo(
1154  Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
1155  if (!Clang->hasTarget())
1156  return true;
1157 
1158  // Inform the target of the language options.
1159  //
1160  // FIXME: We shouldn't need to do this, the target should be immutable once
1161  // created. This complexity should be lifted elsewhere.
1162  Clang->getTarget().adjust(Clang->getLangOpts());
1163 
1164  assert(Clang->getFrontendOpts().Inputs.size() == 1 &&
1165  "Invocation must have exactly one source file!");
1166  assert(Clang->getFrontendOpts().Inputs[0].getKind().getFormat() ==
1168  "FIXME: AST inputs not yet supported here!");
1169  assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() !=
1171  "IR inputs not support here!");
1172 
1173  // Configure the various subsystems.
1174  LangOpts = Clang->getInvocation().LangOpts;
1175  FileSystemOpts = Clang->getFileSystemOpts();
1176 
1177  ResetForParse();
1178 
1179  SourceMgr = new SourceManager(getDiagnostics(), *FileMgr,
1180  UserFilesAreVolatile);
1181  if (!OverrideMainBuffer) {
1182  checkAndRemoveNonDriverDiags(StoredDiagnostics);
1183  TopLevelDeclsInPreamble.clear();
1184  }
1185 
1186  // Create the source manager.
1187  Clang->setSourceManager(&getSourceManager());
1188 
1189  // If the main file has been overridden due to the use of a preamble,
1190  // make that override happen and introduce the preamble.
1191  if (OverrideMainBuffer) {
1192  // The stored diagnostic has the old source manager in it; update
1193  // the locations to refer into the new source manager. Since we've
1194  // been careful to make sure that the source manager's state
1195  // before and after are identical, so that we can reuse the source
1196  // location itself.
1197  checkAndSanitizeDiags(StoredDiagnostics, getSourceManager());
1198 
1199  // Keep track of the override buffer;
1200  SavedMainFileBuffer = std::move(OverrideMainBuffer);
1201  }
1202 
1203  std::unique_ptr<TopLevelDeclTrackerAction> Act(
1204  new TopLevelDeclTrackerAction(*this));
1205 
1206  // Recover resources if we crash before exiting this method.
1207  llvm::CrashRecoveryContextCleanupRegistrar<TopLevelDeclTrackerAction>
1208  ActCleanup(Act.get());
1209 
1210  if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
1211  return true;
1212 
1213  if (SavedMainFileBuffer)
1214  TranslateStoredDiagnostics(getFileManager(), getSourceManager(),
1215  PreambleDiagnostics, StoredDiagnostics);
1216  else
1217  PreambleSrcLocCache.clear();
1218 
1219  if (llvm::Error Err = Act->Execute()) {
1220  consumeError(std::move(Err)); // FIXME this drops errors on the floor.
1221  return true;
1222  }
1223 
1224  transferASTDataFromCompilerInstance(*Clang);
1225 
1226  Act->EndSourceFile();
1227 
1228  FailedParseDiagnostics.clear();
1229 
1230  CleanOnError.release();
1231 
1232  return false;
1233 }
1234 
1235 static std::pair<unsigned, unsigned>
1237  const LangOptions &LangOpts) {
1238  CharSourceRange FileRange = Lexer::makeFileCharRange(Range, SM, LangOpts);
1239  unsigned Offset = SM.getFileOffset(FileRange.getBegin());
1240  unsigned EndOffset = SM.getFileOffset(FileRange.getEnd());
1241  return std::make_pair(Offset, EndOffset);
1242 }
1243 
1245  const LangOptions &LangOpts,
1246  const FixItHint &InFix) {
1247  ASTUnit::StandaloneFixIt OutFix;
1248  OutFix.RemoveRange = makeStandaloneRange(InFix.RemoveRange, SM, LangOpts);
1250  LangOpts);
1251  OutFix.CodeToInsert = InFix.CodeToInsert;
1253  return OutFix;
1254 }
1255 
1258  const StoredDiagnostic &InDiag) {
1260  OutDiag.ID = InDiag.getID();
1261  OutDiag.Level = InDiag.getLevel();
1262  OutDiag.Message = std::string(InDiag.getMessage());
1263  OutDiag.LocOffset = 0;
1264  if (InDiag.getLocation().isInvalid())
1265  return OutDiag;
1266  const SourceManager &SM = InDiag.getLocation().getManager();
1267  SourceLocation FileLoc = SM.getFileLoc(InDiag.getLocation());
1268  OutDiag.Filename = std::string(SM.getFilename(FileLoc));
1269  if (OutDiag.Filename.empty())
1270  return OutDiag;
1271  OutDiag.LocOffset = SM.getFileOffset(FileLoc);
1272  for (const auto &Range : InDiag.getRanges())
1273  OutDiag.Ranges.push_back(makeStandaloneRange(Range, SM, LangOpts));
1274  for (const auto &FixIt : InDiag.getFixIts())
1275  OutDiag.FixIts.push_back(makeStandaloneFixIt(SM, LangOpts, FixIt));
1276 
1277  return OutDiag;
1278 }
1279 
1280 /// Attempt to build or re-use a precompiled preamble when (re-)parsing
1281 /// the source file.
1282 ///
1283 /// This routine will compute the preamble of the main source file. If a
1284 /// non-trivial preamble is found, it will precompile that preamble into a
1285 /// precompiled header so that the precompiled preamble can be used to reduce
1286 /// reparsing time. If a precompiled preamble has already been constructed,
1287 /// this routine will determine if it is still valid and, if so, avoid
1288 /// rebuilding the precompiled preamble.
1289 ///
1290 /// \param AllowRebuild When true (the default), this routine is
1291 /// allowed to rebuild the precompiled preamble if it is found to be
1292 /// out-of-date.
1293 ///
1294 /// \param MaxLines When non-zero, the maximum number of lines that
1295 /// can occur within the preamble.
1296 ///
1297 /// \returns If the precompiled preamble can be used, returns a newly-allocated
1298 /// buffer that should be used in place of the main file when doing so.
1299 /// Otherwise, returns a NULL pointer.
1300 std::unique_ptr<llvm::MemoryBuffer>
1301 ASTUnit::getMainBufferWithPrecompiledPreamble(
1302  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1303  CompilerInvocation &PreambleInvocationIn,
1304  IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, bool AllowRebuild,
1305  unsigned MaxLines) {
1306  auto MainFilePath =
1307  PreambleInvocationIn.getFrontendOpts().Inputs[0].getFile();
1308  std::unique_ptr<llvm::MemoryBuffer> MainFileBuffer =
1309  getBufferForFileHandlingRemapping(PreambleInvocationIn, VFS.get(),
1310  MainFilePath, UserFilesAreVolatile);
1311  if (!MainFileBuffer)
1312  return nullptr;
1313 
1315  *PreambleInvocationIn.getLangOpts(), *MainFileBuffer, MaxLines);
1316  if (!Bounds.Size)
1317  return nullptr;
1318 
1319  if (Preamble) {
1320  if (Preamble->CanReuse(PreambleInvocationIn, *MainFileBuffer, Bounds,
1321  *VFS)) {
1322  // Okay! We can re-use the precompiled preamble.
1323 
1324  // Set the state of the diagnostic object to mimic its state
1325  // after parsing the preamble.
1326  getDiagnostics().Reset();
1328  PreambleInvocationIn.getDiagnosticOpts());
1329  getDiagnostics().setNumWarnings(NumWarningsInPreamble);
1330 
1331  PreambleRebuildCountdown = 1;
1332  return MainFileBuffer;
1333  } else {
1334  Preamble.reset();
1335  PreambleDiagnostics.clear();
1336  TopLevelDeclsInPreamble.clear();
1337  PreambleSrcLocCache.clear();
1338  PreambleRebuildCountdown = 1;
1339  }
1340  }
1341 
1342  // If the preamble rebuild counter > 1, it's because we previously
1343  // failed to build a preamble and we're not yet ready to try
1344  // again. Decrement the counter and return a failure.
1345  if (PreambleRebuildCountdown > 1) {
1346  --PreambleRebuildCountdown;
1347  return nullptr;
1348  }
1349 
1350  assert(!Preamble && "No Preamble should be stored at that point");
1351  // If we aren't allowed to rebuild the precompiled preamble, just
1352  // return now.
1353  if (!AllowRebuild)
1354  return nullptr;
1355 
1356  ++PreambleCounter;
1357 
1358  SmallVector<StandaloneDiagnostic, 4> NewPreambleDiagsStandalone;
1359  SmallVector<StoredDiagnostic, 4> NewPreambleDiags;
1360  ASTUnitPreambleCallbacks Callbacks;
1361  {
1363  if (CaptureDiagnostics != CaptureDiagsKind::None)
1364  Capture.emplace(CaptureDiagnostics, *Diagnostics, &NewPreambleDiags,
1365  &NewPreambleDiagsStandalone);
1366 
1367  // We did not previously compute a preamble, or it can't be reused anyway.
1368  SimpleTimer PreambleTimer(WantTiming);
1369  PreambleTimer.setOutput("Precompiling preamble");
1370 
1371  const bool PreviousSkipFunctionBodies =
1372  PreambleInvocationIn.getFrontendOpts().SkipFunctionBodies;
1373  if (SkipFunctionBodies == SkipFunctionBodiesScope::Preamble)
1374  PreambleInvocationIn.getFrontendOpts().SkipFunctionBodies = true;
1375 
1376  llvm::ErrorOr<PrecompiledPreamble> NewPreamble = PrecompiledPreamble::Build(
1377  PreambleInvocationIn, MainFileBuffer.get(), Bounds, *Diagnostics, VFS,
1378  PCHContainerOps, /*StoreInMemory=*/false, Callbacks);
1379 
1380  PreambleInvocationIn.getFrontendOpts().SkipFunctionBodies =
1381  PreviousSkipFunctionBodies;
1382 
1383  if (NewPreamble) {
1384  Preamble = std::move(*NewPreamble);
1385  PreambleRebuildCountdown = 1;
1386  } else {
1387  switch (static_cast<BuildPreambleError>(NewPreamble.getError().value())) {
1389  // Try again next time.
1390  PreambleRebuildCountdown = 1;
1391  return nullptr;
1396  // These erros are more likely to repeat, retry after some period.
1397  PreambleRebuildCountdown = DefaultPreambleRebuildInterval;
1398  return nullptr;
1399  }
1400  llvm_unreachable("unexpected BuildPreambleError");
1401  }
1402  }
1403 
1404  assert(Preamble && "Preamble wasn't built");
1405 
1406  TopLevelDecls.clear();
1407  TopLevelDeclsInPreamble = Callbacks.takeTopLevelDeclIDs();
1408  PreambleTopLevelHashValue = Callbacks.getHash();
1409 
1410  NumWarningsInPreamble = getDiagnostics().getNumWarnings();
1411 
1412  checkAndRemoveNonDriverDiags(NewPreambleDiags);
1413  StoredDiagnostics = std::move(NewPreambleDiags);
1414  PreambleDiagnostics = std::move(NewPreambleDiagsStandalone);
1415 
1416  // If the hash of top-level entities differs from the hash of the top-level
1417  // entities the last time we rebuilt the preamble, clear out the completion
1418  // cache.
1419  if (CurrentTopLevelHashValue != PreambleTopLevelHashValue) {
1420  CompletionCacheTopLevelHashValue = 0;
1421  PreambleTopLevelHashValue = CurrentTopLevelHashValue;
1422  }
1423 
1424  return MainFileBuffer;
1425 }
1426 
1427 void ASTUnit::RealizeTopLevelDeclsFromPreamble() {
1428  assert(Preamble && "Should only be called when preamble was built");
1429 
1430  std::vector<Decl *> Resolved;
1431  Resolved.reserve(TopLevelDeclsInPreamble.size());
1433  for (const auto TopLevelDecl : TopLevelDeclsInPreamble) {
1434  // Resolve the declaration ID to an actual declaration, possibly
1435  // deserializing the declaration in the process.
1436  if (Decl *D = Source.GetExternalDecl(TopLevelDecl))
1437  Resolved.push_back(D);
1438  }
1439  TopLevelDeclsInPreamble.clear();
1440  TopLevelDecls.insert(TopLevelDecls.begin(), Resolved.begin(), Resolved.end());
1441 }
1442 
1443 void ASTUnit::transferASTDataFromCompilerInstance(CompilerInstance &CI) {
1444  // Steal the created target, context, and preprocessor if they have been
1445  // created.
1446  assert(CI.hasInvocation() && "missing invocation");
1447  LangOpts = CI.getInvocation().LangOpts;
1448  TheSema = CI.takeSema();
1449  Consumer = CI.takeASTConsumer();
1450  if (CI.hasASTContext())
1451  Ctx = &CI.getASTContext();
1452  if (CI.hasPreprocessor())
1453  PP = CI.getPreprocessorPtr();
1454  CI.setSourceManager(nullptr);
1455  CI.setFileManager(nullptr);
1456  if (CI.hasTarget())
1457  Target = &CI.getTarget();
1458  Reader = CI.getASTReader();
1459  HadModuleLoaderFatalFailure = CI.hadModuleLoaderFatalFailure();
1460 }
1461 
1462 StringRef ASTUnit::getMainFileName() const {
1463  if (Invocation && !Invocation->getFrontendOpts().Inputs.empty()) {
1464  const FrontendInputFile &Input = Invocation->getFrontendOpts().Inputs[0];
1465  if (Input.isFile())
1466  return Input.getFile();
1467  else
1468  return Input.getBuffer().getBufferIdentifier();
1469  }
1470 
1471  if (SourceMgr) {
1472  if (const FileEntry *
1473  FE = SourceMgr->getFileEntryForID(SourceMgr->getMainFileID()))
1474  return FE->getName();
1475  }
1476 
1477  return {};
1478 }
1479 
1480 StringRef ASTUnit::getASTFileName() const {
1481  if (!isMainFileAST())
1482  return {};
1483 
1485  Mod = Reader->getModuleManager().getPrimaryModule();
1486  return Mod.FileName;
1487 }
1488 
1489 std::unique_ptr<ASTUnit>
1490 ASTUnit::create(std::shared_ptr<CompilerInvocation> CI,
1492  CaptureDiagsKind CaptureDiagnostics,
1493  bool UserFilesAreVolatile) {
1494  std::unique_ptr<ASTUnit> AST(new ASTUnit(false));
1495  ConfigureDiags(Diags, *AST, CaptureDiagnostics);
1497  createVFSFromCompilerInvocation(*CI, *Diags);
1498  AST->Diagnostics = Diags;
1499  AST->FileSystemOpts = CI->getFileSystemOpts();
1500  AST->Invocation = std::move(CI);
1501  AST->FileMgr = new FileManager(AST->FileSystemOpts, VFS);
1502  AST->UserFilesAreVolatile = UserFilesAreVolatile;
1503  AST->SourceMgr = new SourceManager(AST->getDiagnostics(), *AST->FileMgr,
1504  UserFilesAreVolatile);
1505  AST->ModuleCache = new InMemoryModuleCache;
1506 
1507  return AST;
1508 }
1509 
1511  std::shared_ptr<CompilerInvocation> CI,
1512  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1514  ASTUnit *Unit, bool Persistent, StringRef ResourceFilesPath,
1515  bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
1516  unsigned PrecompilePreambleAfterNParses, bool CacheCodeCompletionResults,
1517  bool UserFilesAreVolatile, std::unique_ptr<ASTUnit> *ErrAST) {
1518  assert(CI && "A CompilerInvocation is required");
1519 
1520  std::unique_ptr<ASTUnit> OwnAST;
1521  ASTUnit *AST = Unit;
1522  if (!AST) {
1523  // Create the AST unit.
1524  OwnAST = create(CI, Diags, CaptureDiagnostics, UserFilesAreVolatile);
1525  AST = OwnAST.get();
1526  if (!AST)
1527  return nullptr;
1528  }
1529 
1530  if (!ResourceFilesPath.empty()) {
1531  // Override the resources path.
1532  CI->getHeaderSearchOpts().ResourceDir = std::string(ResourceFilesPath);
1533  }
1534  AST->OnlyLocalDecls = OnlyLocalDecls;
1535  AST->CaptureDiagnostics = CaptureDiagnostics;
1536  if (PrecompilePreambleAfterNParses > 0)
1537  AST->PreambleRebuildCountdown = PrecompilePreambleAfterNParses;
1538  AST->TUKind = Action ? Action->getTranslationUnitKind() : TU_Complete;
1539  AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults;
1540  AST->IncludeBriefCommentsInCodeCompletion = false;
1541 
1542  // Recover resources if we crash before exiting this method.
1543  llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
1544  ASTUnitCleanup(OwnAST.get());
1545  llvm::CrashRecoveryContextCleanupRegistrar<DiagnosticsEngine,
1546  llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine>>
1547  DiagCleanup(Diags.get());
1548 
1549  // We'll manage file buffers ourselves.
1550  CI->getPreprocessorOpts().RetainRemappedFileBuffers = true;
1551  CI->getFrontendOpts().DisableFree = false;
1552  ProcessWarningOptions(AST->getDiagnostics(), CI->getDiagnosticOpts());
1553 
1554  // Create the compiler instance to use for building the AST.
1555  std::unique_ptr<CompilerInstance> Clang(
1556  new CompilerInstance(std::move(PCHContainerOps)));
1557 
1558  // Recover resources if we crash before exiting this method.
1559  llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
1560  CICleanup(Clang.get());
1561 
1562  Clang->setInvocation(std::move(CI));
1563  AST->OriginalSourceFile =
1564  std::string(Clang->getFrontendOpts().Inputs[0].getFile());
1565 
1566  // Set up diagnostics, capturing any diagnostics that would
1567  // otherwise be dropped.
1568  Clang->setDiagnostics(&AST->getDiagnostics());
1569 
1570  // Create the target instance.
1571  Clang->setTarget(TargetInfo::CreateTargetInfo(
1572  Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
1573  if (!Clang->hasTarget())
1574  return nullptr;
1575 
1576  // Inform the target of the language options.
1577  //
1578  // FIXME: We shouldn't need to do this, the target should be immutable once
1579  // created. This complexity should be lifted elsewhere.
1580  Clang->getTarget().adjust(Clang->getLangOpts());
1581 
1582  assert(Clang->getFrontendOpts().Inputs.size() == 1 &&
1583  "Invocation must have exactly one source file!");
1584  assert(Clang->getFrontendOpts().Inputs[0].getKind().getFormat() ==
1586  "FIXME: AST inputs not yet supported here!");
1587  assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() !=
1589  "IR inputs not support here!");
1590 
1591  // Configure the various subsystems.
1592  AST->TheSema.reset();
1593  AST->Ctx = nullptr;
1594  AST->PP = nullptr;
1595  AST->Reader = nullptr;
1596 
1597  // Create a file manager object to provide access to and cache the filesystem.
1598  Clang->setFileManager(&AST->getFileManager());
1599 
1600  // Create the source manager.
1601  Clang->setSourceManager(&AST->getSourceManager());
1602 
1603  FrontendAction *Act = Action;
1604 
1605  std::unique_ptr<TopLevelDeclTrackerAction> TrackerAct;
1606  if (!Act) {
1607  TrackerAct.reset(new TopLevelDeclTrackerAction(*AST));
1608  Act = TrackerAct.get();
1609  }
1610 
1611  // Recover resources if we crash before exiting this method.
1612  llvm::CrashRecoveryContextCleanupRegistrar<TopLevelDeclTrackerAction>
1613  ActCleanup(TrackerAct.get());
1614 
1615  if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0])) {
1616  AST->transferASTDataFromCompilerInstance(*Clang);
1617  if (OwnAST && ErrAST)
1618  ErrAST->swap(OwnAST);
1619 
1620  return nullptr;
1621  }
1622 
1623  if (Persistent && !TrackerAct) {
1624  Clang->getPreprocessor().addPPCallbacks(
1625  std::make_unique<MacroDefinitionTrackerPPCallbacks>(
1626  AST->getCurrentTopLevelHashValue()));
1627  std::vector<std::unique_ptr<ASTConsumer>> Consumers;
1628  if (Clang->hasASTConsumer())
1629  Consumers.push_back(Clang->takeASTConsumer());
1630  Consumers.push_back(std::make_unique<TopLevelDeclTrackerConsumer>(
1631  *AST, AST->getCurrentTopLevelHashValue()));
1632  Clang->setASTConsumer(
1633  std::make_unique<MultiplexConsumer>(std::move(Consumers)));
1634  }
1635  if (llvm::Error Err = Act->Execute()) {
1636  consumeError(std::move(Err)); // FIXME this drops errors on the floor.
1637  AST->transferASTDataFromCompilerInstance(*Clang);
1638  if (OwnAST && ErrAST)
1639  ErrAST->swap(OwnAST);
1640 
1641  return nullptr;
1642  }
1643 
1644  // Steal the created target, context, and preprocessor.
1645  AST->transferASTDataFromCompilerInstance(*Clang);
1646 
1647  Act->EndSourceFile();
1648 
1649  if (OwnAST)
1650  return OwnAST.release();
1651  else
1652  return AST;
1653 }
1654 
1655 bool ASTUnit::LoadFromCompilerInvocation(
1656  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1657  unsigned PrecompilePreambleAfterNParses,
1659  if (!Invocation)
1660  return true;
1661 
1662  assert(VFS && "VFS is null");
1663 
1664  // We'll manage file buffers ourselves.
1665  Invocation->getPreprocessorOpts().RetainRemappedFileBuffers = true;
1666  Invocation->getFrontendOpts().DisableFree = false;
1667  getDiagnostics().Reset();
1668  ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts());
1669 
1670  std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer;
1671  if (PrecompilePreambleAfterNParses > 0) {
1672  PreambleRebuildCountdown = PrecompilePreambleAfterNParses;
1673  OverrideMainBuffer =
1674  getMainBufferWithPrecompiledPreamble(PCHContainerOps, *Invocation, VFS);
1675  getDiagnostics().Reset();
1676  ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts());
1677  }
1678 
1679  SimpleTimer ParsingTimer(WantTiming);
1680  ParsingTimer.setOutput("Parsing " + getMainFileName());
1681 
1682  // Recover resources if we crash before exiting this method.
1683  llvm::CrashRecoveryContextCleanupRegistrar<llvm::MemoryBuffer>
1684  MemBufferCleanup(OverrideMainBuffer.get());
1685 
1686  return Parse(std::move(PCHContainerOps), std::move(OverrideMainBuffer), VFS);
1687 }
1688 
1689 std::unique_ptr<ASTUnit> ASTUnit::LoadFromCompilerInvocation(
1690  std::shared_ptr<CompilerInvocation> CI,
1691  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1693  bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
1694  unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind,
1695  bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion,
1696  bool UserFilesAreVolatile) {
1697  // Create the AST unit.
1698  std::unique_ptr<ASTUnit> AST(new ASTUnit(false));
1699  ConfigureDiags(Diags, *AST, CaptureDiagnostics);
1700  AST->Diagnostics = Diags;
1701  AST->OnlyLocalDecls = OnlyLocalDecls;
1702  AST->CaptureDiagnostics = CaptureDiagnostics;
1703  AST->TUKind = TUKind;
1704  AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults;
1705  AST->IncludeBriefCommentsInCodeCompletion
1706  = IncludeBriefCommentsInCodeCompletion;
1707  AST->Invocation = std::move(CI);
1708  AST->FileSystemOpts = FileMgr->getFileSystemOpts();
1709  AST->FileMgr = FileMgr;
1710  AST->UserFilesAreVolatile = UserFilesAreVolatile;
1711 
1712  // Recover resources if we crash before exiting this method.
1713  llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
1714  ASTUnitCleanup(AST.get());
1715  llvm::CrashRecoveryContextCleanupRegistrar<DiagnosticsEngine,
1716  llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine>>
1717  DiagCleanup(Diags.get());
1718 
1719  if (AST->LoadFromCompilerInvocation(std::move(PCHContainerOps),
1720  PrecompilePreambleAfterNParses,
1721  &AST->FileMgr->getVirtualFileSystem()))
1722  return nullptr;
1723  return AST;
1724 }
1725 
1727  const char **ArgBegin, const char **ArgEnd,
1728  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1729  IntrusiveRefCntPtr<DiagnosticsEngine> Diags, StringRef ResourceFilesPath,
1730  bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
1731  ArrayRef<RemappedFile> RemappedFiles, bool RemappedFilesKeepOriginalName,
1732  unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind,
1733  bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion,
1734  bool AllowPCHWithCompilerErrors, SkipFunctionBodiesScope SkipFunctionBodies,
1735  bool SingleFileParse, bool UserFilesAreVolatile, bool ForSerialization,
1736  bool RetainExcludedConditionalBlocks,
1737  llvm::Optional<StringRef> ModuleFormat, std::unique_ptr<ASTUnit> *ErrAST,
1739  assert(Diags.get() && "no DiagnosticsEngine was provided");
1740 
1741  SmallVector<StoredDiagnostic, 4> StoredDiagnostics;
1742 
1743  std::shared_ptr<CompilerInvocation> CI;
1744 
1745  {
1746  CaptureDroppedDiagnostics Capture(CaptureDiagnostics, *Diags,
1747  &StoredDiagnostics, nullptr);
1748 
1750  llvm::makeArrayRef(ArgBegin, ArgEnd), Diags, VFS);
1751  if (!CI)
1752  return nullptr;
1753  }
1754 
1755  // Override any files that need remapping
1756  for (const auto &RemappedFile : RemappedFiles) {
1757  CI->getPreprocessorOpts().addRemappedFile(RemappedFile.first,
1758  RemappedFile.second);
1759  }
1760  PreprocessorOptions &PPOpts = CI->getPreprocessorOpts();
1761  PPOpts.RemappedFilesKeepOriginalName = RemappedFilesKeepOriginalName;
1762  PPOpts.AllowPCHWithCompilerErrors = AllowPCHWithCompilerErrors;
1763  PPOpts.SingleFileParseMode = SingleFileParse;
1764  PPOpts.RetainExcludedConditionalBlocks = RetainExcludedConditionalBlocks;
1765 
1766  // Override the resources path.
1767  CI->getHeaderSearchOpts().ResourceDir = std::string(ResourceFilesPath);
1768 
1769  CI->getFrontendOpts().SkipFunctionBodies =
1770  SkipFunctionBodies == SkipFunctionBodiesScope::PreambleAndMainFile;
1771 
1772  if (ModuleFormat)
1773  CI->getHeaderSearchOpts().ModuleFormat =
1774  std::string(ModuleFormat.getValue());
1775 
1776  // Create the AST unit.
1777  std::unique_ptr<ASTUnit> AST;
1778  AST.reset(new ASTUnit(false));
1779  AST->NumStoredDiagnosticsFromDriver = StoredDiagnostics.size();
1780  AST->StoredDiagnostics.swap(StoredDiagnostics);
1781  ConfigureDiags(Diags, *AST, CaptureDiagnostics);
1782  AST->Diagnostics = Diags;
1783  AST->FileSystemOpts = CI->getFileSystemOpts();
1784  if (!VFS)
1785  VFS = llvm::vfs::getRealFileSystem();
1786  VFS = createVFSFromCompilerInvocation(*CI, *Diags, VFS);
1787  AST->FileMgr = new FileManager(AST->FileSystemOpts, VFS);
1788  AST->ModuleCache = new InMemoryModuleCache;
1789  AST->OnlyLocalDecls = OnlyLocalDecls;
1790  AST->CaptureDiagnostics = CaptureDiagnostics;
1791  AST->TUKind = TUKind;
1792  AST->ShouldCacheCodeCompletionResults = CacheCodeCompletionResults;
1793  AST->IncludeBriefCommentsInCodeCompletion
1794  = IncludeBriefCommentsInCodeCompletion;
1795  AST->UserFilesAreVolatile = UserFilesAreVolatile;
1796  AST->Invocation = CI;
1797  AST->SkipFunctionBodies = SkipFunctionBodies;
1798  if (ForSerialization)
1799  AST->WriterData.reset(new ASTWriterData(*AST->ModuleCache));
1800  // Zero out now to ease cleanup during crash recovery.
1801  CI = nullptr;
1802  Diags = nullptr;
1803 
1804  // Recover resources if we crash before exiting this method.
1805  llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
1806  ASTUnitCleanup(AST.get());
1807 
1808  if (AST->LoadFromCompilerInvocation(std::move(PCHContainerOps),
1809  PrecompilePreambleAfterNParses,
1810  VFS)) {
1811  // Some error occurred, if caller wants to examine diagnostics, pass it the
1812  // ASTUnit.
1813  if (ErrAST) {
1814  AST->StoredDiagnostics.swap(AST->FailedParseDiagnostics);
1815  ErrAST->swap(AST);
1816  }
1817  return nullptr;
1818  }
1819 
1820  return AST.release();
1821 }
1822 
1823 bool ASTUnit::Reparse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
1824  ArrayRef<RemappedFile> RemappedFiles,
1826  if (!Invocation)
1827  return true;
1828 
1829  if (!VFS) {
1830  assert(FileMgr && "FileMgr is null on Reparse call");
1831  VFS = &FileMgr->getVirtualFileSystem();
1832  }
1833 
1834  clearFileLevelDecls();
1835 
1836  SimpleTimer ParsingTimer(WantTiming);
1837  ParsingTimer.setOutput("Reparsing " + getMainFileName());
1838 
1839  // Remap files.
1840  PreprocessorOptions &PPOpts = Invocation->getPreprocessorOpts();
1841  for (const auto &RB : PPOpts.RemappedFileBuffers)
1842  delete RB.second;
1843 
1844  Invocation->getPreprocessorOpts().clearRemappedFiles();
1845  for (const auto &RemappedFile : RemappedFiles) {
1846  Invocation->getPreprocessorOpts().addRemappedFile(RemappedFile.first,
1847  RemappedFile.second);
1848  }
1849 
1850  // If we have a preamble file lying around, or if we might try to
1851  // build a precompiled preamble, do so now.
1852  std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer;
1853  if (Preamble || PreambleRebuildCountdown > 0)
1854  OverrideMainBuffer =
1855  getMainBufferWithPrecompiledPreamble(PCHContainerOps, *Invocation, VFS);
1856 
1857  // Clear out the diagnostics state.
1858  FileMgr.reset();
1859  getDiagnostics().Reset();
1860  ProcessWarningOptions(getDiagnostics(), Invocation->getDiagnosticOpts());
1861  if (OverrideMainBuffer)
1862  getDiagnostics().setNumWarnings(NumWarningsInPreamble);
1863 
1864  // Parse the sources
1865  bool Result =
1866  Parse(std::move(PCHContainerOps), std::move(OverrideMainBuffer), VFS);
1867 
1868  // If we're caching global code-completion results, and the top-level
1869  // declarations have changed, clear out the code-completion cache.
1870  if (!Result && ShouldCacheCodeCompletionResults &&
1871  CurrentTopLevelHashValue != CompletionCacheTopLevelHashValue)
1872  CacheCodeCompletionResults();
1873 
1874  // We now need to clear out the completion info related to this translation
1875  // unit; it'll be recreated if necessary.
1876  CCTUInfo.reset();
1877 
1878  return Result;
1879 }
1880 
1882  SavedMainFileBuffer.reset();
1883 
1884  SourceMgr.reset();
1885  TheSema.reset();
1886  Ctx.reset();
1887  PP.reset();
1888  Reader.reset();
1889 
1890  TopLevelDecls.clear();
1891  clearFileLevelDecls();
1892 }
1893 
1894 //----------------------------------------------------------------------------//
1895 // Code completion
1896 //----------------------------------------------------------------------------//
1897 
1898 namespace {
1899 
1900  /// Code completion consumer that combines the cached code-completion
1901  /// results from an ASTUnit with the code-completion results provided to it,
1902  /// then passes the result on to
1903  class AugmentedCodeCompleteConsumer : public CodeCompleteConsumer {
1904  uint64_t NormalContexts;
1905  ASTUnit &AST;
1906  CodeCompleteConsumer &Next;
1907 
1908  public:
1909  AugmentedCodeCompleteConsumer(ASTUnit &AST, CodeCompleteConsumer &Next,
1910  const CodeCompleteOptions &CodeCompleteOpts)
1911  : CodeCompleteConsumer(CodeCompleteOpts), AST(AST), Next(Next) {
1912  // Compute the set of contexts in which we will look when we don't have
1913  // any information about the specific context.
1914  NormalContexts
1928 
1929  if (AST.getASTContext().getLangOpts().CPlusPlus)
1930  NormalContexts |= (1LL << CodeCompletionContext::CCC_EnumTag)
1933  }
1934 
1935  void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context,
1936  CodeCompletionResult *Results,
1937  unsigned NumResults) override;
1938 
1939  void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
1940  OverloadCandidate *Candidates,
1941  unsigned NumCandidates,
1942  SourceLocation OpenParLoc) override {
1943  Next.ProcessOverloadCandidates(S, CurrentArg, Candidates, NumCandidates,
1944  OpenParLoc);
1945  }
1946 
1947  CodeCompletionAllocator &getAllocator() override {
1948  return Next.getAllocator();
1949  }
1950 
1951  CodeCompletionTUInfo &getCodeCompletionTUInfo() override {
1952  return Next.getCodeCompletionTUInfo();
1953  }
1954  };
1955 
1956 } // namespace
1957 
1958 /// Helper function that computes which global names are hidden by the
1959 /// local code-completion results.
1960 static void CalculateHiddenNames(const CodeCompletionContext &Context,
1961  CodeCompletionResult *Results,
1962  unsigned NumResults,
1963  ASTContext &Ctx,
1964  llvm::StringSet<llvm::BumpPtrAllocator> &HiddenNames){
1965  bool OnlyTagNames = false;
1966  switch (Context.getKind()) {
1985  break;
1986 
1990  OnlyTagNames = true;
1991  break;
1992 
2008  // We're looking for nothing, or we're looking for names that cannot
2009  // be hidden.
2010  return;
2011  }
2012 
2013  using Result = CodeCompletionResult;
2014  for (unsigned I = 0; I != NumResults; ++I) {
2015  if (Results[I].Kind != Result::RK_Declaration)
2016  continue;
2017 
2018  unsigned IDNS
2019  = Results[I].Declaration->getUnderlyingDecl()->getIdentifierNamespace();
2020 
2021  bool Hiding = false;
2022  if (OnlyTagNames)
2023  Hiding = (IDNS & Decl::IDNS_Tag);
2024  else {
2025  unsigned HiddenIDNS = (Decl::IDNS_Type | Decl::IDNS_Member |
2028  if (Ctx.getLangOpts().CPlusPlus)
2029  HiddenIDNS |= Decl::IDNS_Tag;
2030  Hiding = (IDNS & HiddenIDNS);
2031  }
2032 
2033  if (!Hiding)
2034  continue;
2035 
2036  DeclarationName Name = Results[I].Declaration->getDeclName();
2037  if (IdentifierInfo *Identifier = Name.getAsIdentifierInfo())
2038  HiddenNames.insert(Identifier->getName());
2039  else
2040  HiddenNames.insert(Name.getAsString());
2041  }
2042 }
2043 
2044 void AugmentedCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &S,
2045  CodeCompletionContext Context,
2046  CodeCompletionResult *Results,
2047  unsigned NumResults) {
2048  // Merge the results we were given with the results we cached.
2049  bool AddedResult = false;
2050  uint64_t InContexts =
2051  Context.getKind() == CodeCompletionContext::CCC_Recovery
2052  ? NormalContexts : (1LL << Context.getKind());
2053  // Contains the set of names that are hidden by "local" completion results.
2054  llvm::StringSet<llvm::BumpPtrAllocator> HiddenNames;
2055  using Result = CodeCompletionResult;
2056  SmallVector<Result, 8> AllResults;
2058  C = AST.cached_completion_begin(),
2059  CEnd = AST.cached_completion_end();
2060  C != CEnd; ++C) {
2061  // If the context we are in matches any of the contexts we are
2062  // interested in, we'll add this result.
2063  if ((C->ShowInContexts & InContexts) == 0)
2064  continue;
2065 
2066  // If we haven't added any results previously, do so now.
2067  if (!AddedResult) {
2068  CalculateHiddenNames(Context, Results, NumResults, S.Context,
2069  HiddenNames);
2070  AllResults.insert(AllResults.end(), Results, Results + NumResults);
2071  AddedResult = true;
2072  }
2073 
2074  // Determine whether this global completion result is hidden by a local
2075  // completion result. If so, skip it.
2076  if (C->Kind != CXCursor_MacroDefinition &&
2077  HiddenNames.count(C->Completion->getTypedText()))
2078  continue;
2079 
2080  // Adjust priority based on similar type classes.
2081  unsigned Priority = C->Priority;
2082  CodeCompletionString *Completion = C->Completion;
2083  if (!Context.getPreferredType().isNull()) {
2084  if (C->Kind == CXCursor_MacroDefinition) {
2085  Priority = getMacroUsagePriority(C->Completion->getTypedText(),
2086  S.getLangOpts(),
2087  Context.getPreferredType()->isAnyPointerType());
2088  } else if (C->Type) {
2091  Context.getPreferredType().getUnqualifiedType());
2093  if (ExpectedSTC == C->TypeClass) {
2094  // We know this type is similar; check for an exact match.
2095  llvm::StringMap<unsigned> &CachedCompletionTypes
2096  = AST.getCachedCompletionTypes();
2097  llvm::StringMap<unsigned>::iterator Pos
2098  = CachedCompletionTypes.find(QualType(Expected).getAsString());
2099  if (Pos != CachedCompletionTypes.end() && Pos->second == C->Type)
2101  else
2103  }
2104  }
2105  }
2106 
2107  // Adjust the completion string, if required.
2108  if (C->Kind == CXCursor_MacroDefinition &&
2109  Context.getKind() == CodeCompletionContext::CCC_MacroNameUse) {
2110  // Create a new code-completion string that just contains the
2111  // macro name, without its arguments.
2112  CodeCompletionBuilder Builder(getAllocator(), getCodeCompletionTUInfo(),
2113  CCP_CodePattern, C->Availability);
2114  Builder.AddTypedTextChunk(C->Completion->getTypedText());
2116  Completion = Builder.TakeString();
2117  }
2118 
2119  AllResults.push_back(Result(Completion, Priority, C->Kind,
2120  C->Availability));
2121  }
2122 
2123  // If we did not add any cached completion results, just forward the
2124  // results we were given to the next consumer.
2125  if (!AddedResult) {
2126  Next.ProcessCodeCompleteResults(S, Context, Results, NumResults);
2127  return;
2128  }
2129 
2130  Next.ProcessCodeCompleteResults(S, Context, AllResults.data(),
2131  AllResults.size());
2132 }
2133 
2135  StringRef File, unsigned Line, unsigned Column,
2136  ArrayRef<RemappedFile> RemappedFiles, bool IncludeMacros,
2137  bool IncludeCodePatterns, bool IncludeBriefComments,
2138  CodeCompleteConsumer &Consumer,
2139  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
2140  DiagnosticsEngine &Diag, LangOptions &LangOpts, SourceManager &SourceMgr,
2141  FileManager &FileMgr, SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics,
2143  if (!Invocation)
2144  return;
2145 
2146  SimpleTimer CompletionTimer(WantTiming);
2147  CompletionTimer.setOutput("Code completion @ " + File + ":" +
2148  Twine(Line) + ":" + Twine(Column));
2149 
2150  auto CCInvocation = std::make_shared<CompilerInvocation>(*Invocation);
2151 
2152  FrontendOptions &FrontendOpts = CCInvocation->getFrontendOpts();
2153  CodeCompleteOptions &CodeCompleteOpts = FrontendOpts.CodeCompleteOpts;
2154  PreprocessorOptions &PreprocessorOpts = CCInvocation->getPreprocessorOpts();
2155 
2156  CodeCompleteOpts.IncludeMacros = IncludeMacros &&
2157  CachedCompletionResults.empty();
2158  CodeCompleteOpts.IncludeCodePatterns = IncludeCodePatterns;
2159  CodeCompleteOpts.IncludeGlobals = CachedCompletionResults.empty();
2160  CodeCompleteOpts.IncludeBriefComments = IncludeBriefComments;
2161  CodeCompleteOpts.LoadExternal = Consumer.loadExternal();
2162  CodeCompleteOpts.IncludeFixIts = Consumer.includeFixIts();
2163 
2164  assert(IncludeBriefComments == this->IncludeBriefCommentsInCodeCompletion);
2165 
2166  FrontendOpts.CodeCompletionAt.FileName = std::string(File);
2167  FrontendOpts.CodeCompletionAt.Line = Line;
2168  FrontendOpts.CodeCompletionAt.Column = Column;
2169 
2170  // Set the language options appropriately.
2171  LangOpts = *CCInvocation->getLangOpts();
2172 
2173  // Spell-checking and warnings are wasteful during code-completion.
2174  LangOpts.SpellChecking = false;
2175  CCInvocation->getDiagnosticOpts().IgnoreWarnings = true;
2176 
2177  std::unique_ptr<CompilerInstance> Clang(
2178  new CompilerInstance(PCHContainerOps));
2179 
2180  // Recover resources if we crash before exiting this method.
2181  llvm::CrashRecoveryContextCleanupRegistrar<CompilerInstance>
2182  CICleanup(Clang.get());
2183 
2184  auto &Inv = *CCInvocation;
2185  Clang->setInvocation(std::move(CCInvocation));
2186  OriginalSourceFile =
2187  std::string(Clang->getFrontendOpts().Inputs[0].getFile());
2188 
2189  // Set up diagnostics, capturing any diagnostics produced.
2190  Clang->setDiagnostics(&Diag);
2191  CaptureDroppedDiagnostics Capture(CaptureDiagsKind::All,
2192  Clang->getDiagnostics(),
2193  &StoredDiagnostics, nullptr);
2194  ProcessWarningOptions(Diag, Inv.getDiagnosticOpts());
2195 
2196  // Create the target instance.
2197  Clang->setTarget(TargetInfo::CreateTargetInfo(
2198  Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
2199  if (!Clang->hasTarget()) {
2200  Clang->setInvocation(nullptr);
2201  return;
2202  }
2203 
2204  // Inform the target of the language options.
2205  //
2206  // FIXME: We shouldn't need to do this, the target should be immutable once
2207  // created. This complexity should be lifted elsewhere.
2208  Clang->getTarget().adjust(Clang->getLangOpts());
2209 
2210  assert(Clang->getFrontendOpts().Inputs.size() == 1 &&
2211  "Invocation must have exactly one source file!");
2212  assert(Clang->getFrontendOpts().Inputs[0].getKind().getFormat() ==
2214  "FIXME: AST inputs not yet supported here!");
2215  assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() !=
2217  "IR inputs not support here!");
2218 
2219  // Use the source and file managers that we were given.
2220  Clang->setFileManager(&FileMgr);
2221  Clang->setSourceManager(&SourceMgr);
2222 
2223  // Remap files.
2224  PreprocessorOpts.clearRemappedFiles();
2225  PreprocessorOpts.RetainRemappedFileBuffers = true;
2226  for (const auto &RemappedFile : RemappedFiles) {
2227  PreprocessorOpts.addRemappedFile(RemappedFile.first, RemappedFile.second);
2228  OwnedBuffers.push_back(RemappedFile.second);
2229  }
2230 
2231  // Use the code completion consumer we were given, but adding any cached
2232  // code-completion results.
2233  AugmentedCodeCompleteConsumer *AugmentedConsumer
2234  = new AugmentedCodeCompleteConsumer(*this, Consumer, CodeCompleteOpts);
2235  Clang->setCodeCompletionConsumer(AugmentedConsumer);
2236 
2237  auto getUniqueID =
2238  [&FileMgr](StringRef Filename) -> Optional<llvm::sys::fs::UniqueID> {
2239  if (auto Status = FileMgr.getVirtualFileSystem().status(Filename))
2240  return Status->getUniqueID();
2241  return None;
2242  };
2243 
2244  auto hasSameUniqueID = [getUniqueID](StringRef LHS, StringRef RHS) {
2245  if (LHS == RHS)
2246  return true;
2247  if (auto LHSID = getUniqueID(LHS))
2248  if (auto RHSID = getUniqueID(RHS))
2249  return *LHSID == *RHSID;
2250  return false;
2251  };
2252 
2253  // If we have a precompiled preamble, try to use it. We only allow
2254  // the use of the precompiled preamble if we're if the completion
2255  // point is within the main file, after the end of the precompiled
2256  // preamble.
2257  std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer;
2258  if (Preamble && Line > 1 && hasSameUniqueID(File, OriginalSourceFile)) {
2259  OverrideMainBuffer = getMainBufferWithPrecompiledPreamble(
2260  PCHContainerOps, Inv, &FileMgr.getVirtualFileSystem(), false, Line - 1);
2261  }
2262 
2263  // If the main file has been overridden due to the use of a preamble,
2264  // make that override happen and introduce the preamble.
2265  if (OverrideMainBuffer) {
2266  assert(Preamble &&
2267  "No preamble was built, but OverrideMainBuffer is not null");
2268 
2270  &FileMgr.getVirtualFileSystem();
2271  Preamble->AddImplicitPreamble(Clang->getInvocation(), VFS,
2272  OverrideMainBuffer.get());
2273  // FIXME: there is no way to update VFS if it was changed by
2274  // AddImplicitPreamble as FileMgr is accepted as a parameter by this method.
2275  // We use on-disk preambles instead and rely on FileMgr's VFS to ensure the
2276  // PCH files are always readable.
2277  OwnedBuffers.push_back(OverrideMainBuffer.release());
2278  } else {
2279  PreprocessorOpts.PrecompiledPreambleBytes.first = 0;
2280  PreprocessorOpts.PrecompiledPreambleBytes.second = false;
2281  }
2282 
2283  // Disable the preprocessing record if modules are not enabled.
2284  if (!Clang->getLangOpts().Modules)
2285  PreprocessorOpts.DetailedRecord = false;
2286 
2287  std::unique_ptr<SyntaxOnlyAction> Act;
2288  Act.reset(new SyntaxOnlyAction);
2289  if (Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0])) {
2290  if (llvm::Error Err = Act->Execute()) {
2291  consumeError(std::move(Err)); // FIXME this drops errors on the floor.
2292  }
2293  Act->EndSourceFile();
2294  }
2295 }
2296 
2297 bool ASTUnit::Save(StringRef File) {
2298  if (HadModuleLoaderFatalFailure)
2299  return true;
2300 
2301  // Write to a temporary file and later rename it to the actual file, to avoid
2302  // possible race conditions.
2303  SmallString<128> TempPath;
2304  TempPath = File;
2305  TempPath += "-%%%%%%%%";
2306  // FIXME: Can we somehow regenerate the stat cache here, or do we need to
2307  // unconditionally create a stat cache when we parse the file?
2308 
2309  if (llvm::Error Err = llvm::writeFileAtomically(
2310  TempPath, File, [this](llvm::raw_ostream &Out) {
2311  return serialize(Out) ? llvm::make_error<llvm::StringError>(
2312  "ASTUnit serialization failed",
2313  llvm::inconvertibleErrorCode())
2314  : llvm::Error::success();
2315  })) {
2316  consumeError(std::move(Err));
2317  return true;
2318  }
2319  return false;
2320 }
2321 
2322 static bool serializeUnit(ASTWriter &Writer,
2323  SmallVectorImpl<char> &Buffer,
2324  Sema &S,
2325  bool hasErrors,
2326  raw_ostream &OS) {
2327  Writer.WriteAST(S, std::string(), nullptr, "", hasErrors);
2328 
2329  // Write the generated bitstream to "Out".
2330  if (!Buffer.empty())
2331  OS.write(Buffer.data(), Buffer.size());
2332 
2333  return false;
2334 }
2335 
2336 bool ASTUnit::serialize(raw_ostream &OS) {
2337  // For serialization we are lenient if the errors were only warn-as-error kind.
2338  bool hasErrors = getDiagnostics().hasUncompilableErrorOccurred();
2339 
2340  if (WriterData)
2341  return serializeUnit(WriterData->Writer, WriterData->Buffer,
2342  getSema(), hasErrors, OS);
2343 
2344  SmallString<128> Buffer;
2345  llvm::BitstreamWriter Stream(Buffer);
2346  InMemoryModuleCache ModuleCache;
2347  ASTWriter Writer(Stream, Buffer, ModuleCache, {});
2348  return serializeUnit(Writer, Buffer, getSema(), hasErrors, OS);
2349 }
2350 
2352 
2353 void ASTUnit::TranslateStoredDiagnostics(
2354  FileManager &FileMgr,
2355  SourceManager &SrcMgr,
2358  // Map the standalone diagnostic into the new source manager. We also need to
2359  // remap all the locations to the new view. This includes the diag location,
2360  // any associated source ranges, and the source ranges of associated fix-its.
2361  // FIXME: There should be a cleaner way to do this.
2363  Result.reserve(Diags.size());
2364 
2365  for (const auto &SD : Diags) {
2366  // Rebuild the StoredDiagnostic.
2367  if (SD.Filename.empty())
2368  continue;
2369  auto FE = FileMgr.getFile(SD.Filename);
2370  if (!FE)
2371  continue;
2372  SourceLocation FileLoc;
2373  auto ItFileID = PreambleSrcLocCache.find(SD.Filename);
2374  if (ItFileID == PreambleSrcLocCache.end()) {
2375  FileID FID = SrcMgr.translateFile(*FE);
2376  FileLoc = SrcMgr.getLocForStartOfFile(FID);
2377  PreambleSrcLocCache[SD.Filename] = FileLoc;
2378  } else {
2379  FileLoc = ItFileID->getValue();
2380  }
2381 
2382  if (FileLoc.isInvalid())
2383  continue;
2384  SourceLocation L = FileLoc.getLocWithOffset(SD.LocOffset);
2385  FullSourceLoc Loc(L, SrcMgr);
2386 
2388  Ranges.reserve(SD.Ranges.size());
2389  for (const auto &Range : SD.Ranges) {
2390  SourceLocation BL = FileLoc.getLocWithOffset(Range.first);
2391  SourceLocation EL = FileLoc.getLocWithOffset(Range.second);
2392  Ranges.push_back(CharSourceRange::getCharRange(BL, EL));
2393  }
2394 
2396  FixIts.reserve(SD.FixIts.size());
2397  for (const auto &FixIt : SD.FixIts) {
2398  FixIts.push_back(FixItHint());
2399  FixItHint &FH = FixIts.back();
2400  FH.CodeToInsert = FixIt.CodeToInsert;
2401  SourceLocation BL = FileLoc.getLocWithOffset(FixIt.RemoveRange.first);
2402  SourceLocation EL = FileLoc.getLocWithOffset(FixIt.RemoveRange.second);
2404  }
2405 
2406  Result.push_back(StoredDiagnostic(SD.Level, SD.ID,
2407  SD.Message, Loc, Ranges, FixIts));
2408  }
2409  Result.swap(Out);
2410 }
2411 
2413  assert(D);
2414 
2415  // We only care about local declarations.
2416  if (D->isFromASTFile())
2417  return;
2418 
2419  SourceManager &SM = *SourceMgr;
2420  SourceLocation Loc = D->getLocation();
2421  if (Loc.isInvalid() || !SM.isLocalSourceLocation(Loc))
2422  return;
2423 
2424  // We only keep track of the file-level declarations of each file.
2425  if (!D->getLexicalDeclContext()->isFileContext())
2426  return;
2427 
2428  SourceLocation FileLoc = SM.getFileLoc(Loc);
2429  assert(SM.isLocalSourceLocation(FileLoc));
2430  FileID FID;
2431  unsigned Offset;
2432  std::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc);
2433  if (FID.isInvalid())
2434  return;
2435 
2436  std::unique_ptr<LocDeclsTy> &Decls = FileDecls[FID];
2437  if (!Decls)
2438  Decls = std::make_unique<LocDeclsTy>();
2439 
2440  std::pair<unsigned, Decl *> LocDecl(Offset, D);
2441 
2442  if (Decls->empty() || Decls->back().first <= Offset) {
2443  Decls->push_back(LocDecl);
2444  return;
2445  }
2446 
2447  LocDeclsTy::iterator I =
2448  llvm::upper_bound(*Decls, LocDecl, llvm::less_first());
2449 
2450  Decls->insert(I, LocDecl);
2451 }
2452 
2453 void ASTUnit::findFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
2454  SmallVectorImpl<Decl *> &Decls) {
2455  if (File.isInvalid())
2456  return;
2457 
2458  if (SourceMgr->isLoadedFileID(File)) {
2459  assert(Ctx->getExternalSource() && "No external source!");
2460  return Ctx->getExternalSource()->FindFileRegionDecls(File, Offset, Length,
2461  Decls);
2462  }
2463 
2464  FileDeclsTy::iterator I = FileDecls.find(File);
2465  if (I == FileDecls.end())
2466  return;
2467 
2468  LocDeclsTy &LocDecls = *I->second;
2469  if (LocDecls.empty())
2470  return;
2471 
2472  LocDeclsTy::iterator BeginIt =
2473  llvm::partition_point(LocDecls, [=](std::pair<unsigned, Decl *> LD) {
2474  return LD.first < Offset;
2475  });
2476  if (BeginIt != LocDecls.begin())
2477  --BeginIt;
2478 
2479  // If we are pointing at a top-level decl inside an objc container, we need
2480  // to backtrack until we find it otherwise we will fail to report that the
2481  // region overlaps with an objc container.
2482  while (BeginIt != LocDecls.begin() &&
2483  BeginIt->second->isTopLevelDeclInObjCContainer())
2484  --BeginIt;
2485 
2486  LocDeclsTy::iterator EndIt = llvm::upper_bound(
2487  LocDecls, std::make_pair(Offset + Length, (Decl *)nullptr),
2488  llvm::less_first());
2489  if (EndIt != LocDecls.end())
2490  ++EndIt;
2491 
2492  for (LocDeclsTy::iterator DIt = BeginIt; DIt != EndIt; ++DIt)
2493  Decls.push_back(DIt->second);
2494 }
2495 
2497  unsigned Line, unsigned Col) const {
2498  const SourceManager &SM = getSourceManager();
2499  SourceLocation Loc = SM.translateFileLineCol(File, Line, Col);
2500  return SM.getMacroArgExpandedLocation(Loc);
2501 }
2502 
2504  unsigned Offset) const {
2505  const SourceManager &SM = getSourceManager();
2506  SourceLocation FileLoc = SM.translateFileLineCol(File, 1, 1);
2507  return SM.getMacroArgExpandedLocation(FileLoc.getLocWithOffset(Offset));
2508 }
2509 
2510 /// If \arg Loc is a loaded location from the preamble, returns
2511 /// the corresponding local location of the main file, otherwise it returns
2512 /// \arg Loc.
2514  FileID PreambleID;
2515  if (SourceMgr)
2516  PreambleID = SourceMgr->getPreambleFileID();
2517 
2518  if (Loc.isInvalid() || !Preamble || PreambleID.isInvalid())
2519  return Loc;
2520 
2521  unsigned Offs;
2522  if (SourceMgr->isInFileID(Loc, PreambleID, &Offs) && Offs < Preamble->getBounds().Size) {
2523  SourceLocation FileLoc
2524  = SourceMgr->getLocForStartOfFile(SourceMgr->getMainFileID());
2525  return FileLoc.getLocWithOffset(Offs);
2526  }
2527 
2528  return Loc;
2529 }
2530 
2531 /// If \arg Loc is a local location of the main file but inside the
2532 /// preamble chunk, returns the corresponding loaded location from the
2533 /// preamble, otherwise it returns \arg Loc.
2535  FileID PreambleID;
2536  if (SourceMgr)
2537  PreambleID = SourceMgr->getPreambleFileID();
2538 
2539  if (Loc.isInvalid() || !Preamble || PreambleID.isInvalid())
2540  return Loc;
2541 
2542  unsigned Offs;
2543  if (SourceMgr->isInFileID(Loc, SourceMgr->getMainFileID(), &Offs) &&
2544  Offs < Preamble->getBounds().Size) {
2545  SourceLocation FileLoc = SourceMgr->getLocForStartOfFile(PreambleID);
2546  return FileLoc.getLocWithOffset(Offs);
2547  }
2548 
2549  return Loc;
2550 }
2551 
2553  FileID FID;
2554  if (SourceMgr)
2555  FID = SourceMgr->getPreambleFileID();
2556 
2557  if (Loc.isInvalid() || FID.isInvalid())
2558  return false;
2559 
2560  return SourceMgr->isInFileID(Loc, FID);
2561 }
2562 
2564  FileID FID;
2565  if (SourceMgr)
2566  FID = SourceMgr->getMainFileID();
2567 
2568  if (Loc.isInvalid() || FID.isInvalid())
2569  return false;
2570 
2571  return SourceMgr->isInFileID(Loc, FID);
2572 }
2573 
2575  FileID FID;
2576  if (SourceMgr)
2577  FID = SourceMgr->getPreambleFileID();
2578 
2579  if (FID.isInvalid())
2580  return {};
2581 
2582  return SourceMgr->getLocForEndOfFile(FID);
2583 }
2584 
2586  FileID FID;
2587  if (SourceMgr)
2588  FID = SourceMgr->getMainFileID();
2589 
2590  if (FID.isInvalid())
2591  return {};
2592 
2593  return SourceMgr->getLocForStartOfFile(FID);
2594 }
2595 
2596 llvm::iterator_range<PreprocessingRecord::iterator>
2598  if (isMainFileAST()) {
2600  Mod = Reader->getModuleManager().getPrimaryModule();
2601  return Reader->getModulePreprocessedEntities(Mod);
2602  }
2603 
2604  if (PreprocessingRecord *PPRec = PP->getPreprocessingRecord())
2605  return llvm::make_range(PPRec->local_begin(), PPRec->local_end());
2606 
2607  return llvm::make_range(PreprocessingRecord::iterator(),
2609 }
2610 
2612  if (isMainFileAST()) {
2614  Mod = Reader->getModuleManager().getPrimaryModule();
2615  for (const auto *D : Reader->getModuleFileLevelDecls(Mod)) {
2616  if (!Fn(context, D))
2617  return false;
2618  }
2619 
2620  return true;
2621  }
2622 
2624  TLEnd = top_level_end();
2625  TL != TLEnd; ++TL) {
2626  if (!Fn(context, *TL))
2627  return false;
2628  }
2629 
2630  return true;
2631 }
2632 
2634  if (!Reader)
2635  return nullptr;
2636 
2637  serialization::ModuleFile *Mod = nullptr;
2638  Reader->getModuleManager().visit([&Mod](serialization::ModuleFile &M) {
2639  switch (M.Kind) {
2640  case serialization::MK_ImplicitModule:
2641  case serialization::MK_ExplicitModule:
2642  case serialization::MK_PrebuiltModule:
2643  return true; // skip dependencies.
2644  case serialization::MK_PCH:
2645  Mod = &M;
2646  return true; // found it.
2647  case serialization::MK_Preamble:
2648  return false; // look in dependencies.
2649  case serialization::MK_MainFile:
2650  return false; // look in dependencies.
2651  }
2652 
2653  return true;
2654  });
2655  if (Mod)
2656  return Mod->File;
2657 
2658  return nullptr;
2659 }
2660 
2663 }
2664 
2666  auto &LangOpts = getLangOpts();
2667 
2668  Language Lang;
2669  if (LangOpts.OpenCL)
2670  Lang = Language::OpenCL;
2671  else if (LangOpts.CUDA)
2672  Lang = Language::CUDA;
2673  else if (LangOpts.RenderScript)
2674  Lang = Language::RenderScript;
2675  else if (LangOpts.CPlusPlus)
2676  Lang = LangOpts.ObjC ? Language::ObjCXX : Language::CXX;
2677  else
2678  Lang = LangOpts.ObjC ? Language::ObjC : Language::C;
2679 
2681  if (LangOpts.getCompilingModule() == LangOptions::CMK_ModuleMap)
2682  Fmt = InputKind::ModuleMap;
2683 
2684  // We don't know if input was preprocessed. Assume not.
2685  bool PP = false;
2686 
2687  return InputKind(Lang, Fmt, PP);
2688 }
2689 
2690 #ifndef NDEBUG
2691 ASTUnit::ConcurrencyState::ConcurrencyState() {
2692  Mutex = new std::recursive_mutex;
2693 }
2694 
2695 ASTUnit::ConcurrencyState::~ConcurrencyState() {
2696  delete static_cast<std::recursive_mutex *>(Mutex);
2697 }
2698 
2699 void ASTUnit::ConcurrencyState::start() {
2700  bool acquired = static_cast<std::recursive_mutex *>(Mutex)->try_lock();
2701  assert(acquired && "Concurrent access to ASTUnit!");
2702 }
2703 
2704 void ASTUnit::ConcurrencyState::finish() {
2705  static_cast<std::recursive_mutex *>(Mutex)->unlock();
2706 }
2707 
2708 #else // NDEBUG
2709 
2710 ASTUnit::ConcurrencyState::ConcurrencyState() { Mutex = nullptr; }
2711 ASTUnit::ConcurrencyState::~ConcurrencyState() {}
2712 void ASTUnit::ConcurrencyState::start() {}
2713 void ASTUnit::ConcurrencyState::finish() {}
2714 
2715 #endif // NDEBUG
clang::ASTUnit::top_level_begin
top_level_iterator top_level_begin()
Definition: ASTUnit.h:502
isInMainFile
static bool isInMainFile(const clang::Diagnostic &D)
Definition: ASTUnit.cpp:679
clang::ASTUnit::getASTReader
IntrusiveRefCntPtr< ASTReader > getASTReader() const
Definition: ASTUnit.cpp:719
clang::CodeCompletionContext::CCC_SymbolOrNewName
@ CCC_SymbolOrNewName
Code completion occurred where both a new name and an existing symbol is permissible.
Definition: CodeCompleteConsumer.h:278
clang::Language::CUDA
@ CUDA
clang::DiagnosticsEngine::Level
Level
The level of the diagnostic, after it has been through mapping.
Definition: Diagnostic.h:194
clang::Lexer::makeFileCharRange
static CharSourceRange makeFileCharRange(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts)
Accepts a range and returns a character range with file locations.
Definition: Lexer.cpp:878
clang::CodeCompleteOptions::IncludeMacros
unsigned IncludeMacros
Show macros in code completion results.
Definition: CodeCompleteOptions.h:18
clang::CodeCompletionContext::CCC_Other
@ CCC_Other
An unspecified code-completion context.
Definition: CodeCompleteConsumer.h:191
clang::DiagnosticsEngine::Reset
void Reset()
Reset the state of the diagnostic object to its initial configuration.
Definition: Diagnostic.cpp:133
clang::ASTUnit
Utility class for loading a ASTContext from an AST file.
Definition: ASTUnit.h:89
clang::FullSourceLoc::getManager
const SourceManager & getManager() const
Definition: SourceLocation.h:383
clang::Decl::IDNS_Type
@ IDNS_Type
Types, declared with 'struct foo', typedefs, etc.
Definition: DeclBase.h:133
clang::PreambleCallbacks
A set of callbacks to gather useful information while building a preamble.
Definition: PrecompiledPreamble.h:273
clang::ASTUnit::mapLocationFromPreamble
SourceLocation mapLocationFromPreamble(SourceLocation Loc) const
If Loc is a loaded location from the preamble, returns the corresponding local location of the main f...
Definition: ASTUnit.cpp:2513
clang::CompilerInvocationBase::getPreprocessorOpts
PreprocessorOptions & getPreprocessorOpts()
Definition: CompilerInvocation.h:108
clang::InputKind::Format
Format
The input file format.
Definition: FrontendOptions.h:152
clang::comments::CommandTraits::registerCommentOptions
void registerCommentOptions(const CommentOptions &CommentOptions)
Definition: CommentCommandTraits.cpp:24
clang::SourceManager::getPreambleFileID
FileID getPreambleFileID() const
Get the file ID for the precompiled preamble if there is one.
Definition: SourceManager.h:856
clang::CodeCompleteConsumer::loadExternal
bool loadExternal() const
Hint whether to load data from the external AST in order to provide full results.
Definition: CodeCompleteConsumer.h:1106
clang::ASTUnit::StandaloneFixIt::CodeToInsert
std::string CodeToInsert
Definition: ASTUnit.h:94
clang::CharSourceRange::getBegin
SourceLocation getBegin() const
Definition: SourceLocation.h:285
clang::ASTReader::HadErrors
@ HadErrors
The AST file has errors.
Definition: ASTReader.h:390
clang::ASTUnit::LoadFromCompilerInvocationAction
static ASTUnit * LoadFromCompilerInvocationAction(std::shared_ptr< CompilerInvocation > CI, std::shared_ptr< PCHContainerOperations > PCHContainerOps, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, FrontendAction *Action=nullptr, ASTUnit *Unit=nullptr, bool Persistent=true, StringRef ResourceFilesPath=StringRef(), bool OnlyLocalDecls=false, CaptureDiagsKind CaptureDiagnostics=CaptureDiagsKind::None, unsigned PrecompilePreambleAfterNParses=0, bool CacheCodeCompletionResults=false, bool UserFilesAreVolatile=false, std::unique_ptr< ASTUnit > *ErrAST=nullptr)
Create an ASTUnit from a source file, via a CompilerInvocation object, by invoking the optionally pro...
Definition: ASTUnit.cpp:1510
clang::FullSourceLoc
A SourceLocation and its associated SourceManager.
Definition: SourceLocation.h:366
clang::SourceManager::isInFileID
bool isInFileID(SourceLocation Loc, FileID FID, unsigned *RelativeOffset=nullptr) const
Given a specific FileID, returns true if Loc is inside that FileID chunk and sets relative offset (of...
Definition: SourceManager.h:1518
clang::DeclaratorContext::File
@ File
clang::DiagnosticsEngine::setClient
void setClient(DiagnosticConsumer *client, bool ShouldOwnClient=true)
Set the diagnostic client associated with this diagnostic object.
Definition: Diagnostic.cpp:111
clang::PreprocessorOptions
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
Definition: PreprocessorOptions.h:64
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1302
clang::ProcessWarningOptions
void ProcessWarningOptions(DiagnosticsEngine &Diags, const DiagnosticOptions &Opts, bool ReportDiags=true)
ProcessWarningOptions - Initialize the diagnostic client and process the warning options specified on...
Definition: Warnings.cpp:44
clang::CodeCompletionContext::CCC_ObjCInstanceMessage
@ CCC_ObjCInstanceMessage
Code completion where an Objective-C instance message is expected.
Definition: CodeCompleteConsumer.h:317
clang::CompilerInstance::getPreprocessorPtr
std::shared_ptr< Preprocessor > getPreprocessorPtr()
Definition: CompilerInstance.h:446
clang::ASTUnit::cached_completion_iterator
std::vector< CachedCodeCompletionResult >::iterator cached_completion_iterator
Definition: ASTUnit.h:614
clang::CodeCompletionContext::CCC_Expression
@ CCC_Expression
Code completion occurred where an expression is expected.
Definition: CodeCompleteConsumer.h:221
Diag
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Definition: LiteralSupport.cpp:78
clang::ASTReader::Failure
@ Failure
The AST file itself appears corrupted.
Definition: ASTReader.h:373
llvm::SmallVector
Definition: LLVM.h:35
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:89
clang::LangOptions::isCompilingModule
bool isCompilingModule() const
Are we compiling a module interface (.cppm or module map)?
Definition: LangOptions.h:354
clang::CodeCompleteOptions::IncludeBriefComments
unsigned IncludeBriefComments
Show brief documentation comments in code completion results.
Definition: CodeCompleteOptions.h:35
clang::PPCallbacks
This interface provides a way to observe the actions of the preprocessor as it does its thing.
Definition: PPCallbacks.h:35
clang::ASTUnit::RemappedFile
std::pair< std::string, llvm::MemoryBuffer * > RemappedFile
A mapping from a file name to the memory buffer that stores the remapped contents of that file.
Definition: ASTUnit.h:662
clang::CodeCompletionContext::CCC_Type
@ CCC_Type
Code completion occurred where a type name is expected.
Definition: CodeCompleteConsumer.h:271
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:223
TargetInfo.h
clang::NamedDecl::getUnderlyingDecl
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:429
clang::MultiVersionKind::Target
@ Target
clang::CodeCompleteOptions::IncludeFixIts
unsigned IncludeFixIts
Include results after corrections (small fix-its), e.g.
Definition: CodeCompleteOptions.h:44
clang::FrontendOptions::SkipFunctionBodies
unsigned SkipFunctionBodies
Skip over function bodies to speed up parsing in cases you do not need them (e.g.
Definition: FrontendOptions.h:268
clang::CodeCompletionContext::CCC_ObjCImplementation
@ CCC_ObjCImplementation
Code completion occurred within an Objective-C implementation or category implementation.
Definition: CodeCompleteConsumer.h:207
clang::ASTUnit::visitLocalTopLevelDecls
bool visitLocalTopLevelDecls(void *context, DeclVisitorFn Fn)
Iterate over local declarations (locally parsed if this is a parsed source file or the loaded declara...
Definition: ASTUnit.cpp:2611
clang::ASTUnit::LoadASTOnly
@ LoadASTOnly
Load the AST, but do not restore Sema state.
Definition: ASTUnit.h:675
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:661
clang::FrontendAction::EndSourceFile
void EndSourceFile()
Perform any per-file post processing, deallocate per-file objects, and run statistics and output file...
Definition: FrontendAction.cpp:971
clang::ASTUnit::isInMainFileID
bool isInMainFileID(SourceLocation Loc) const
Definition: ASTUnit.cpp:2563
clang::DiagnosticConsumer
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1707
AttributeLangSupport::C
@ C
Definition: SemaDeclAttr.cpp:52
clang::Token::getIdentifierInfo
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:179
clang::ASTUnit::getCachedCompletionTypes
llvm::StringMap< unsigned > & getCachedCompletionTypes()
Retrieve the mapping from formatted type names to unique type identifiers.
Definition: ASTUnit.h:306
clang::ASTUnit::getSema
Sema & getSema() const
Definition: ASTUnit.h:456
Filename
StringRef Filename
Definition: Format.cpp:2145
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:191
DeclCXX.h
clang::FrontendInputFile
An input file for the front end.
Definition: FrontendOptions.h:184
clang::PreprocessingRecord
A record of the steps taken while preprocessing a source file, including the various preprocessing di...
Definition: PreprocessingRecord.h:308
Module.h
clang::SkipFunctionBodiesScope
SkipFunctionBodiesScope
Enumerates the available scopes for skipping function bodies.
Definition: ASTUnit.h:83
CodeCompleteConsumer.h
clang::LangOptions::CMK_ModuleMap
@ CMK_ModuleMap
Compiling a module from a module map.
Definition: LangOptions.h:88
clang::StoredDiagnostic::getRanges
ArrayRef< CharSourceRange > getRanges() const
Definition: Diagnostic.h:1690
ActiveASTUnitObjects
static std::atomic< unsigned > ActiveASTUnitObjects
Tracks the number of ASTUnit objects that are currently active.
Definition: ASTUnit.cpp:240
llvm::Optional
Definition: LLVM.h:37
clang::CodeCompletionContext::CCC_IncludedFile
@ CCC_IncludedFile
Code completion inside the filename part of a include directive.
Definition: CodeCompleteConsumer.h:330
clang::ASTUnit::DeclVisitorFn
bool(*)(void *context, const Decl *D) DeclVisitorFn
Type for a function iterating over a number of declarations.
Definition: ASTUnit.h:636
clang::ASTUnit::getASTMutationListener
ASTMutationListener * getASTMutationListener()
Definition: ASTUnit.cpp:723
clang::QualType::getAsString
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition: Type.h:1003
SourceManager.h
clang::ASTUnit::enableSourceFileDiagnostics
void enableSourceFileDiagnostics()
Enable source-range based diagnostic messages.
Definition: ASTUnit.cpp:279
clang::StoredDiagnostic::getMessage
StringRef getMessage() const
Definition: Diagnostic.h:1680
llvm::Expected
Definition: LLVM.h:38
clang::STC_Void
@ STC_Void
Definition: CodeCompleteConsumer.h:158
clang::PrintingPolicy
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:59
ContinuousRangeMap.h
clang::DiagnosticsEngine::hasUncompilableErrorOccurred
bool hasUncompilableErrorOccurred() const
Errors that actually prevent compilation, not those that are upgraded from a warning by -Werror.
Definition: Diagnostic.h:837
clang::sema::Capture
Definition: ScopeInfo.h:517
clang::PreprocessorOptions::DetailedRecord
bool DetailedRecord
Whether we should maintain a detailed record of all macro definitions and expansions.
Definition: PreprocessorOptions.h:76
clang::ASTUnit::StandaloneDiagnostic::Ranges
std::vector< std::pair< unsigned, unsigned > > Ranges
Definition: ASTUnit.h:104
ASTWriter.h
clang::createInvocationFromCommandLine
std::unique_ptr< CompilerInvocation > createInvocationFromCommandLine(ArrayRef< const char * > Args, IntrusiveRefCntPtr< DiagnosticsEngine > Diags=IntrusiveRefCntPtr< DiagnosticsEngine >(), IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS=nullptr, bool ShouldRecoverOnErrors=false, std::vector< std::string > *CC1Args=nullptr)
createInvocationFromCommandLine - Construct a compiler invocation object for a command line argument ...
Definition: CreateInvocationFromCommandLine.cpp:27
Identifier
StringRef Identifier
Definition: Format.cpp:2153
FrontendAction.h
clang::DiagnosticConsumer::EndSourceFile
virtual void EndSourceFile()
Callback to inform the diagnostic client that processing of a source file has ended.
Definition: Diagnostic.h:1739
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
clang::InputKind
The kind of a file that we've been handed as an input.
Definition: FrontendOptions.h:144
clang::ASTUnit::getTranslationUnitKind
TranslationUnitKind getTranslationUnitKind() const
Determine what kind of translation unit this AST represents.
Definition: ASTUnit.h:655
clang::getMacroUsagePriority
unsigned getMacroUsagePriority(StringRef MacroName, const LangOptions &LangOpts, bool PreferredTypeIsPointer=false)
Determine the priority to be given to a macro code completion result with the given name.
Definition: SemaCodeComplete.cpp:3794
clang::CCP_NestedNameSpecifier
@ CCP_NestedNameSpecifier
Priority for a nested-name-specifier.
Definition: CodeCompleteConsumer.h:93
clang::ASTUnit::ASTWriterData::Writer
ASTWriter Writer
Definition: ASTUnit.cpp:221
DefaultPreambleRebuildInterval
const unsigned DefaultPreambleRebuildInterval
After failing to build a precompiled preamble (due to errors in the source that occurs in the preambl...
Definition: ASTUnit.cpp:235
clang::DeclarationName
The name of a declaration.
Definition: DeclarationName.h:145
clang::InputKind::Source
@ Source
Definition: FrontendOptions.h:153
clang::ASTUnit::Save
bool Save(StringRef File)
Save this translation unit to a file with the given name.
Definition: ASTUnit.cpp:2297
clang::FrontendInputFile::getFile
StringRef getFile() const
Definition: FrontendOptions.h:215
clang::StoredDiagnostic::getID
unsigned getID() const
Definition: Diagnostic.h:1677
CompilerInvocation.h
clang::Preprocessor::getIdentifierTable
IdentifierTable & getIdentifierTable()
Definition: Preprocessor.h:929
clang::PCHContainerReader
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
Definition: PCHContainerOperations.h:57
clang::ASTUnit::getEndOfPreambleFileID
SourceLocation getEndOfPreambleFileID() const
Definition: ASTUnit.cpp:2574
clang::DisableValidationForModuleKind::None
@ None
Perform validation, don't disable it.
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:624
clang::CodeCompletionResult
Captures a result of code completion.
Definition: CodeCompleteConsumer.h:746
clang::FrontendOptions::Inputs
SmallVector< FrontendInputFile, 0 > Inputs
The input files and their types.
Definition: FrontendOptions.h:382
clang::ParsedSourceLocation::FileName
std::string FileName
Definition: CommandLineSourceLoc.h:25
clang::Sema::Context
ASTContext & Context
Definition: Sema.h:402
clang::Preprocessor::getLangOpts
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:922
checkAndRemoveNonDriverDiags
static void checkAndRemoveNonDriverDiags(SmallVectorImpl< StoredDiagnostic > &StoredDiags)
Definition: ASTUnit.cpp:1068
Preprocessor.h
clang::HeaderSearch
Encapsulates the information needed to find the file referenced by a #include or #include_next,...
Definition: HeaderSearch.h:158
Decl.h
DeclObjC.h
clang::ParsedSourceLocation::Line
unsigned Line
Definition: CommandLineSourceLoc.h:26
Offset
unsigned Offset
Definition: Format.cpp:2147
clang::FileSystemOptions
Keeps track of options that affect how file operations are performed.
Definition: FileSystemOptions.h:22
clang::StoredDiagnostic::getFixIts
ArrayRef< FixItHint > getFixIts() const
Definition: Diagnostic.h:1700
clang::FixItHint
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
Definition: Diagnostic.h:70
clang::Diagnostic
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1532
clang::Sema::getLangOpts
const LangOptions & getLangOpts() const
Definition: Sema.h:1521
clang::ASTUnit::getASTContext
const ASTContext & getASTContext() const
Definition: ASTUnit.h:439
clang::ASTUnit::getLocalPreprocessingEntities
llvm::iterator_range< PreprocessingRecord::iterator > getLocalPreprocessingEntities() const
Returns an iterator range for the local preprocessing entities of the local Preprocessor,...
Definition: ASTUnit.cpp:2597
PrettyPrinter.h
clang::CodeCompletionContext::CCC_ObjCCategoryName
@ CCC_ObjCCategoryName
Code completion where an Objective-C category name is expected.
Definition: CodeCompleteConsumer.h:327
clang::CharSourceRange::getCharRange
static CharSourceRange getCharRange(SourceRange R)
Definition: SourceLocation.h:267
clang::CodeCompletionContext::CCC_TopLevel
@ CCC_TopLevel
Code completion occurred within a "top-level" completion context, e.g., at namespace or global scope.
Definition: CodeCompleteConsumer.h:199
clang::Decl::getLexicalDeclContext
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:843
clang::ASTUnit::StandaloneDiagnostic::ID
unsigned ID
Definition: ASTUnit.h:99
clang::ASTUnit::StandaloneDiagnostic::Level
DiagnosticsEngine::Level Level
Definition: ASTUnit.h:100
clang::ASTUnit::ASTWriterData::ASTWriterData
ASTWriterData(InMemoryModuleCache &ModuleCache)
Definition: ASTUnit.cpp:223
clang::ASTUnit::getHeaderSearchOpts
const HeaderSearchOptions & getHeaderSearchOpts() const
Definition: ASTUnit.h:466
clang::DiagnosticConsumer::HandleDiagnostic
virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info)
Handle this diagnostic, reporting it to the user or capturing it to a log as needed.
Definition: Diagnostic.cpp:547
clang::getAsString
llvm::StringRef getAsString(SyncScope S)
Definition: SyncScope.h:50
clang::ASTContext::getExternalSource
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1058
clang::ASTReader::Success
@ Success
The control block was read successfully.
Definition: ASTReader.h:370
clang::Language::RenderScript
@ RenderScript
clang::ASTUnit::top_level_end
top_level_iterator top_level_end()
Definition: ASTUnit.h:509
clang::PreprocessingRecord::iterator
Iteration over the preprocessed entities.
Definition: PreprocessingRecord.h:430
clang::CodeCompleteOptions::IncludeGlobals
unsigned IncludeGlobals
Show top-level decls in code completion results.
Definition: CodeCompleteOptions.h:24
AddTopLevelDeclarationToHash
static void AddTopLevelDeclarationToHash(Decl *D, unsigned &Hash)
Add the given declaration to the hash of all top-level entities.
Definition: ASTUnit.cpp:893
clang::FrontendInputFile::getBuffer
llvm::MemoryBufferRef getBuffer() const
Definition: FrontendOptions.h:220
clang::Module
Describes a module or submodule.
Definition: Module.h:96
clang::ASTUnit::getSourceManager
const SourceManager & getSourceManager() const
Definition: ASTUnit.h:432
clang::CodeCompletionContext::CCC_Recovery
@ CCC_Recovery
An unknown context, in which we are recovering from a parsing error and don't know which completions ...
Definition: CodeCompleteConsumer.h:334
DeclTemplate.h
clang::ASTUnit::Reparse
bool Reparse(std::shared_ptr< PCHContainerOperations > PCHContainerOps, ArrayRef< RemappedFile > RemappedFiles=None, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS=nullptr)
Reparse the source files using the same command-line options that were originally used to produce thi...
Definition: ASTUnit.cpp:1823
clang::CodeCompletionContext::CCC_ObjCProtocolName
@ CCC_ObjCProtocolName
Code completion occurred where a protocol name is expected.
Definition: CodeCompleteConsumer.h:264
HeaderSearchOptions.h
clang::DiagnosticsEngine::takeClient
std::unique_ptr< DiagnosticConsumer > takeClient()
Return the current diagnostic client along with ownership of that client.
Definition: Diagnostic.h:573
clang::CodeCompletionContext::CCC_EnumTag
@ CCC_EnumTag
Code completion occurred after the "enum" keyword, to indicate an enumeration name.
Definition: CodeCompleteConsumer.h:253
clang::FileManager::getVirtualFileSystem
llvm::vfs::FileSystem & getVirtualFileSystem() const
Definition: FileManager.h:243
CodeCompleteOptions.h
clang::ASTUnit::cached_completion_begin
cached_completion_iterator cached_completion_begin()
Definition: ASTUnit.h:616
FrontendOptions.h
clang::ASTUnit::getStartOfMainFileID
SourceLocation getStartOfMainFileID() const
Definition: ASTUnit.cpp:2585
clang::CodeCompleteOptions::IncludeCodePatterns
unsigned IncludeCodePatterns
Show code patterns in code completion results.
Definition: CodeCompleteOptions.h:21
DeclBase.h
clang::CodeCompletionBuilder
A builder class used to construct new code-completion strings.
Definition: CodeCompleteConsumer.h:671
clang::XRayInstrKind::None
constexpr XRayInstrMask None
Definition: XRayInstr.h:38
clang::ASTUnit::LoadFromASTFile
static std::unique_ptr< ASTUnit > LoadFromASTFile(const std::string &Filename, const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, const FileSystemOptions &FileSystemOpts, bool UseDebugInfo=false, bool OnlyLocalDecls=false, CaptureDiagsKind CaptureDiagnostics=CaptureDiagsKind::None, bool AllowASTWithCompilerErrors=false, bool UserFilesAreVolatile=false)
Create a ASTUnit from an AST file.
Definition: ASTUnit.cpp:757
clang::ASTReader::ARR_None
@ ARR_None
The client can't handle any AST loading failures.
Definition: ASTReader.h:1529
clang::ASTUnit::StandaloneFixIt::RemoveRange
std::pair< unsigned, unsigned > RemoveRange
Definition: ASTUnit.h:92
clang::FrontendAction::BeginSourceFile
bool BeginSourceFile(CompilerInstance &CI, const FrontendInputFile &Input)
Prepare the action for processing the input file Input.
Definition: FrontendAction.cpp:548
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
clang::CodeCompletionContext::CCC_ArrowMemberAccess
@ CCC_ArrowMemberAccess
Code completion occurred on the right-hand side of a member access expression using the arrow operato...
Definition: CodeCompleteConsumer.h:241
clang::SyntaxOnlyAction
Definition: FrontendActions.h:162
clang::SourceManager::getMainFileID
FileID getMainFileID() const
Returns the FileID of the main source file.
Definition: SourceManager.h:837
LangOptions.h
clang::CodeCompletionContext::CCC_Symbol
@ CCC_Symbol
Code completion occurred where an existing name(such as type, function or variable) is expected.
Definition: CodeCompleteConsumer.h:282
getBufferForFileHandlingRemapping
static std::unique_ptr< llvm::MemoryBuffer > getBufferForFileHandlingRemapping(const CompilerInvocation &Invocation, llvm::vfs::FileSystem *VFS, StringRef FilePath, bool isVolatile)
Get a source buffer for MainFilePath, handling all file-to-file and file-to-buffer remappings inside ...
Definition: ASTUnit.cpp:159
Diagnostic.h
clang::FrontendOptions
FrontendOptions - Options for controlling the behavior of the frontend.
Definition: FrontendOptions.h:227
clang::Preprocessor::getSelectorTable
SelectorTable & getSelectorTable()
Definition: Preprocessor.h:931
PrecompiledPreamble.h
Utils.h
clang::ASTUnit::getDiagnostics
const DiagnosticsEngine & getDiagnostics() const
Definition: ASTUnit.h:429
clang::ASTConsumer
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition: ASTConsumer.h:33
clang::ASTUnit::getInputKind
InputKind getInputKind() const
Determine the input kind this AST unit represents.
Definition: ASTUnit.cpp:2665
clang::ASTMutationListener
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
Definition: ASTMutationListener.h:46
clang::DisableValidationForModuleKind
DisableValidationForModuleKind
Whether to disable the normal validation performed on precompiled headers and module files when they ...
Definition: PreprocessorOptions.h:46
clang::ASTUnit::ASTWriterData
Definition: ASTUnit.cpp:218
clang::CodeCompletionContext::CCC_ObjCInterfaceName
@ CCC_ObjCInterfaceName
Code completion where the name of an Objective-C class is expected.
Definition: CodeCompleteConsumer.h:324
IdentifierTable.h
clang::DeclContext::isTranslationUnit
bool isTranslationUnit() const
Definition: DeclBase.h:1890
clang::ASTUnit::StandaloneFixIt
Definition: ASTUnit.h:91
Type.h
clang::PreprocessorOptions::AllowPCHWithCompilerErrors
bool AllowPCHWithCompilerErrors
When true, a PCH with compiler errors will not be rejected.
Definition: PreprocessorOptions.h:107
clang::FixItHint::BeforePreviousInsertions
bool BeforePreviousInsertions
Definition: Diagnostic.h:84
clang::DiagnosticsEngine::getClient
DiagnosticConsumer * getClient()
Definition: Diagnostic.h:565
clang::ASTUnit::StandaloneDiagnostic::FixIts
std::vector< StandaloneFixIt > FixIts
Definition: ASTUnit.h:105
clang::PCHContainerReader::getFormat
virtual llvm::StringRef getFormat() const =0
Equivalent to the format passed to -fmodule-format=.
llvm::SmallString< 128 >
clang::FrontendInputFile::isFile
bool isFile() const
Definition: FrontendOptions.h:211
clang::Language::C
@ C
Languages that the frontend can parse and compile.
ASTContext.h
clang::PreambleBounds
Describes the bounds (start, size) of the preamble and a flag required by PreprocessorOptions::Precom...
Definition: Lexer.h:58
clang::CaptureDiagsKind::All
@ All
clang::PreambleBounds::Size
unsigned Size
Size of the preamble in bytes.
Definition: Lexer.h:60
clang::ASTUnit::ResetForParse
void ResetForParse()
Free data that will be re-generated on the next parse.
Definition: ASTUnit.cpp:1881
AddDefinedMacroToHash
static void AddDefinedMacroToHash(const Token &MacroNameTok, unsigned &Hash)
Add the given macro to the hash of all top-level entities.
Definition: ASTUnit.cpp:870
clang::ASTUnit::StandaloneFixIt::BeforePreviousInsertions
bool BeforePreviousInsertions
Definition: ASTUnit.h:95
clang::CodeCompletionContext::CCC_ObjCMessageReceiver
@ CCC_ObjCMessageReceiver
Code completion occurred where an Objective-C message receiver is expected.
Definition: CodeCompleteConsumer.h:225
clang::ASTContext::getCanonicalType
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2354
clang::ASTContext::getCommentCommandTraits
comments::CommandTraits & getCommentCommandTraits() const
Definition: ASTContext.h:844
clang::CompilerInstance::getPreprocessor
Preprocessor & getPreprocessor() const
Return the current preprocessor.
Definition: CompilerInstance.h:441
clang::TargetInfo::CreateTargetInfo
static TargetInfo * CreateTargetInfo(DiagnosticsEngine &Diags, const std::shared_ptr< TargetOptions > &Opts)
Construct a target for the given options.
Definition: Targets.cpp:645
clang::Preprocessor::setCounterValue
void setCounterValue(unsigned V)
Definition: Preprocessor.h:1984
clang::FixItHint::InsertFromRange
CharSourceRange InsertFromRange
Code in the specific range that should be inserted in the insertion location.
Definition: Diagnostic.h:78
clang::DiagnosticsEngine::getNumWarnings
unsigned getNumWarnings() const
Definition: Diagnostic.h:848
clang::CCF_ExactTypeMatch
@ CCF_ExactTypeMatch
Divide by this factor when a code-completion result's type exactly matches the type we expect.
Definition: CodeCompleteConsumer.h:139
clang::FrontendAction::getTranslationUnitKind
virtual TranslationUnitKind getTranslationUnitKind()
For AST-based actions, the kind of translation unit we're handling.
Definition: FrontendAction.h:188
clang::CompilerInstance::getASTContext
ASTContext & getASTContext() const
Definition: CompilerInstance.h:461
clang::ASTUnit::getLangOpts
const LangOptions & getLangOpts() const
Definition: ASTUnit.h:461
clang::SourceManager::getLocForEndOfFile
SourceLocation getLocForEndOfFile(FileID FID) const
Return the source location corresponding to the last byte of the specified file.
Definition: SourceManager.h:1123
clang::DeclContext::getLookupParent
DeclContext * getLookupParent()
Find the parent context of this context that will be used for unqualified name lookup.
Definition: DeclBase.cpp:1089
clang::CanQual< Type >
clang::ASTWriter
Writes an AST file containing the contents of a translation unit.
Definition: ASTWriter.h:99
clang::ASTUnit::CodeComplete
void CodeComplete(StringRef File, unsigned Line, unsigned Column, ArrayRef< RemappedFile > RemappedFiles, bool IncludeMacros, bool IncludeCodePatterns, bool IncludeBriefComments, CodeCompleteConsumer &Consumer, std::shared_ptr< PCHContainerOperations > PCHContainerOps, DiagnosticsEngine &Diag, LangOptions &LangOpts, SourceManager &SourceMgr, FileManager &FileMgr, SmallVectorImpl< StoredDiagnostic > &StoredDiagnostics, SmallVectorImpl< const llvm::MemoryBuffer * > &OwnedBuffers)
Perform code completion at the given file, line, and column within this translation unit.
Definition: ASTUnit.cpp:2134
Line
const AnnotatedLine * Line
Definition: UsingDeclarationsSorter.cpp:68
DeclGroup.h
clang::CCF_SimilarTypeMatch
@ CCF_SimilarTypeMatch
Divide by this factor when a code-completion result's type is similar to the type we expect (e....
Definition: CodeCompleteConsumer.h:144
clang::ASTUnit::getLocation
SourceLocation getLocation(const FileEntry *File, unsigned Line, unsigned Col) const
Get the source location for the given file:line:col triplet.
Definition: ASTUnit.cpp:2496
clang::CompilerInstance
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Definition: CompilerInstance.h:73
clang::FileManager::getFileSystemOpts
FileSystemOptions & getFileSystemOpts()
Returns the current file system options.
Definition: FileManager.h:240
Sema.h
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:331
clang::Decl::IDNS_Member
@ IDNS_Member
Members, declared with object declarations within tag definitions.
Definition: DeclBase.h:139
clang::CodeCompletionString
A "string" used to describe how code completion can be performed for an entity.
Definition: CodeCompleteConsumer.h:439
InMemoryModuleCache.h
clang::Decl::IDNS_Ordinary
@ IDNS_Ordinary
Ordinary names.
Definition: DeclBase.h:147
ExternalASTSource.h
clang::CompilerInstance::hasTarget
bool hasTarget() const
Definition: CompilerInstance.h:366
clang::ASTUnit::top_level_iterator
std::vector< Decl * >::iterator top_level_iterator
Definition: ASTUnit.h:500
clang::CodeCompletionContext::CCC_OtherWithMacros
@ CCC_OtherWithMacros
An unspecified code-completion context where we should also add macro completions.
Definition: CodeCompleteConsumer.h:195
clang::QualType::getUnqualifiedType
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:6500
clang::CodeCompletionContext::CCC_Namespace
@ CCC_Namespace
Code completion occurred where a namespace or namespace alias is expected.
Definition: CodeCompleteConsumer.h:268
clang::serialization::ModuleFile::File
OptionalFileEntryRefDegradesToFileEntryPtr File
The file entry for the module file.
Definition: ModuleFile.h:166
clang::StoredDiagnostic
Represents a diagnostic in a form that can be retained until its corresponding source manager is dest...
Definition: Diagnostic.h:1656
clang::SourceManager::getLocForStartOfFile
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
Definition: SourceManager.h:1115
clang::Preprocessor::getSourceManager
SourceManager & getSourceManager() const
Definition: Preprocessor.h:926
clang::ParsedSourceLocation::Column
unsigned Column
Definition: CommandLineSourceLoc.h:27
clang::InputKind::ModuleMap
@ ModuleMap
Definition: FrontendOptions.h:154
clang::Decl::IDNS_Namespace
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
Definition: DeclBase.h:143
clang::ASTUnit::getASTFileName
StringRef getASTFileName() const
If this ASTUnit came from an AST file, returns the filename for it.
Definition: ASTUnit.cpp:1480
ASTBitCodes.h
clang::getSimplifiedTypeClass
SimplifiedTypeClass getSimplifiedTypeClass(CanQualType T)
Determine the simplified type class of the given canonical type.
Definition: SemaCodeComplete.cpp:822
clang::BuildPreambleError::BadInputs
@ BadInputs
moveOnNoError
static bool moveOnNoError(llvm::ErrorOr< T > Val, T &Output)
Definition: ASTUnit.cpp:149
SourceLocation.h
clang::CodeCompletionContext::CCC_ObjCPropertyAccess
@ CCC_ObjCPropertyAccess
Code completion occurred on the right-hand side of an Objective-C property access expression.
Definition: CodeCompleteConsumer.h:249
clang::CompilerInstance::takeASTConsumer
std::unique_ptr< ASTConsumer > takeASTConsumer()
takeASTConsumer - Remove the current AST consumer and give ownership to the caller.
Definition: CompilerInstance.h:491
clang::PreprocessorOptions::RetainRemappedFileBuffers
bool RetainRemappedFileBuffers
Whether the compiler instance should retain (i.e., not free) the buffers associated with remapped fil...
Definition: PreprocessorOptions.h:166
clang::StoredDiagnostic::getLocation
const FullSourceLoc & getLocation() const
Definition: Diagnostic.h:1679
clang::FixItHint::CodeToInsert
std::string CodeToInsert
The actual code to insert at the insertion location, as a string.
Definition: Diagnostic.h:82
getDeclShowContexts
static uint64_t getDeclShowContexts(const NamedDecl *ND, const LangOptions &LangOpts, bool &IsNestedNameSpecifier)
Determine the set of code-completion contexts in which this declaration should be shown.
Definition: ASTUnit.cpp:287
clang::PreprocessorOptions::SingleFileParseMode
bool SingleFileParseMode
When enabled, preprocessor is in a mode for parsing a single file only.
Definition: PreprocessorOptions.h:140
clang::DiagnosticConsumer::BeginSourceFile
virtual void BeginSourceFile(const LangOptions &LangOpts, const Preprocessor *PP=nullptr)
Callback to inform the diagnostic client that processing of a source file is beginning.
Definition: Diagnostic.h:1731
clang::ASTUnit::addTopLevelDecl
void addTopLevelDecl(Decl *D)
Add a new top-level declaration.
Definition: ASTUnit.h:527
clang::Decl::isFromASTFile
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:716
clang::Preprocessor::getBuiltinInfo
Builtin::Context & getBuiltinInfo()
Definition: Preprocessor.h:932
clang::FrontendOptions::CodeCompleteOpts
CodeCompleteOptions CodeCompleteOpts
Definition: FrontendOptions.h:306
false
#define false
Definition: stdbool.h:17
clang::Language
Language
The language for the input, used to select and validate the language standard and possible actions.
Definition: LangStandard.h:19
clang::ASTDeserializationListener
Definition: ASTDeserializationListener.h:30
clang::CodeCompletionContext::CCC_PreprocessorExpression
@ CCC_PreprocessorExpression
Code completion occurred within a preprocessor expression.
Definition: CodeCompleteConsumer.h:292
clang::CompilerInstance::hasPreprocessor
bool hasPreprocessor() const
Definition: CompilerInstance.h:438
LangStandard.h
clang::Diagnostic::getLocation
const SourceLocation & getLocation() const
Definition: Diagnostic.h:1543
clang::CompilerInvocationBase::getLangOpts
LangOptions * getLangOpts()
Definition: CompilerInvocation.h:86
clang::BuildPreambleError::BeginSourceFileFailed
@ BeginSourceFileFailed
clang::ASTWriter::getDeclID
serialization::DeclID getDeclID(const Decl *D)
Determine the declaration ID of an already-emitted declaration.
Definition: ASTWriter.cpp:5312
CXCursor_MacroDefinition
@ CXCursor_MacroDefinition
Definition: Index.h:2638
TargetOptions.h
clang::Language::CXX
@ CXX
clang::ASTReader::OutOfDate
@ OutOfDate
The AST file is out-of-date relative to its input files, and needs to be regenerated.
Definition: ASTReader.h:380
PreprocessingRecord.h
TypeOrdering.h
clang::Language::ObjCXX
@ ObjCXX
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:726
llvm::ArrayRef
Definition: LLVM.h:31
clang::Language::LLVM_IR
@ LLVM_IR
LLVM IR: we accept this so that we can run the optimizer on it, and compile it to assembly or object ...
clang::frontend::FixIt
@ FixIt
Parse and apply any fixits to the source.
Definition: FrontendOptions.h:78
Lexer.h
clang::CodeCompletionContext::CCC_PreprocessorDirective
@ CCC_PreprocessorDirective
Code completion occurred where a preprocessor directive is expected.
Definition: CodeCompleteConsumer.h:296
Value
Value
Definition: UninitializedValues.cpp:102
clang::ASTUnit::getFileManager
const FileManager & getFileManager() const
Definition: ASTUnit.h:476
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
clang::PreprocessorOptions::RemappedFileBuffers
std::vector< std::pair< std::string, llvm::MemoryBuffer * > > RemappedFileBuffers
The set of file-to-buffer remappings, which take existing files on the system (the first part of each...
Definition: PreprocessorOptions.h:158
clang::CompilerInstance::getInvocation
CompilerInvocation & getInvocation()
Definition: CompilerInstance.h:228
clang::BuildPreambleError
BuildPreambleError
Definition: PrecompiledPreamble.h:304
clang::ASTUnit::WhatToLoad
WhatToLoad
Definition: ASTUnit.h:670
clang::CodeCompleteConsumer::includeFixIts
bool includeFixIts() const
Whether to include completion items with small fix-its, e.g.
Definition: CodeCompleteConsumer.h:1102
clang::ASTUnit::create
static std::unique_ptr< ASTUnit > create(std::shared_ptr< CompilerInvocation > CI, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, CaptureDiagsKind CaptureDiagnostics, bool UserFilesAreVolatile)
Create a ASTUnit. Gets ownership of the passed CompilerInvocation.
Definition: ASTUnit.cpp:1490
clang::ASTUnit::ASTWriterData::Stream
llvm::BitstreamWriter Stream
Definition: ASTUnit.cpp:220
HeaderSearch.h
clang::DeclGroupRef
Definition: DeclGroup.h:51
clang::OverloadCandidate
OverloadCandidate - A single candidate in an overload set (C++ 13.3).
Definition: Overload.h:790
makeStandaloneFixIt
static ASTUnit::StandaloneFixIt makeStandaloneFixIt(const SourceManager &SM, const LangOptions &LangOpts, const FixItHint &InFix)
Definition: ASTUnit.cpp:1244
clang::CharSourceRange
Represents a character-granular source range.
Definition: SourceLocation.h:255
clang::FrontendAction::Execute
llvm::Error Execute()
Set the source manager's main input file, and run the action.
Definition: FrontendAction.cpp:942
clang::PreprocessorOptions::PrecompiledPreambleBytes
std::pair< unsigned, bool > PrecompiledPreambleBytes
If non-zero, the implicit PCH include is actually a precompiled preamble that covers this number of b...
Definition: PreprocessorOptions.h:121
clang::ASTReader::ConfigurationMismatch
@ ConfigurationMismatch
The AST file was writtten with a different language/target configuration.
Definition: ASTReader.h:387
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:343
clang::Decl::IDNS_NonMemberOperator
@ IDNS_NonMemberOperator
This declaration is a C++ operator declared in a non-class context.
Definition: DeclBase.h:171
FrontendActions.h
ASTUnit.h
LLVM.h
clang::CompilerInstance::hadModuleLoaderFatalFailure
bool hadModuleLoaderFatalFailure() const
Definition: CompilerInstance.h:804
clang::CodeCompletionContext::CCC_ClassStructUnion
@ CCC_ClassStructUnion
Code completion occurred within a class, struct, or union.
Definition: CodeCompleteConsumer.h:214
clang::CodeCompletionContext::CCC_Statement
@ CCC_Statement
Code completion occurred where a statement (or declaration) is expected in a function,...
Definition: CodeCompleteConsumer.h:218
clang::CodeCompleteConsumer
Abstract interface for a consumer of code-completion information.
Definition: CodeCompleteConsumer.h:997
clang::Language::ObjC
@ ObjC
clang::CodeCompletionContext::CCC_DotMemberAccess
@ CCC_DotMemberAccess
Code completion occurred on the right-hand side of a member access expression using the dot operator.
Definition: CodeCompleteConsumer.h:233
isNonDriverDiag
static bool isNonDriverDiag(const StoredDiagnostic &StoredDiag)
Definition: ASTUnit.cpp:1063
clang::DisableValidationForModuleKind::All
@ All
Disable validation for all kinds.
clang::CaptureDiagsKind::None
@ None
ASTConsumer.h
clang::Diagnostic::getSourceManager
SourceManager & getSourceManager() const
Definition: Diagnostic.h:1545
clang::StoredDiagnostic::getLevel
DiagnosticsEngine::Level getLevel() const
Definition: Diagnostic.h:1678
clang::ASTContext::setPrintingPolicy
void setPrintingPolicy(const clang::PrintingPolicy &Policy)
Definition: ASTContext.h:639
clang::CharSourceRange::getEnd
SourceLocation getEnd() const
Definition: SourceLocation.h:286
clang::DeclContext::isFileContext
bool isFileContext() const
Definition: DeclBase.h:1885
clang::ASTUnit::StandaloneDiagnostic
Definition: ASTUnit.h:98
clang::createVFSFromCompilerInvocation
IntrusiveRefCntPtr< llvm::vfs::FileSystem > createVFSFromCompilerInvocation(const CompilerInvocation &CI, DiagnosticsEngine &Diags)
Definition: CompilerInvocation.cpp:4526
clang::ASTUnit::getBufferForFile
std::unique_ptr< llvm::MemoryBuffer > getBufferForFile(StringRef Filename, std::string *ErrorStr=nullptr)
Definition: ASTUnit.cpp:736
valueOrNull
static std::unique_ptr< T > valueOrNull(llvm::ErrorOr< std::unique_ptr< T >> Val)
Definition: ASTUnit.cpp:142
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:59
clang::SimplifiedTypeClass
SimplifiedTypeClass
A simplified classification of types used when determining "similar" types for code completion.
Definition: CodeCompleteConsumer.h:149
serializeUnit
static bool serializeUnit(ASTWriter &Writer, SmallVectorImpl< char > &Buffer, Sema &S, bool hasErrors, raw_ostream &OS)
Definition: ASTUnit.cpp:2322
clang::ASTUnit::mapLocationToPreamble
SourceLocation mapLocationToPreamble(SourceLocation Loc) const
If Loc is a local location of the main file but inside the preamble chunk, returns the corresponding ...
Definition: ASTUnit.cpp:2534
PCHContainerOperations.h
Priority
int Priority
Definition: Format.cpp:2149
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
clang::ASTWriter::WriteAST
ASTFileSignature WriteAST(Sema &SemaRef, const std::string &OutputFile, Module *WritingModule, StringRef isysroot, bool hasErrors=false, bool ShouldCacheASTInMemory=false)
Write a precompiled header for the given semantic analysis.
Definition: ASTWriter.cpp:4348
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::ASTUnit::StandaloneDiagnostic::Message
std::string Message
Definition: ASTUnit.h:101
clang::ASTUnit::ASTWriterData::Buffer
SmallString< 128 > Buffer
Definition: ASTUnit.cpp:219
clang::SourceManager::isLoadedFileID
bool isLoadedFileID(FileID FID) const
Returns true if FID came from a PCH/Module.
Definition: SourceManager.h:1730
clang::ASTReader
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:342
clang::BuildPreambleError::CouldntEmitPCH
@ CouldntEmitPCH
clang::TranslationUnitKind
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:653
clang::ASTUnit::StandaloneDiagnostic::Filename
std::string Filename
Definition: ASTUnit.h:102
DeclarationName.h
clang::ASTUnit::cached_completion_end
cached_completion_iterator cached_completion_end()
Definition: ASTUnit.h:620
clang::CompilerInvocation::getFrontendOpts
FrontendOptions & getFrontendOpts()
Definition: CompilerInvocation.h:228
ModuleFile.h
clang::CompilerInstance::getTarget
TargetInfo & getTarget() const
Definition: CompilerInstance.h:368
clang::CodeCompletionContext::CCC_NaturalLanguage
@ CCC_NaturalLanguage
Code completion occurred in a context where natural language is expected, e.g., a comment or string l...
Definition: CodeCompleteConsumer.h:303
clang::FrontendAction
Abstract base class for actions which can be performed by the frontend.
Definition: FrontendAction.h:36
clang::IdentifierInfo::getName
StringRef getName() const
Return the actual identifier string.
Definition: IdentifierTable.h:160
clang::Builtin::ID
ID
Definition: Builtins.h:46
clang::SourceLocation::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:111
clang
Dataflow Directional Tag Classes.
Definition: CalledOnceCheck.h:17
clang::FileManager
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
clang::Preprocessor::addPPCallbacks
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
Definition: Preprocessor.h:1020
makeStandaloneRange
static std::pair< unsigned, unsigned > makeStandaloneRange(CharSourceRange Range, const SourceManager &SM, const LangOptions &LangOpts)
Definition: ASTUnit.cpp:1236
clang::ASTUnit::serialize
bool serialize(raw_ostream &OS)
Serialize this translation unit with the given output stream.
Definition: ASTUnit.cpp:2336
PPCallbacks.h
clang::ASTUnit::addFileLevelDecl
void addFileLevelDecl(Decl *D)
Add a new local file-level declaration.
Definition: ASTUnit.cpp:2412
FrontendDiagnostic.h
clang::CodeCompletionContext::CCC_NewName
@ CCC_NewName
Code completion occurred where a new name is expected.
Definition: CodeCompleteConsumer.h:274
clang::MacroDirective
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
Definition: MacroInfo.h:290
clang::getDeclUsageType
QualType getDeclUsageType(ASTContext &C, const NamedDecl *ND)
Determine the type that this declaration will have if it is used as a type or in an expression.
Definition: SemaCodeComplete.cpp:891
clang::CaptureDiagsKind
CaptureDiagsKind
Enumerates the available kinds for capturing diagnostics.
Definition: ASTUnit.h:86
clang::ContinuousRangeMap
A map from continuous integer ranges to some value, with a very specialized interface.
Definition: ContinuousRangeMap.h:37
ASTReader.h
clang::Preprocessor::getDiagnostics
DiagnosticsEngine & getDiagnostics() const
Definition: Preprocessor.h:919
clang::ASTUnit::isInPreambleFileID
bool isInPreambleFileID(SourceLocation Loc) const
Definition: ASTUnit.cpp:2552
clang::ASTReaderListener
Abstract interface for callback invocations by the ASTReader.
Definition: ASTReader.h:114
clang::BuildPreambleError::CouldntCreateTargetInfo
@ CouldntCreateTargetInfo
clang::prec::Level
Level
Definition: OperatorPrecedence.h:26
clang::FileID
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition: SourceLocation.h:41
clang::CompilerInvocation
Helper class for holding the data necessary to invoke the compiler.
Definition: CompilerInvocation.h:120
clang::ASTReader::VersionMismatch
@ VersionMismatch
The AST file was written by a different version of Clang.
Definition: ASTReader.h:383
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:110
clang::ASTUnit::getMainFileName
StringRef getMainFileName() const
Definition: ASTUnit.cpp:1462
clang::FileID::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:48
clang::ASTUnit::StandaloneDiagnostic::LocOffset
unsigned LocOffset
Definition: ASTUnit.h:103
clang::SourceManager::getFileEntryForID
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
Definition: SourceManager.h:1027
clang::InMemoryModuleCache
In-memory cache for modules.
Definition: InMemoryModuleCache.h:30
clang::CompilerInstance::setFileManager
void setFileManager(FileManager *Value)
Replace the current file manager and virtual file system.
Definition: CompilerInstance.cpp:152
clang::CodeCompletionContext::CCC_ObjCIvarList
@ CCC_ObjCIvarList
Code completion occurred within the instance variable list of an Objective-C interface,...
Definition: CodeCompleteConsumer.h:211
clang::ASTUnit::StandaloneFixIt::InsertFromRange
std::pair< unsigned, unsigned > InsertFromRange
Definition: ASTUnit.h:93
clang::ASTUnit::LoadEverything
@ LoadEverything
Load everything, including Sema.
Definition: ASTUnit.h:678
makeStandaloneDiagnostic
static ASTUnit::StandaloneDiagnostic makeStandaloneDiagnostic(const LangOptions &LangOpts, const StoredDiagnostic &InDiag)
Definition: ASTUnit.cpp:1257
clang::CodeCompleteOptions
Options controlling the behavior of code completion.
Definition: CodeCompleteOptions.h:15
clang::CaptureDiagsKind::AllWithoutNonErrorsFromIncludes
@ AllWithoutNonErrorsFromIncludes
checkAndSanitizeDiags
static void checkAndSanitizeDiags(SmallVectorImpl< StoredDiagnostic > &StoredDiagnostics, SourceManager &SM)
Definition: ASTUnit.cpp:1076
clang::CodeCompletionAllocator
An allocator used specifically for the purpose of code completion.
Definition: CodeCompleteConsumer.h:636
clang::ASTUnit::setPreprocessor
void setPreprocessor(std::shared_ptr< Preprocessor > pp)
Definition: ASTUnit.cpp:275
clang::CCP_CodePattern
@ CCP_CodePattern
Priority for a code pattern.
Definition: CodeCompleteConsumer.h:78
clang::CodeCompletionContext::CCC_ParenthesizedExpression
@ CCC_ParenthesizedExpression
Code completion in a parenthesized expression, which means that we may also have types here in C and ...
Definition: CodeCompleteConsumer.h:313
clang::FileManager::getFile
llvm::ErrorOr< const FileEntry * > getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
Definition: FileManager.cpp:196
clang::CodeCompletionContext::CCC_SelectorName
@ CCC_SelectorName
Code completion for a selector, as in an @selector expression.
Definition: CodeCompleteConsumer.h:306
clang::Diagnostic::hasSourceManager
bool hasSourceManager() const
Definition: Diagnostic.h:1544
clang::TU_Complete
@ TU_Complete
The translation unit is a complete translation unit.
Definition: LangOptions.h:655
CompilerInstance.h
clang::serialization::MK_MainFile
@ MK_MainFile
File is a PCH file treated as the actual main file.
Definition: ModuleFile.h:55
clang::PreprocessorOptions::clearRemappedFiles
void clearRemappedFiles()
Definition: PreprocessorOptions.h:233
clang::CompilerInstance::getASTReader
IntrusiveRefCntPtr< ASTReader > getASTReader() const
Definition: CompilerInstance.cpp:190
clang::LangOptions::CommentOpts
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:321
clang::ASTUnit::getPCHFile
const FileEntry * getPCHFile()
Get the PCH file if one was included.
Definition: ASTUnit.cpp:2633
clang::FixItHint::RemoveRange
CharSourceRange RemoveRange
Code that should be replaced to correct the error.
Definition: Diagnostic.h:74
clang::HeaderSearchOptions::ResourceDir
std::string ResourceDir
The directory which holds the compiler resource files (builtin includes, etc.).
Definition: HeaderSearchOptions.h:109
clang::ExternalASTSource::GetExternalDecl
virtual Decl * GetExternalDecl(uint32_t ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
Definition: ExternalASTSource.cpp:71
clang::TargetOptions
Options for controlling the target.
Definition: TargetOptions.h:26
clang::serialization::ModuleFile::FileName
std::string FileName
The file name of the module file.
Definition: ModuleFile.h:125
clang::ASTUnit::findFileRegionDecls
void findFileRegionDecls(FileID File, unsigned Offset, unsigned Length, SmallVectorImpl< Decl * > &Decls)
Get the decls that are contained in a file in the Offset/Length range.
Definition: ASTUnit.cpp:2453
clang::ASTFrontendAction
Abstract base class to use for AST consumer-based frontend actions.
Definition: FrontendAction.h:243
llvm::SmallVectorImpl
Definition: LLVM.h:36
clang::CodeCompletionContext
The context in which code completion occurred, so that the code-completion consumer can process the r...
Definition: CodeCompleteConsumer.h:187
FileManager.h
clang::CodeCompleteOptions::LoadExternal
unsigned LoadExternal
Hint whether to load data from the external AST to provide full results.
Definition: CodeCompleteOptions.h:40
CalculateHiddenNames
static void CalculateHiddenNames(const CodeCompletionContext &Context, CodeCompletionResult *Results, unsigned NumResults, ASTContext &Ctx, llvm::StringSet< llvm::BumpPtrAllocator > &HiddenNames)
Helper function that computes which global names are hidden by the local code-completion results.
Definition: ASTUnit.cpp:1960
clang::ComputePreambleBounds
PreambleBounds ComputePreambleBounds(const LangOptions &LangOpts, const llvm::MemoryBufferRef &Buffer, unsigned MaxLines)
Runs lexer to compute suggested preamble bounds.
Definition: PrecompiledPreamble.cpp:305
clang::ASTUnit::isMainFileAST
bool isMainFileAST() const
Definition: ASTUnit.h:424
clang::PreprocessorOptions::addRemappedFile
void addRemappedFile(StringRef From, StringRef To)
Definition: PreprocessorOptions.h:225
PreprocessorOptions.h
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:129
clang::CompilerInstance::setSourceManager
void setSourceManager(SourceManager *Value)
setSourceManager - Replace the current source manager.
Definition: CompilerInstance.cpp:156
SM
#define SM(sm)
Definition: Cuda.cpp:68
clang::CompilerInstance::takeSema
std::unique_ptr< Sema > takeSema()
Definition: CompilerInstance.cpp:186
clang::ASTUnit::getDeserializationListener
ASTDeserializationListener * getDeserializationListener()
Definition: ASTUnit.cpp:729
Token.h
clang::ExternalASTSource
Abstract interface for external sources of AST nodes.
Definition: ExternalASTSource.h:62
clang::ASTUnit::getCurrentTopLevelHashValue
unsigned & getCurrentTopLevelHashValue()
Retrieve a reference to the current top-level name hash value.
Definition: ASTUnit.h:543
clang::ASTContext::InitBuiltinTypes
void InitBuiltinTypes(const TargetInfo &Target, const TargetInfo *AuxTarget=nullptr)
Initialize built-in types.
Definition: ASTContext.cpp:1256
clang::DiagnosticsEngine::Warning
@ Warning
Definition: Diagnostic.h:198
CommentCommandTraits.h
clang::SourceManager::translateFile
FileID translateFile(const FileEntry *SourceFile) const
Get the FileID for the given file.
Definition: SourceManager.cpp:1608
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:430
clang::PrecompiledPreamble::Build
static llvm::ErrorOr< PrecompiledPreamble > Build(const CompilerInvocation &Invocation, const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds, DiagnosticsEngine &Diagnostics, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, std::shared_ptr< PCHContainerOperations > PCHContainerOps, bool StoreInMemory, PreambleCallbacks &Callbacks)
Try to build PrecompiledPreamble for Invocation.
Definition: PrecompiledPreamble.cpp:311
clang::Decl::IDNS_Tag
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition: DeclBase.h:128
clang::DiagnosticsEngine::setNumWarnings
void setNumWarnings(unsigned NumWarnings)
Definition: Diagnostic.h:850
clang::CodeCompletionContext::CCC_UnionTag
@ CCC_UnionTag
Code completion occurred after the "union" keyword, to indicate a union name.
Definition: CodeCompleteConsumer.h:257
clang::SourceManager::isWrittenInMainFile
bool isWrittenInMainFile(SourceLocation Loc) const
Returns true if the spelling location for the given location is in the main file buffer.
Definition: SourceManager.h:1462
clang::serialization::ModuleFile
Information about a module that has been loaded by the ASTReader.
Definition: ModuleFile.h:110
clang::FrontendOptions::CodeCompletionAt
ParsedSourceLocation CodeCompletionAt
If given, enable code completion at the provided location.
Definition: FrontendOptions.h:398
clang::CompilerInstance::hasInvocation
bool hasInvocation() const
Definition: CompilerInstance.h:226
clang::PreprocessorOptions::RetainExcludedConditionalBlocks
bool RetainExcludedConditionalBlocks
When enabled, excluded conditional blocks retain in the main file.
Definition: PreprocessorOptions.h:169
clang::CodeCompletionContext::CCC_MacroName
@ CCC_MacroName
Code completion occurred where an macro is being defined.
Definition: CodeCompleteConsumer.h:285
clang::ASTContext::getLangOpts
const LangOptions & getLangOpts() const
Definition: ASTContext.h:688
clang::ASTUnit::isModuleFile
bool isModuleFile() const
Returns true if the ASTUnit was constructed from a serialized module file.
Definition: ASTUnit.cpp:2661
clang::CompilerInvocationBase::getDiagnosticOpts
DiagnosticOptions & getDiagnosticOpts() const
Definition: CompilerInvocation.h:92
llvm::IntrusiveRefCntPtr
Definition: LLVM.h:44
clang::CodeCompletionContext::CCC_ObjCClassMessage
@ CCC_ObjCClassMessage
Code completion where an Objective-C class message is expected.
Definition: CodeCompleteConsumer.h:320
clang::CodeCompletionTUInfo
Definition: CodeCompleteConsumer.h:645
clang::SourceLocation::getLocWithOffset
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
Definition: SourceLocation.h:136
clang::CodeCompletionContext::CCC_ObjCInterface
@ CCC_ObjCInterface
Code completion occurred within an Objective-C interface, protocol, or category interface.
Definition: CodeCompleteConsumer.h:203
clang::CodeCompletionContext::CCC_ClassOrStructTag
@ CCC_ClassOrStructTag
Code completion occurred after the "struct" or "class" keyword, to indicate a struct or class name.
Definition: CodeCompleteConsumer.h:261
clang::OpenCL
@ OpenCL
clang::Preprocessor::Initialize
void Initialize(const TargetInfo &Target, const TargetInfo *AuxTarget=nullptr)
Initialize the preprocessor using information about the target.
Definition: Preprocessor.cpp:195
clang::CodeCompletionContext::CCC_TypeQualifiers
@ CCC_TypeQualifiers
Code completion within a type-qualifier list.
Definition: CodeCompleteConsumer.h:309
clang::HeaderSearchOptions
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
Definition: HeaderSearchOptions.h:67
clang::SkipFunctionBodiesScope::Preamble
@ Preamble
clang::BuildPreambleError::CouldntCreateTempFile
@ CouldntCreateTempFile
clang::PreprocessorOptions::RemappedFilesKeepOriginalName
bool RemappedFilesKeepOriginalName
True if the SourceManager should report the original file name for contents of files that were remapp...
Definition: PreprocessorOptions.h:147
clang::CompilerInstance::hasASTContext
bool hasASTContext() const
Definition: CompilerInstance.h:459
clang::serialization::ModuleFile::Kind
ModuleKind Kind
The type of this module.
Definition: ModuleFile.h:122
clang::CodeCompletionContext::CCC_MacroNameUse
@ CCC_MacroNameUse
Code completion occurred where a macro name is expected (without any arguments, in the case of a func...
Definition: CodeCompleteConsumer.h:289
clang::CompilerInvocationBase::LangOpts
std::shared_ptr< LangOptions > LangOpts
Options controlling the language variant.
Definition: CompilerInvocation.h:67
clang::ASTUnit::LoadFromCommandLine
static ASTUnit * LoadFromCommandLine(const char **ArgBegin, const char **ArgEnd, std::shared_ptr< PCHContainerOperations > PCHContainerOps, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, StringRef ResourceFilesPath, bool OnlyLocalDecls=false, CaptureDiagsKind CaptureDiagnostics=CaptureDiagsKind::None, ArrayRef< RemappedFile > RemappedFiles=None, bool RemappedFilesKeepOriginalName=true, unsigned PrecompilePreambleAfterNParses=0, TranslationUnitKind TUKind=TU_Complete, bool CacheCodeCompletionResults=false, bool IncludeBriefCommentsInCodeCompletion=false, bool AllowPCHWithCompilerErrors=false, SkipFunctionBodiesScope SkipFunctionBodies=SkipFunctionBodiesScope::None, bool SingleFileParse=false, bool UserFilesAreVolatile=false, bool ForSerialization=false, bool RetainExcludedConditionalBlocks=false, llvm::Optional< StringRef > ModuleFormat=llvm::None, std::unique_ptr< ASTUnit > *ErrAST=nullptr, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS=nullptr)
LoadFromCommandLine - Create an ASTUnit from a vector of command line arguments, which must specify e...
Definition: ASTUnit.cpp:1726
clang::Decl::getDeclContext
DeclContext * getDeclContext()
Definition: DeclBase.h:439
clang::SkipFunctionBodiesScope::PreambleAndMainFile
@ PreambleAndMainFile
clang::ASTReader::Missing
@ Missing
The AST file was missing.
Definition: ASTReader.h:376
clang::Preprocessor::getPreprocessingRecord
PreprocessingRecord * getPreprocessingRecord() const
Retrieve the preprocessing record, or NULL if there is no preprocessing record.
Definition: Preprocessor.h:1286
MultiplexConsumer.h