yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1// slang-doc.h 2#ifndef SLANG_DOC_EXTRACTOR_H 3#define SLANG_DOC_EXTRACTOR_H 4 5#include "../core/slang-basic.h" 6#include "slang-lexer.h" 7#include "slang-source-loc.h" 8 9namespace Slang 10{ 11 12enum class MarkupVisibility :uint8_t 13{ 14Public ,///< Always available 15Internal ,///< Can be available in more verbose 'internal' documentation 16Hidden ,///< Not generally available 17}; 18 19/* Extracts 'markup' from comments in Slang source core. The comments are extracted and associated 20in declarations. The association is held in DocMarkup type. The comment style follows the doxygen 21style */ 22class DocMarkupExtractor 23{ 24public : 25typedef uint32_t MarkupFlags ; 26struct MarkupFlag 27 { 28enum Enum :MarkupFlags 29 { 30Before = 0x1 , 31After = 0x2 , 32IsMultiToken = 0x4 ,///< Can use more than one token 33IsBlock = 0x8 ,///< 34 }; 35 }; 36 37// NOTE! Don't change order without fixing isBefore and isAfter 38enum class MarkupType 39 { 40None , 41 42BlockBefore ,/// /** */ or /*! */. 43LineBangBefore ,/// //! Can be multiple lines 44LineSlashBefore ,/// /// Can be multiple lines 45OrdinaryBlockBefore , 46OrdinaryLineBefore , 47 48BlockAfter ,/// /*!< */ or /**< */ 49LineBangAfter ,/// //!< Can be multiple lines 50LineSlashAfter ,/// ///< Can be multiple lines 51OrdinaryLineAfter , 52 }; 53 54static bool isBefore (MarkupType type ) 55 { 56return Index (type ) >=Index (MarkupType ::BlockBefore )&& 57Index (type ) <=Index (MarkupType ::OrdinaryLineBefore ); 58 } 59static bool isAfter (MarkupType type ) {return Index (type ) >=Index (MarkupType ::BlockAfter ); } 60 61struct IndexRange 62 { 63SLANG_FORCE_INLINE Index getCount ()const {return end - start ; } 64 65Index start ; 66Index end ; 67 }; 68 69enum class Location 70 { 71None ,///< No defined location 72Before , 73AfterParam ,///< Can have trailing , or ) 74AfterSemicolon ,///< Can have a trailing ; 75AfterEnumCase ,///< Can have a , or before } 76AfterGenericParam ,///< Can have trailing , or > 77 }; 78 79static bool isAfter (Location location ) 80 { 81return Index (location ) >=Index (Location ::AfterParam ); 82 } 83static bool isBefore (Location location ) {return location == Location ::Before ; } 84 85struct FoundMarkup 86 { 87void reset () 88 { 89location = Location ::None ; 90type = MarkupType ::None ; 91range = IndexRange {0 ,0 }; 92 } 93 94Location location = Location ::None ; 95MarkupType type = MarkupType ::None ; 96IndexRange range ; 97 }; 98 99enum SearchStyle 100 { 101None ,///< Cannot be searched for 102EnumCase ,///< An enum case 103Param ,///< A parameter in a function/method 104Variable ,///< A variable-like declaration 105Before ,///< Only allows before 106Function ,///< Function/method 107GenericParam ,///< Generic parameter 108Attribute ,///< Attribute definition 109 }; 110 111/// An input search item 112struct SearchItemInput 113 { 114SourceLoc sourceLoc ; 115SearchStyle searchStyle ;///< The search style when looking for an item 116 }; 117 118/// The items will be in source order 119struct SearchItemOutput 120 { 121Index viewIndex ;///< Index into the array of views on the output 122Index inputIndex ;///< The index to this item in the input 123String text ;///< The found text 124MarkupVisibility visibilty ;///< Visibility of the item 125 }; 126 127struct FindInfo 128 { 129SourceView * sourceView ;///< The source view the tokens were generated from 130TokenList * tokenList ;///< The token list 131Index tokenIndex ;///< The token index location (where searches start from) 132Index lineIndex ;///< The line number for the decl 133 }; 134 135void setSearchInOrdinaryComments (bool val ) {m_searchInOrindaryComments = val ; } 136 137/// Extracts 'markup' doc information for the specified input items 138/// The output is placed in out - with the items now in the source order *not* the order of the 139/// input items The inputIndex on the output holds the input item index The outViews holds the 140/// views specified in viewIndex in the output, which may be useful for determining where the 141/// documentation was placed in source 142SlangResult extract ( 143const SearchItemInput * inputItems , 144Index inputCount , 145SourceManager * sourceManager , 146DiagnosticSink * sink , 147List < SourceView *>& outViews , 148List < SearchItemOutput >& out ); 149 150static MarkupFlags getFlags (MarkupType type ); 151static MarkupType findMarkupType (const Token & tok ); 152static UnownedStringSlice removeStart (MarkupType type ,const UnownedStringSlice & comment ); 153 154protected : 155/// returns SLANG_E_NOT_FOUND if not found, SLANG_OK on success else an error 156SlangResult _findMarkup (const FindInfo & info ,Location location ,FoundMarkup & out ); 157 158/// Locations are processed in order, and the first successful used. If found in another 159/// location will issue a warning. returns SLANG_E_NOT_FOUND if not found, SLANG_OK on success 160/// else an error 161SlangResult _findFirstMarkup ( 162const FindInfo & info , 163const Location * locs , 164Index locCount , 165FoundMarkup & out , 166Index & outIndex ); 167 168SlangResult _findMarkup ( 169const FindInfo & info , 170const Location * locs , 171Index locCount , 172FoundMarkup & out ); 173 174/// Given the decl, the token stream, and the decls tokenIndex, try to find some associated 175/// markup 176SlangResult _findMarkup (const FindInfo & info ,SearchStyle searchStyle ,FoundMarkup & out ); 177 178/// Given a found markup location extracts the contents of the tokens into out 179SlangResult _extractMarkup ( 180const FindInfo & info , 181const FoundMarkup & foundMarkup , 182StringBuilder & out ); 183 184/// Given a location, try to find the first token index that could potentially be markup 185/// Will return -1 if not found 186Index _findStartIndex (const FindInfo & info ,Location location ); 187 188/// True if the tok is 'on' lineIndex. Interpretation of 'on' depends on the markup type. 189static bool _isTokenOnLineIndex ( 190SourceView * sourceView , 191MarkupType type , 192const Token & tok , 193Index lineIndex ); 194 195DiagnosticSink * m_sink ; 196 197bool m_searchInOrindaryComments = false; 198}; 199 200}// namespace Slang 201 202#endif