clang 23.0.0git
ASTUnit.h
Go to the documentation of this file.
1//===- ASTUnit.h - ASTUnit utility ------------------------------*- C++ -*-===//
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 utility class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_FRONTEND_ASTUNIT_H
14#define LLVM_CLANG_FRONTEND_ASTUNIT_H
15
16#include "clang-c/Index.h"
20#include "clang/Basic/LLVM.h"
33#include "llvm/ADT/ArrayRef.h"
34#include "llvm/ADT/DenseMap.h"
35#include "llvm/ADT/IntrusiveRefCntPtr.h"
36#include "llvm/ADT/STLExtras.h"
37#include "llvm/ADT/SmallVector.h"
38#include "llvm/ADT/StringMap.h"
39#include "llvm/ADT/StringRef.h"
40#include "llvm/ADT/iterator_range.h"
41#include "llvm/Bitstream/BitstreamWriter.h"
42#include <cassert>
43#include <cstddef>
44#include <cstdint>
45#include <memory>
46#include <optional>
47#include <string>
48#include <utility>
49#include <vector>
50
51namespace llvm {
52
53class MemoryBuffer;
54
55namespace vfs {
56
57class FileSystem;
58
59} // namespace vfs
60} // namespace llvm
61
62namespace clang {
63
64class ASTContext;
67class ASTReader;
68class CodeGenOptions;
71class Decl;
72class FileEntry;
73class FileManager;
74class FrontendAction;
75class HeaderSearch;
76class InputKind;
77class ModuleCache;
80class Preprocessor;
82class Sema;
83class TargetInfo;
85
86/// \brief Enumerates the available scopes for skipping function bodies.
88
89/// \brief Enumerates the available kinds for capturing diagnostics.
91
92/// Utility class for loading a ASTContext from an AST file.
93class ASTUnit {
94 std::unique_ptr<LangOptions> LangOpts;
95 std::unique_ptr<CodeGenOptions> CodeGenOpts;
96 // FIXME: The documentation on \c LoadFrom* member functions states that the
97 // DiagnosticsEngine (and therefore DiagnosticOptions) must outlive the
98 // returned ASTUnit. This is not the case. Enfore it by storing non-owning
99 // pointers here.
100 std::shared_ptr<DiagnosticOptions> DiagOpts;
104 std::shared_ptr<ModuleCache> ModCache;
105 std::unique_ptr<HeaderSearch> HeaderInfo;
107 std::shared_ptr<Preprocessor> PP;
109 std::shared_ptr<TargetOptions> TargetOpts;
110 std::unique_ptr<HeaderSearchOptions> HSOpts;
111 std::shared_ptr<PreprocessorOptions> PPOpts;
113 bool HadModuleLoaderFatalFailure = false;
114 bool StorePreamblesInMemory = false;
115
116 /// Utility struct for managing ASTWriter and its associated data streams.
117 struct ASTWriterData {
118 SmallString<128> Buffer;
119 llvm::BitstreamWriter Stream;
120 ASTWriter Writer;
121
122 ASTWriterData(ModuleCache &ModCache, const CodeGenOptions &CGOpts)
123 : Stream(Buffer), Writer(Stream, Buffer, ModCache, CGOpts, {}) {}
124 };
125 std::unique_ptr<ASTWriterData> WriterData;
126
127 FileSystemOptions FileSystemOpts;
128 std::string PreambleStoragePath;
129
130 /// The AST consumer that received information about the translation
131 /// unit as it was parsed or loaded.
132 std::unique_ptr<ASTConsumer> Consumer;
133
134 /// The semantic analysis object used to type-check the translation
135 /// unit.
136 std::unique_ptr<Sema> TheSema;
137
138 /// Optional owned invocation, just used to make the invocation used in
139 /// LoadFromCommandLine available.
140 std::shared_ptr<CompilerInvocation> Invocation;
141 /// Optional owned invocation, just used to make the invocation used in
142 /// Parse available.
143 std::shared_ptr<CompilerInvocation> CCInvocation;
144
145 /// Optional owned invocation, just used to keep the invocation alive for the
146 /// members initialized in transferASTDataFromCompilerInstance.
147 std::shared_ptr<CompilerInvocation> ModifiedInvocation;
148
149 /// Fake module loader: the AST unit doesn't need to load any modules.
150 TrivialModuleLoader ModuleLoader;
151
152 // OnlyLocalDecls - when true, walking this AST should only visit declarations
153 // that come from the AST itself, not from included precompiled headers.
154 // FIXME: This is temporary; eventually, CIndex will always do this.
155 bool OnlyLocalDecls = false;
156
157 /// Whether to capture any diagnostics produced.
158 CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None;
159
160 /// Track whether the main file was loaded from an AST or not.
161 bool MainFileIsAST;
162
163 /// What kind of translation unit this AST represents.
165
166 /// Whether we should time each operation.
167 bool WantTiming;
168
169 /// Whether the ASTUnit should delete the remapped buffers.
170 bool OwnsRemappedFileBuffers = true;
171
172 /// Track the top-level decls which appeared in an ASTUnit which was loaded
173 /// from a source file.
174 //
175 // FIXME: This is just an optimization hack to avoid deserializing large parts
176 // of a PCH file when using the Index library on an ASTUnit loaded from
177 // source. In the long term we should make the Index library use efficient and
178 // more scalable search mechanisms.
179 std::vector<Decl*> TopLevelDecls;
180
181 /// Sorted (by file offset) vector of pairs of file offset/Decl.
182 using LocDeclsTy = SmallVector<std::pair<unsigned, Decl *>, 64>;
183 using FileDeclsTy = llvm::DenseMap<FileID, std::unique_ptr<LocDeclsTy>>;
184
185 /// Map from FileID to the file-level declarations that it contains.
186 /// The files and decls are only local (and non-preamble) ones.
187 FileDeclsTy FileDecls;
188
189 /// The name of the original source file used to generate this ASTUnit.
190 std::string OriginalSourceFile;
191
192 /// The set of diagnostics produced when creating the preamble.
193 SmallVector<StandaloneDiagnostic, 4> PreambleDiagnostics;
194
195 /// The set of diagnostics produced when creating this
196 /// translation unit.
197 SmallVector<StoredDiagnostic, 4> StoredDiagnostics;
198
199 /// The set of diagnostics produced when failing to parse, e.g. due
200 /// to failure to load the PCH.
201 SmallVector<StoredDiagnostic, 4> FailedParseDiagnostics;
202
203 /// The number of stored diagnostics that come from the driver
204 /// itself.
205 ///
206 /// Diagnostics that come from the driver are retained from one parse to
207 /// the next.
208 unsigned NumStoredDiagnosticsFromDriver = 0;
209
210 /// Counter that determines when we want to try building a
211 /// precompiled preamble.
212 ///
213 /// If zero, we will never build a precompiled preamble. Otherwise,
214 /// it's treated as a counter that decrements each time we reparse
215 /// without the benefit of a precompiled preamble. When it hits 1,
216 /// we'll attempt to rebuild the precompiled header. This way, if
217 /// building the precompiled preamble fails, we won't try again for
218 /// some number of calls.
219 unsigned PreambleRebuildCountdown = 0;
220
221 /// Counter indicating how often the preamble was build in total.
222 unsigned PreambleCounter = 0;
223
224 /// Cache pairs "filename - source location"
225 ///
226 /// Cache contains only source locations from preamble so it is
227 /// guaranteed that they stay valid when the SourceManager is recreated.
228 /// This cache is used when loading preamble to increase performance
229 /// of that loading. It must be cleared when preamble is recreated.
230 llvm::StringMap<SourceLocation> PreambleSrcLocCache;
231
232 /// The contents of the preamble.
233 std::optional<PrecompiledPreamble> Preamble;
234
235 /// When non-NULL, this is the buffer used to store the contents of
236 /// the main file when it has been padded for use with the precompiled
237 /// preamble.
238 std::unique_ptr<llvm::MemoryBuffer> SavedMainFileBuffer;
239
240 /// The number of warnings that occurred while parsing the preamble.
241 ///
242 /// This value will be used to restore the state of the \c DiagnosticsEngine
243 /// object when re-using the precompiled preamble. Note that only the
244 /// number of warnings matters, since we will not save the preamble
245 /// when any errors are present.
246 unsigned NumWarningsInPreamble = 0;
247
248 /// A list of the serialization ID numbers for each of the top-level
249 /// declarations parsed within the precompiled preamble.
250 std::vector<LocalDeclID> TopLevelDeclsInPreamble;
251
252 /// Whether we should be caching code-completion results.
253 bool ShouldCacheCodeCompletionResults : 1;
254
255 /// Whether to include brief documentation within the set of code
256 /// completions cached.
257 bool IncludeBriefCommentsInCodeCompletion : 1;
258
259 /// True if non-system source files should be treated as volatile
260 /// (likely to change while trying to use them).
261 bool UserFilesAreVolatile : 1;
262
263 static void ConfigureDiags(IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
264 ASTUnit &AST, CaptureDiagsKind CaptureDiagnostics);
265
266 void clearFileLevelDecls();
267
268public:
269 /// A cached code-completion result, which may be introduced in one of
270 /// many different contexts.
272 /// The code-completion string corresponding to this completion
273 /// result.
275
276 /// A bitmask that indicates which code-completion contexts should
277 /// contain this completion result.
278 ///
279 /// The bits in the bitmask correspond to the values of
280 /// CodeCompleteContext::Kind. To map from a completion context kind to a
281 /// bit, shift 1 by that number of bits. Many completions can occur in
282 /// several different contexts.
284
285 /// The priority given to this code-completion result.
286 unsigned Priority;
287
288 /// The libclang cursor kind corresponding to this code-completion
289 /// result.
291
292 /// The availability of this code-completion result.
294
295 /// The simplified type class for a non-macro completion result.
297
298 /// The type of a non-macro completion result, stored as a unique
299 /// integer used by the string map of cached completion types.
300 ///
301 /// This value will be zero if the type is not known, or a unique value
302 /// determined by the formatted type string. Se \c CachedCompletionTypes
303 /// for more information.
304 unsigned Type;
305 };
306
307 /// Retrieve the mapping from formatted type names to unique type
308 /// identifiers.
309 llvm::StringMap<unsigned> &getCachedCompletionTypes() {
310 return CachedCompletionTypes;
311 }
312
313 /// Retrieve the allocator used to cache global code completions.
314 std::shared_ptr<GlobalCodeCompletionAllocator>
316 return CachedCompletionAllocator;
317 }
318
320 if (!CCTUInfo)
321 CCTUInfo = std::make_unique<CodeCompletionTUInfo>(
322 std::make_shared<GlobalCodeCompletionAllocator>());
323 return *CCTUInfo;
324 }
325
326private:
327 /// Allocator used to store cached code completions.
328 std::shared_ptr<GlobalCodeCompletionAllocator> CachedCompletionAllocator;
329
330 std::unique_ptr<CodeCompletionTUInfo> CCTUInfo;
331
332 /// The set of cached code-completion results.
333 std::vector<CachedCodeCompletionResult> CachedCompletionResults;
334
335 /// A mapping from the formatted type name to a unique number for that
336 /// type, which is used for type equality comparisons.
337 llvm::StringMap<unsigned> CachedCompletionTypes;
338
339 /// A string hash of the top-level declaration and macro definition
340 /// names processed the last time that we reparsed the file.
341 ///
342 /// This hash value is used to determine when we need to refresh the
343 /// global code-completion cache.
344 unsigned CompletionCacheTopLevelHashValue = 0;
345
346 /// A string hash of the top-level declaration and macro definition
347 /// names processed the last time that we reparsed the precompiled preamble.
348 ///
349 /// This hash value is used to determine when we need to refresh the
350 /// global code-completion cache after a rebuild of the precompiled preamble.
351 unsigned PreambleTopLevelHashValue = 0;
352
353 /// The current hash value for the top-level declaration and macro
354 /// definition names
355 unsigned CurrentTopLevelHashValue = 0;
356
357 /// Bit used by CIndex to mark when a translation unit may be in an
358 /// inconsistent state, and is not safe to free.
359 LLVM_PREFERRED_TYPE(bool)
360 unsigned UnsafeToFree : 1;
361
362 /// \brief Enumerator specifying the scope for skipping function bodies.
364
365 /// Cache any "global" code-completion results, so that we can avoid
366 /// recomputing them with each completion.
367 void CacheCodeCompletionResults();
368
369 /// Clear out and deallocate
370 void ClearCachedCompletionResults();
371
372 explicit ASTUnit(bool MainFileIsAST);
373
374 bool Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
375 std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer,
377
378 std::unique_ptr<llvm::MemoryBuffer> getMainBufferWithPrecompiledPreamble(
379 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
380 CompilerInvocation &PreambleInvocationIn,
381 IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, bool AllowRebuild = true,
382 unsigned MaxLines = 0);
383 void RealizeTopLevelDeclsFromPreamble();
384
385 /// Transfers ownership of the objects (like SourceManager) from
386 /// \param CI to this ASTUnit.
387 void transferASTDataFromCompilerInstance(CompilerInstance &CI);
388
389 /// Allows us to assert that ASTUnit is not being used concurrently,
390 /// which is not supported.
391 ///
392 /// Clients should create instances of the ConcurrencyCheck class whenever
393 /// using the ASTUnit in a way that isn't intended to be concurrent, which is
394 /// just about any usage.
395 /// Becomes a noop in release mode; only useful for debug mode checking.
396 class ConcurrencyState {
397 void *Mutex; // a std::recursive_mutex in debug;
398
399 public:
400 ConcurrencyState();
401 ~ConcurrencyState();
402 ConcurrencyState(const ConcurrencyState &) = delete;
403 ConcurrencyState &operator=(const ConcurrencyState &) = delete;
404
405 void start();
406 void finish();
407 };
408 ConcurrencyState ConcurrencyCheckValue;
409
410public:
411 friend class ConcurrencyCheck;
412
414 ASTUnit &Self;
415
416 public:
417 explicit ConcurrencyCheck(ASTUnit &Self) : Self(Self) {
418 Self.ConcurrencyCheckValue.start();
419 }
420
422 Self.ConcurrencyCheckValue.finish();
423 }
424 };
425
426 ASTUnit(const ASTUnit &) = delete;
427 ASTUnit &operator=(const ASTUnit &) = delete;
428 ~ASTUnit();
429
430 bool isMainFileAST() const { return MainFileIsAST; }
431
432 bool isUnsafeToFree() const { return UnsafeToFree; }
433 void setUnsafeToFree(bool Value) { UnsafeToFree = Value; }
434
435 const DiagnosticsEngine &getDiagnostics() const { return *Diagnostics; }
436 DiagnosticsEngine &getDiagnostics() { return *Diagnostics; }
440
441 const SourceManager &getSourceManager() const { return *SourceMgr; }
442 SourceManager &getSourceManager() { return *SourceMgr; }
446
447 const Preprocessor &getPreprocessor() const { return *PP; }
448 Preprocessor &getPreprocessor() { return *PP; }
449 std::shared_ptr<Preprocessor> getPreprocessorPtr() const { return PP; }
450
451 const ASTContext &getASTContext() const { return *Ctx; }
452 ASTContext &getASTContext() { return *Ctx; }
454
456 Ctx = std::move(ctx);
457 }
458 void setPreprocessor(std::shared_ptr<Preprocessor> pp);
459
460 /// Enable source-range based diagnostic messages.
461 ///
462 /// If diagnostic messages with source-range information are to be expected
463 /// and AST comes not from file (e.g. after LoadFromCompilerInvocation) this
464 /// function has to be called.
465 /// The function is to be called only once and the AST should be associated
466 /// with the same source file afterwards.
468
469 bool hasSema() const { return (bool)TheSema; }
470
471 Sema &getSema() const {
472 assert(TheSema && "ASTUnit does not have a Sema object!");
473 return *TheSema;
474 }
475
476 const LangOptions &getLangOpts() const {
477 assert(LangOpts && "ASTUnit does not have language options");
478 return *LangOpts;
479 }
480
482 assert(CodeGenOpts && "ASTUnit does not have codegen options");
483 return *CodeGenOpts;
484 }
485
487 assert(HSOpts && "ASTUnit does not have header search options");
488 return *HSOpts;
489 }
490
492 assert(PPOpts && "ASTUnit does not have preprocessor options");
493 return *PPOpts;
494 }
495
497 // FIXME: Don't defer VFS ownership to the FileManager.
498 return FileMgr->getVirtualFileSystemPtr();
499 }
500
501 const FileManager &getFileManager() const { return *FileMgr; }
502 FileManager &getFileManager() { return *FileMgr; }
504
505 const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; }
506
508
509 StringRef getOriginalSourceFileName() const {
510 return OriginalSourceFile;
511 }
512
515
516 bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
517
518 bool getOwnsRemappedFileBuffers() const { return OwnsRemappedFileBuffers; }
519 void setOwnsRemappedFileBuffers(bool val) { OwnsRemappedFileBuffers = val; }
520
521 StringRef getMainFileName() const;
522
523 /// If this ASTUnit came from an AST file, returns the filename for it.
524 StringRef getASTFileName() const;
525
526 using top_level_iterator = std::vector<Decl *>::iterator;
527
529 assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
530 if (!TopLevelDeclsInPreamble.empty())
531 RealizeTopLevelDeclsFromPreamble();
532 return TopLevelDecls.begin();
533 }
534
536 assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
537 if (!TopLevelDeclsInPreamble.empty())
538 RealizeTopLevelDeclsFromPreamble();
539 return TopLevelDecls.end();
540 }
541
542 std::size_t top_level_size() const {
543 assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
544 return TopLevelDeclsInPreamble.size() + TopLevelDecls.size();
545 }
546
547 bool top_level_empty() const {
548 assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
549 return TopLevelDeclsInPreamble.empty() && TopLevelDecls.empty();
550 }
551
552 /// Add a new top-level declaration.
554 TopLevelDecls.push_back(D);
555 }
556
557 /// Add a new local file-level declaration.
558 void addFileLevelDecl(Decl *D);
559
560 /// Get the decls that are contained in a file in the Offset/Length
561 /// range. \p Length can be 0 to indicate a point at \p Offset instead of
562 /// a range.
563 void findFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
565
566 /// Retrieve a reference to the current top-level name hash value.
567 ///
568 /// Note: This is used internally by the top-level tracking action
569 unsigned &getCurrentTopLevelHashValue() { return CurrentTopLevelHashValue; }
570
571 /// Get the source location for the given file:line:col triplet.
572 ///
573 /// The difference with SourceManager::getLocation is that this method checks
574 /// whether the requested location points inside the precompiled preamble
575 /// in which case the returned source location will be a "loaded" one.
577 unsigned Line, unsigned Col) const;
578
579 /// Get the source location for the given file:offset pair.
580 SourceLocation getLocation(const FileEntry *File, unsigned Offset) const;
581
582 /// If \p Loc is a loaded location from the preamble, returns
583 /// the corresponding local location of the main file, otherwise it returns
584 /// \p Loc.
586
587 /// If \p Loc is a local location of the main file but inside the
588 /// preamble chunk, returns the corresponding loaded location from the
589 /// preamble, otherwise it returns \p Loc.
591
592 bool isInPreambleFileID(SourceLocation Loc) const;
593 bool isInMainFileID(SourceLocation Loc) const;
596
597 /// \see mapLocationFromPreamble.
602
603 /// \see mapLocationToPreamble.
605 return SourceRange(mapLocationToPreamble(R.getBegin()),
606 mapLocationToPreamble(R.getEnd()));
607 }
608
609 unsigned getPreambleCounterForTests() const { return PreambleCounter; }
610
611 // Retrieve the diagnostics associated with this AST
614
616 return StoredDiagnostics.begin();
617 }
618
620 return StoredDiagnostics.begin();
621 }
622
624 return StoredDiagnostics.end();
625 }
626
628 return StoredDiagnostics.end();
629 }
630
631 using diags_range = llvm::iterator_range<stored_diag_iterator>;
632 using const_diags_range = llvm::iterator_range<stored_diag_const_iterator>;
633
637
641
642 unsigned stored_diag_size() const { return StoredDiagnostics.size(); }
643
645 if (NumStoredDiagnosticsFromDriver > StoredDiagnostics.size())
646 NumStoredDiagnosticsFromDriver = 0;
647 return StoredDiagnostics.begin() + NumStoredDiagnosticsFromDriver;
648 }
649
651 std::vector<CachedCodeCompletionResult>::iterator;
652
654 return CachedCompletionResults.begin();
655 }
656
658 return CachedCompletionResults.end();
659 }
660
661 unsigned cached_completion_size() const {
662 return CachedCompletionResults.size();
663 }
664
665 /// Returns an iterator range for the local preprocessing entities
666 /// of the local Preprocessor, if this is a parsed source file, or the loaded
667 /// preprocessing entities of the primary module if this is an AST file.
668 llvm::iterator_range<PreprocessingRecord::iterator>
670
671 /// Type for a function iterating over a number of declarations.
672 /// \returns true to continue iteration and false to abort.
673 using DeclVisitorFn = bool (*)(void *context, const Decl *D);
674
675 /// Iterate over local declarations (locally parsed if this is a parsed
676 /// source file or the loaded declarations of the primary module if this is an
677 /// AST file).
678 /// \returns true if the iteration was complete or false if it was aborted.
679 bool visitLocalTopLevelDecls(void *context, DeclVisitorFn Fn);
680
681 /// Get the PCH file if one was included.
683
684 /// Returns true if the ASTUnit was constructed from a serialized
685 /// module file.
686 bool isModuleFile() const;
687
688 std::unique_ptr<llvm::MemoryBuffer>
689 getBufferForFile(StringRef Filename, std::string *ErrorStr = nullptr);
690
691 /// Determine what kind of translation unit this AST represents.
693
694 /// Determine the input kind this AST unit represents.
695 InputKind getInputKind() const;
696
697 /// A mapping from a file name to the memory buffer that stores the
698 /// remapped contents of that file.
699 using RemappedFile = std::pair<std::string, llvm::MemoryBuffer *>;
700
701 /// Create a ASTUnit. Gets ownership of the passed CompilerInvocation.
702 static std::unique_ptr<ASTUnit>
703 create(std::shared_ptr<CompilerInvocation> CI,
704 std::shared_ptr<DiagnosticOptions> DiagOpts,
706 CaptureDiagsKind CaptureDiagnostics, bool UserFilesAreVolatile);
707
709 /// Load options and the preprocessor state.
711
712 /// Load the AST, but do not restore Sema state.
714
715 /// Load everything, including Sema.
717 };
718
719 /// Create a ASTUnit from an AST file.
720 ///
721 /// \param Filename - The AST file to load.
722 ///
723 /// \param PCHContainerRdr - The PCHContainerOperations to use for loading and
724 /// creating modules.
725 /// \param Diags - The diagnostics engine to use for reporting errors; its
726 /// lifetime is expected to extend past that of the returned ASTUnit.
727 ///
728 /// \returns - The initialized ASTUnit or null if the AST failed to load.
729 static std::unique_ptr<ASTUnit> LoadFromASTFile(
730 StringRef Filename, const PCHContainerReader &PCHContainerRdr,
732 std::shared_ptr<DiagnosticOptions> DiagOpts,
734 const FileSystemOptions &FileSystemOpts,
735 const HeaderSearchOptions &HSOpts, const LangOptions *LangOpts = nullptr,
736 bool OnlyLocalDecls = false,
737 CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
738 bool AllowASTWithCompilerErrors = false,
739 bool UserFilesAreVolatile = false);
740
741private:
742 /// Helper function for \c LoadFromCompilerInvocation() and
743 /// \c LoadFromCommandLine(), which loads an AST from a compiler invocation.
744 ///
745 /// \param PrecompilePreambleAfterNParses After how many parses the preamble
746 /// of this translation unit should be precompiled, to improve the performance
747 /// of reparsing. Set to zero to disable preambles.
748 ///
749 /// \param VFS - A llvm::vfs::FileSystem to be used for all file accesses.
750 /// Note that preamble is saved to a temporary directory on a RealFileSystem,
751 /// so in order for it to be loaded correctly, VFS should have access to
752 /// it(i.e., be an overlay over RealFileSystem).
753 ///
754 /// \returns \c true if a catastrophic failure occurred (which means that the
755 /// \c ASTUnit itself is invalid), or \c false otherwise.
756 bool LoadFromCompilerInvocation(
757 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
758 unsigned PrecompilePreambleAfterNParses,
760
761public:
762 /// Create an ASTUnit from a source file, via a CompilerInvocation
763 /// object, by invoking the optionally provided ASTFrontendAction.
764 ///
765 /// \param CI - The compiler invocation to use; it must have exactly one input
766 /// source file. The ASTUnit takes ownership of the CompilerInvocation object.
767 ///
768 /// \param PCHContainerOps - The PCHContainerOperations to use for loading and
769 /// creating modules.
770 ///
771 /// \param Diags - The diagnostics engine to use for reporting errors; its
772 /// lifetime is expected to extend past that of the returned ASTUnit.
773 ///
774 /// \param Action - The ASTFrontendAction to invoke. Its ownership is not
775 /// transferred.
776 ///
777 /// \param Unit - optionally an already created ASTUnit. Its ownership is not
778 /// transferred.
779 ///
780 /// \param Persistent - if true the returned ASTUnit will be complete.
781 /// false means the caller is only interested in getting info through the
782 /// provided \see Action.
783 ///
784 /// \param ErrAST - If non-null and parsing failed without any AST to return
785 /// (e.g. because the PCH could not be loaded), this accepts the ASTUnit
786 /// mainly to allow the caller to see the diagnostics.
787 /// This will only receive an ASTUnit if a new one was created. If an already
788 /// created ASTUnit was passed in \p Unit then the caller can check that.
789 ///
791 std::shared_ptr<CompilerInvocation> CI,
792 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
793 std::shared_ptr<DiagnosticOptions> DiagOpts,
795 FrontendAction *Action = nullptr, ASTUnit *Unit = nullptr,
796 bool Persistent = true, StringRef ResourceFilesPath = StringRef(),
797 bool OnlyLocalDecls = false,
798 CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
799 unsigned PrecompilePreambleAfterNParses = 0,
800 bool CacheCodeCompletionResults = false,
801 bool UserFilesAreVolatile = false,
802 std::unique_ptr<ASTUnit> *ErrAST = nullptr);
803
804 /// LoadFromCompilerInvocation - Create an ASTUnit from a source file, via a
805 /// CompilerInvocation object.
806 ///
807 /// \param CI - The compiler invocation to use; it must have exactly one input
808 /// source file. The ASTUnit takes ownership of the CompilerInvocation object.
809 ///
810 /// \param PCHContainerOps - The PCHContainerOperations to use for loading and
811 /// creating modules.
812 ///
813 /// \param Diags - The diagnostics engine to use for reporting errors; its
814 /// lifetime is expected to extend past that of the returned ASTUnit.
815 //
816 // FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we
817 // shouldn't need to specify them at construction time.
818 static std::unique_ptr<ASTUnit> LoadFromCompilerInvocation(
819 std::shared_ptr<CompilerInvocation> CI,
820 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
821 std::shared_ptr<DiagnosticOptions> DiagOpts,
823 IntrusiveRefCntPtr<FileManager> FileMgr, bool OnlyLocalDecls = false,
824 CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
825 unsigned PrecompilePreambleAfterNParses = 0,
827 bool CacheCodeCompletionResults = false,
828 bool IncludeBriefCommentsInCodeCompletion = false,
829 bool UserFilesAreVolatile = false);
830
831 friend std::unique_ptr<ASTUnit> CreateASTUnitFromCommandLine(
832 const char **ArgBegin, const char **ArgEnd,
833 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
834 std::shared_ptr<DiagnosticOptions> DiagOpts,
835 IntrusiveRefCntPtr<DiagnosticsEngine> Diags, StringRef ResourceFilesPath,
836 bool StorePreamblesInMemory, StringRef PreambleStoragePath,
837 bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
839 bool RemappedFilesKeepOriginalName,
840 unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind,
841 bool CacheCodeCompletionResults,
842 bool IncludeBriefCommentsInCodeCompletion,
843 bool AllowPCHWithCompilerErrors,
844 SkipFunctionBodiesScope SkipFunctionBodies, bool SingleFileParse,
845 bool UserFilesAreVolatile, bool ForSerialization,
846 bool RetainExcludedConditionalBlocks,
847 std::optional<StringRef> ModuleFormat, std::unique_ptr<ASTUnit> *ErrAST,
849
850 /// Reparse the source files using the same command-line options that
851 /// were originally used to produce this translation unit.
852 ///
853 /// \param VFS - A llvm::vfs::FileSystem to be used for all file accesses.
854 /// Note that preamble is saved to a temporary directory on a RealFileSystem,
855 /// so in order for it to be loaded correctly, VFS should give an access to
856 /// this(i.e. be an overlay over RealFileSystem).
857 /// FileMgr->getVirtualFileSystem() will be used if \p VFS is nullptr.
858 ///
859 /// \returns True if a failure occurred that causes the ASTUnit not to
860 /// contain any translation-unit information, false otherwise.
861 bool Reparse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
862 ArrayRef<RemappedFile> RemappedFiles = {},
864
865 /// Free data that will be re-generated on the next parse.
866 ///
867 /// Preamble-related data is not affected.
868 void ResetForParse();
869
870 /// Perform code completion at the given file, line, and
871 /// column within this translation unit.
872 ///
873 /// \param File The file in which code completion will occur.
874 ///
875 /// \param Line The line at which code completion will occur.
876 ///
877 /// \param Column The column at which code completion will occur.
878 ///
879 /// \param IncludeMacros Whether to include macros in the code-completion
880 /// results.
881 ///
882 /// \param IncludeCodePatterns Whether to include code patterns (such as a
883 /// for loop) in the code-completion results.
884 ///
885 /// \param IncludeBriefComments Whether to include brief documentation within
886 /// the set of code completions returned.
887 ///
888 /// \param Act If supplied, this argument is used to parse the input file,
889 /// allowing customized parsing by overriding SyntaxOnlyAction lifecycle
890 /// methods.
891 ///
892 /// FIXME: The Diag, LangOpts, SourceMgr, FileMgr, StoredDiagnostics, and
893 /// OwnedBuffers parameters are all disgusting hacks. They will go away.
894 void CodeComplete(StringRef File, unsigned Line, unsigned Column,
895 ArrayRef<RemappedFile> RemappedFiles, bool IncludeMacros,
896 bool IncludeCodePatterns, bool IncludeBriefComments,
897 CodeCompleteConsumer &Consumer,
898 std::shared_ptr<PCHContainerOperations> PCHContainerOps,
900 LangOptions &LangOpts,
903 SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics,
905 std::unique_ptr<SyntaxOnlyAction> Act);
906
907 /// Save this translation unit to a file with the given name.
908 ///
909 /// \returns true if there was a file error or false if the save was
910 /// successful.
911 bool Save(StringRef File);
912
913 /// Serialize this translation unit with the given output stream.
914 ///
915 /// \returns True if an error occurred, false otherwise.
916 bool serialize(raw_ostream &OS);
917};
918
919/// Diagnostic consumer that saves each diagnostic it is given.
923 bool CaptureNonErrorsFromIncludes = true;
924 const LangOptions *LangOpts = nullptr;
925 SourceManager *SourceMgr = nullptr;
926
927public:
931 bool CaptureNonErrorsFromIncludes);
932
933 void BeginSourceFile(const LangOptions &LangOpts,
934 const Preprocessor *PP = nullptr) override;
935
937 const Diagnostic &Info) override;
938};
939
940/// RAII object that optionally captures and filters diagnostics, if
941/// there is no diagnostic client to capture them already.
943 DiagnosticsEngine &Diags;
945 DiagnosticConsumer *PreviousClient = nullptr;
946 std::unique_ptr<DiagnosticConsumer> OwningPreviousClient;
947
948public:
950 CaptureDiagsKind CaptureDiagnostics, DiagnosticsEngine &Diags,
953
958};
959
960} // namespace clang
961
962#endif // LLVM_CLANG_FRONTEND_ASTUNIT_H
Defines the clang::ASTContext interface.
Defines the Diagnostic-related interfaces.
Defines the clang::FileSystemOptions interface.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
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.
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Defines the clang::TargetOptions class.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:226
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
Reads an AST files chain containing the contents of a translation unit.
Definition ASTReader.h:430
ConcurrencyCheck(ASTUnit &Self)
Definition ASTUnit.h:417
Utility class for loading a ASTContext from an AST file.
Definition ASTUnit.h:93
const PreprocessorOptions & getPreprocessorOpts() const
Definition ASTUnit.h:491
unsigned & getCurrentTopLevelHashValue()
Retrieve a reference to the current top-level name hash value.
Definition ASTUnit.h:569
ASTContext & getASTContext()
Definition ASTUnit.h:452
CodeCompletionTUInfo & getCodeCompletionTUInfo()
Definition ASTUnit.h:319
void enableSourceFileDiagnostics()
Enable source-range based diagnostic messages.
Definition ASTUnit.cpp:267
stored_diag_iterator stored_diag_end()
Definition ASTUnit.h:627
void addFileLevelDecl(Decl *D)
Add a new local file-level declaration.
Definition ASTUnit.cpp:2227
const FileManager & getFileManager() const
Definition ASTUnit.h:501
void setOwnsRemappedFileBuffers(bool val)
Definition ASTUnit.h:519
bool isUnsafeToFree() const
Definition ASTUnit.h:432
void CodeComplete(StringRef File, unsigned Line, unsigned Column, ArrayRef< RemappedFile > RemappedFiles, bool IncludeMacros, bool IncludeCodePatterns, bool IncludeBriefComments, CodeCompleteConsumer &Consumer, std::shared_ptr< PCHContainerOperations > PCHContainerOps, llvm::IntrusiveRefCntPtr< DiagnosticsEngine > Diag, LangOptions &LangOpts, llvm::IntrusiveRefCntPtr< SourceManager > SourceMgr, llvm::IntrusiveRefCntPtr< FileManager > FileMgr, SmallVectorImpl< StoredDiagnostic > &StoredDiagnostics, SmallVectorImpl< const llvm::MemoryBuffer * > &OwnedBuffers, std::unique_ptr< SyntaxOnlyAction > Act)
Perform code completion at the given file, line, and column within this translation unit.
Definition ASTUnit.cpp:2025
cached_completion_iterator cached_completion_end()
Definition ASTUnit.h:657
SourceRange mapRangeFromPreamble(SourceRange R) const
Definition ASTUnit.h:598
bool hasSema() const
Definition ASTUnit.h:469
static std::unique_ptr< ASTUnit > LoadFromASTFile(StringRef Filename, const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, std::shared_ptr< DiagnosticOptions > DiagOpts, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, const FileSystemOptions &FileSystemOpts, const HeaderSearchOptions &HSOpts, const LangOptions *LangOpts=nullptr, bool OnlyLocalDecls=false, CaptureDiagsKind CaptureDiagnostics=CaptureDiagsKind::None, bool AllowASTWithCompilerErrors=false, bool UserFilesAreVolatile=false)
Create a ASTUnit from an AST file.
Definition ASTUnit.cpp:693
bool top_level_empty() const
Definition ASTUnit.h:547
llvm::IntrusiveRefCntPtr< ASTContext > getASTContextPtr()
Definition ASTUnit.h:453
bool serialize(raw_ostream &OS)
Serialize this translation unit with the given output stream.
Definition ASTUnit.cpp:2216
llvm::iterator_range< stored_diag_iterator > diags_range
Definition ASTUnit.h:631
bool getOwnsRemappedFileBuffers() const
Definition ASTUnit.h:518
const CodeGenOptions & getCodeGenOpts() const
Definition ASTUnit.h:481
const FileSystemOptions & getFileSystemOpts() const
Definition ASTUnit.h:505
ASTDeserializationListener * getDeserializationListener()
Definition ASTUnit.cpp:665
stored_diag_const_iterator stored_diag_end() const
Definition ASTUnit.h:623
bool Reparse(std::shared_ptr< PCHContainerOperations > PCHContainerOps, ArrayRef< RemappedFile > RemappedFiles={}, 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:1709
void setUnsafeToFree(bool Value)
Definition ASTUnit.h:433
std::unique_ptr< llvm::MemoryBuffer > getBufferForFile(StringRef Filename, std::string *ErrorStr=nullptr)
Definition ASTUnit.cpp:672
llvm::StringMap< unsigned > & getCachedCompletionTypes()
Retrieve the mapping from formatted type names to unique type identifiers.
Definition ASTUnit.h:309
const DiagnosticsEngine & getDiagnostics() const
Definition ASTUnit.h:435
SourceLocation getLocation(const FileEntry *File, unsigned Line, unsigned Col) const
Get the source location for the given file:line:col triplet.
Definition ASTUnit.cpp:2309
void ResetForParse()
Free data that will be re-generated on the next parse.
Definition ASTUnit.cpp:1768
llvm::IntrusiveRefCntPtr< SourceManager > getSourceManagerPtr()
Definition ASTUnit.h:443
bool getOnlyLocalDecls() const
Definition ASTUnit.h:516
InputKind getInputKind() const
Determine the input kind this AST unit represents.
Definition ASTUnit.cpp:2478
OptionalFileEntryRef getPCHFile()
Get the PCH file if one was included.
Definition ASTUnit.cpp:2446
StringRef getMainFileName() const
Definition ASTUnit.cpp:1442
Sema & getSema() const
Definition ASTUnit.h:471
ASTUnit(const ASTUnit &)=delete
stored_diag_const_iterator stored_diag_begin() const
Definition ASTUnit.h:615
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:2347
cached_completion_iterator cached_completion_begin()
Definition ASTUnit.h:653
const LangOptions & getLangOpts() const
Definition ASTUnit.h:476
bool isMainFileAST() const
Definition ASTUnit.h:430
std::vector< Decl * >::iterator top_level_iterator
Definition ASTUnit.h:526
const SourceManager & getSourceManager() const
Definition ASTUnit.h:441
ASTUnit & operator=(const ASTUnit &)=delete
unsigned stored_diag_size() const
Definition ASTUnit.h:642
const_diags_range storedDiagnostics() const
Definition ASTUnit.h:638
Preprocessor & getPreprocessor()
Definition ASTUnit.h:448
DiagnosticsEngine & getDiagnostics()
Definition ASTUnit.h:436
const StoredDiagnostic * stored_diag_const_iterator
Definition ASTUnit.h:613
SourceLocation getEndOfPreambleFileID() const
Definition ASTUnit.cpp:2387
std::vector< CachedCodeCompletionResult >::iterator cached_completion_iterator
Definition ASTUnit.h:650
stored_diag_iterator stored_diag_afterDriver_begin()
Definition ASTUnit.h:644
llvm::IntrusiveRefCntPtr< DiagnosticsEngine > getDiagnosticsPtr()
Definition ASTUnit.h:437
static ASTUnit * LoadFromCompilerInvocationAction(std::shared_ptr< CompilerInvocation > CI, std::shared_ptr< PCHContainerOperations > PCHContainerOps, std::shared_ptr< DiagnosticOptions > DiagOpts, 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:1493
@ LoadPreprocessorOnly
Load options and the preprocessor state.
Definition ASTUnit.h:710
@ LoadASTOnly
Load the AST, but do not restore Sema state.
Definition ASTUnit.h:713
@ LoadEverything
Load everything, including Sema.
Definition ASTUnit.h:716
top_level_iterator top_level_end()
Definition ASTUnit.h:535
SourceLocation getStartOfMainFileID() const
Definition ASTUnit.cpp:2398
SourceRange mapRangeToPreamble(SourceRange R) const
Definition ASTUnit.h:604
diags_range storedDiagnostics()
Definition ASTUnit.h:634
FileManager & getFileManager()
Definition ASTUnit.h:502
IntrusiveRefCntPtr< ASTReader > getASTReader() const
Definition ASTUnit.cpp:655
IntrusiveRefCntPtr< FileManager > getFileManagerPtr()
Definition ASTUnit.h:503
bool(*)(void *context, const Decl *D) DeclVisitorFn
Type for a function iterating over a number of declarations.
Definition ASTUnit.h:673
StoredDiagnostic * stored_diag_iterator
Definition ASTUnit.h:612
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:2424
IntrusiveRefCntPtr< llvm::vfs::FileSystem > getVirtualFileSystemPtr()
Definition ASTUnit.h:496
llvm::iterator_range< PreprocessingRecord::iterator > getLocalPreprocessingEntities() const
Returns an iterator range for the local preprocessing entities of the local Preprocessor,...
Definition ASTUnit.cpp:2410
StringRef getOriginalSourceFileName() const
Definition ASTUnit.h:509
top_level_iterator top_level_begin()
Definition ASTUnit.h:528
ASTMutationListener * getASTMutationListener()
Definition ASTUnit.cpp:659
stored_diag_iterator stored_diag_begin()
Definition ASTUnit.h:619
TranslationUnitKind getTranslationUnitKind() const
Determine what kind of translation unit this AST represents.
Definition ASTUnit.h:692
std::shared_ptr< Preprocessor > getPreprocessorPtr() const
Definition ASTUnit.h:449
void setPreprocessor(std::shared_ptr< Preprocessor > pp)
Definition ASTUnit.cpp:263
StringRef getASTFileName() const
If this ASTUnit came from an AST file, returns the filename for it.
Definition ASTUnit.cpp:1460
bool Save(StringRef File)
Save this translation unit to a file with the given name.
Definition ASTUnit.cpp:2185
SourceManager & getSourceManager()
Definition ASTUnit.h:442
const HeaderSearchOptions & getHeaderSearchOpts() const
Definition ASTUnit.h:486
friend std::unique_ptr< ASTUnit > CreateASTUnitFromCommandLine(const char **ArgBegin, const char **ArgEnd, std::shared_ptr< PCHContainerOperations > PCHContainerOps, std::shared_ptr< DiagnosticOptions > DiagOpts, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, StringRef ResourceFilesPath, bool StorePreamblesInMemory, StringRef PreambleStoragePath, bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics, ArrayRef< ASTUnit::RemappedFile > RemappedFiles, bool RemappedFilesKeepOriginalName, unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind, bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion, bool AllowPCHWithCompilerErrors, SkipFunctionBodiesScope SkipFunctionBodies, bool SingleFileParse, bool UserFilesAreVolatile, bool ForSerialization, bool RetainExcludedConditionalBlocks, std::optional< StringRef > ModuleFormat, std::unique_ptr< ASTUnit > *ErrAST, IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS)
Create an ASTUnit from a vector of command line arguments, which must specify exactly one source file...
void setASTContext(llvm::IntrusiveRefCntPtr< ASTContext > ctx)
Definition ASTUnit.h:455
unsigned getPreambleCounterForTests() const
Definition ASTUnit.h:609
unsigned cached_completion_size() const
Definition ASTUnit.h:661
static std::unique_ptr< ASTUnit > create(std::shared_ptr< CompilerInvocation > CI, std::shared_ptr< DiagnosticOptions > DiagOpts, IntrusiveRefCntPtr< DiagnosticsEngine > Diags, CaptureDiagsKind CaptureDiagnostics, bool UserFilesAreVolatile)
Create a ASTUnit. Gets ownership of the passed CompilerInvocation.
Definition ASTUnit.cpp:1470
void addTopLevelDecl(Decl *D)
Add a new top-level declaration.
Definition ASTUnit.h:553
const Preprocessor & getPreprocessor() const
Definition ASTUnit.h:447
std::shared_ptr< GlobalCodeCompletionAllocator > getCachedCompletionAllocator()
Retrieve the allocator used to cache global code completions.
Definition ASTUnit.h:315
llvm::iterator_range< stored_diag_const_iterator > const_diags_range
Definition ASTUnit.h:632
bool isInMainFileID(SourceLocation Loc) const
Definition ASTUnit.cpp:2376
bool isModuleFile() const
Returns true if the ASTUnit was constructed from a serialized module file.
Definition ASTUnit.cpp:2474
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:2266
const ASTContext & getASTContext() const
Definition ASTUnit.h:451
bool isInPreambleFileID(SourceLocation Loc) const
Definition ASTUnit.cpp:2365
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:2326
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:699
std::size_t top_level_size() const
Definition ASTUnit.h:542
Writes an AST file containing the contents of a translation unit.
Definition ASTWriter.h:97
CaptureDroppedDiagnostics(const CaptureDroppedDiagnostics &)=delete
CaptureDroppedDiagnostics(CaptureDiagsKind CaptureDiagnostics, DiagnosticsEngine &Diags, SmallVectorImpl< StoredDiagnostic > *StoredDiags, SmallVectorImpl< StandaloneDiagnostic > *StandaloneDiags)
Definition ASTUnit.cpp:634
CaptureDroppedDiagnostics & operator=(const CaptureDroppedDiagnostics &)=delete
Abstract interface for a consumer of code-completion information.
A "string" used to describe how code completion can be performed for an entity.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Helper class for holding the data necessary to invoke the compiler.
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine a...
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:232
Level
The level of the diagnostic, after it has been through mapping.
Definition Diagnostic.h:237
Cached information about one file (either on disk or in the virtual file system).
Definition FileEntry.h:302
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Implements support for file system lookup, file system caching, and directory search management.
Definition FileManager.h:53
Keeps track of options that affect how file operations are performed.
Diagnostic consumer that saves each diagnostic it is given.
Definition ASTUnit.h:920
void BeginSourceFile(const LangOptions &LangOpts, const Preprocessor *PP=nullptr) override
Callback to inform the diagnostic client that processing of a source file is beginning.
Definition ASTUnit.cpp:588
FilterAndStoreDiagnosticConsumer(SmallVectorImpl< StoredDiagnostic > *StoredDiags, SmallVectorImpl< StandaloneDiagnostic > *StandaloneDiags, bool CaptureNonErrorsFromIncludes)
Definition ASTUnit.cpp:578
void HandleDiagnostic(DiagnosticsEngine::Level Level, const Diagnostic &Info) override
Handle this diagnostic, reporting it to the user or capturing it to a log as needed.
Definition ASTUnit.cpp:603
Abstract base class for actions which can be performed by the frontend.
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
Encapsulates the information needed to find the file referenced by a #include or #include_next,...
The kind of a file that we've been handed as an input.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
The module cache used for compiling modules implicitly.
Definition ModuleCache.h:25
A registry of PCHContainerWriter and -Reader objects for different formats.
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:868
Encodes a location in the source.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
Represents a diagnostic in a form that can be retained until its corresponding source manager is dest...
Exposes information about the current target.
Definition TargetInfo.h:226
A module loader that doesn't know how to create or load modules.
#define bool
Definition gpuintrin.h:32
CXCursorKind
Describes the kind of entity that a cursor refers to.
Definition Index.h:1186
CXAvailabilityKind
Describes the availability of a particular entity, which indicates whether the use of this entity wil...
Definition Index.h:130
The JSON file list parser is used to communicate input to InstallAPI.
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
Definition FileEntry.h:208
SkipFunctionBodiesScope
Enumerates the available scopes for skipping function bodies.
Definition ASTUnit.h:87
@ Parse
Parse the block; this code is always used.
Definition Parser.h:137
SimplifiedTypeClass
A simplified classification of types used when determining "similar" types for code completion.
CaptureDiagsKind
Enumerates the available kinds for capturing diagnostics.
Definition ASTUnit.h:90
TranslationUnitKind
Describes the kind of translation unit being processed.
@ TU_Complete
The translation unit is a complete translation unit.
@ None
The alignment was not explicit in code.
Definition ASTContext.h:179
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
A cached code-completion result, which may be introduced in one of many different contexts.
Definition ASTUnit.h:271
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:304
CXCursorKind Kind
The libclang cursor kind corresponding to this code-completion result.
Definition ASTUnit.h:290
CXAvailabilityKind Availability
The availability of this code-completion result.
Definition ASTUnit.h:293
unsigned Priority
The priority given to this code-completion result.
Definition ASTUnit.h:286
SimplifiedTypeClass TypeClass
The simplified type class for a non-macro completion result.
Definition ASTUnit.h:296
uint64_t ShowInContexts
A bitmask that indicates which code-completion contexts should contain this completion result.
Definition ASTUnit.h:283
CodeCompletionString * Completion
The code-completion string corresponding to this completion result.
Definition ASTUnit.h:274