clang  3.7.0
ASTUnit.h
Go to the documentation of this file.
1 //===--- ASTUnit.h - ASTUnit utility ----------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // ASTUnit utility class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_FRONTEND_ASTUNIT_H
15 #define LLVM_CLANG_FRONTEND_ASTUNIT_H
16 
17 #include "clang-c/Index.h"
18 #include "clang/AST/ASTContext.h"
25 #include "clang/Lex/ModuleLoader.h"
29 #include "llvm/ADT/IntrusiveRefCntPtr.h"
30 #include "llvm/ADT/SmallVector.h"
31 #include "llvm/ADT/StringMap.h"
32 #include "llvm/Support/MD5.h"
33 #include "llvm/Support/Path.h"
34 #include <cassert>
35 #include <map>
36 #include <memory>
37 #include <string>
38 #include <sys/types.h>
39 #include <utility>
40 #include <vector>
41 
42 namespace llvm {
43  class MemoryBuffer;
44 }
45 
46 namespace clang {
47 class Sema;
48 class ASTContext;
49 class ASTReader;
50 class CodeCompleteConsumer;
51 class CompilerInvocation;
52 class CompilerInstance;
53 class Decl;
54 class DiagnosticsEngine;
55 class FileEntry;
56 class FileManager;
57 class HeaderSearch;
58 class Preprocessor;
59 class PCHContainerOperations;
60 class PCHContainerReader;
61 class SourceManager;
62 class TargetInfo;
63 class ASTFrontendAction;
64 class ASTDeserializationListener;
65 
66 /// \brief Utility class for loading a ASTContext from an AST file.
67 ///
68 class ASTUnit : public ModuleLoader {
69 public:
70  struct StandaloneFixIt {
71  std::pair<unsigned, unsigned> RemoveRange;
72  std::pair<unsigned, unsigned> InsertFromRange;
73  std::string CodeToInsert;
75  };
76 
78  unsigned ID;
80  std::string Message;
81  std::string Filename;
82  unsigned LocOffset;
83  std::vector<std::pair<unsigned, unsigned> > Ranges;
84  std::vector<StandaloneFixIt> FixIts;
85  };
86 
87 private:
88  std::shared_ptr<LangOptions> LangOpts;
92  std::unique_ptr<HeaderSearch> HeaderInfo;
96  std::shared_ptr<TargetOptions> TargetOpts;
99  bool HadModuleLoaderFatalFailure;
100 
101  struct ASTWriterData;
102  std::unique_ptr<ASTWriterData> WriterData;
103 
104  FileSystemOptions FileSystemOpts;
105 
106  /// \brief The AST consumer that received information about the translation
107  /// unit as it was parsed or loaded.
108  std::unique_ptr<ASTConsumer> Consumer;
109 
110  /// \brief The semantic analysis object used to type-check the translation
111  /// unit.
112  std::unique_ptr<Sema> TheSema;
113 
114  /// Optional owned invocation, just used to make the invocation used in
115  /// LoadFromCommandLine available.
117 
118  // OnlyLocalDecls - when true, walking this AST should only visit declarations
119  // that come from the AST itself, not from included precompiled headers.
120  // FIXME: This is temporary; eventually, CIndex will always do this.
121  bool OnlyLocalDecls;
122 
123  /// \brief Whether to capture any diagnostics produced.
124  bool CaptureDiagnostics;
125 
126  /// \brief Track whether the main file was loaded from an AST or not.
127  bool MainFileIsAST;
128 
129  /// \brief What kind of translation unit this AST represents.
130  TranslationUnitKind TUKind;
131 
132  /// \brief Whether we should time each operation.
133  bool WantTiming;
134 
135  /// \brief Whether the ASTUnit should delete the remapped buffers.
136  bool OwnsRemappedFileBuffers;
137 
138  /// Track the top-level decls which appeared in an ASTUnit which was loaded
139  /// from a source file.
140  //
141  // FIXME: This is just an optimization hack to avoid deserializing large parts
142  // of a PCH file when using the Index library on an ASTUnit loaded from
143  // source. In the long term we should make the Index library use efficient and
144  // more scalable search mechanisms.
145  std::vector<Decl*> TopLevelDecls;
146 
147  /// \brief Sorted (by file offset) vector of pairs of file offset/Decl.
149  typedef llvm::DenseMap<FileID, LocDeclsTy *> FileDeclsTy;
150 
151  /// \brief Map from FileID to the file-level declarations that it contains.
152  /// The files and decls are only local (and non-preamble) ones.
153  FileDeclsTy FileDecls;
154 
155  /// The name of the original source file used to generate this ASTUnit.
156  std::string OriginalSourceFile;
157 
158  /// \brief The set of diagnostics produced when creating the preamble.
159  SmallVector<StandaloneDiagnostic, 4> PreambleDiagnostics;
160 
161  /// \brief The set of diagnostics produced when creating this
162  /// translation unit.
163  SmallVector<StoredDiagnostic, 4> StoredDiagnostics;
164 
165  /// \brief The set of diagnostics produced when failing to parse, e.g. due
166  /// to failure to load the PCH.
167  SmallVector<StoredDiagnostic, 4> FailedParseDiagnostics;
168 
169  /// \brief The number of stored diagnostics that come from the driver
170  /// itself.
171  ///
172  /// Diagnostics that come from the driver are retained from one parse to
173  /// the next.
174  unsigned NumStoredDiagnosticsFromDriver;
175 
176  /// \brief Counter that determines when we want to try building a
177  /// precompiled preamble.
178  ///
179  /// If zero, we will never build a precompiled preamble. Otherwise,
180  /// it's treated as a counter that decrements each time we reparse
181  /// without the benefit of a precompiled preamble. When it hits 1,
182  /// we'll attempt to rebuild the precompiled header. This way, if
183  /// building the precompiled preamble fails, we won't try again for
184  /// some number of calls.
185  unsigned PreambleRebuildCounter;
186 
187 public:
188  class PreambleData {
189  const FileEntry *File;
190  std::vector<char> Buffer;
191  mutable unsigned NumLines;
192 
193  public:
194  PreambleData() : File(nullptr), NumLines(0) { }
195 
196  void assign(const FileEntry *F, const char *begin, const char *end) {
197  File = F;
198  Buffer.assign(begin, end);
199  NumLines = 0;
200  }
201 
202  void clear() { Buffer.clear(); File = nullptr; NumLines = 0; }
203 
204  size_t size() const { return Buffer.size(); }
205  bool empty() const { return Buffer.empty(); }
206 
207  const char *getBufferStart() const { return &Buffer[0]; }
208 
209  unsigned getNumLines() const {
210  if (NumLines)
211  return NumLines;
212  countLines();
213  return NumLines;
214  }
215 
218  return SourceRange(FileLoc, FileLoc.getLocWithOffset(size()-1));
219  }
220 
221  private:
222  void countLines() const;
223  };
224 
225  const PreambleData &getPreambleData() const {
226  return Preamble;
227  }
228 
229  /// Data used to determine if a file used in the preamble has been changed.
231  /// All files have size set.
232  off_t Size;
233 
234  /// Modification time is set for files that are on disk. For memory
235  /// buffers it is zero.
236  time_t ModTime;
237 
238  /// Memory buffers have MD5 instead of modification time. We don't
239  /// compute MD5 for on-disk files because we hope that modification time is
240  /// enough to tell if the file was changed.
241  llvm::MD5::MD5Result MD5;
242 
243  static PreambleFileHash createForFile(off_t Size, time_t ModTime);
244  static PreambleFileHash
245  createForMemoryBuffer(const llvm::MemoryBuffer *Buffer);
246 
247  friend bool operator==(const PreambleFileHash &LHS,
248  const PreambleFileHash &RHS);
249 
250  friend bool operator!=(const PreambleFileHash &LHS,
251  const PreambleFileHash &RHS) {
252  return !(LHS == RHS);
253  }
254  };
255 
256 private:
257  /// \brief The contents of the preamble that has been precompiled to
258  /// \c PreambleFile.
259  PreambleData Preamble;
260 
261  /// \brief Whether the preamble ends at the start of a new line.
262  ///
263  /// Used to inform the lexer as to whether it's starting at the beginning of
264  /// a line after skipping the preamble.
265  bool PreambleEndsAtStartOfLine;
266 
267  /// \brief Keeps track of the files that were used when computing the
268  /// preamble, with both their buffer size and their modification time.
269  ///
270  /// If any of the files have changed from one compile to the next,
271  /// the preamble must be thrown away.
272  llvm::StringMap<PreambleFileHash> FilesInPreamble;
273 
274  /// \brief When non-NULL, this is the buffer used to store the contents of
275  /// the main file when it has been padded for use with the precompiled
276  /// preamble.
277  std::unique_ptr<llvm::MemoryBuffer> SavedMainFileBuffer;
278 
279  /// \brief When non-NULL, this is the buffer used to store the
280  /// contents of the preamble when it has been padded to build the
281  /// precompiled preamble.
282  std::unique_ptr<llvm::MemoryBuffer> PreambleBuffer;
283 
284  /// \brief The number of warnings that occurred while parsing the preamble.
285  ///
286  /// This value will be used to restore the state of the \c DiagnosticsEngine
287  /// object when re-using the precompiled preamble. Note that only the
288  /// number of warnings matters, since we will not save the preamble
289  /// when any errors are present.
290  unsigned NumWarningsInPreamble;
291 
292  /// \brief A list of the serialization ID numbers for each of the top-level
293  /// declarations parsed within the precompiled preamble.
294  std::vector<serialization::DeclID> TopLevelDeclsInPreamble;
295 
296  /// \brief Whether we should be caching code-completion results.
297  bool ShouldCacheCodeCompletionResults : 1;
298 
299  /// \brief Whether to include brief documentation within the set of code
300  /// completions cached.
301  bool IncludeBriefCommentsInCodeCompletion : 1;
302 
303  /// \brief True if non-system source files should be treated as volatile
304  /// (likely to change while trying to use them).
305  bool UserFilesAreVolatile : 1;
306 
307  /// \brief The language options used when we load an AST file.
308  LangOptions ASTFileLangOpts;
309 
310  static void ConfigureDiags(IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
311  ASTUnit &AST, bool CaptureDiagnostics);
312 
313  void TranslateStoredDiagnostics(FileManager &FileMgr,
314  SourceManager &SrcMan,
317 
318  void clearFileLevelDecls();
319 
320 public:
321  /// \brief A cached code-completion result, which may be introduced in one of
322  /// many different contexts.
324  /// \brief The code-completion string corresponding to this completion
325  /// result.
327 
328  /// \brief A bitmask that indicates which code-completion contexts should
329  /// contain this completion result.
330  ///
331  /// The bits in the bitmask correspond to the values of
332  /// CodeCompleteContext::Kind. To map from a completion context kind to a
333  /// bit, shift 1 by that number of bits. Many completions can occur in
334  /// several different contexts.
335  uint64_t ShowInContexts;
336 
337  /// \brief The priority given to this code-completion result.
338  unsigned Priority;
339 
340  /// \brief The libclang cursor kind corresponding to this code-completion
341  /// result.
343 
344  /// \brief The availability of this code-completion result.
346 
347  /// \brief The simplified type class for a non-macro completion result.
349 
350  /// \brief The type of a non-macro completion result, stored as a unique
351  /// integer used by the string map of cached completion types.
352  ///
353  /// This value will be zero if the type is not known, or a unique value
354  /// determined by the formatted type string. Se \c CachedCompletionTypes
355  /// for more information.
356  unsigned Type;
357  };
358 
359  /// \brief Retrieve the mapping from formatted type names to unique type
360  /// identifiers.
361  llvm::StringMap<unsigned> &getCachedCompletionTypes() {
362  return CachedCompletionTypes;
363  }
364 
365  /// \brief Retrieve the allocator used to cache global code completions.
368  return CachedCompletionAllocator;
369  }
370 
372  if (!CCTUInfo)
373  CCTUInfo.reset(new CodeCompletionTUInfo(
375  return *CCTUInfo;
376  }
377 
378 private:
379  /// \brief Allocator used to store cached code completions.
381  CachedCompletionAllocator;
382 
383  std::unique_ptr<CodeCompletionTUInfo> CCTUInfo;
384 
385  /// \brief The set of cached code-completion results.
386  std::vector<CachedCodeCompletionResult> CachedCompletionResults;
387 
388  /// \brief A mapping from the formatted type name to a unique number for that
389  /// type, which is used for type equality comparisons.
390  llvm::StringMap<unsigned> CachedCompletionTypes;
391 
392  /// \brief A string hash of the top-level declaration and macro definition
393  /// names processed the last time that we reparsed the file.
394  ///
395  /// This hash value is used to determine when we need to refresh the
396  /// global code-completion cache.
397  unsigned CompletionCacheTopLevelHashValue;
398 
399  /// \brief A string hash of the top-level declaration and macro definition
400  /// names processed the last time that we reparsed the precompiled preamble.
401  ///
402  /// This hash value is used to determine when we need to refresh the
403  /// global code-completion cache after a rebuild of the precompiled preamble.
404  unsigned PreambleTopLevelHashValue;
405 
406  /// \brief The current hash value for the top-level declaration and macro
407  /// definition names
408  unsigned CurrentTopLevelHashValue;
409 
410  /// \brief Bit used by CIndex to mark when a translation unit may be in an
411  /// inconsistent state, and is not safe to free.
412  unsigned UnsafeToFree : 1;
413 
414  /// \brief Cache any "global" code-completion results, so that we can avoid
415  /// recomputing them with each completion.
416  void CacheCodeCompletionResults();
417 
418  /// \brief Clear out and deallocate
419  void ClearCachedCompletionResults();
420 
421  ASTUnit(const ASTUnit &) = delete;
422  void operator=(const ASTUnit &) = delete;
423 
424  explicit ASTUnit(bool MainFileIsAST);
425 
426  void CleanTemporaryFiles();
427  bool Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
428  std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer);
429 
430  struct ComputedPreamble {
431  llvm::MemoryBuffer *Buffer;
432  std::unique_ptr<llvm::MemoryBuffer> Owner;
433  unsigned Size;
434  bool PreambleEndsAtStartOfLine;
435  ComputedPreamble(llvm::MemoryBuffer *Buffer,
436  std::unique_ptr<llvm::MemoryBuffer> Owner, unsigned Size,
437  bool PreambleEndsAtStartOfLine)
438  : Buffer(Buffer), Owner(std::move(Owner)), Size(Size),
439  PreambleEndsAtStartOfLine(PreambleEndsAtStartOfLine) {}
440  ComputedPreamble(ComputedPreamble &&C)
441  : Buffer(C.Buffer), Owner(std::move(C.Owner)), Size(C.Size),
442  PreambleEndsAtStartOfLine(C.PreambleEndsAtStartOfLine) {}
443  };
444  ComputedPreamble ComputePreamble(CompilerInvocation &Invocation,
445  unsigned MaxLines);
446 
447  std::unique_ptr<llvm::MemoryBuffer> getMainBufferWithPrecompiledPreamble(
448  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
449  const CompilerInvocation &PreambleInvocationIn, bool AllowRebuild = true,
450  unsigned MaxLines = 0);
451  void RealizeTopLevelDeclsFromPreamble();
452 
453  /// \brief Transfers ownership of the objects (like SourceManager) from
454  /// \param CI to this ASTUnit.
455  void transferASTDataFromCompilerInstance(CompilerInstance &CI);
456 
457  /// \brief Allows us to assert that ASTUnit is not being used concurrently,
458  /// which is not supported.
459  ///
460  /// Clients should create instances of the ConcurrencyCheck class whenever
461  /// using the ASTUnit in a way that isn't intended to be concurrent, which is
462  /// just about any usage.
463  /// Becomes a noop in release mode; only useful for debug mode checking.
464  class ConcurrencyState {
465  void *Mutex; // a llvm::sys::MutexImpl in debug;
466 
467  public:
468  ConcurrencyState();
469  ~ConcurrencyState();
470 
471  void start();
472  void finish();
473  };
474  ConcurrencyState ConcurrencyCheckValue;
475 
476 public:
478  ASTUnit &Self;
479 
480  public:
481  explicit ConcurrencyCheck(ASTUnit &Self)
482  : Self(Self)
483  {
484  Self.ConcurrencyCheckValue.start();
485  }
487  Self.ConcurrencyCheckValue.finish();
488  }
489  };
490  friend class ConcurrencyCheck;
491 
492  ~ASTUnit() override;
493 
494  bool isMainFileAST() const { return MainFileIsAST; }
495 
496  bool isUnsafeToFree() const { return UnsafeToFree; }
497  void setUnsafeToFree(bool Value) { UnsafeToFree = Value; }
498 
499  const DiagnosticsEngine &getDiagnostics() const { return *Diagnostics; }
500  DiagnosticsEngine &getDiagnostics() { return *Diagnostics; }
501 
502  const SourceManager &getSourceManager() const { return *SourceMgr; }
504 
505  const Preprocessor &getPreprocessor() const { return *PP; }
506  Preprocessor &getPreprocessor() { return *PP; }
507 
508  const ASTContext &getASTContext() const { return *Ctx; }
509  ASTContext &getASTContext() { return *Ctx; }
510 
511  void setASTContext(ASTContext *ctx) { Ctx = ctx; }
512  void setPreprocessor(Preprocessor *pp);
513 
514  bool hasSema() const { return (bool)TheSema; }
515  Sema &getSema() const {
516  assert(TheSema && "ASTUnit does not have a Sema object!");
517  return *TheSema;
518  }
519 
520  const LangOptions &getLangOpts() const {
521  assert(LangOpts && " ASTUnit does not have language options");
522  return *LangOpts;
523  }
524 
525  const FileManager &getFileManager() const { return *FileMgr; }
526  FileManager &getFileManager() { return *FileMgr; }
527 
528  const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; }
529 
531  return OriginalSourceFile;
532  }
533 
536 
537  /// \brief Add a temporary file that the ASTUnit depends on.
538  ///
539  /// This file will be erased when the ASTUnit is destroyed.
540  void addTemporaryFile(StringRef TempFile);
541 
542  bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
543 
544  bool getOwnsRemappedFileBuffers() const { return OwnsRemappedFileBuffers; }
545  void setOwnsRemappedFileBuffers(bool val) { OwnsRemappedFileBuffers = val; }
546 
547  StringRef getMainFileName() const;
548 
549  /// \brief If this ASTUnit came from an AST file, returns the filename for it.
550  StringRef getASTFileName() const;
551 
552  typedef std::vector<Decl *>::iterator top_level_iterator;
553 
555  assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
556  if (!TopLevelDeclsInPreamble.empty())
557  RealizeTopLevelDeclsFromPreamble();
558  return TopLevelDecls.begin();
559  }
560 
562  assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
563  if (!TopLevelDeclsInPreamble.empty())
564  RealizeTopLevelDeclsFromPreamble();
565  return TopLevelDecls.end();
566  }
567 
569  assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
570  return TopLevelDeclsInPreamble.size() + TopLevelDecls.size();
571  }
572 
573  bool top_level_empty() const {
574  assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
575  return TopLevelDeclsInPreamble.empty() && TopLevelDecls.empty();
576  }
577 
578  /// \brief Add a new top-level declaration.
580  TopLevelDecls.push_back(D);
581  }
582 
583  /// \brief Add a new local file-level declaration.
584  void addFileLevelDecl(Decl *D);
585 
586  /// \brief Get the decls that are contained in a file in the Offset/Length
587  /// range. \p Length can be 0 to indicate a point at \p Offset instead of
588  /// a range.
589  void findFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
590  SmallVectorImpl<Decl *> &Decls);
591 
592  /// \brief Add a new top-level declaration, identified by its ID in
593  /// the precompiled preamble.
595  TopLevelDeclsInPreamble.push_back(D);
596  }
597 
598  /// \brief Retrieve a reference to the current top-level name hash value.
599  ///
600  /// Note: This is used internally by the top-level tracking action
601  unsigned &getCurrentTopLevelHashValue() { return CurrentTopLevelHashValue; }
602 
603  /// \brief Get the source location for the given file:line:col triplet.
604  ///
605  /// The difference with SourceManager::getLocation is that this method checks
606  /// whether the requested location points inside the precompiled preamble
607  /// in which case the returned source location will be a "loaded" one.
609  unsigned Line, unsigned Col) const;
610 
611  /// \brief Get the source location for the given file:offset pair.
612  SourceLocation getLocation(const FileEntry *File, unsigned Offset) const;
613 
614  /// \brief If \p Loc is a loaded location from the preamble, returns
615  /// the corresponding local location of the main file, otherwise it returns
616  /// \p Loc.
618 
619  /// \brief If \p Loc is a local location of the main file but inside the
620  /// preamble chunk, returns the corresponding loaded location from the
621  /// preamble, otherwise it returns \p Loc.
623 
625  bool isInMainFileID(SourceLocation Loc);
628 
629  /// \see mapLocationFromPreamble.
633  }
634 
635  /// \see mapLocationToPreamble.
639  }
640 
641  // Retrieve the diagnostics associated with this AST
645  return StoredDiagnostics.begin();
646  }
648  return StoredDiagnostics.begin();
649  }
651  return StoredDiagnostics.end();
652  }
654  return StoredDiagnostics.end();
655  }
656  unsigned stored_diag_size() const { return StoredDiagnostics.size(); }
657 
659  if (NumStoredDiagnosticsFromDriver > StoredDiagnostics.size())
660  NumStoredDiagnosticsFromDriver = 0;
661  return StoredDiagnostics.begin() + NumStoredDiagnosticsFromDriver;
662  }
663 
664  typedef std::vector<CachedCodeCompletionResult>::iterator
666 
668  return CachedCompletionResults.begin();
669  }
670 
672  return CachedCompletionResults.end();
673  }
674 
675  unsigned cached_completion_size() const {
676  return CachedCompletionResults.size();
677  }
678 
679  /// \brief Returns an iterator range for the local preprocessing entities
680  /// of the local Preprocessor, if this is a parsed source file, or the loaded
681  /// preprocessing entities of the primary module if this is an AST file.
682  llvm::iterator_range<PreprocessingRecord::iterator>
684 
685  /// \brief Type for a function iterating over a number of declarations.
686  /// \returns true to continue iteration and false to abort.
687  typedef bool (*DeclVisitorFn)(void *context, const Decl *D);
688 
689  /// \brief Iterate over local declarations (locally parsed if this is a parsed
690  /// source file or the loaded declarations of the primary module if this is an
691  /// AST file).
692  /// \returns true if the iteration was complete or false if it was aborted.
693  bool visitLocalTopLevelDecls(void *context, DeclVisitorFn Fn);
694 
695  /// \brief Get the PCH file if one was included.
696  const FileEntry *getPCHFile();
697 
698  /// \brief Returns true if the ASTUnit was constructed from a serialized
699  /// module file.
700  bool isModuleFile();
701 
702  std::unique_ptr<llvm::MemoryBuffer>
703  getBufferForFile(StringRef Filename, std::string *ErrorStr = nullptr);
704 
705  /// \brief Determine what kind of translation unit this AST represents.
706  TranslationUnitKind getTranslationUnitKind() const { return TUKind; }
707 
708  /// \brief A mapping from a file name to the memory buffer that stores the
709  /// remapped contents of that file.
710  typedef std::pair<std::string, llvm::MemoryBuffer *> RemappedFile;
711 
712  /// \brief Create a ASTUnit. Gets ownership of the passed CompilerInvocation.
713  static ASTUnit *create(CompilerInvocation *CI,
715  bool CaptureDiagnostics,
716  bool UserFilesAreVolatile);
717 
718  /// \brief Create a ASTUnit from an AST file.
719  ///
720  /// \param Filename - The AST file to load.
721  ///
722  /// \param PCHContainerOps - The PCHContainerOperations to use for loading and
723  /// creating modules.
724  /// \param Diags - The diagnostics engine to use for reporting errors; its
725  /// lifetime is expected to extend past that of the returned ASTUnit.
726  ///
727  /// \returns - The initialized ASTUnit or null if the AST failed to load.
728  static std::unique_ptr<ASTUnit> LoadFromASTFile(
729  const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
731  const FileSystemOptions &FileSystemOpts, bool OnlyLocalDecls = false,
732  ArrayRef<RemappedFile> RemappedFiles = None,
733  bool CaptureDiagnostics = false, bool AllowPCHWithCompilerErrors = false,
734  bool UserFilesAreVolatile = false);
735 
736 private:
737  /// \brief Helper function for \c LoadFromCompilerInvocation() and
738  /// \c LoadFromCommandLine(), which loads an AST from a compiler invocation.
739  ///
740  /// \param PrecompilePreamble Whether to precompile the preamble of this
741  /// translation unit, to improve the performance of reparsing.
742  ///
743  /// \returns \c true if a catastrophic failure occurred (which means that the
744  /// \c ASTUnit itself is invalid), or \c false otherwise.
745  bool LoadFromCompilerInvocation(
746  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
747  bool PrecompilePreamble);
748 
749 public:
750 
751  /// \brief Create an ASTUnit from a source file, via a CompilerInvocation
752  /// object, by invoking the optionally provided ASTFrontendAction.
753  ///
754  /// \param CI - The compiler invocation to use; it must have exactly one input
755  /// source file. The ASTUnit takes ownership of the CompilerInvocation object.
756  ///
757  /// \param PCHContainerOps - The PCHContainerOperations to use for loading and
758  /// creating modules.
759  ///
760  /// \param Diags - The diagnostics engine to use for reporting errors; its
761  /// lifetime is expected to extend past that of the returned ASTUnit.
762  ///
763  /// \param Action - The ASTFrontendAction to invoke. Its ownership is not
764  /// transferred.
765  ///
766  /// \param Unit - optionally an already created ASTUnit. Its ownership is not
767  /// transferred.
768  ///
769  /// \param Persistent - if true the returned ASTUnit will be complete.
770  /// false means the caller is only interested in getting info through the
771  /// provided \see Action.
772  ///
773  /// \param ErrAST - If non-null and parsing failed without any AST to return
774  /// (e.g. because the PCH could not be loaded), this accepts the ASTUnit
775  /// mainly to allow the caller to see the diagnostics.
776  /// This will only receive an ASTUnit if a new one was created. If an already
777  /// created ASTUnit was passed in \p Unit then the caller can check that.
778  ///
780  CompilerInvocation *CI,
781  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
783  ASTFrontendAction *Action = nullptr, ASTUnit *Unit = nullptr,
784  bool Persistent = true, StringRef ResourceFilesPath = StringRef(),
785  bool OnlyLocalDecls = false, bool CaptureDiagnostics = false,
786  bool PrecompilePreamble = false, bool CacheCodeCompletionResults = false,
787  bool IncludeBriefCommentsInCodeCompletion = false,
788  bool UserFilesAreVolatile = false,
789  std::unique_ptr<ASTUnit> *ErrAST = nullptr);
790 
791  /// LoadFromCompilerInvocation - Create an ASTUnit from a source file, via a
792  /// CompilerInvocation object.
793  ///
794  /// \param CI - The compiler invocation to use; it must have exactly one input
795  /// source file. The ASTUnit takes ownership of the CompilerInvocation object.
796  ///
797  /// \param PCHContainerOps - The PCHContainerOperations to use for loading and
798  /// creating modules.
799  ///
800  /// \param Diags - The diagnostics engine to use for reporting errors; its
801  /// lifetime is expected to extend past that of the returned ASTUnit.
802  //
803  // FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we
804  // shouldn't need to specify them at construction time.
805  static std::unique_ptr<ASTUnit> LoadFromCompilerInvocation(
806  CompilerInvocation *CI,
807  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
808  IntrusiveRefCntPtr<DiagnosticsEngine> Diags, bool OnlyLocalDecls = false,
809  bool CaptureDiagnostics = false, bool PrecompilePreamble = false,
811  bool CacheCodeCompletionResults = false,
812  bool IncludeBriefCommentsInCodeCompletion = false,
813  bool UserFilesAreVolatile = false);
814 
815  /// LoadFromCommandLine - Create an ASTUnit from a vector of command line
816  /// arguments, which must specify exactly one source file.
817  ///
818  /// \param ArgBegin - The beginning of the argument vector.
819  ///
820  /// \param ArgEnd - The end of the argument vector.
821  ///
822  /// \param PCHContainerOps - The PCHContainerOperations to use for loading and
823  /// creating modules.
824  ///
825  /// \param Diags - The diagnostics engine to use for reporting errors; its
826  /// lifetime is expected to extend past that of the returned ASTUnit.
827  ///
828  /// \param ResourceFilesPath - The path to the compiler resource files.
829  ///
830  /// \param ErrAST - If non-null and parsing failed without any AST to return
831  /// (e.g. because the PCH could not be loaded), this accepts the ASTUnit
832  /// mainly to allow the caller to see the diagnostics.
833  ///
834  // FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we
835  // shouldn't need to specify them at construction time.
837  const char **ArgBegin, const char **ArgEnd,
838  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
839  IntrusiveRefCntPtr<DiagnosticsEngine> Diags, StringRef ResourceFilesPath,
840  bool OnlyLocalDecls = false, bool CaptureDiagnostics = false,
841  ArrayRef<RemappedFile> RemappedFiles = None,
842  bool RemappedFilesKeepOriginalName = true,
843  bool PrecompilePreamble = false, TranslationUnitKind TUKind = TU_Complete,
844  bool CacheCodeCompletionResults = false,
845  bool IncludeBriefCommentsInCodeCompletion = false,
846  bool AllowPCHWithCompilerErrors = false, bool SkipFunctionBodies = false,
847  bool UserFilesAreVolatile = false, bool ForSerialization = false,
848  std::unique_ptr<ASTUnit> *ErrAST = nullptr);
849 
850  /// \brief Reparse the source files using the same command-line options that
851  /// were originally used to produce this translation unit.
852  ///
853  /// \returns True if a failure occurred that causes the ASTUnit not to
854  /// contain any translation-unit information, false otherwise.
855  bool Reparse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
856  ArrayRef<RemappedFile> RemappedFiles = None);
857 
858  /// \brief Perform code completion at the given file, line, and
859  /// column within this translation unit.
860  ///
861  /// \param File The file in which code completion will occur.
862  ///
863  /// \param Line The line at which code completion will occur.
864  ///
865  /// \param Column The column at which code completion will occur.
866  ///
867  /// \param IncludeMacros Whether to include macros in the code-completion
868  /// results.
869  ///
870  /// \param IncludeCodePatterns Whether to include code patterns (such as a
871  /// for loop) in the code-completion results.
872  ///
873  /// \param IncludeBriefComments Whether to include brief documentation within
874  /// the set of code completions returned.
875  ///
876  /// FIXME: The Diag, LangOpts, SourceMgr, FileMgr, StoredDiagnostics, and
877  /// OwnedBuffers parameters are all disgusting hacks. They will go away.
878  void CodeComplete(StringRef File, unsigned Line, unsigned Column,
879  ArrayRef<RemappedFile> RemappedFiles, bool IncludeMacros,
880  bool IncludeCodePatterns, bool IncludeBriefComments,
881  CodeCompleteConsumer &Consumer,
882  std::shared_ptr<PCHContainerOperations> PCHContainerOps,
883  DiagnosticsEngine &Diag, LangOptions &LangOpts,
885  SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics,
887 
888  /// \brief Save this translation unit to a file with the given name.
889  ///
890  /// \returns true if there was a file error or false if the save was
891  /// successful.
892  bool Save(StringRef File);
893 
894  /// \brief Serialize this translation unit with the given output stream.
895  ///
896  /// \returns True if an error occurred, false otherwise.
897  bool serialize(raw_ostream &OS);
898 
901  bool IsInclusionDirective) override {
902  // ASTUnit doesn't know how to load modules (not that this matters).
903  return ModuleLoadResult();
904  }
905 
907  SourceLocation ImportLoc) override {}
908 
910  { return nullptr; }
911  bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override
912  { return 0; };
913 };
914 
915 } // namespace clang
916 
917 #endif
stored_diag_iterator stored_diag_afterDriver_begin()
Definition: ASTUnit.h:658
bool hasSema() const
Definition: ASTUnit.h:514
Defines the clang::ASTContext interface.
CXAvailabilityKind
Describes the availability of a particular entity, which indicates whether the use of this entity wil...
Definition: Index.h:125
SourceLocation getEnd() const
StringRef getMainFileName() const
Definition: ASTUnit.cpp:1673
llvm::iterator_range< PreprocessingRecord::iterator > getLocalPreprocessingEntities() const
Returns an iterator range for the local preprocessing entities of the local Preprocessor, if this is a parsed source file, or the loaded preprocessing entities of the primary module if this is an AST file.
Definition: ASTUnit.cpp:2749
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.
bool isInMainFileID(SourceLocation Loc)
Definition: ASTUnit.cpp:2715
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:115
std::pair< unsigned, unsigned > InsertFromRange
Definition: ASTUnit.h:72
void addTopLevelDecl(Decl *D)
Add a new top-level declaration.
Definition: ASTUnit.h:579
Defines the clang::FileManager interface and associated types.
IntrusiveRefCntPtr< GlobalCodeCompletionAllocator > getCachedCompletionAllocator()
Retrieve the allocator used to cache global code completions.
Definition: ASTUnit.h:367
const DiagnosticsEngine & getDiagnostics() const
Definition: ASTUnit.h:499
~ASTUnit() override
Definition: ASTUnit.cpp:233
Sema & getSema() const
Definition: ASTUnit.h:515
CXAvailabilityKind Availability
The availability of this code-completion result.
Definition: ASTUnit.h:345
Defines the SourceManager interface.
SourceLocation getEndOfPreambleFileID()
Definition: ASTUnit.cpp:2726
Represents a diagnostic in a form that can be retained until its corresponding source manager is dest...
Definition: Diagnostic.h:1258
unsigned getNumLines() const
Definition: ASTUnit.h:209
FileManager & getFileManager()
Definition: ASTUnit.h:526
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:62
Allocator for a cached set of global code completions.
void assign(const FileEntry *F, const char *begin, const char *end)
Definition: ASTUnit.h:196
bool(* DeclVisitorFn)(void *context, const Decl *D)
Type for a function iterating over a number of declarations.
Definition: ASTUnit.h:687
bool getOnlyLocalDecls() const
Definition: ASTUnit.h:542
Data used to determine if a file used in the preamble has been changed.
Definition: ASTUnit.h:230
void addTopLevelDeclFromPreamble(serialization::DeclID D)
Add a new top-level declaration, identified by its ID in the precompiled preamble.
Definition: ASTUnit.h:594
bool isModuleFile()
Returns true if the ASTUnit was constructed from a serialized module file.
Definition: ASTUnit.cpp:2822
bool lookupMissingImports(StringRef Name, SourceLocation TriggerLoc) override
Definition: ASTUnit.h:911
static PreambleFileHash createForMemoryBuffer(const llvm::MemoryBuffer *Buffer)
Definition: ASTUnit.cpp:1254
static ASTUnit * create(CompilerInvocation *CI, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, bool CaptureDiagnostics, bool UserFilesAreVolatile)
Create a ASTUnit. Gets ownership of the passed CompilerInvocation.
Definition: ASTUnit.cpp:1700
friend bool operator!=(const PreambleFileHash &LHS, const PreambleFileHash &RHS)
Definition: ASTUnit.h:250
std::vector< std::pair< unsigned, unsigned > > Ranges
Definition: ASTUnit.h:83
void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility, SourceLocation ImportLoc) override
Make the given module visible.
Definition: ASTUnit.h:906
cached_completion_iterator cached_completion_end()
Definition: ASTUnit.h:671
unsigned Type
The type of a non-macro completion result, stored as a unique integer used by the string map of cache...
Definition: ASTUnit.h:356
CXCursorKind Kind
The libclang cursor kind corresponding to this code-completion result.
Definition: ASTUnit.h:342
stored_diag_const_iterator stored_diag_begin() const
Definition: ASTUnit.h:644
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:89
Utility class for loading a ASTContext from an AST file.
Definition: ASTUnit.h:68
A "string" used to describe how code completion can be performed for an entity.
Preprocessor & getPreprocessor()
Definition: ASTUnit.h:506
static std::unique_ptr< ASTUnit > LoadFromASTFile(const std::string &Filename, const PCHContainerReader &PCHContainerRdr, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, const FileSystemOptions &FileSystemOpts, bool OnlyLocalDecls=false, ArrayRef< RemappedFile > RemappedFiles=None, bool CaptureDiagnostics=false, bool AllowPCHWithCompilerErrors=false, bool UserFilesAreVolatile=false)
Create a ASTUnit from an AST file.
Definition: ASTUnit.cpp:651
unsigned stored_diag_size() const
Definition: ASTUnit.h:656
FrontendAction * Action
Definition: Tooling.cpp:168
std::unique_ptr< llvm::MemoryBuffer > getBufferForFile(StringRef Filename, std::string *ErrorStr=nullptr)
Definition: ASTUnit.cpp:633
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
Describes a module or submodule.
Definition: Basic/Module.h:49
const SourceManager & getSourceManager() const
Definition: ASTUnit.h:502
SourceRange mapRangeFromPreamble(SourceRange R)
Definition: ASTUnit.h:630
DiagnosticsEngine::Level Level
Definition: ASTUnit.h:79
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
uint64_t ShowInContexts
A bitmask that indicates which code-completion contexts should contain this completion result...
Definition: ASTUnit.h:335
uint32_t Offset
Definition: CacheTokens.cpp:43
const FileEntry * getPCHFile()
Get the PCH file if one was included.
Definition: ASTUnit.cpp:2810
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:32
bool serialize(raw_ostream &OS)
Serialize this translation unit with the given output stream.
Definition: ASTUnit.cpp:2498
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:135
bool getOwnsRemappedFileBuffers() const
Definition: ASTUnit.h:544
void addFileLevelDecl(Decl *D)
Add a new local file-level declaration.
Definition: ASTUnit.cpp:2564
ASTDeserializationListener * getDeserializationListener()
Definition: ASTUnit.cpp:626
ConcurrencyCheck(ASTUnit &Self)
Definition: ASTUnit.h:481
CXCursorKind
Describes the kind of entity that a cursor refers to.
Definition: Index.h:1525
void setASTContext(ASTContext *ctx)
Definition: ASTUnit.h:511
const LangOptions & getLangOpts() const
Definition: ASTUnit.h:520
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:258
StringRef getASTFileName() const
If this ASTUnit came from an AST file, returns the filename for it.
Definition: ASTUnit.cpp:1691
Describes the result of attempting to load a module.
Definition: ModuleLoader.h:33
void setPreprocessor(Preprocessor *pp)
Definition: ASTUnit.cpp:260
ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path, Module::NameVisibilityKind Visibility, bool IsInclusionDirective) override
Attempt to load the given module.
Definition: ASTUnit.h:899
SourceManager & SM
const FileManager & getFileManager() const
Definition: ASTUnit.h:525
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. Length can be 0 to indicate a ...
Definition: ASTUnit.cpp:2605
CodeCompletionTUInfo & getCodeCompletionTUInfo()
Definition: ASTUnit.h:371
Defines the clang::LangOptions interface.
GlobalModuleIndex * loadGlobalModuleIndex(SourceLocation TriggerLoc) override
Load, create, or return global module. This function returns an existing global module index...
Definition: ASTUnit.h:909
std::pair< unsigned, unsigned > RemoveRange
Definition: ASTUnit.h:71
off_t Size
All files have size set.
Definition: ASTUnit.h:232
unsigned & getCurrentTopLevelHashValue()
Retrieve a reference to the current top-level name hash value.
Definition: ASTUnit.h:601
SourceManager & SourceMgr
Definition: Format.cpp:1205
std::vector< StandaloneFixIt > FixIts
Definition: ASTUnit.h:84
StringRef getOriginalSourceFileName()
Definition: ASTUnit.h:530
static PreambleFileHash createForFile(off_t Size, time_t ModTime)
Definition: ASTUnit.cpp:1246
#define bool
Definition: stdbool.h:31
FileID getPreambleFileID() const
Get the file ID for the precompiled preamble if there is one.
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
stored_diag_const_iterator stored_diag_end() const
Definition: ASTUnit.h:650
void setOwnsRemappedFileBuffers(bool val)
Definition: ASTUnit.h:545
top_level_iterator top_level_begin()
Definition: ASTUnit.h:554
const StoredDiagnostic * stored_diag_const_iterator
Definition: ASTUnit.h:643
size_t size() const
Definition: ASTUnit.h:204
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
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:710
AnnotatedLine & Line
llvm::StringMap< unsigned > & getCachedCompletionTypes()
Retrieve the mapping from formatted type names to unique type identifiers.
Definition: ASTUnit.h:361
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:53
void setUnsafeToFree(bool Value)
Definition: ASTUnit.h:497
Abstract base class to use for AST consumer-based frontend actions.
Defines the clang::TargetOptions class.
const PreambleData & getPreambleData() const
Definition: ASTUnit.h:225
unsigned cached_completion_size() const
Definition: ASTUnit.h:675
SourceRange mapRangeToPreamble(SourceRange R)
Definition: ASTUnit.h:636
SourceLocation getBegin() const
static ASTUnit * LoadFromCompilerInvocationAction(CompilerInvocation *CI, std::shared_ptr< PCHContainerOperations > PCHContainerOps, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, ASTFrontendAction *Action=nullptr, ASTUnit *Unit=nullptr, bool Persistent=true, StringRef ResourceFilesPath=StringRef(), bool OnlyLocalDecls=false, bool CaptureDiagnostics=false, bool PrecompilePreamble=false, bool CacheCodeCompletionResults=false, bool IncludeBriefCommentsInCodeCompletion=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:1722
const FileSystemOptions & getFileSystemOpts() const
Definition: ASTUnit.h:528
A global index for a set of module files, providing information about the identifiers within those mo...
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:2763
StoredDiagnostic * stored_diag_iterator
Definition: ASTUnit.h:642
const ASTContext & getASTContext() const
Definition: ASTUnit.h:508
__SIZE_TYPE__ size_t
Definition: stddef.h:62
bool isInPreambleFileID(SourceLocation Loc)
Definition: ASTUnit.cpp:2704
static ASTUnit * LoadFromCommandLine(const char **ArgBegin, const char **ArgEnd, std::shared_ptr< PCHContainerOperations > PCHContainerOps, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, StringRef ResourceFilesPath, bool OnlyLocalDecls=false, bool CaptureDiagnostics=false, ArrayRef< RemappedFile > RemappedFiles=None, bool RemappedFilesKeepOriginalName=true, bool PrecompilePreamble=false, TranslationUnitKind TUKind=TU_Complete, bool CacheCodeCompletionResults=false, bool IncludeBriefCommentsInCodeCompletion=false, bool AllowPCHWithCompilerErrors=false, bool SkipFunctionBodies=false, bool UserFilesAreVolatile=false, bool ForSerialization=false, std::unique_ptr< ASTUnit > *ErrAST=nullptr)
Definition: ASTUnit.cpp:1930
Abstract interface for a consumer of code-completion information.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool Reparse(std::shared_ptr< PCHContainerOperations > PCHContainerOps, ArrayRef< RemappedFile > RemappedFiles=None)
Reparse the source files using the same command-line options that were originally used to produce thi...
Definition: ASTUnit.cpp:2017
CodeCompletionString * Completion
The code-completion string corresponding to this completion result.
Definition: ASTUnit.h:326
const Preprocessor & getPreprocessor() const
Definition: ASTUnit.h:505
std::vector< Decl * >::iterator top_level_iterator
Definition: ASTUnit.h:552
ASTMutationListener * getASTMutationListener()
Definition: ASTUnit.cpp:620
ASTContext & getASTContext()
Definition: ASTUnit.h:509
Helper class for holding the data necessary to invoke the compiler.
llvm::MD5::MD5Result MD5
Definition: ASTUnit.h:241
void addTemporaryFile(StringRef TempFile)
Add a temporary file that the ASTUnit depends on.
Definition: ASTUnit.cpp:199
top_level_iterator top_level_end()
Definition: ASTUnit.h:561
Abstract interface for a module loader.
Definition: ModuleLoader.h:56
bool isMainFileAST() const
Definition: ASTUnit.h:494
SourceLocation getStartOfMainFileID()
Definition: ASTUnit.cpp:2737
SourceLocation mapLocationFromPreamble(SourceLocation Loc)
If Loc is a loaded location from the preamble, returns the corresponding local location of the main f...
Definition: ASTUnit.cpp:2665
bool Save(StringRef File)
Save this translation unit to a file with the given name.
Definition: ASTUnit.cpp:2452
TranslationUnitKind getTranslationUnitKind() const
Determine what kind of translation unit this AST represents.
Definition: ASTUnit.h:706
cached_completion_iterator cached_completion_begin()
Definition: ASTUnit.h:667
Defines the clang::FileSystemOptions interface.
SourceManager & getSourceManager()
Definition: ASTUnit.h:503
SourceRange getSourceRange(const SourceManager &SM) const
Definition: ASTUnit.h:216
Keeps track of options that affect how file operations are performed.
DiagnosticsEngine & getDiagnostics()
Definition: ASTUnit.h:500
bool isUnsafeToFree() const
Definition: ASTUnit.h:496
SourceLocation getLocation(const FileEntry *File, unsigned Line, unsigned Col) const
Get the source location for the given file:line:col triplet.
Definition: ASTUnit.cpp:2648
SimplifiedTypeClass TypeClass
The simplified type class for a non-macro completion result.
Definition: ASTUnit.h:348
stored_diag_iterator stored_diag_end()
Definition: ASTUnit.h:653
Level
The level of the diagnostic, after it has been through mapping.
Definition: Diagnostic.h:141
std::size_t top_level_size() const
Definition: ASTUnit.h:568
A cached code-completion result, which may be introduced in one of many different contexts...
Definition: ASTUnit.h:323
std::vector< CachedCodeCompletionResult >::iterator cached_completion_iterator
Definition: ASTUnit.h:665
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:163
NameVisibilityKind
Describes the visibility of the various names within a particular module.
Definition: Basic/Module.h:205
The translation unit is a complete translation unit.
Definition: LangOptions.h:165
SourceLocation mapLocationToPreamble(SourceLocation Loc)
If Loc is a local location of the main file but inside the preamble chunk, returns the corresponding ...
Definition: ASTUnit.cpp:2686
const char * getBufferStart() const
Definition: ASTUnit.h:207
SimplifiedTypeClass
A simplified classification of types used when determining "similar" types for code completion...
unsigned Priority
The priority given to this code-completion result.
Definition: ASTUnit.h:338
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
bool top_level_empty() const
Definition: ASTUnit.h:573
A trivial tuple used to represent a source range.
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:2304
friend bool operator==(const PreambleFileHash &LHS, const PreambleFileHash &RHS)
Definition: ASTUnit.cpp:1268
stored_diag_iterator stored_diag_begin()
Definition: ASTUnit.h:647
This class handles loading and caching of source files into memory.
unsigned Column
Definition: Format.cpp:1202
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:96