From ca1f93a916ce6b984cba402c8d3710988f2b618f Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 27 Mar 2023 13:57:42 -0400 Subject: Using SourceMap for location output (#2736) * #include an absolute path didn't work - because paths were taken to always be relative. * WIP using SourceMap with SourceManager. * Add a test to check obfuscation map is working. --------- Co-authored-by: Yong He --- source/compiler-core/slang-source-map.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'source/compiler-core/slang-source-map.h') diff --git a/source/compiler-core/slang-source-map.h b/source/compiler-core/slang-source-map.h index accd2473f..1ccc87e90 100644 --- a/source/compiler-core/slang-source-map.h +++ b/source/compiler-core/slang-source-map.h @@ -2,21 +2,17 @@ #define SLANG_COMPILER_CORE_SOURCE_MAP_H #include "../../slang.h" -#include "../../slang-com-helper.h" -#include "../../slang-com-ptr.h" #include "../core/slang-string.h" #include "../core/slang-list.h" -#include "../core/slang-rtti-info.h" #include "../core/slang-string-slice-pool.h" -#include "slang-json-value.h" - namespace Slang { -struct SourceMap : public RefObject +class SourceMap : public RefObject { +public: struct Entry { void init() @@ -36,12 +32,6 @@ struct SourceMap : public RefObject Index nameIndex; ///< Name index }; - /// Decode from root into the source map - SlangResult decode(JSONContainer* container, JSONValue root, DiagnosticSink* sink); - - /// Converts the source map contents into JSON - SlangResult encode(JSONContainer* container, DiagnosticSink* sink, JSONValue& outValue); - /// Get the total number of generated lines Count getGeneratedLineCount() const { return m_lineStarts.getCount(); } /// Get the entries on the line @@ -61,6 +51,16 @@ struct SourceMap : public RefObject /// Get the name index Index getNameIndex(const UnownedStringSlice& slice); + /// Given a row and col index, find the closest entry + /// NOTE! Zero indexed line and column. + Index findEntry(Index lineIndex, Index colIndex) const; + + /// Given an entry index return the entry + const Entry& getEntryByIndex(Index i) const {return m_lineEntries[i]; } + + /// Given the sourceFileIndex return the name + UnownedStringSlice getSourceFileName(Index sourceFileIndex) const; + /// Clear the contents of the source map void clear(); -- cgit v1.2.3