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