class
#include <slang/text/SourceManager.h>
SourceManager SourceManager - Handles loading and tracking source files.
The source manager abstracts away the differences between locations in files and locations generated by macro expansion. See SourceLocation for more details.
The methods in this class are thread safe unless otherwise noted.
Public types
- struct LineDirectiveInfo
- Stores information specified in a `pragma diagnostic directive, which alters the / currently active set of diagnostic mappings.
Constructors, destructors, conversion operators
- SourceManager()
- Default constructor.
Public functions
-
std::
error_code addSystemDirectories(std:: string_view pattern) - Adds one or more system include directories that match the given pattern.
-
std::
error_code addUserDirectories(std:: string_view pattern) - Adds one or more user include directories that match the given pattern.
-
size_
t getLineNumber(SourceLocation location) const - Gets the source line number for a given source location.
-
std::
string_view getFileName(SourceLocation location) const - Gets the source file name for a given source location.
-
const std::
filesystem:: path& getFullPath(BufferID buffer) const - Gets the source file name for a given source buffer, not taking into account any `line directives that may be in the file.
-
size_
t getColumnNumber(SourceLocation location) const - Gets the column line number for a given source location.
-
size_
t getDisplayColumnNumber(SourceLocation location) const - Gets the display column number for a given source location, accounting for UTF-8 character widths and tab expansion.
- SourceLocation getIncludedFrom(BufferID buffer) const
- Gets a location that indicates from where the given buffer was included.
- const SourceLibrary* getLibraryFor(BufferID buffer) const
- Gets the source library of which the given buffer is a part, or nullptr if it's not explicitly part of any library.
-
std::
string_view getMacroName(SourceLocation location) const - Attempts to get the name of the macro represented by a macro location.
- bool isFileLoc(SourceLocation location) const
- Determines whether the given location exists in a source file.
- bool isMacroLoc(SourceLocation location) const
- Determines whether the given location points to a macro expansion.
- bool isMacroArgLoc(SourceLocation location) const
- Determines whether the given location points to a macro argument expansion.
- bool isIncludedFileLoc(SourceLocation location) const
- Determines whether the given location is inside an include file.
- bool isPreprocessedLoc(SourceLocation location) const
- Determines whether the given location is from a macro expansion or an include file.
-
std::
optional<bool> isBeforeInCompilationUnit(SourceLocation left, SourceLocation right) const - Determines whether the left location comes before the right location within the "compilation unit space", which is a hypothetical source space where all macros and include files have been expanded out into a flat file.
- SourceLocation getExpansionLoc(SourceLocation location) const
- Gets the expansion location of a given macro location.
- SourceRange getExpansionRange(SourceLocation location) const
- Gets the expansion range of a given macro location.
- SourceLocation getOriginalLoc(SourceLocation location) const
- Gets the original source location of a given macro location.
- SourceLocation getFullyOriginalLoc(SourceLocation location) const
- Gets the actual original location where source is written, given a location inside a macro.
- SourceRange getFullyOriginalRange(SourceRange range) const
- Build the original location range where source is written.
- SourceLocation getFullyExpandedLoc(SourceLocation location) const
- If the given location is a macro location, fully expands it out to its actual file expansion location.
-
std::
string_view getSourceText(BufferID buffer) const - Gets the actual source text for a given file buffer.
-
uint64_
t getSortKey(BufferID buffer) const - Gets a value that can be used to sort a given buffer when comparing to other buffers.
- SourceLocation createExpansionLoc(SourceLocation originalLoc, SourceRange expansionRange, bool isMacroArg)
- Creates a macro expansion location; used by the preprocessor.
-
SourceLocation createExpansionLoc(SourceLocation originalLoc,
SourceRange expansionRange,
std::
string_view macroName) - Creates a macro expansion location; used by the preprocessor.
-
SourceBuffer assignText(std::
string_view text, SourceLocation includedFrom = SourceLocation(), const SourceLibrary* library = nullptr) - Instead of loading source from a file, copy it from text already in memory.
-
SourceBuffer assignText(std::
string_view path, std:: string_view text, SourceLocation includedFrom = SourceLocation(), const SourceLibrary* library = nullptr) - Instead of loading source from a file, copy it from text already in memory.
-
SourceBuffer assignBuffer(std::
string_view path, SmallVector<char>&& buffer, SourceLocation includedFrom = SourceLocation(), const SourceLibrary* library = nullptr) - Instead of loading source from a file, move it from text already in memory.
-
BufferOrError readSource(const std::
filesystem:: path& path, const SourceLibrary* library, uint64_ t sortKey = UINT64_MAX) - Read in a source file from disk.
-
BufferOrError readHeader(std::
string_view path, SourceLocation includedFrom, const SourceLibrary* library, bool isSystemPath, std:: span<std:: filesystem:: path const> additionalIncludePaths) - Read in a header file from disk.
-
bool isCached(const std::
filesystem:: path& path) const - Returns true if the given file path is already loaded and cached in the source manager.
- void setDisableProximatePaths(bool set)
- Sets whether filenames should be made "proximate" to the current directory for diagnostic reporting purposes.
- void setDisableLocalIncludes(bool set)
- Sets whether to disable "local" include path lookup, where include directives search relative to the file containing the directive first.
-
void addLineDirective(SourceLocation location,
size_
t lineNum, std:: string_view name, uint8_ t level) - Adds a line directive at the given location.
-
void addDiagnosticDirective(SourceLocation location,
std::
string_view name, DiagnosticSeverity severity) - Adds a diagnostic directive at the given location.
Function documentation
std:: error_code slang:: SourceManager:: addSystemDirectories(std:: string_view pattern)
Adds one or more system include directories that match the given pattern.
Returns | An error code if the given pattern is for an exact path and that path does not exist or is not a directory. |
---|
std:: error_code slang:: SourceManager:: addUserDirectories(std:: string_view pattern)
Adds one or more user include directories that match the given pattern.
Returns | An error code if the given pattern is for an exact path and that path does not exist or is not a directory. |
---|
const std:: filesystem:: path& slang:: SourceManager:: getFullPath(BufferID buffer) const
Gets the source file name for a given source buffer, not taking into account any `line directives that may be in the file.
std::string_view getRawFileName(BufferID buffer) const;
/ Gets the full path to the given source buffer. This does not take / into account any `line directives. If the buffer is not a file buffer, returns an empty string.
size_ t slang:: SourceManager:: getColumnNumber(SourceLocation location) const
Gets the column line number for a given source location.
location must be a file location.
size_ t slang:: SourceManager:: getDisplayColumnNumber(SourceLocation location) const
Gets the display column number for a given source location, accounting for UTF-8 character widths and tab expansion.
location must be a file location.
SourceLocation slang:: SourceManager:: getIncludedFrom(BufferID buffer) const
Gets a location that indicates from where the given buffer was included.
location must be a file location.
std:: string_view slang:: SourceManager:: getMacroName(SourceLocation location) const
Attempts to get the name of the macro represented by a macro location.
If no macro name can be found, returns an empty string view.
std:: optional<bool> slang:: SourceManager:: isBeforeInCompilationUnit(SourceLocation left,
SourceLocation right) const
Determines whether the left location comes before the right location within the "compilation unit space", which is a hypothetical source space where all macros and include files have been expanded out into a flat file.
Returns std::nullopt if the locations are in unrelated compilation units.
SourceLocation slang:: SourceManager:: getFullyOriginalLoc(SourceLocation location) const
Gets the actual original location where source is written, given a location inside a macro.
Otherwise just returns the location itself.
SourceLocation slang:: SourceManager:: getFullyExpandedLoc(SourceLocation location) const
If the given location is a macro location, fully expands it out to its actual file expansion location.
Otherwise just returns the location itself.
SourceBuffer slang:: SourceManager:: assignText(std:: string_view path,
std:: string_view text,
SourceLocation includedFrom = SourceLocation(),
const SourceLibrary* library = nullptr)
Instead of loading source from a file, copy it from text already in memory.
Pretend it came from a file located at path.
SourceBuffer slang:: SourceManager:: assignBuffer(std:: string_view path,
SmallVector<char>&& buffer,
SourceLocation includedFrom = SourceLocation(),
const SourceLibrary* library = nullptr)
Instead of loading source from a file, move it from text already in memory.
Pretend it came from a file located at path.
void slang:: SourceManager:: setDisableProximatePaths(bool set)
Sets whether filenames should be made "proximate" to the current directory for diagnostic reporting purposes.
This is on by default but can be disabled to always use the simple filename.