clang 23.0.0git
SourceManager.h
Go to the documentation of this file.
1//===- SourceManager.h - Track and cache source files -----------*- 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/// \file
10/// Defines the SourceManager interface.
11///
12/// There are three different types of locations in a %file: a spelling
13/// location, an expansion location, and a presumed location.
14///
15/// Given an example of:
16/// \code
17/// #define min(x, y) x < y ? x : y
18/// \endcode
19///
20/// and then later on a use of min:
21/// \code
22/// #line 17
23/// return min(a, b);
24/// \endcode
25///
26/// The expansion location is the line in the source code where the macro
27/// was expanded (the return statement), the spelling location is the
28/// location in the source where the macro was originally defined,
29/// and the presumed location is where the line directive states that
30/// the line is 17, or any other line.
31//
32//===----------------------------------------------------------------------===//
33
34#ifndef LLVM_CLANG_BASIC_SOURCEMANAGER_H
35#define LLVM_CLANG_BASIC_SOURCEMANAGER_H
36
41#include "llvm/ADT/ArrayRef.h"
42#include "llvm/ADT/BitVector.h"
43#include "llvm/ADT/DenseMap.h"
44#include "llvm/ADT/DenseSet.h"
45#include "llvm/ADT/IntrusiveRefCntPtr.h"
46#include "llvm/ADT/PagedVector.h"
47#include "llvm/ADT/PointerIntPair.h"
48#include "llvm/ADT/SmallVector.h"
49#include "llvm/ADT/StringRef.h"
50#include "llvm/Support/Allocator.h"
51#include "llvm/Support/Compiler.h"
52#include "llvm/Support/MemoryBuffer.h"
53#include <cassert>
54#include <cstddef>
55#include <map>
56#include <memory>
57#include <optional>
58#include <string>
59#include <utility>
60#include <vector>
61
62namespace clang {
63
64class ASTReader;
65class ASTWriter;
66class FileManager;
67class LineTableInfo;
68class SourceManager;
69
70/// Public enums and private classes that are part of the
71/// SourceManager implementation.
72namespace SrcMgr {
73
74/// Indicates whether a file or directory holds normal user code,
75/// system code, or system code which is implicitly 'extern "C"' in C++ mode.
76///
77/// Entire directories can be tagged with this (this is maintained by
78/// DirectoryLookup and friends) as can specific FileInfos when a \#pragma
79/// system_header is seen or in various other cases.
80///
88
89/// Determine whether a file / directory characteristic is for system code.
91 return CK != C_User && CK != C_User_ModuleMap;
92}
93
94/// Determine whether a file characteristic is for a module map.
96 return CK == C_User_ModuleMap || CK == C_System_ModuleMap;
97}
98
99/// Mapping of line offsets into a source file. This does not own the storage
100/// for the line numbers.
102public:
103 explicit operator bool() const { return Storage; }
104 unsigned size() const {
105 assert(Storage);
106 return Storage[0];
107 }
109 assert(Storage);
110 return ArrayRef<unsigned>(Storage + 1, Storage + 1 + size());
111 }
112 const unsigned *begin() const { return getLines().begin(); }
113 const unsigned *end() const { return getLines().end(); }
114 const unsigned &operator[](int I) const { return getLines()[I]; }
115
116 static LineOffsetMapping get(llvm::MemoryBufferRef Buffer,
117 llvm::BumpPtrAllocator &Alloc);
118
119 LineOffsetMapping() = default;
121 llvm::BumpPtrAllocator &Alloc);
122
123private:
124 /// First element is the size, followed by elements at off-by-one indexes.
125 unsigned *Storage = nullptr;
126};
127
128/// One instance of this struct is kept for every file loaded or used.
129///
130/// This object owns the MemoryBuffer object.
131class alignas(8) ContentCache {
132 /// The actual buffer containing the characters from the input
133 /// file.
134 mutable std::unique_ptr<llvm::MemoryBuffer> Buffer;
135
136public:
137 /// Reference to the file entry representing this ContentCache.
138 ///
139 /// This reference does not own the FileEntry object.
140 ///
141 /// It is possible for this to be NULL if the ContentCache encapsulates
142 /// an imaginary text buffer.
143 ///
144 /// FIXME: Make non-optional using a virtual file as needed, remove \c
145 /// Filename and use \c OrigEntry.getNameAsRequested() instead.
147
148 /// References the file which the contents were actually loaded from.
149 ///
150 /// Can be different from 'Entry' if we overridden the contents of one file
151 /// with the contents of another file.
153
154 /// The filename that is used to access OrigEntry.
155 ///
156 /// FIXME: Remove this once OrigEntry is a FileEntryRef with a stable name.
157 StringRef Filename;
158
159 /// A bump pointer allocated array of offsets for each source line.
160 ///
161 /// This is lazily computed. The lines are owned by the SourceManager
162 /// BumpPointerAllocator object.
164
165 /// Indicates whether the buffer itself was provided to override
166 /// the actual file contents.
167 ///
168 /// When true, the original entry may be a virtual file that does not
169 /// exist.
170 LLVM_PREFERRED_TYPE(bool)
172
173 /// True if this content cache was initially created for a source file
174 /// considered to be volatile (likely to change between stat and open).
175 LLVM_PREFERRED_TYPE(bool)
176 unsigned IsFileVolatile : 1;
177
178 /// True if this file may be transient, that is, if it might not
179 /// exist at some later point in time when this content entry is used,
180 /// after serialization and deserialization.
181 LLVM_PREFERRED_TYPE(bool)
182 unsigned IsTransient : 1;
183
184 LLVM_PREFERRED_TYPE(bool)
185 mutable unsigned IsBufferInvalid : 1;
186
191
193
197
198 /// The copy ctor does not allow copies where source object has either
199 /// a non-NULL Buffer or SourceLineCache. Ownership of allocated memory
200 /// is not transferred, so this is a logical error.
204 OrigEntry = RHS.OrigEntry;
206
207 assert(!RHS.Buffer && !RHS.SourceLineCache &&
208 "Passed ContentCache object cannot own a buffer.");
209 }
210
211 ContentCache &operator=(const ContentCache &RHS) = delete;
212
213 /// Returns the memory buffer for the associated content.
214 ///
215 /// \param Diag Object through which diagnostics will be emitted if the
216 /// buffer cannot be retrieved.
217 ///
218 /// \param Loc If specified, is the location that invalid file diagnostics
219 /// will be emitted at.
220 std::optional<llvm::MemoryBufferRef>
222 SourceLocation Loc = SourceLocation()) const;
223
224 /// Returns the size of the content encapsulated by this
225 /// ContentCache.
226 ///
227 /// This can be the size of the source file or the size of an
228 /// arbitrary scratch buffer. If the ContentCache encapsulates a source
229 /// file this size is retrieved from the file's FileEntry.
230 unsigned getSize() const;
231
232 /// Returns the number of bytes actually mapped for this
233 /// ContentCache.
234 ///
235 /// This can be 0 if the MemBuffer was not actually expanded.
236 unsigned getSizeBytesMapped() const;
237
238 /// Returns the kind of memory used to back the memory buffer for
239 /// this content cache. This is used for performance analysis.
240 llvm::MemoryBuffer::BufferKind getMemoryBufferKind() const;
241
242 /// Return the buffer, only if it has been loaded.
243 std::optional<llvm::MemoryBufferRef> getBufferIfLoaded() const {
244 if (Buffer)
245 return Buffer->getMemBufferRef();
246 return std::nullopt;
247 }
248
249 /// Return a StringRef to the source buffer data, only if it has already
250 /// been loaded.
251 std::optional<StringRef> getBufferDataIfLoaded() const {
252 if (Buffer)
253 return Buffer->getBuffer();
254 return std::nullopt;
255 }
256
257 /// Set the buffer.
258 void setBuffer(std::unique_ptr<llvm::MemoryBuffer> B) {
259 IsBufferInvalid = false;
260 Buffer = std::move(B);
261 }
262
263 /// Set the buffer to one that's not owned (or to nullptr).
264 ///
265 /// \pre Buffer cannot already be set.
266 void setUnownedBuffer(std::optional<llvm::MemoryBufferRef> B) {
267 assert(!Buffer && "Expected to be called right after construction");
268 if (B)
269 setBuffer(llvm::MemoryBuffer::getMemBuffer(*B));
270 }
271
272 // If BufStr has an invalid BOM, returns the BOM name; otherwise, returns
273 // nullptr
274 static const char *getInvalidBOM(StringRef BufStr);
275};
276
277// Assert that the \c ContentCache objects will always be 8-byte aligned so
278// that we can pack 3 bits of integer into pointers to such objects.
279static_assert(alignof(ContentCache) >= 8,
280 "ContentCache must be 8-byte aligned.");
281
282/// Information about a FileID, basically just the logical file
283/// that it represents and include stack information.
284///
285/// Each FileInfo has include stack information, indicating where it came
286/// from. This information encodes the \#include chain that a token was
287/// expanded from. The main include file has an invalid IncludeLoc.
288///
289/// FileInfo should not grow larger than ExpansionInfo. Doing so will
290/// cause memory to bloat in compilations with many unloaded macro
291/// expansions, since the two data structurs are stored in a union in
292/// SLocEntry. Extra fields should instead go in "ContentCache *", which
293/// stores file contents and other bits on the side.
294///
295class FileInfo {
297 friend class clang::ASTWriter;
298 friend class clang::ASTReader;
299
300 /// The location of the \#include that brought in this file.
301 ///
302 /// This is an invalid SLOC for the main file (top of the \#include chain).
303 SourceLocation IncludeLoc;
304
305 /// Number of FileIDs (files and macros) that were created during
306 /// preprocessing of this \#include, including this SLocEntry.
307 ///
308 /// Zero means the preprocessor didn't provide such info for this SLocEntry.
309 unsigned NumCreatedFIDs : 31;
310
311 /// Whether this FileInfo has any \#line directives.
312 LLVM_PREFERRED_TYPE(bool)
313 unsigned HasLineDirectives : 1;
314
315 /// The content cache and the characteristic of the file.
316 llvm::PointerIntPair<const ContentCache *, 3, CharacteristicKind>
317 ContentAndKind;
318
319public:
320 /// Return a FileInfo object.
322 CharacteristicKind FileCharacter, StringRef Filename) {
323 FileInfo X;
324 X.IncludeLoc = IL;
325 X.NumCreatedFIDs = 0;
326 X.HasLineDirectives = false;
327 X.ContentAndKind.setPointer(&Con);
328 X.ContentAndKind.setInt(FileCharacter);
329 Con.Filename = Filename;
330 return X;
331 }
332
334 return IncludeLoc;
335 }
336
338 return *ContentAndKind.getPointer();
339 }
340
341 /// Return whether this is a system header or not.
343 return ContentAndKind.getInt();
344 }
345
346 /// Return true if this FileID has \#line directives in it.
347 bool hasLineDirectives() const { return HasLineDirectives; }
348
349 /// Set the flag that indicates that this FileID has
350 /// line table entries associated with it.
351 void setHasLineDirectives() { HasLineDirectives = true; }
352
353 /// Returns the name of the file that was used when the file was loaded from
354 /// the underlying file system.
355 StringRef getName() const { return getContentCache().Filename; }
356};
357
358/// Each ExpansionInfo encodes the expansion location - where
359/// the token was ultimately expanded, and the SpellingLoc - where the actual
360/// character data for the token came from.
362 // Really these are all SourceLocations.
363
364 /// Where the spelling for the token can be found.
365 SourceLocation SpellingLoc;
366
367 /// In a macro expansion, ExpansionLocStart and ExpansionLocEnd
368 /// indicate the start and end of the expansion. In object-like macros,
369 /// they will be the same. In a function-like macro expansion, the start
370 /// will be the identifier and the end will be the ')'. Finally, in
371 /// macro-argument instantiations, the end will be 'SourceLocation()', an
372 /// invalid location.
373 SourceLocation ExpansionLocStart, ExpansionLocEnd;
374
375 /// Whether the expansion range is a token range.
376 bool ExpansionIsTokenRange;
377
378public:
380 return SpellingLoc.isInvalid() ? getExpansionLocStart() : SpellingLoc;
381 }
382
384 return ExpansionLocStart;
385 }
386
388 return ExpansionLocEnd.isInvalid() ? getExpansionLocStart()
389 : ExpansionLocEnd;
390 }
391
392 bool isExpansionTokenRange() const { return ExpansionIsTokenRange; }
393
399
400 bool isMacroArgExpansion() const {
401 // Note that this needs to return false for default constructed objects.
402 return getExpansionLocStart().isValid() && ExpansionLocEnd.isInvalid();
403 }
404
405 bool isMacroBodyExpansion() const {
406 return getExpansionLocStart().isValid() && ExpansionLocEnd.isValid();
407 }
408
413
414 /// Return a ExpansionInfo for an expansion.
415 ///
416 /// Start and End specify the expansion range (where the macro is
417 /// expanded), and SpellingLoc specifies the spelling location (where
418 /// the characters from the token come from). All three can refer to
419 /// normal File SLocs or expansion locations.
421 SourceLocation End,
422 bool ExpansionIsTokenRange = true) {
424 X.SpellingLoc = SpellingLoc;
425 X.ExpansionLocStart = Start;
426 X.ExpansionLocEnd = End;
427 X.ExpansionIsTokenRange = ExpansionIsTokenRange;
428 return X;
429 }
430
431 /// Return a special ExpansionInfo for the expansion of
432 /// a macro argument into a function-like macro's body.
433 ///
434 /// ExpansionLoc specifies the expansion location (where the macro is
435 /// expanded). This doesn't need to be a range because a macro is always
436 /// expanded at a macro parameter reference, and macro parameters are
437 /// always exactly one token. SpellingLoc specifies the spelling location
438 /// (where the characters from the token come from). ExpansionLoc and
439 /// SpellingLoc can both refer to normal File SLocs or expansion locations.
440 ///
441 /// Given the code:
442 /// \code
443 /// #define F(x) f(x)
444 /// F(42);
445 /// \endcode
446 ///
447 /// When expanding '\c F(42)', the '\c x' would call this with an
448 /// SpellingLoc pointing at '\c 42' and an ExpansionLoc pointing at its
449 /// location in the definition of '\c F'.
451 SourceLocation ExpansionLoc) {
452 // We store an intentionally invalid source location for the end of the
453 // expansion range to mark that this is a macro argument location rather
454 // than a normal one.
455 return create(SpellingLoc, ExpansionLoc, SourceLocation());
456 }
457
458 /// Return a special ExpansionInfo representing a token that ends
459 /// prematurely. This is used to model a '>>' token that has been split
460 /// into '>' tokens and similar cases. Unlike for the other forms of
461 /// expansion, the expansion range in this case is a character range, not
462 /// a token range.
464 SourceLocation Start,
465 SourceLocation End) {
466 return create(SpellingLoc, Start, End, false);
467 }
468};
469
470// Assert that the \c FileInfo objects are no bigger than \c ExpansionInfo
471// objects. This controls the size of \c SLocEntry, of which we have one for
472// each macro expansion. The number of (unloaded) macro expansions can be
473// very large. Any other fields needed in FileInfo should go in ContentCache.
474static_assert(sizeof(FileInfo) <= sizeof(ExpansionInfo),
475 "FileInfo must be no larger than ExpansionInfo.");
476
477/// This is a discriminated union of FileInfo and ExpansionInfo.
478///
479/// SourceManager keeps an array of these objects, and they are uniquely
480/// identified by the FileID datatype.
482 static constexpr int OffsetBits = 8 * sizeof(SourceLocation::UIntTy) - 1;
483 SourceLocation::UIntTy Offset : OffsetBits;
484 LLVM_PREFERRED_TYPE(bool)
485 SourceLocation::UIntTy IsExpansion : 1;
486 union {
489 };
490
491public:
492 SLocEntry() : Offset(), IsExpansion(), File() {}
493
494 SourceLocation::UIntTy getOffset() const { return Offset; }
495
496 bool isExpansion() const { return IsExpansion; }
497 bool isFile() const { return !isExpansion(); }
498
499 const FileInfo &getFile() const {
500 return const_cast<SLocEntry *>(this)->getFile();
501 }
502
504 assert(isFile() && "Not a file SLocEntry!");
505 return File;
506 }
507
509 assert(isExpansion() && "Not a macro expansion SLocEntry!");
510 return Expansion;
511 }
512
513 /// Creates an incomplete SLocEntry that is only able to report its offset.
515 assert(!(Offset & (1ULL << OffsetBits)) && "Offset is too large");
516 SLocEntry E;
517 E.Offset = Offset;
518 return E;
519 }
520
521 static SLocEntry get(SourceLocation::UIntTy Offset, const FileInfo &FI) {
522 assert(!(Offset & (1ULL << OffsetBits)) && "Offset is too large");
523 SLocEntry E;
524 E.Offset = Offset;
525 E.IsExpansion = false;
526 E.File = FI;
527 return E;
528 }
529
531 const ExpansionInfo &Expansion) {
532 assert(!(Offset & (1ULL << OffsetBits)) && "Offset is too large");
533 SLocEntry E;
534 E.Offset = Offset;
535 E.IsExpansion = true;
537 return E;
538 }
539};
540
541} // namespace SrcMgr
542
543/// External source of source location entries.
545public:
547
548 /// Read the source location entry with index ID, which will always be
549 /// less than -1.
550 ///
551 /// \returns true if an error occurred that prevented the source-location
552 /// entry from being loaded.
553 virtual bool ReadSLocEntry(int ID) = 0;
554
555 /// Get the index ID for the loaded SourceLocation offset.
556 ///
557 /// \returns Invalid index ID (0) if an error occurred that prevented the
558 /// SLocEntry from being loaded.
559 virtual int getSLocEntryID(SourceLocation::UIntTy SLocOffset) = 0;
560
561 /// Retrieve the module import location and name for the given ID, if
562 /// in fact it was loaded from a module (rather than, say, a precompiled
563 /// header).
564 virtual std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) = 0;
565};
566
567/// Holds the cache used by isBeforeInTranslationUnit.
568///
569/// The cache structure is complex enough to be worth breaking out of
570/// SourceManager.
572 /// The FileID's of the cached query.
573 ///
574 /// If these match up with a subsequent query, the result can be reused.
575 FileID LQueryFID, RQueryFID;
576
577 /// The relative order of FileIDs that the CommonFID *immediately* includes.
578 ///
579 /// This is used to compare macro expansion locations.
580 bool LChildBeforeRChild;
581
582 /// The file found in common between the two \#include traces, i.e.,
583 /// the nearest common ancestor of the \#include tree.
584 FileID CommonFID;
585
586 /// The offset of the previous query in CommonFID.
587 ///
588 /// Usually, this represents the location of the \#include for QueryFID, but
589 /// if LQueryFID is a parent of RQueryFID (or vice versa) then these can be a
590 /// random token in the parent.
591 unsigned LCommonOffset, RCommonOffset;
592
593public:
595 InBeforeInTUCacheEntry(FileID L, FileID R) : LQueryFID(L), RQueryFID(R) {
596 assert(L != R);
597 }
598
599 /// Return true if the currently cached values match up with
600 /// the specified LHS/RHS query.
601 ///
602 /// If not, we can't use the cache.
603 bool isCacheValid() const {
604 return CommonFID.isValid();
605 }
606
607 /// If the cache is valid, compute the result given the
608 /// specified offsets in the LHS/RHS FileID's.
609 bool getCachedResult(unsigned LOffset, unsigned ROffset) const {
610 // If one of the query files is the common file, use the offset. Otherwise,
611 // use the #include loc in the common file.
612 if (LQueryFID != CommonFID) LOffset = LCommonOffset;
613 if (RQueryFID != CommonFID) ROffset = RCommonOffset;
614
615 // It is common for multiple macro expansions to be "included" from the same
616 // location (expansion location), in which case use the order of the FileIDs
617 // to determine which came first. This will also take care the case where
618 // one of the locations points at the inclusion/expansion point of the other
619 // in which case its FileID will come before the other.
620 if (LOffset == ROffset)
621 return LChildBeforeRChild;
622
623 return LOffset < ROffset;
624 }
625
626 /// Set up a new query.
627 /// If it matches the old query, we can keep the cached answer.
628 void setQueryFIDs(FileID LHS, FileID RHS) {
629 assert(LHS != RHS);
630 if (LQueryFID != LHS || RQueryFID != RHS) {
631 LQueryFID = LHS;
632 RQueryFID = RHS;
633 CommonFID = FileID();
634 }
635 }
636
637 void setCommonLoc(FileID commonFID, unsigned lCommonOffset,
638 unsigned rCommonOffset, bool LParentBeforeRParent) {
639 CommonFID = commonFID;
640 LCommonOffset = lCommonOffset;
641 RCommonOffset = rCommonOffset;
642 LChildBeforeRChild = LParentBeforeRParent;
643 }
644};
645
646/// The stack used when building modules on demand, which is used
647/// to provide a link between the source managers of the different compiler
648/// instances.
650
651/// This class handles loading and caching of source files into memory.
652///
653/// This object owns the MemoryBuffer objects for all of the loaded
654/// files and assigns unique FileID's for each unique \#include chain.
655///
656/// The SourceManager can be queried for information about SourceLocation
657/// objects, turning them into either spelling or expansion locations. Spelling
658/// locations represent where the bytes corresponding to a token came from and
659/// expansion locations represent where the location is in the user's view. In
660/// the case of a macro expansion, for example, the spelling location indicates
661/// where the expanded token came from and the expansion location specifies
662/// where it was expanded.
663class SourceManager : public RefCountedBase<SourceManager> {
664 /// DiagnosticsEngine object.
665 DiagnosticsEngine &Diag;
666
667 FileManager &FileMgr;
668
669 mutable llvm::BumpPtrAllocator ContentCacheAlloc;
670
671 /// Memoized information about all of the files tracked by this
672 /// SourceManager.
673 ///
674 /// This map allows us to merge ContentCache entries based
675 /// on their FileEntry*. All ContentCache objects will thus have unique,
676 /// non-null, FileEntry pointers.
677 llvm::DenseMap<FileEntryRef, SrcMgr::ContentCache*> FileInfos;
678
679 /// True if the ContentCache for files that are overridden by other
680 /// files, should report the original file name. Defaults to true.
681 bool OverridenFilesKeepOriginalName = true;
682
683 /// True if non-system source files should be treated as volatile
684 /// (likely to change while trying to use them). Defaults to false.
685 bool UserFilesAreVolatile;
686
687 /// True if all files read during this compilation should be treated
688 /// as transient (may not be present in later compilations using a module
689 /// file created from this compilation). Defaults to false.
690 bool FilesAreTransient = false;
691
692 struct OverriddenFilesInfoTy {
693 /// Files that have been overridden with the contents from another
694 /// file.
695 llvm::DenseMap<const FileEntry *, FileEntryRef> OverriddenFiles;
696
697 /// Files that were overridden with a memory buffer.
698 llvm::DenseSet<const FileEntry *> OverriddenFilesWithBuffer;
699 };
700
701 /// Lazily create the object keeping overridden files info, since
702 /// it is uncommonly used.
703 std::unique_ptr<OverriddenFilesInfoTy> OverriddenFilesInfo;
704
705 OverriddenFilesInfoTy &getOverriddenFilesInfo() {
706 if (!OverriddenFilesInfo)
707 OverriddenFilesInfo.reset(new OverriddenFilesInfoTy);
708 return *OverriddenFilesInfo;
709 }
710
711 /// Information about various memory buffers that we have read in.
712 ///
713 /// All FileEntry* within the stored ContentCache objects are NULL,
714 /// as they do not refer to a file.
715 std::vector<SrcMgr::ContentCache*> MemBufferInfos;
716
717 /// Per-FileID content caches for aliased file references.
718 ///
719 /// These caches preserve the spelling used for a particular include while
720 /// sharing file contents with the canonical cache in \c FileInfos.
721 std::vector<SrcMgr::ContentCache *> FileIDContentCaches;
722
723 /// The table of SLocEntries that are local to this module.
724 ///
725 /// Positive FileIDs are indexes into this table. Entry 0 indicates an invalid
726 /// expansion.
727 SmallVector<SrcMgr::SLocEntry, 0> LocalSLocEntryTable;
728 /// An in-parallel offset table, merely used for speeding up FileID lookup.
729 SmallVector<SourceLocation::UIntTy> LocalLocOffsetTable;
730
731 /// The table of SLocEntries that are loaded from other modules.
732 ///
733 /// Negative FileIDs are indexes into this table. To get from ID to an index,
734 /// use (-ID - 2).
735 llvm::PagedVector<SrcMgr::SLocEntry, 32> LoadedSLocEntryTable;
736
737 /// For each allocation in LoadedSLocEntryTable, we keep the first FileID.
738 /// We assume exactly one allocation per AST file, and use that to determine
739 /// whether two FileIDs come from the same AST file.
740 SmallVector<FileID, 0> LoadedSLocEntryAllocBegin;
741
742 /// The starting offset of the next local SLocEntry.
743 ///
744 /// This is LocalSLocEntryTable.back().Offset + the size of that entry.
745 SourceLocation::UIntTy NextLocalOffset;
746
747 /// The starting offset of the latest batch of loaded SLocEntries.
748 ///
749 /// This is LoadedSLocEntryTable.back().Offset, except that that entry might
750 /// not have been loaded, so that value would be unknown.
751 SourceLocation::UIntTy CurrentLoadedOffset;
752
753 /// The highest possible offset is 2^31-1 (2^63-1 for 64-bit source
754 /// locations), so CurrentLoadedOffset starts at 2^31 (2^63 resp.).
755 static const SourceLocation::UIntTy MaxLoadedOffset =
756 1ULL << (8 * sizeof(SourceLocation::UIntTy) - 1);
757
758 /// A bitmap that indicates whether the entries of LoadedSLocEntryTable
759 /// have already been loaded from the external source.
760 ///
761 /// Same indexing as LoadedSLocEntryTable.
762 llvm::BitVector SLocEntryLoaded;
763
764 /// A bitmap that indicates whether the entries of LoadedSLocEntryTable
765 /// have already had their offset loaded from the external source.
766 ///
767 /// Superset of SLocEntryLoaded. Same indexing as SLocEntryLoaded.
768 llvm::BitVector SLocEntryOffsetLoaded;
769
770 /// An external source for source location entries.
771 ExternalSLocEntrySource *ExternalSLocEntries = nullptr;
772
773 /// A one-entry cache to speed up getFileID.
774 ///
775 /// LastFileIDLookup records the last FileID looked up or created, because it
776 /// is very common to look up many tokens from the same file.
777 mutable FileID LastFileIDLookup;
778 mutable SourceLocation::UIntTy LastLookupStartOffset;
779 mutable SourceLocation::UIntTy LastLookupEndOffset; // exclude
780
781 /// Holds information for \#line directives.
782 ///
783 /// This is referenced by indices from SLocEntryTable.
784 std::unique_ptr<LineTableInfo> LineTable;
785
786 /// These ivars serve as a cache used in the getLineNumber
787 /// method which is used to speedup getLineNumber calls to nearby locations.
788 mutable FileID LastLineNoFileIDQuery;
789 mutable const SrcMgr::ContentCache *LastLineNoContentCache;
790 mutable unsigned LastLineNoFilePos;
791 mutable unsigned LastLineNoResult;
792
793 /// The file ID for the main source file of the translation unit.
794 FileID MainFileID;
795
796 /// The file ID for the precompiled preamble there is one.
797 FileID PreambleFileID;
798
799 // Statistics for -print-stats.
800 mutable unsigned NumLinearScans = 0;
801 mutable unsigned NumBinaryProbes = 0;
802
803 /// Associates a FileID with its "included/expanded in" decomposed
804 /// location.
805 ///
806 /// Used to cache results from and speed-up \c getDecomposedIncludedLoc
807 /// function.
808 mutable llvm::DenseMap<FileID, FileIDAndOffset> IncludedLocMap;
809
810 /// The key value into the IsBeforeInTUCache table.
811 using IsBeforeInTUCacheKey = std::pair<FileID, FileID>;
812
813 /// The IsBeforeInTranslationUnitCache is a mapping from FileID pairs
814 /// to cache results.
815 using InBeforeInTUCache =
816 llvm::DenseMap<IsBeforeInTUCacheKey, InBeforeInTUCacheEntry>;
817
818 /// Cache results for the isBeforeInTranslationUnit method.
819 mutable InBeforeInTUCache IBTUCache;
820 mutable InBeforeInTUCacheEntry IBTUCacheOverflow;
821
822 /// Return the cache entry for comparing the given file IDs
823 /// for isBeforeInTranslationUnit.
824 InBeforeInTUCacheEntry &getInBeforeInTUCache(FileID LFID, FileID RFID) const;
825
826 // Cache for the "fake" buffer used for error-recovery purposes.
827 mutable std::unique_ptr<llvm::MemoryBuffer> FakeBufferForRecovery;
828
829 mutable std::unique_ptr<SrcMgr::ContentCache> FakeContentCacheForRecovery;
830
831 mutable std::unique_ptr<SrcMgr::SLocEntry> FakeSLocEntryForRecovery;
832
833 /// Lazily computed map of macro argument chunks to their expanded
834 /// source location.
835 using MacroArgsMap = std::map<unsigned, SourceLocation>;
836
837 mutable llvm::DenseMap<FileID, std::unique_ptr<MacroArgsMap>>
838 MacroArgsCacheMap;
839
840 /// The stack of modules being built, which is used to detect
841 /// cycles in the module dependency graph as modules are being built, as
842 /// well as to describe why we're rebuilding a particular module.
843 ///
844 /// There is no way to set this value from the command line. If we ever need
845 /// to do so (e.g., if on-demand module construction moves out-of-process),
846 /// we can add a cc1-level option to do so.
847 SmallVector<std::pair<std::string, FullSourceLoc>, 2> StoredModuleBuildStack;
848
849public:
851 bool UserFilesAreVolatile = false);
852 explicit SourceManager(const SourceManager &) = delete;
855
856 void clearIDTables();
857
858 /// Initialize this source manager suitably to replay the compilation
859 /// described by \p Old. Requires that \p Old outlive \p *this.
860 void initializeForReplay(const SourceManager &Old);
861
862 DiagnosticsEngine &getDiagnostics() const { return Diag; }
863
864 FileManager &getFileManager() const { return FileMgr; }
865
866 /// Set true if the SourceManager should report the original file name
867 /// for contents of files that were overridden by other files. Defaults to
868 /// true.
870 OverridenFilesKeepOriginalName = value;
871 }
872
873 /// True if non-system source files should be treated as volatile
874 /// (likely to change while trying to use them).
875 bool userFilesAreVolatile() const { return UserFilesAreVolatile; }
876
877 /// Retrieve the module build stack.
879 return StoredModuleBuildStack;
880 }
881
882 /// Set the module build stack.
884 StoredModuleBuildStack.clear();
885 StoredModuleBuildStack.append(stack.begin(), stack.end());
886 }
887
888 /// Push an entry to the module build stack.
889 void pushModuleBuildStack(StringRef moduleName, FullSourceLoc importLoc) {
890 StoredModuleBuildStack.push_back(std::make_pair(moduleName.str(),importLoc));
891 }
892
893 //===--------------------------------------------------------------------===//
894 // MainFileID creation and querying methods.
895 //===--------------------------------------------------------------------===//
896
897 /// Returns the FileID of the main source file.
898 FileID getMainFileID() const { return MainFileID; }
899
900 /// Set the file ID for the main source file.
902 MainFileID = FID;
903 }
904
905 /// Returns true when the given FileEntry corresponds to the main file.
906 ///
907 /// The main file should be set prior to calling this function.
908 bool isMainFile(const FileEntry &SourceFile);
909
910 /// Set the file ID for the precompiled preamble.
912 assert(PreambleFileID.isInvalid() && "PreambleFileID already set!");
913 PreambleFileID = Preamble;
914 }
915
916 /// Get the file ID for the precompiled preamble if there is one.
917 FileID getPreambleFileID() const { return PreambleFileID; }
918
919 //===--------------------------------------------------------------------===//
920 // Methods to create new FileID's and macro expansions.
921 //===--------------------------------------------------------------------===//
922
923 /// Create a new FileID that represents the specified file
924 /// being \#included from the specified IncludePosition.
925 FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos,
926 SrcMgr::CharacteristicKind FileCharacter,
927 int LoadedID = 0,
928 SourceLocation::UIntTy LoadedOffset = 0);
929
930 /// Create a new FileID that represents the specified memory buffer.
931 ///
932 /// This does no caching of the buffer and takes ownership of the
933 /// MemoryBuffer, so only pass a MemoryBuffer to this once.
934 FileID createFileID(std::unique_ptr<llvm::MemoryBuffer> Buffer,
936 int LoadedID = 0, SourceLocation::UIntTy LoadedOffset = 0,
937 SourceLocation IncludeLoc = SourceLocation());
938
939 /// Create a new FileID that represents the specified memory buffer.
940 ///
941 /// This does not take ownership of the MemoryBuffer. The memory buffer must
942 /// outlive the SourceManager.
943 FileID createFileID(const llvm::MemoryBufferRef &Buffer,
945 int LoadedID = 0, SourceLocation::UIntTy LoadedOffset = 0,
946 SourceLocation IncludeLoc = SourceLocation());
947
948 /// Get the FileID for \p SourceFile if it exists. Otherwise, create a
949 /// new FileID for the \p SourceFile.
951 SrcMgr::CharacteristicKind FileCharacter);
952
953 /// Creates an expansion SLocEntry for the substitution of an argument into a
954 /// function-like macro's body. Returns the start of the expansion.
955 ///
956 /// The macro argument was written at \p SpellingLoc with length \p Length.
957 /// \p ExpansionLoc is the parameter name in the (expanded) macro body.
959 SourceLocation ExpansionLoc,
960 unsigned Length);
961
962 /// Creates an expansion SLocEntry for a macro use. Returns its start.
963 ///
964 /// The macro body begins at \p SpellingLoc with length \p Length.
965 /// The macro use spans [ExpansionLocStart, ExpansionLocEnd].
967 SourceLocation ExpansionLocStart,
968 SourceLocation ExpansionLocEnd,
969 unsigned Length,
970 bool ExpansionIsTokenRange = true,
971 int LoadedID = 0,
972 SourceLocation::UIntTy LoadedOffset = 0);
973
974 /// Return a new SourceLocation that encodes that the token starting
975 /// at \p TokenStart ends prematurely at \p TokenEnd.
977 SourceLocation TokenStart,
978 SourceLocation TokenEnd);
979
980 /// Retrieve the memory buffer associated with the given file.
981 ///
982 /// Returns std::nullopt if the buffer is not valid.
983 std::optional<llvm::MemoryBufferRef>
985
986 /// Retrieve the memory buffer associated with the given file.
987 ///
988 /// Returns a fake buffer if there isn't a real one.
991 return *B;
992 return getFakeBufferForRecovery();
993 }
994
995 /// Override the contents of the given source file by providing an
996 /// already-allocated buffer.
997 ///
998 /// \param SourceFile the source file whose contents will be overridden.
999 ///
1000 /// \param Buffer the memory buffer whose contents will be used as the
1001 /// data in the given source file.
1003 const llvm::MemoryBufferRef &Buffer) {
1004 overrideFileContents(SourceFile, llvm::MemoryBuffer::getMemBuffer(Buffer));
1005 }
1006
1007 /// Override the contents of the given source file by providing an
1008 /// already-allocated buffer.
1009 ///
1010 /// \param SourceFile the source file whose contents will be overridden.
1011 ///
1012 /// \param Buffer the memory buffer whose contents will be used as the
1013 /// data in the given source file.
1014 void overrideFileContents(FileEntryRef SourceFile,
1015 std::unique_ptr<llvm::MemoryBuffer> Buffer);
1016
1017 /// Override the given source file with another one.
1018 ///
1019 /// \param SourceFile the source file which will be overridden.
1020 ///
1021 /// \param NewFile the file whose contents will be used as the
1022 /// data instead of the contents of the given source file.
1023 void overrideFileContents(const FileEntry *SourceFile, FileEntryRef NewFile);
1024
1025 /// Returns true if the file contents have been overridden.
1026 bool isFileOverridden(const FileEntry *File) const {
1027 if (OverriddenFilesInfo) {
1028 if (OverriddenFilesInfo->OverriddenFilesWithBuffer.count(File))
1029 return true;
1030 if (OverriddenFilesInfo->OverriddenFiles.contains(File))
1031 return true;
1032 }
1033 return false;
1034 }
1035
1036 /// Bypass the overridden contents of a file. This creates a new FileEntry
1037 /// and initializes the content cache for it. Returns std::nullopt if there
1038 /// is no such file in the filesystem.
1039 ///
1040 /// This should be called before parsing has begun.
1042
1043 /// Specify that a file is transient.
1044 void setFileIsTransient(FileEntryRef SourceFile);
1045
1046 /// Specify that all files that are read during this compilation are
1047 /// transient.
1048 void setAllFilesAreTransient(bool Transient) {
1049 FilesAreTransient = Transient;
1050 }
1051
1052 //===--------------------------------------------------------------------===//
1053 // FileID manipulation methods.
1054 //===--------------------------------------------------------------------===//
1055
1056 /// Return the buffer for the specified FileID.
1057 ///
1058 /// If there is an error opening this buffer the first time, return
1059 /// std::nullopt.
1060 std::optional<llvm::MemoryBufferRef>
1062 if (auto *Entry = getSLocEntryForFile(FID))
1063 return Entry->getFile().getContentCache().getBufferOrNone(
1064 Diag, getFileManager(), Loc);
1065 return std::nullopt;
1066 }
1067
1068 /// Return the buffer for the specified FileID.
1069 ///
1070 /// If there is an error opening this buffer the first time, this
1071 /// manufactures a temporary buffer and returns it.
1072 llvm::MemoryBufferRef
1074 if (auto B = getBufferOrNone(FID, Loc))
1075 return *B;
1076 return getFakeBufferForRecovery();
1077 }
1078
1079 /// Returns the FileEntry record for the provided FileID.
1081 if (auto FE = getFileEntryRefForID(FID))
1082 return *FE;
1083 return nullptr;
1084 }
1085
1086 /// Returns the FileEntryRef for the provided FileID.
1088 if (auto *Entry = getSLocEntryForFile(FID))
1089 return Entry->getFile().getContentCache().OrigEntry;
1090 return std::nullopt;
1091 }
1092
1093 /// Returns the filename for the provided FileID, unless it's a built-in
1094 /// buffer that's not represented by a filename.
1095 ///
1096 /// Returns std::nullopt for non-files and built-in files.
1097 std::optional<StringRef> getNonBuiltinFilenameForID(FileID FID) const;
1098
1099 /// Returns the FileEntry record for the provided SLocEntry.
1100 const FileEntry *
1102 if (auto FE = SLocEntry.getFile().getContentCache().OrigEntry)
1103 return *FE;
1104 return nullptr;
1105 }
1106
1107 /// Return a StringRef to the source buffer data for the
1108 /// specified FileID.
1109 ///
1110 /// \param FID The file ID whose contents will be returned.
1111 /// \param Invalid If non-NULL, will be set true if an error occurred.
1112 StringRef getBufferData(FileID FID, bool *Invalid = nullptr) const;
1113
1114 /// Return a StringRef to the source buffer data for the
1115 /// specified FileID, returning std::nullopt if invalid.
1116 ///
1117 /// \param FID The file ID whose contents will be returned.
1118 std::optional<StringRef> getBufferDataOrNone(FileID FID) const;
1119
1120 /// Return a StringRef to the source buffer data for the
1121 /// specified FileID, returning std::nullopt if it's not yet loaded.
1122 ///
1123 /// \param FID The file ID whose contents will be returned.
1124 std::optional<StringRef> getBufferDataIfLoaded(FileID FID) const;
1125
1126 /// Get the number of FileIDs (files and macros) that were created
1127 /// during preprocessing of \p FID, including it.
1129 if (auto *Entry = getSLocEntryForFile(FID))
1130 return Entry->getFile().NumCreatedFIDs;
1131 return 0;
1132 }
1133
1134 /// Set the number of FileIDs (files and macros) that were created
1135 /// during preprocessing of \p FID, including it.
1136 void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs,
1137 bool Force = false) {
1138 auto *Entry = getSLocEntryForFile(FID);
1139 if (!Entry)
1140 return;
1141 assert((Force || Entry->getFile().NumCreatedFIDs == 0) && "Already set!");
1142 Entry->getFile().NumCreatedFIDs = NumFIDs;
1143 }
1144
1145 //===--------------------------------------------------------------------===//
1146 // SourceLocation manipulation methods.
1147 //===--------------------------------------------------------------------===//
1148
1149 /// Return the FileID for a SourceLocation.
1150 ///
1151 /// This is a very hot method that is used for all SourceManager queries
1152 /// that start with a SourceLocation object. It is responsible for finding
1153 /// the entry in SLocEntryTable which contains the specified location.
1154 ///
1155 FileID getFileID(SourceLocation SpellingLoc) const {
1156 return getFileID(SpellingLoc.getOffset());
1157 }
1158
1159 /// Return the filename of the file containing a SourceLocation.
1160 StringRef getFilename(SourceLocation SpellingLoc) const;
1161
1162 /// Return the source location corresponding to the first byte of
1163 /// the specified file.
1165 if (auto *Entry = getSLocEntryForFile(FID))
1166 return SourceLocation::getFileLoc(Entry->getOffset());
1167 return SourceLocation();
1168 }
1169
1170 /// Return the source location corresponding to the last byte of the
1171 /// specified file.
1173 if (auto *Entry = getSLocEntryForFile(FID))
1174 return SourceLocation::getFileLoc(Entry->getOffset() +
1175 getFileIDSize(FID));
1176 return SourceLocation();
1177 }
1178
1179 /// Returns the include location if \p FID is a \#include'd file
1180 /// otherwise it returns an invalid location.
1182 if (auto *Entry = getSLocEntryForFile(FID))
1183 return Entry->getFile().getIncludeLoc();
1184 return SourceLocation();
1185 }
1186
1187 // Returns the import location if the given source location is
1188 // located within a module, or an invalid location if the source location
1189 // is within the current translation unit.
1190 std::pair<SourceLocation, StringRef>
1192 FileID FID = getFileID(Loc);
1193
1194 // Positive file IDs are in the current translation unit, and -1 is a
1195 // placeholder.
1196 if (FID.ID >= -1)
1197 return std::make_pair(SourceLocation(), "");
1198
1199 return ExternalSLocEntries->getModuleImportLoc(FID.ID);
1200 }
1201
1202 /// Given a SourceLocation object \p Loc, return the expansion
1203 /// location referenced by the ID.
1205 // Handle the non-mapped case inline, defer to out of line code to handle
1206 // expansions.
1207 if (Loc.isFileID()) return Loc;
1208 return getExpansionLocSlowCase(Loc);
1209 }
1210
1211 /// Given \p Loc, if it is a macro location return the expansion
1212 /// location or the spelling location, depending on if it comes from a
1213 /// macro argument or not.
1215 if (Loc.isFileID()) return Loc;
1216 return getFileLocSlowCase(Loc);
1217 }
1218
1219 /// Return the start/end of the expansion information for an
1220 /// expansion location.
1221 ///
1222 /// \pre \p Loc is required to be an expansion location.
1224
1225 /// Given a SourceLocation object, return the range of
1226 /// tokens covered by the expansion in the ultimate file.
1228
1229 /// Given a SourceRange object, return the range of
1230 /// tokens or characters covered by the expansion in the ultimate file.
1232 SourceLocation Begin = getExpansionRange(Range.getBegin()).getBegin();
1233 CharSourceRange End = getExpansionRange(Range.getEnd());
1234 return CharSourceRange(SourceRange(Begin, End.getEnd()),
1235 End.isTokenRange());
1236 }
1237
1238 /// Given a CharSourceRange object, return the range of
1239 /// tokens or characters covered by the expansion in the ultimate file.
1241 CharSourceRange Expansion = getExpansionRange(Range.getAsRange());
1242 if (Expansion.getEnd() == Range.getEnd())
1243 Expansion.setTokenRange(Range.isTokenRange());
1244 return Expansion;
1245 }
1246
1247 /// Given a SourceLocation object, return the spelling
1248 /// location referenced by the ID.
1249 ///
1250 /// This is the place where the characters that make up the lexed token
1251 /// can be found.
1253 // Handle the non-mapped case inline, defer to out of line code to handle
1254 // expansions.
1255 if (Loc.isFileID()) return Loc;
1256 return getSpellingLocSlowCase(Loc);
1257 }
1258
1259 /// Given a SourceLocation object, return the spelling location
1260 /// referenced by the ID.
1261 ///
1262 /// This is the first level down towards the place where the characters
1263 /// that make up the lexed token can be found. This should not generally
1264 /// be used by clients.
1266
1267 /// Form a SourceLocation from a FileID and Offset pair.
1268 SourceLocation getComposedLoc(FileID FID, unsigned Offset) const {
1269 auto *Entry = getSLocEntryOrNull(FID);
1270 if (!Entry)
1271 return SourceLocation();
1272
1273 SourceLocation::UIntTy GlobalOffset = Entry->getOffset() + Offset;
1274 return Entry->isFile() ? SourceLocation::getFileLoc(GlobalOffset)
1275 : SourceLocation::getMacroLoc(GlobalOffset);
1276 }
1277
1278 /// Decompose the specified location into a raw FileID + Offset pair.
1279 ///
1280 /// The first element is the FileID, the second is the offset from the
1281 /// start of the buffer of the location.
1283 FileID FID = getFileID(Loc);
1284 auto *Entry = getSLocEntryOrNull(FID);
1285 if (!Entry)
1286 return std::make_pair(FileID(), 0);
1287 return std::make_pair(FID, Loc.getOffset() - Entry->getOffset());
1288 }
1289
1290 /// Decompose the specified location into a raw FileID + Offset pair.
1291 ///
1292 /// If the location is an expansion record, walk through it until we find
1293 /// the final location expanded.
1297
1298 /// Decompose the specified location into a raw FileID + Offset pair.
1299 ///
1300 /// If the location is an expansion record, walk through it until we find
1301 /// its spelling record.
1305
1306 /// Returns the "included/expanded in" decomposed location of the given
1307 /// FileID.
1309
1310 /// Returns the offset from the start of the file that the
1311 /// specified SourceLocation represents.
1312 ///
1313 /// This is not very meaningful for a macro ID.
1314 unsigned getFileOffset(SourceLocation SpellingLoc) const {
1315 return getDecomposedLoc(SpellingLoc).second;
1316 }
1317
1318 /// Tests whether the given source location represents a macro
1319 /// argument's expansion into the function-like macro definition.
1320 ///
1321 /// \param StartLoc If non-null and function returns true, it is set to the
1322 /// start location of the macro argument expansion.
1323 ///
1324 /// Such source locations only appear inside of the expansion
1325 /// locations representing where a particular function-like macro was
1326 /// expanded.
1328 SourceLocation *StartLoc = nullptr) const;
1329
1330 /// Tests whether the given source location represents the expansion of
1331 /// a macro body.
1332 ///
1333 /// This is equivalent to testing whether the location is part of a macro
1334 /// expansion but not the expansion of an argument to a function-like macro.
1335 bool isMacroBodyExpansion(SourceLocation Loc) const;
1336
1337 /// Returns true if the given MacroID location points at the beginning
1338 /// of the immediate macro expansion.
1339 ///
1340 /// \param MacroBegin If non-null and function returns true, it is set to the
1341 /// begin location of the immediate macro expansion.
1343 SourceLocation *MacroBegin = nullptr) const;
1344
1345 /// Returns true if the given MacroID location points at the character
1346 /// end of the immediate macro expansion.
1347 ///
1348 /// \param MacroEnd If non-null and function returns true, it is set to the
1349 /// character end location of the immediate macro expansion.
1350 bool
1352 SourceLocation *MacroEnd = nullptr) const;
1353
1354 /// Returns true if \p Loc is inside the [\p Start, +\p Length)
1355 /// chunk of the source location address space.
1356 ///
1357 /// If it's true and \p RelativeOffset is non-null, it will be set to the
1358 /// relative offset of \p Loc inside the chunk.
1359 bool
1361 SourceLocation::UIntTy *RelativeOffset = nullptr) const {
1362 assert(((Start.getOffset() < NextLocalOffset &&
1363 Start.getOffset()+Length <= NextLocalOffset) ||
1364 (Start.getOffset() >= CurrentLoadedOffset &&
1365 Start.getOffset()+Length < MaxLoadedOffset)) &&
1366 "Chunk is not valid SLoc address space");
1367 SourceLocation::UIntTy LocOffs = Loc.getOffset();
1368 SourceLocation::UIntTy BeginOffs = Start.getOffset();
1369 SourceLocation::UIntTy EndOffs = BeginOffs + Length;
1370 if (LocOffs >= BeginOffs && LocOffs < EndOffs) {
1371 if (RelativeOffset)
1372 *RelativeOffset = LocOffs - BeginOffs;
1373 return true;
1374 }
1375
1376 return false;
1377 }
1378
1379 /// Return true if both \p LHS and \p RHS are in the local source
1380 /// location address space or the loaded one.
1381 ///
1382 /// If it's true and \p RelativeOffset is non-null, it will be set to the
1383 /// offset of \p RHS relative to \p LHS.
1385 SourceLocation::IntTy *RelativeOffset) const {
1386 SourceLocation::UIntTy LHSOffs = LHS.getOffset(), RHSOffs = RHS.getOffset();
1387 bool LHSLoaded = LHSOffs >= CurrentLoadedOffset;
1388 bool RHSLoaded = RHSOffs >= CurrentLoadedOffset;
1389
1390 if (LHSLoaded == RHSLoaded) {
1391 if (RelativeOffset)
1392 *RelativeOffset = RHSOffs - LHSOffs;
1393 return true;
1394 }
1395
1396 return false;
1397 }
1398
1399 //===--------------------------------------------------------------------===//
1400 // Queries about the code at a SourceLocation.
1401 //===--------------------------------------------------------------------===//
1402
1403 /// Return a pointer to the start of the specified location
1404 /// in the appropriate spelling MemoryBuffer.
1405 ///
1406 /// \param Invalid If non-NULL, will be set \c true if an error occurs.
1407 const char *getCharacterData(SourceLocation SL,
1408 bool *Invalid = nullptr) const;
1409
1410 /// Return the column # for the specified file position.
1411 ///
1412 /// This is significantly cheaper to compute than the line number. This
1413 /// returns zero if the column number isn't known. This may only be called
1414 /// on a file sloc, so you must choose a spelling or expansion location
1415 /// before calling this method.
1416 unsigned getColumnNumber(FileID FID, unsigned FilePos,
1417 bool *Invalid = nullptr) const;
1418 unsigned getColumnNumber(SourceLocation Loc, bool *Invalid = nullptr) const;
1420 bool *Invalid = nullptr) const {
1422 }
1424 bool *Invalid = nullptr) const {
1426 }
1428 bool *Invalid = nullptr) const;
1429
1430 /// Given a SourceLocation, return the spelling line number
1431 /// for the position indicated.
1432 ///
1433 /// This requires building and caching a table of line offsets for the
1434 /// MemoryBuffer, so this is not cheap: use only when about to emit a
1435 /// diagnostic.
1436 unsigned getLineNumber(FileID FID, unsigned FilePos, bool *Invalid = nullptr) const;
1437 unsigned getLineNumber(SourceLocation Loc, bool *Invalid = nullptr) const;
1439 bool *Invalid = nullptr) const {
1440 return getLineNumber(getSpellingLoc(Loc), Invalid);
1441 }
1443 bool *Invalid = nullptr) const {
1445 }
1446 unsigned getPresumedLineNumber(SourceLocation Loc, bool *Invalid = nullptr) const;
1447
1448 /// Return the filename or buffer identifier of the buffer the
1449 /// location is in.
1450 ///
1451 /// Note that this name does not respect \#line directives. Use
1452 /// getPresumedLoc for normal clients.
1453 StringRef getBufferName(SourceLocation Loc, bool *Invalid = nullptr) const;
1454
1455 /// Return the file characteristic of the specified source
1456 /// location, indicating whether this is a normal file, a system
1457 /// header, or an "implicit extern C" system header.
1458 ///
1459 /// This state can be modified with flags on GNU linemarker directives like:
1460 /// \code
1461 /// # 4 "foo.h" 3
1462 /// \endcode
1463 /// which changes all source locations in the current file after that to be
1464 /// considered to be from a system header.
1466
1467 /// Returns the "presumed" location of a SourceLocation specifies.
1468 ///
1469 /// A "presumed location" can be modified by \#line or GNU line marker
1470 /// directives. This provides a view on the data that a user should see
1471 /// in diagnostics, for example.
1472 ///
1473 /// Note that a presumed location is always given as the expansion point of
1474 /// an expansion location, not at the spelling location.
1475 ///
1476 /// \returns The presumed location of the specified SourceLocation. If the
1477 /// presumed location cannot be calculated (e.g., because \p Loc is invalid
1478 /// or the file containing \p Loc has changed on disk), returns an invalid
1479 /// presumed location.
1481 bool UseLineDirectives = true) const;
1482
1483 /// Returns whether the PresumedLoc for a given SourceLocation is
1484 /// in the main file.
1485 ///
1486 /// This computes the "presumed" location for a SourceLocation, then checks
1487 /// whether it came from a file other than the main file. This is different
1488 /// from isWrittenInMainFile() because it takes line marker directives into
1489 /// account.
1490 bool isInMainFile(SourceLocation Loc) const;
1491
1492 /// Returns true if the spelling locations for both SourceLocations
1493 /// are part of the same file buffer.
1494 ///
1495 /// This check ignores line marker directives.
1497 return getFileID(Loc1) == getFileID(Loc2);
1498 }
1499
1500 /// Returns true if the spelling location for the given location
1501 /// is in the main file buffer.
1502 ///
1503 /// This check ignores line marker directives.
1505 return getFileID(Loc) == getMainFileID();
1506 }
1507
1508 /// Returns whether \p Loc is located in a <built-in> file.
1510 PresumedLoc Presumed = getPresumedLoc(Loc);
1511 if (Presumed.isInvalid())
1512 return false;
1513 StringRef Filename(Presumed.getFilename());
1514 return Filename == "<built-in>";
1515 }
1516
1517 /// Returns whether \p Loc is located in a <command line> file.
1519 PresumedLoc Presumed = getPresumedLoc(Loc);
1520 if (Presumed.isInvalid())
1521 return false;
1522 StringRef Filename(Presumed.getFilename());
1523 return Filename == "<command line>";
1524 }
1525
1526 /// Returns whether \p Loc is located in a <scratch space> file.
1528 PresumedLoc Presumed = getPresumedLoc(Loc);
1529 if (Presumed.isInvalid())
1530 return false;
1531 StringRef Filename(Presumed.getFilename());
1532 return Filename == "<scratch space>";
1533 }
1534
1535 /// Returns whether \p Loc is located in a <module-includes> file.
1537 PresumedLoc Presumed = getPresumedLoc(Loc);
1538 if (Presumed.isInvalid())
1539 return false;
1540 StringRef Filename(Presumed.getFilename());
1541 return Filename == "<module-includes>";
1542 }
1543
1544 /// Returns whether \p Loc is located in a built-in or command line source.
1546 PresumedLoc Presumed = getPresumedLoc(Loc);
1547 if (Presumed.isInvalid())
1548 return false;
1549 StringRef Filename(Presumed.getFilename());
1550 return Filename == "<built-in>" || Filename == "<command line>";
1551 }
1552
1553 /// Returns if a SourceLocation is in a system header.
1555 if (Loc.isInvalid())
1556 return false;
1557 return isSystem(getFileCharacteristic(Loc));
1558 }
1559
1560 /// Returns if a SourceLocation is in an "extern C" system header.
1564
1565 /// Returns whether \p Loc is expanded from a macro in a system header.
1567 if (!loc.isMacroID())
1568 return false;
1569
1570 // This happens when the macro is the result of a paste, in that case
1571 // its spelling is the scratch memory, so we take the parent context.
1572 // There can be several level of token pasting.
1574 do {
1575 loc = getImmediateMacroCallerLoc(loc);
1577 return isInSystemMacro(loc);
1578 }
1579
1580 return isInSystemHeader(getSpellingLoc(loc));
1581 }
1582
1583 /// The size of the SLocEntry that \p FID represents.
1584 unsigned getFileIDSize(FileID FID) const;
1585
1586 /// Given a specific FileID, returns true if \p Loc is inside that
1587 /// FileID chunk and sets relative offset (offset of \p Loc from beginning
1588 /// of FileID) to \p relativeOffset.
1590 unsigned *RelativeOffset = nullptr) const {
1591 SourceLocation::UIntTy Offs = Loc.getOffset();
1592 if (isOffsetInFileID(FID, Offs)) {
1593 if (RelativeOffset)
1594 *RelativeOffset = Offs - getSLocEntry(FID).getOffset();
1595 return true;
1596 }
1597
1598 return false;
1599 }
1600
1601 //===--------------------------------------------------------------------===//
1602 // Line Table Manipulation Routines
1603 //===--------------------------------------------------------------------===//
1604
1605 /// Return the uniqued ID for the specified filename.
1606 unsigned getLineTableFilenameID(StringRef Str);
1607
1608 /// Add a line note to the line table for the FileID and offset
1609 /// specified by Loc.
1610 ///
1611 /// If FilenameID is -1, it is considered to be unspecified.
1612 void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID,
1613 bool IsFileEntry, bool IsFileExit,
1615
1616 /// Determine if the source manager has a line table.
1617 bool hasLineTable() const { return LineTable != nullptr; }
1618
1619 /// Retrieve the stored line table.
1621
1622 //===--------------------------------------------------------------------===//
1623 // Queries for performance analysis.
1624 //===--------------------------------------------------------------------===//
1625
1626 /// Return the total amount of physical memory allocated by the
1627 /// ContentCache allocator.
1628 size_t getContentCacheSize() const {
1629 return ContentCacheAlloc.getTotalMemory();
1630 }
1631
1639
1640 /// Return the amount of memory used by memory buffers, breaking down
1641 /// by heap-backed versus mmap'ed memory.
1642 MemoryBufferSizes getMemoryBufferSizes() const;
1643
1644 /// Return the amount of memory used for various side tables and
1645 /// data structures in the SourceManager.
1646 size_t getDataStructureSizes() const;
1647
1648 //===--------------------------------------------------------------------===//
1649 // Other miscellaneous methods.
1650 //===--------------------------------------------------------------------===//
1651
1652 /// Get the source location for the given file:line:col triplet.
1653 ///
1654 /// If the source file is included multiple times, the source location will
1655 /// be based upon the first inclusion.
1657 unsigned Line, unsigned Col) const;
1658
1659 /// Get the FileID for the given file.
1660 ///
1661 /// If the source file is included multiple times, the FileID will be the
1662 /// first inclusion.
1663 FileID translateFile(const FileEntry *SourceFile) const;
1665 return translateFile(&SourceFile.getFileEntry());
1666 }
1667
1668 /// Get the source location in \p FID for the given line:col.
1669 /// Returns null location if \p FID is not a file SLocEntry.
1671 unsigned Line, unsigned Col) const;
1672
1673 /// If \p Loc points inside a function macro argument, the returned
1674 /// location will be the macro location in which the argument was expanded.
1675 /// If a macro argument is used multiple times, the expanded location will
1676 /// be at the first expansion of the argument.
1677 /// e.g.
1678 /// MY_MACRO(foo);
1679 /// ^
1680 /// Passing a file location pointing at 'foo', will yield a macro location
1681 /// where 'foo' was expanded into.
1683
1684 /// Determines the order of 2 source locations in the translation unit.
1685 ///
1686 /// \returns true if LHS source location comes before RHS, false otherwise.
1688
1689 /// Determines whether the two decomposed source location is in the
1690 /// same translation unit. As a byproduct, it also calculates the order
1691 /// of the source locations in case they are in the same TU.
1692 ///
1693 /// \returns Pair of bools the first component is true if the two locations
1694 /// are in the same TU. The second bool is true if the first is true
1695 /// and \p LOffs is before \p ROffs.
1696 std::pair<bool, bool>
1698 FileIDAndOffset &ROffs) const;
1699
1700 /// \param Loc a source location in a loaded AST (of a PCH/Module file).
1701 /// \returns a FileID uniquely identifies the AST of a loaded
1702 /// module/PCH where `Loc` is at.
1704
1705 /// Determines whether the two decomposed source location is in the same TU.
1707 const FileIDAndOffset &ROffs) const;
1708
1709 /// Determines the order of 2 source locations in the "source location
1710 /// address space".
1712 return isBeforeInSLocAddrSpace(LHS, RHS.getOffset());
1713 }
1714
1715 /// Determines the order of a source location and a source location
1716 /// offset in the "source location address space".
1717 ///
1718 /// Note that we always consider source locations loaded from
1720 SourceLocation::UIntTy RHS) const {
1721 SourceLocation::UIntTy LHSOffset = LHS.getOffset();
1722 bool LHSLoaded = LHSOffset >= CurrentLoadedOffset;
1723 bool RHSLoaded = RHS >= CurrentLoadedOffset;
1724 if (LHSLoaded == RHSLoaded)
1725 return LHSOffset < RHS;
1726
1727 return LHSLoaded;
1728 }
1729
1730 /// Return true if the Point is within Start and End.
1732 SourceLocation End) const {
1733 return Location == Start || Location == End ||
1734 (isBeforeInTranslationUnit(Start, Location) &&
1735 isBeforeInTranslationUnit(Location, End));
1736 }
1737
1738 // Iterators over FileInfos.
1740 llvm::DenseMap<FileEntryRef, SrcMgr::ContentCache *>::const_iterator;
1741
1742 fileinfo_iterator fileinfo_begin() const { return FileInfos.begin(); }
1743 fileinfo_iterator fileinfo_end() const { return FileInfos.end(); }
1744 bool hasFileInfo(const FileEntry *File) const {
1745 return FileInfos.find_as(File) != FileInfos.end();
1746 }
1747
1748 /// Print statistics to stderr.
1749 void PrintStats() const;
1750
1751 void dump() const;
1752
1753 // Produce notes describing the current source location address space usage.
1755 std::optional<unsigned> MaxNotes = 32) const;
1756
1757 /// Get the number of local SLocEntries we have.
1758 unsigned local_sloc_entry_size() const { return LocalSLocEntryTable.size(); }
1759
1760 /// Get a local SLocEntry. This is exposed for indexing.
1761 const SrcMgr::SLocEntry &getLocalSLocEntry(unsigned Index) const {
1762 return const_cast<SourceManager *>(this)->getLocalSLocEntry(Index);
1763 }
1764
1765 /// Get a local SLocEntry. This is exposed for indexing.
1767 assert(Index < LocalSLocEntryTable.size() && "Invalid index");
1768 return LocalSLocEntryTable[Index];
1769 }
1770
1771 /// Get the number of loaded SLocEntries we have.
1772 unsigned loaded_sloc_entry_size() const { return LoadedSLocEntryTable.size();}
1773
1774 /// Get a loaded SLocEntry. This is exposed for indexing.
1776 bool *Invalid = nullptr) const {
1777 return const_cast<SourceManager *>(this)->getLoadedSLocEntry(Index,
1778 Invalid);
1779 }
1780
1781 /// Get a loaded SLocEntry. This is exposed for indexing.
1783 bool *Invalid = nullptr) {
1784 assert(Index < LoadedSLocEntryTable.size() && "Invalid index");
1785 if (SLocEntryLoaded[Index])
1786 return LoadedSLocEntryTable[Index];
1787 return loadSLocEntry(Index, Invalid);
1788 }
1789
1791 bool *Invalid = nullptr) const {
1792 return const_cast<SourceManager *>(this)->getSLocEntry(FID, Invalid);
1793 }
1794
1796 if (FID.ID == 0 || FID.ID == -1) {
1797 if (Invalid) *Invalid = true;
1798 return LocalSLocEntryTable[0];
1799 }
1800 return getSLocEntryByID(FID.ID, Invalid);
1801 }
1802
1803 SourceLocation::UIntTy getNextLocalOffset() const { return NextLocalOffset; }
1804
1806 assert(LoadedSLocEntryTable.empty() &&
1807 "Invalidating existing loaded entries");
1808 ExternalSLocEntries = Source;
1809 }
1810
1811 /// Allocate a number of loaded SLocEntries, which will be actually
1812 /// loaded on demand from the external source.
1813 ///
1814 /// NumSLocEntries will be allocated, which occupy a total of TotalSize space
1815 /// in the global source view. The lowest ID and the base offset of the
1816 /// entries will be returned.
1817 std::pair<int, SourceLocation::UIntTy>
1818 AllocateLoadedSLocEntries(unsigned NumSLocEntries,
1819 SourceLocation::UIntTy TotalSize);
1820
1821 /// Returns true if \p Loc came from a PCH/Module.
1823 return isLoadedOffset(Loc.getOffset());
1824 }
1825
1826 /// Returns true if \p Loc did not come from a PCH/Module.
1828 return isLocalOffset(Loc.getOffset());
1829 }
1830
1831 /// Returns true if \p FID came from a PCH/Module.
1832 bool isLoadedFileID(FileID FID) const {
1833 assert(FID.ID != -1 && "Using FileID sentinel value");
1834 return FID.ID < 0;
1835 }
1836
1837 /// Returns true if \p FID did not come from a PCH/Module.
1838 bool isLocalFileID(FileID FID) const {
1839 return !isLoadedFileID(FID);
1840 }
1841
1842 /// Gets the location of the immediate macro caller, one level up the stack
1843 /// toward the initial macro typed into the source.
1845 if (!Loc.isMacroID()) return Loc;
1846
1847 // When we have the location of (part of) an expanded parameter, its
1848 // spelling location points to the argument as expanded in the macro call,
1849 // and therefore is used to locate the macro caller.
1850 if (isMacroArgExpansion(Loc))
1851 return getImmediateSpellingLoc(Loc);
1852
1853 // Otherwise, the caller of the macro is located where this macro is
1854 // expanded (while the spelling is part of the macro definition).
1856 }
1857
1858 /// \return Location of the top-level macro caller.
1860
1861private:
1862 friend class ASTReader;
1863 friend class ASTWriter;
1864
1865 llvm::MemoryBufferRef getFakeBufferForRecovery() const;
1866 SrcMgr::ContentCache &getFakeContentCacheForRecovery() const;
1867
1868 const SrcMgr::SLocEntry &loadSLocEntry(unsigned Index, bool *Invalid) const;
1869 SrcMgr::SLocEntry &loadSLocEntry(unsigned Index, bool *Invalid);
1870
1871 const SrcMgr::SLocEntry *getSLocEntryOrNull(FileID FID) const {
1872 return const_cast<SourceManager *>(this)->getSLocEntryOrNull(FID);
1873 }
1874
1875 SrcMgr::SLocEntry *getSLocEntryOrNull(FileID FID) {
1876 bool Invalid = false;
1877 SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid);
1878 return Invalid ? nullptr : &Entry;
1879 }
1880
1881 const SrcMgr::SLocEntry *getSLocEntryForFile(FileID FID) const {
1882 return const_cast<SourceManager *>(this)->getSLocEntryForFile(FID);
1883 }
1884
1885 SrcMgr::SLocEntry *getSLocEntryForFile(FileID FID) {
1886 if (auto *Entry = getSLocEntryOrNull(FID))
1887 if (Entry->isFile())
1888 return Entry;
1889 return nullptr;
1890 }
1891
1892 /// Get the entry with the given unwrapped FileID.
1893 /// Invalid will not be modified for Local IDs.
1894 const SrcMgr::SLocEntry &getSLocEntryByID(int ID,
1895 bool *Invalid = nullptr) const {
1896 return const_cast<SourceManager *>(this)->getSLocEntryByID(ID, Invalid);
1897 }
1898
1899 SrcMgr::SLocEntry &getSLocEntryByID(int ID, bool *Invalid = nullptr) {
1900 assert(ID != -1 && "Using FileID sentinel value");
1901 if (ID < 0)
1902 return getLoadedSLocEntryByID(ID, Invalid);
1903 return getLocalSLocEntry(static_cast<unsigned>(ID));
1904 }
1905
1906 const SrcMgr::SLocEntry &
1907 getLoadedSLocEntryByID(int ID, bool *Invalid = nullptr) const {
1908 return const_cast<SourceManager *>(this)->getLoadedSLocEntryByID(ID,
1909 Invalid);
1910 }
1911
1912 SrcMgr::SLocEntry &getLoadedSLocEntryByID(int ID, bool *Invalid = nullptr) {
1913 return getLoadedSLocEntry(static_cast<unsigned>(-ID - 2), Invalid);
1914 }
1915
1916 FileID getFileID(SourceLocation::UIntTy SLocOffset) const {
1917 // If our one-entry cache covers this offset, just return it.
1918 if (SLocOffset >= LastLookupStartOffset && SLocOffset < LastLookupEndOffset)
1919 return LastFileIDLookup;
1920 return getFileIDSlow(SLocOffset);
1921 }
1922
1923 bool isLocalOffset(SourceLocation::UIntTy SLocOffset) const {
1924 return SLocOffset < CurrentLoadedOffset;
1925 }
1926
1927 bool isLoadedOffset(SourceLocation::UIntTy SLocOffset) const {
1928 return SLocOffset >= CurrentLoadedOffset;
1929 }
1930
1931 /// Implements the common elements of storing an expansion info struct into
1932 /// the SLocEntry table and producing a source location that refers to it.
1933 SourceLocation
1934 createExpansionLocImpl(const SrcMgr::ExpansionInfo &Expansion,
1935 unsigned Length, int LoadedID = 0,
1936 SourceLocation::UIntTy LoadedOffset = 0);
1937
1938 /// Return true if the specified FileID contains the
1939 /// specified SourceLocation offset. This is a very hot method.
1940 inline bool isOffsetInFileID(FileID FID,
1941 SourceLocation::UIntTy SLocOffset) const {
1942 const SrcMgr::SLocEntry &Entry = getSLocEntry(FID);
1943 // If the entry is after the offset, it can't contain it.
1944 if (SLocOffset < Entry.getOffset()) return false;
1945
1946 // If this is the very last entry then it does.
1947 if (FID.ID == -2)
1948 return true;
1949
1950 // If it is the last local entry, then it does if the location is local.
1951 if (FID.ID+1 == static_cast<int>(LocalSLocEntryTable.size()))
1952 return SLocOffset < NextLocalOffset;
1953
1954 // Otherwise, the entry after it has to not include it. This works for both
1955 // local and loaded entries.
1956 return SLocOffset < getSLocEntryByID(FID.ID+1).getOffset();
1957 }
1958
1959 /// Returns the previous in-order FileID or an invalid FileID if there
1960 /// is no previous one.
1961 FileID getPreviousFileID(FileID FID) const;
1962
1963 /// Returns the next in-order FileID or an invalid FileID if there is
1964 /// no next one.
1965 FileID getNextFileID(FileID FID) const;
1966
1967 /// Create a new fileID for the specified ContentCache and
1968 /// include position.
1969 ///
1970 /// This works regardless of whether the ContentCache corresponds to a
1971 /// file or some other input source.
1972 FileID createFileIDImpl(SrcMgr::ContentCache &File, StringRef Filename,
1973 SourceLocation IncludePos,
1974 SrcMgr::CharacteristicKind DirCharacter, int LoadedID,
1975 SourceLocation::UIntTy LoadedOffset);
1976
1977 SrcMgr::ContentCache &getOrCreateContentCache(FileEntryRef SourceFile,
1978 bool isSystemFile = false);
1979
1980 /// Create a new ContentCache for the specified memory buffer.
1981 SrcMgr::ContentCache &
1982 createMemBufferContentCache(std::unique_ptr<llvm::MemoryBuffer> Buf);
1983
1984 FileID getFileIDSlow(SourceLocation::UIntTy SLocOffset) const;
1985 FileID getFileIDLocal(SourceLocation::UIntTy SLocOffset) const;
1986 FileID getFileIDLoaded(SourceLocation::UIntTy SLocOffset) const;
1987
1988 SourceLocation getExpansionLocSlowCase(SourceLocation Loc) const;
1989 SourceLocation getSpellingLocSlowCase(SourceLocation Loc) const;
1990 SourceLocation getFileLocSlowCase(SourceLocation Loc) const;
1991
1992 void computeMacroArgsCache(MacroArgsMap &MacroArgsCache, FileID FID) const;
1993 void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache,
1994 FileID FID,
1995 SourceLocation SpellLoc,
1996 SourceLocation ExpansionLoc,
1997 unsigned ExpansionLength) const;
1998 void updateSlocUsageStats() const;
1999};
2000
2001/// Comparison function object.
2002template<typename T>
2004
2005/// Compare two source locations.
2006template<>
2008 SourceManager &SM;
2009
2010public:
2011 explicit BeforeThanCompare(SourceManager &SM) : SM(SM) {}
2012
2014 return SM.isBeforeInTranslationUnit(LHS, RHS);
2015 }
2016};
2017
2018/// Compare two non-overlapping source ranges.
2019template<>
2021 SourceManager &SM;
2022
2023public:
2024 explicit BeforeThanCompare(SourceManager &SM) : SM(SM) {}
2025
2026 bool operator()(SourceRange LHS, SourceRange RHS) const {
2027 return SM.isBeforeInTranslationUnit(LHS.getBegin(), RHS.getBegin());
2028 }
2029};
2030
2031/// SourceManager and necessary dependencies (e.g. VFS, FileManager) for a
2032/// single in-memorty file.
2034public:
2035 /// Creates SourceManager and necessary dependencies (e.g. VFS, FileManager).
2036 /// The main file in the SourceManager will be \p FileName with \p Content.
2037 SourceManagerForFile(StringRef FileName, StringRef Content);
2038
2040 assert(SourceMgr);
2041 return *SourceMgr;
2042 }
2043
2044private:
2045 // The order of these fields are important - they should be in the same order
2046 // as they are created in `createSourceManagerForFile` so that they can be
2047 // deleted in the reverse order as they are created.
2048 std::unique_ptr<FileManager> FileMgr;
2049 std::unique_ptr<DiagnosticOptions> DiagOpts;
2050 std::unique_ptr<DiagnosticsEngine> Diagnostics;
2051 std::unique_ptr<SourceManager> SourceMgr;
2052};
2053
2054} // namespace clang
2055
2056#endif // LLVM_CLANG_BASIC_SOURCEMANAGER_H
Defines the Diagnostic-related interfaces.
Defines interfaces for clang::FileEntry and clang::FileEntryRef.
Defines the clang::FileManager interface and associated types.
#define X(type, name)
Definition Value.h:97
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.
Reads an AST files chain containing the contents of a translation unit.
Definition ASTReader.h:427
Writes an AST file containing the contents of a translation unit.
Definition ASTWriter.h:97
bool operator()(SourceLocation LHS, SourceLocation RHS) const
bool operator()(SourceRange LHS, SourceRange RHS) const
Comparison function object.
Represents a byte-granular source range.
bool isTokenRange() const
Return true if the end of this range specifies the start of the last token.
SourceLocation getEnd() const
SourceLocation getBegin() const
void setTokenRange(bool TR)
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:234
External source of source location entries.
virtual int getSLocEntryID(SourceLocation::UIntTy SLocOffset)=0
Get the index ID for the loaded SourceLocation offset.
virtual std::pair< SourceLocation, StringRef > getModuleImportLoc(int ID)=0
Retrieve the module import location and name for the given ID, if in fact it was loaded from a module...
virtual bool ReadSLocEntry(int ID)=0
Read the source location entry with index ID, which will always be less than -1.
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
Definition FileEntry.h:57
const FileEntry & getFileEntry() const
Definition FileEntry.h:70
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:52
A SourceLocation and its associated SourceManager.
Holds the cache used by isBeforeInTranslationUnit.
void setCommonLoc(FileID commonFID, unsigned lCommonOffset, unsigned rCommonOffset, bool LParentBeforeRParent)
bool getCachedResult(unsigned LOffset, unsigned ROffset) const
If the cache is valid, compute the result given the specified offsets in the LHS/RHS FileID's.
void setQueryFIDs(FileID LHS, FileID RHS)
Set up a new query.
InBeforeInTUCacheEntry(FileID L, FileID R)
bool isCacheValid() const
Return true if the currently cached values match up with the specified LHS/RHS query.
Used to hold and unique data used to represent #line information.
Represents an unpacked "presumed" location which can be presented to the user.
const char * getFilename() const
Return the presumed filename of this location.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceManagerForFile(StringRef FileName, StringRef Content)
Creates SourceManager and necessary dependencies (e.g.
This class handles loading and caching of source files into memory.
std::optional< StringRef > getNonBuiltinFilenameForID(FileID FID) const
Returns the filename for the provided FileID, unless it's a built-in buffer that's not represented by...
FileIDAndOffset getDecomposedExpansionLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
bool isMacroBodyExpansion(SourceLocation Loc) const
Tests whether the given source location represents the expansion of a macro body.
FileIDAndOffset getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
unsigned getPresumedLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
bool isBeforeInSLocAddrSpace(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the "source locationaddress space".
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
bool isAtEndOfImmediateMacroExpansion(SourceLocation Loc, SourceLocation *MacroEnd=nullptr) const
Returns true if the given MacroID location points at the character end of the immediate macro expansi...
DiagnosticsEngine & getDiagnostics() const
bool isInPredefinedFile(SourceLocation Loc) const
Returns whether Loc is located in a built-in or command line source.
SourceLocation::UIntTy getNextLocalOffset() const
bool isWrittenInBuiltinFile(SourceLocation Loc) const
Returns whether Loc is located in a <built-in> file.
unsigned getColumnNumber(FileID FID, unsigned FilePos, bool *Invalid=nullptr) const
Return the column # for the specified file position.
void noteSLocAddressSpaceUsage(DiagnosticsEngine &Diag, std::optional< unsigned > MaxNotes=32) const
void setAllFilesAreTransient(bool Transient)
Specify that all files that are read during this compilation are transient.
bool isWrittenInModuleIncludes(SourceLocation Loc) const
Returns whether Loc is located in a <module-includes> file.
unsigned getFileOffset(SourceLocation SpellingLoc) const
Returns the offset from the start of the file that the specified SourceLocation represents.
bool isLocalSourceLocation(SourceLocation Loc) const
Returns true if Loc did not come from a PCH/Module.
bool isInMainFile(SourceLocation Loc) const
Returns whether the PresumedLoc for a given SourceLocation is in the main file.
void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID, bool IsFileEntry, bool IsFileExit, SrcMgr::CharacteristicKind FileKind)
Add a line note to the line table for the FileID and offset specified by Loc.
SourceManager(DiagnosticsEngine &Diag, FileManager &FileMgr, bool UserFilesAreVolatile=false)
SourceLocation createTokenSplitLoc(SourceLocation SpellingLoc, SourceLocation TokenStart, SourceLocation TokenEnd)
Return a new SourceLocation that encodes that the token starting at TokenStart ends prematurely at To...
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
const FileEntry * getFileEntryForSLocEntry(const SrcMgr::SLocEntry &SLocEntry) const
Returns the FileEntry record for the provided SLocEntry.
bool isInTheSameTranslationUnitImpl(const FileIDAndOffset &LOffs, const FileIDAndOffset &ROffs) const
Determines whether the two decomposed source location is in the same TU.
unsigned getExpansionLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
bool isWrittenInCommandLineFile(SourceLocation Loc) const
Returns whether Loc is located in a <command line> file.
MemoryBufferSizes getMemoryBufferSizes() const
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memor...
void setFileIsTransient(FileEntryRef SourceFile)
Specify that a file is transient.
unsigned getExpansionColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const
bool isFileOverridden(const FileEntry *File) const
Returns true if the file contents have been overridden.
OptionalFileEntryRef getFileEntryRefForID(FileID FID) const
Returns the FileEntryRef for the provided FileID.
CharSourceRange getExpansionRange(SourceRange Range) const
Given a SourceRange object, return the range of tokens or characters covered by the expansion in the ...
SourceLocation getFileLoc(SourceLocation Loc) const
Given Loc, if it is a macro location return the expansion location or the spelling location,...
bool isInSLocAddrSpace(SourceLocation Loc, SourceLocation Start, unsigned Length, SourceLocation::UIntTy *RelativeOffset=nullptr) const
Returns true if Loc is inside the [Start, +Length) chunk of the source location address space.
SourceLocation translateLineCol(FileID FID, unsigned Line, unsigned Col) const
Get the source location in FID for the given line:col.
size_t getContentCacheSize() const
Return the total amount of physical memory allocated by the ContentCache allocator.
StringRef getBufferName(SourceLocation Loc, bool *Invalid=nullptr) const
Return the filename or buffer identifier of the buffer the location is in.
SourceLocation getTopMacroCallerLoc(SourceLocation Loc) const
std::optional< StringRef > getBufferDataOrNone(FileID FID) const
Return a StringRef to the source buffer data for the specified FileID, returning std::nullopt if inva...
FileID translateFile(const FileEntry *SourceFile) const
Get the FileID for the given file.
CharSourceRange getExpansionRange(CharSourceRange Range) const
Given a CharSourceRange object, return the range of tokens or characters covered by the expansion in ...
void setModuleBuildStack(ModuleBuildStack stack)
Set the module build stack.
StringRef getBufferData(FileID FID, bool *Invalid=nullptr) const
Return a StringRef to the source buffer data for the specified FileID.
FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
void PrintStats() const
Print statistics to stderr.
FileID getUniqueLoadedASTFileID(SourceLocation Loc) const
SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr)
bool isMainFile(const FileEntry &SourceFile)
Returns true when the given FileEntry corresponds to the main file.
size_t getDataStructureSizes() const
Return the amount of memory used for various side tables and data structures in the SourceManager.
bool isMacroArgExpansion(SourceLocation Loc, SourceLocation *StartLoc=nullptr) const
Tests whether the given source location represents a macro argument's expansion into the function-lik...
unsigned getSpellingColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const
const SrcMgr::SLocEntry & getLocalSLocEntry(unsigned Index) const
Get a local SLocEntry. This is exposed for indexing.
SourceLocation getComposedLoc(FileID FID, unsigned Offset) const
Form a SourceLocation from a FileID and Offset pair.
void setPreambleFileID(FileID Preamble)
Set the file ID for the precompiled preamble.
OptionalFileEntryRef bypassFileContentsOverride(FileEntryRef File)
Bypass the overridden contents of a file.
bool userFilesAreVolatile() const
True if non-system source files should be treated as volatile (likely to change while trying to use t...
const SrcMgr::SLocEntry & getLoadedSLocEntry(unsigned Index, bool *Invalid=nullptr) const
Get a loaded SLocEntry. This is exposed for indexing.
llvm::DenseMap< FileEntryRef, SrcMgr::ContentCache * >::const_iterator fileinfo_iterator
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID.
FileManager & getFileManager() const
void setOverridenFilesKeepOriginalName(bool value)
Set true if the SourceManager should report the original file name for contents of files that were ov...
fileinfo_iterator fileinfo_end() const
FileID translateFile(FileEntryRef SourceFile) const
ModuleBuildStack getModuleBuildStack() const
Retrieve the module build stack.
unsigned local_sloc_entry_size() const
Get the number of local SLocEntries we have.
std::optional< StringRef > getBufferDataIfLoaded(FileID FID) const
Return a StringRef to the source buffer data for the specified FileID, returning std::nullopt if it's...
SourceLocation getLocForEndOfFile(FileID FID) const
Return the source location corresponding to the last byte of the specified file.
FileIDAndOffset getDecomposedSpellingLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
FileID getMainFileID() const
Returns the FileID of the main source file.
SourceLocation getImmediateMacroCallerLoc(SourceLocation Loc) const
Gets the location of the immediate macro caller, one level up the stack toward the initial macro type...
const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const
Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer.
std::pair< int, SourceLocation::UIntTy > AllocateLoadedSLocEntries(unsigned NumSLocEntries, SourceLocation::UIntTy TotalSize)
Allocate a number of loaded SLocEntries, which will be actually loaded on demand from the external so...
void pushModuleBuildStack(StringRef moduleName, FullSourceLoc importLoc)
Push an entry to the module build stack.
void overrideFileContents(FileEntryRef SourceFile, const llvm::MemoryBufferRef &Buffer)
Override the contents of the given source file by providing an already-allocated buffer.
SourceLocation getIncludeLoc(FileID FID) const
Returns the include location if FID is a #include'd file otherwise it returns an invalid location.
llvm::MemoryBufferRef getBufferOrFake(FileID FID, SourceLocation Loc=SourceLocation()) const
Return the buffer for the specified FileID.
unsigned getFileIDSize(FileID FID) const
The size of the SLocEntry that FID represents.
bool isInSystemMacro(SourceLocation loc) const
Returns whether Loc is expanded from a macro in a system header.
void setMainFileID(FileID FID)
Set the file ID for the main source file.
unsigned getLineNumber(FileID FID, unsigned FilePos, bool *Invalid=nullptr) const
Given a SourceLocation, return the spelling line number for the position indicated.
CharSourceRange getImmediateExpansionRange(SourceLocation Loc) const
Return the start/end of the expansion information for an expansion location.
bool hasLineTable() const
Determine if the source manager has a line table.
CharSourceRange getExpansionRange(SourceLocation Loc) const
Given a SourceLocation object, return the range of tokens covered by the expansion in the ultimate fi...
bool isWrittenInScratchSpace(SourceLocation Loc) const
Returns whether Loc is located in a <scratch space> file.
bool isInFileID(SourceLocation Loc, FileID FID, unsigned *RelativeOffset=nullptr) const
Given a specific FileID, returns true if Loc is inside that FileID chunk and sets relative offset (of...
void setExternalSLocEntrySource(ExternalSLocEntrySource *Source)
unsigned getLineTableFilenameID(StringRef Str)
Return the uniqued ID for the specified filename.
void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs, bool Force=false)
Set the number of FileIDs (files and macros) that were created during preprocessing of FID,...
bool isLocalFileID(FileID FID) const
Returns true if FID did not come from a PCH/Module.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
FileID getPreambleFileID() const
Get the file ID for the precompiled preamble if there is one.
SrcMgr::SLocEntry & getLocalSLocEntry(unsigned Index)
Get a local SLocEntry. This is exposed for indexing.
void initializeForReplay(const SourceManager &Old)
Initialize this source manager suitably to replay the compilation described by Old.
FileIDAndOffset getDecomposedIncludedLoc(FileID FID) const
Returns the "included/expanded in" decomposed location of the given FileID.
bool isLoadedSourceLocation(SourceLocation Loc) const
Returns true if Loc came from a PCH/Module.
unsigned loaded_sloc_entry_size() const
Get the number of loaded SLocEntries we have.
unsigned getSpellingLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
SourceManager & operator=(const SourceManager &)=delete
FileID getOrCreateFileID(FileEntryRef SourceFile, SrcMgr::CharacteristicKind FileCharacter)
Get the FileID for SourceFile if it exists.
bool hasFileInfo(const FileEntry *File) const
SourceLocation translateFileLineCol(const FileEntry *SourceFile, unsigned Line, unsigned Col) const
Get the source location for the given file:line:col triplet.
std::pair< SourceLocation, StringRef > getModuleImportLoc(SourceLocation Loc) const
bool isLoadedFileID(FileID FID) const
Returns true if FID came from a PCH/Module.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
bool isInSameSLocAddrSpace(SourceLocation LHS, SourceLocation RHS, SourceLocation::IntTy *RelativeOffset) const
Return true if both LHS and RHS are in the local source location address space or the loaded one.
llvm::MemoryBufferRef getMemoryBufferForFileOrFake(FileEntryRef File)
Retrieve the memory buffer associated with the given file.
SrcMgr::SLocEntry & getLoadedSLocEntry(unsigned Index, bool *Invalid=nullptr)
Get a loaded SLocEntry. This is exposed for indexing.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
bool isAtStartOfImmediateMacroExpansion(SourceLocation Loc, SourceLocation *MacroBegin=nullptr) const
Returns true if the given MacroID location points at the beginning of the immediate macro expansion.
SrcMgr::CharacteristicKind getFileCharacteristic(SourceLocation Loc) const
Return the file characteristic of the specified source location, indicating whether this is a normal ...
SourceLocation createExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned Length, bool ExpansionIsTokenRange=true, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Creates an expansion SLocEntry for a macro use.
bool isWrittenInSameFile(SourceLocation Loc1, SourceLocation Loc2) const
Returns true if the spelling locations for both SourceLocations are part of the same file buffer.
bool isInExternCSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in an "extern C" system header.
unsigned getPresumedColumnNumber(SourceLocation Loc, bool *Invalid=nullptr) const
bool isWrittenInMainFile(SourceLocation Loc) const
Returns true if the spelling location for the given location is in the main file buffer.
std::pair< bool, bool > isInTheSameTranslationUnit(FileIDAndOffset &LOffs, FileIDAndOffset &ROffs) const
Determines whether the two decomposed source location is in the same translation unit.
bool isPointWithin(SourceLocation Location, SourceLocation Start, SourceLocation End) const
Return true if the Point is within Start and End.
SourceManager(const SourceManager &)=delete
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID.
SourceLocation getMacroArgExpandedLocation(SourceLocation Loc) const
If Loc points inside a function macro argument, the returned location will be the macro location in w...
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
unsigned getNumCreatedFIDsForFileID(FileID FID) const
Get the number of FileIDs (files and macros) that were created during preprocessing of FID,...
std::optional< llvm::MemoryBufferRef > getBufferOrNone(FileID FID, SourceLocation Loc=SourceLocation()) const
Return the buffer for the specified FileID.
fileinfo_iterator fileinfo_begin() const
bool isBeforeInSLocAddrSpace(SourceLocation LHS, SourceLocation::UIntTy RHS) const
Determines the order of a source location and a source location offset in the "source location addres...
LineTableInfo & getLineTable()
Retrieve the stored line table.
SourceLocation getImmediateSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID.
std::optional< llvm::MemoryBufferRef > getMemoryBufferForFileOrNone(FileEntryRef File)
Retrieve the memory buffer associated with the given file.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
SourceLocation createMacroArgExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLoc, unsigned Length)
Creates an expansion SLocEntry for the substitution of an argument into a function-like macro's body.
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
One instance of this struct is kept for every file loaded or used.
void setBuffer(std::unique_ptr< llvm::MemoryBuffer > B)
Set the buffer.
std::optional< StringRef > getBufferDataIfLoaded() const
Return a StringRef to the source buffer data, only if it has already been loaded.
void setUnownedBuffer(std::optional< llvm::MemoryBufferRef > B)
Set the buffer to one that's not owned (or to nullptr).
OptionalFileEntryRef ContentsEntry
References the file which the contents were actually loaded from.
unsigned getSizeBytesMapped() const
Returns the number of bytes actually mapped for this ContentCache.
unsigned IsTransient
True if this file may be transient, that is, if it might not exist at some later point in time when t...
StringRef Filename
The filename that is used to access OrigEntry.
ContentCache(FileEntryRef Ent)
ContentCache(FileEntryRef Ent, FileEntryRef contentEnt)
unsigned getSize() const
Returns the size of the content encapsulated by this ContentCache.
llvm::MemoryBuffer::BufferKind getMemoryBufferKind() const
Returns the kind of memory used to back the memory buffer for this content cache.
unsigned IsFileVolatile
True if this content cache was initially created for a source file considered to be volatile (likely ...
LineOffsetMapping SourceLineCache
A bump pointer allocated array of offsets for each source line.
std::optional< llvm::MemoryBufferRef > getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM, SourceLocation Loc=SourceLocation()) const
Returns the memory buffer for the associated content.
static const char * getInvalidBOM(StringRef BufStr)
std::optional< llvm::MemoryBufferRef > getBufferIfLoaded() const
Return the buffer, only if it has been loaded.
unsigned BufferOverridden
Indicates whether the buffer itself was provided to override the actual file contents.
ContentCache(const ContentCache &RHS)
The copy ctor does not allow copies where source object has either a non-NULL Buffer or SourceLineCac...
ContentCache & operator=(const ContentCache &RHS)=delete
OptionalFileEntryRef OrigEntry
Reference to the file entry representing this ContentCache.
Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded,...
SourceLocation getExpansionLocStart() const
static ExpansionInfo create(SourceLocation SpellingLoc, SourceLocation Start, SourceLocation End, bool ExpansionIsTokenRange=true)
Return a ExpansionInfo for an expansion.
SourceLocation getSpellingLoc() const
CharSourceRange getExpansionLocRange() const
static ExpansionInfo createForMacroArg(SourceLocation SpellingLoc, SourceLocation ExpansionLoc)
Return a special ExpansionInfo for the expansion of a macro argument into a function-like macro's bod...
static ExpansionInfo createForTokenSplit(SourceLocation SpellingLoc, SourceLocation Start, SourceLocation End)
Return a special ExpansionInfo representing a token that ends prematurely.
SourceLocation getExpansionLocEnd() const
Information about a FileID, basically just the logical file that it represents and include stack info...
const ContentCache & getContentCache() const
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
static FileInfo get(SourceLocation IL, ContentCache &Con, CharacteristicKind FileCharacter, StringRef Filename)
Return a FileInfo object.
bool hasLineDirectives() const
Return true if this FileID has #line directives in it.
void setHasLineDirectives()
Set the flag that indicates that this FileID has line table entries associated with it.
SourceLocation getIncludeLoc() const
StringRef getName() const
Returns the name of the file that was used when the file was loaded from the underlying file system.
Mapping of line offsets into a source file.
const unsigned * begin() const
const unsigned * end() const
const unsigned & operator[](int I) const
static LineOffsetMapping get(llvm::MemoryBufferRef Buffer, llvm::BumpPtrAllocator &Alloc)
ArrayRef< unsigned > getLines() const
This is a discriminated union of FileInfo and ExpansionInfo.
SourceLocation::UIntTy getOffset() const
static SLocEntry getOffsetOnly(SourceLocation::UIntTy Offset)
Creates an incomplete SLocEntry that is only able to report its offset.
static SLocEntry get(SourceLocation::UIntTy Offset, const FileInfo &FI)
const FileInfo & getFile() const
static SLocEntry get(SourceLocation::UIntTy Offset, const ExpansionInfo &Expansion)
const ExpansionInfo & getExpansion() const
Public enums and private classes that are part of the SourceManager implementation.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
bool isSystem(CharacteristicKind CK)
Determine whether a file / directory characteristic is for system code.
bool isModuleMap(CharacteristicKind CK)
Determine whether a file characteristic is for a module map.
The JSON file list parser is used to communicate input to InstallAPI.
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
Definition FileEntry.h:196
ArrayRef< std::pair< std::string, FullSourceLoc > > ModuleBuildStack
The stack used when building modules on demand, which is used to provide a link between the source ma...
std::pair< FileID, unsigned > FileIDAndOffset
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
#define false
Definition stdbool.h:26
MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes)