summaryrefslogtreecommitdiff
path: root/source/compiler-core/slang-source-loc.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-04-17 15:09:37 -0400
committerGitHub <noreply@github.com>2023-04-17 15:09:37 -0400
commit90a9f43573ec0777c2ae4fa20c8fdc51a4ae7b3a (patch)
tree360750778be872a086674024a9ce5a68bf4e7cb3 /source/compiler-core/slang-source-loc.h
parenta3f622ace1bdef1f1a4150ec85d1328d1a589333 (diff)
Round trip source map (#2810)
* #include an absolute path didn't work - because paths were taken to always be relative. * Make output of obfuscation locs work in a slang-module. * Tidy up detection for writing serialized source locs. * Support for .zip references. Handling of obfuscated source maps read from containers. A test to check obfuscated source map working on a module. * When using obfuscation, always obfuscate locs instead of stripping them. We keep a source map, so we can still produce reasonable errors. * Write out source locs if debug information is enabled. * Check output without sourcemap. * Small fixes. * Small improvements around hash calculation for source map name. * Disable test that fails on x86 gcc linux for now. * Fix issues around obfuscated source map using lines rather than columns. Fix some issues around encoding/decoding. * Make column calculation of source locs take into account utf8/tabs. Don't special case obfuscated source map for lookup for source loc. * Support following multiple source maps. * Small fixes/improvements around SourceMap lookup.
Diffstat (limited to 'source/compiler-core/slang-source-loc.h')
-rw-r--r--source/compiler-core/slang-source-loc.h34
1 files changed, 22 insertions, 12 deletions
diff --git a/source/compiler-core/slang-source-loc.h b/source/compiler-core/slang-source-loc.h
index 4103c9d6d..98b1bdbbd 100644
--- a/source/compiler-core/slang-source-loc.h
+++ b/source/compiler-core/slang-source-loc.h
@@ -218,8 +218,13 @@ public:
/// Calculate the line based on the offset
int calcLineIndexFromOffset(int offset);
- /// Calculate the offset for a line
- int calcColumnIndex(int line, int offset);
+ /// Calculate the offset (in bytes) for a line
+ int calcColumnOffset(int line, int offset);
+
+ /// Given a line and offset (in bytes for the whole file), return the column index, taking into account tabs
+ /// and utf8 encoding.
+ /// Passing tabSize uses the default tab size (currently tab set to 1)
+ int calcColumnIndex(int line, int offset, int tabSize = -1);
/// Get the content holding blob
ISlangBlob* getContentBlob() const { return m_contentBlob; }
@@ -247,11 +252,11 @@ public:
/// Get the source manager this was created on
SourceManager* getSourceManager() const { return m_sourceManager; }
- /// If set this "file" only exists as a way to obfuscate locations
- /// The mapping between the two is specified in the specified source map
- SourceMap* getObfuscatedSourceMap() const { return m_obfuscatedSourceMap; }
- /// Set the obfuscated source map
- void setObfuscatedSourceMap(SourceMap* sourceMap) { m_obfuscatedSourceMap = sourceMap; }
+ /// Get the source map associated with this file. If it's set when doing
+ /// lookup for source locations, the source map will be used
+ SourceMap* getSourceMap() const { return m_sourceMap; }
+ /// Set a source map
+ void setSourceMap(SourceMap* sourceMap) { m_sourceMap = sourceMap; }
/// Ctor
SourceFile(SourceManager* sourceManager, const PathInfo& pathInfo, size_t contentSize);
@@ -272,15 +277,15 @@ public:
// the input file:
List<uint32_t> m_lineBreakOffsets;
- // If set then this file isn't a regular source file, but provides obfuscation.
- // The mapping of that obfuscation can be found via the obfuscated source map
- RefPtr<SourceMap> m_obfuscatedSourceMap;
+ // If set then the locations in this file are really from locations from elsewhere,
+ // where the SourceMap specifies that mapping
+ RefPtr<SourceMap> m_sourceMap;
};
enum class SourceLocType
{
- Nominal, ///< The normal interpretation which takes into account #line directives
- Actual, ///< Ignores #line directives - and is the location as seen in the actual file
+ Nominal, ///< The normal interpretation which takes into account #line directives and source maps
+ Actual, ///< Ignores #line directives/source maps - and is the location as seen in the actual file
};
// A source location in a format a human might like to see
@@ -441,6 +446,11 @@ struct SourceManager
/// Find if the source file is defined on this manager.
SourceFile* findSourceFile(const String& uniqueIdentity) const;
+ /// Find a source file by path.
+ SourceFile* findSourceFileByPath(const String& name) const;
+ /// Find a source file by path recursively.
+ SourceFile* findSourceFileByPathRecursively(const String& name) const;
+
/// Searches this manager, and then the parent to see if can find a match
SourceFile* findSourceFileByContentRecursively(const char* text);
/// Find the source file that contains *the memory* text points to.