yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1#ifndef SLANG_COMPILER_CORE_SOURCE_MAP_H 2#define SLANG_COMPILER_CORE_SOURCE_MAP_H 3 4#include "../core/slang-list.h" 5#include "../core/slang-string-slice-pool.h" 6#include "../core/slang-string.h" 7#include "slang.h" 8 9namespace Slang 10{ 11 12class SourceMap 13{ 14public : 15typedef SourceMap ThisType ; 16 17SLANG_CLASS_GUID (0x731383ea ,0xe516 ,0x4cc3 , {0xa6 ,0xcf ,0x37 ,0xd2 ,0x8c ,0x24 ,0x5c ,0x5e }); 18 19struct Entry 20 { 21typedef Entry ThisType ; 22 23void init () 24 { 25generatedColumn = 0 ; 26sourceFileIndex = 0 ; 27sourceLine = 0 ; 28sourceColumn = 0 ; 29nameIndex = 0 ; 30 } 31 32bool operator == (const ThisType & rhs )const 33 { 34return generatedColumn == rhs .generatedColumn && 35sourceFileIndex == rhs .sourceFileIndex && sourceLine == rhs .sourceLine && 36sourceColumn == rhs .sourceColumn && nameIndex == rhs .nameIndex ; 37 } 38SLANG_FORCE_INLINE bool operator != (const ThisType & rhs )const {return !(* this == rhs ); } 39 40// Note! All column/line are zero indexed 41Index generatedColumn ;///< The generated column 42Index sourceFileIndex ;///< The index into the source name/contents 43Index sourceLine ;///< The line number in the originating source 44Index sourceColumn ;///< The column number in the originating source 45Index nameIndex ;///< Name index 46 }; 47 48/// Get the total number of generated lines 49Count getGeneratedLineCount ()const {return m_lineStarts .getCount (); } 50/// Get the entries on the line 51SLANG_FORCE_INLINE ConstArrayView < Entry > getEntriesForLine (Index generatedLine )const ; 52 53/// Advance to the specified line index. 54/// It is an error to specify a line *before* the current line. It should either be the current 55/// output line or a later output line. Interveining lines will be set as empty 56void advanceToLine (Index lineIndex ); 57 58/// Add an entry to the current line 59void addEntry (const Entry & entry ) {m_lineEntries .add (entry ); } 60 61/// Given the slice returns the index 62Index getSourceFileIndex (const UnownedStringSlice & slice ); 63 64/// Get the name index 65Index getNameIndex (const UnownedStringSlice & slice ); 66 67/// Given a row and col index, find the closest entry 68/// NOTE! Zero indexed line and column. 69Index findEntry (Index lineIndex ,Index colIndex )const ; 70 71/// Given an entry index return the entry 72const Entry & getEntryByIndex (Index i )const {return m_lineEntries [i ]; } 73 74/// Given the sourceFileIndex return the name 75UnownedStringSlice getSourceFileName (Index sourceFileIndex )const ; 76 77/// Clear the contents of the source map 78void clear (); 79 80/// Swap this with rhs 81void swapWith (ThisType & rhs ); 82 83/// == 84/// 85/// Note that equality requires that entries for a line must be *in the same order* 86/// even though strictly speaking with different orders could be considered equivalent. 87bool operator == (const ThisType & rhs )const ; 88/// != 89bool operator != (const ThisType & rhs )const {return !(* this == rhs ); } 90 91/// Ctor 92SourceMap () 93 :m_slicePool (StringSlicePool ::Style ::Default ) 94 { 95clear (); 96 } 97/// Copy Ctor 98SourceMap (const ThisType & rhs )= default; 99/// Assignment 100ThisType & operator = ( const ThisType & rhs) = default; 101 102String m_file; 103String m_sourceRoot; 104 105List < StringSlicePool::Handle > m_sources; 106 107/// Storage for the contents. Can be unset null to indicate not set. 108List < StringSlicePool::Handle > m_sourcesContent; 109 110/// The names 111List < StringSlicePool::Handle > m_names; 112 113List < Index > m_lineStarts; 114List < Entry > m_lineEntries; 115 116StringSlicePool m_slicePool; 117}; 118 119// ------------------------------------------------------------- 120SLANG_FORCE_INLINE ConstArrayView < SourceMap::Entry > SourceMap:: getEntriesForLine ( 121Index generatedLine) const 122{ 123SLANG_ASSERT (generatedLine >= 0 && generatedLine < m_lineStarts. getCount ()); 124 125const Index start = m_lineStarts[generatedLine]; 126 127const Index end = (generatedLine + 1 >= m_lineStarts. getCount ()) 128? m_lineEntries. getCount () 129: m_lineStarts[generatedLine + 1 ]; 130 131const auto entries = m_lineEntries. begin (); 132 133SLANG_ASSERT (start >= 0 && start <= m_lineEntries. getCount ()); 134SLANG_ASSERT (end >= start && end >= 0 && end <= m_lineEntries. getCount ()); 135 136return ConstArrayView < SourceMap::Entry > (entries + start, end - start); 137} 138 139} // namespace Slang 140 141#endif // SLANG_COMPILER_CORE_SOURCE_MAP_H