From 088644c21c015eb60a41a59f417990023f1f4ef8 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 20 Apr 2023 13:42:20 -0400 Subject: Improve SourceMap coverage/testing (#2818) * #include an absolute path didn't work - because paths were taken to always be relative. * WIP around more value like behavior for SourceMap/StringPool. * Use default impls on SourceMap ctor/assignment. * Handle comparison of SourceMaps. Some small fixes. Expand unit tests. --- source/compiler-core/slang-source-map.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (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 e0c8d065a..0c55d3a1a 100644 --- a/source/compiler-core/slang-source-map.h +++ b/source/compiler-core/slang-source-map.h @@ -19,6 +19,8 @@ public: struct Entry { + typedef Entry ThisType; + void init() { generatedColumn = 0; @@ -28,6 +30,16 @@ public: nameIndex = 0; } + bool operator==(const ThisType& rhs) const + { + return generatedColumn == rhs.generatedColumn && + sourceFileIndex == rhs.sourceFileIndex && + sourceLine == rhs.sourceLine && + sourceColumn == rhs.sourceColumn && + nameIndex == rhs.nameIndex; + } + SLANG_FORCE_INLINE bool operator!=(const ThisType& rhs) const { return !(*this == rhs); } + // Note! All column/line are zero indexed Index generatedColumn; ///< The generated column Index sourceFileIndex; ///< The index into the source name/contents @@ -71,12 +83,24 @@ public: /// Swap this with rhs void swapWith(ThisType& rhs); + /// == + /// + /// Note that equality requires that entries for a line must be *in the same order* + /// even though strictly speaking with different orders could be considered equivalent. + bool operator==(const ThisType& rhs) const; + /// != + bool operator!=(const ThisType& rhs) const { return !(*this == rhs); } + /// Ctor SourceMap(): m_slicePool(StringSlicePool::Style::Default) { clear(); } + /// Copy Ctor + SourceMap(const ThisType& rhs) = default; + /// Assignment + ThisType& operator=(const ThisType& rhs) = default; String m_file; String m_sourceRoot; -- cgit v1.2.3