yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
eaa8dcfcc
master
1#pragma once 2 3#include "diagnostics.h" 4 5namespace CppParse 6{ 7using namespace Slang ; 8 9enum class IdentifierStyle 10{ 11None ,///< It's not an identifier 12 13Identifier ,///< Just an identifier 14 15PreDeclare ,///< Declare a type (not visible in C++ code) 16TypeSet ,///< TypeSet 17 18TypeModifier ,///< const, volatile etc 19Keyword ,///< A keyword C/C++ keyword that is not another type 20 21Class ,///< class 22Struct ,///< struct 23Namespace ,///< namespace 24Enum ,///< enum 25 26TypeDef ,///< typedef 27 28Access ,///< public, protected, private 29 30Reflected , 31Unreflected , 32 33CallingConvention ,///< Used on a method 34Virtual ,///< 35 36Template , 37 38Static , 39 40IntegerModifier , 41 42Extern , 43 44CallableMisc ,///< For SLANG_NO_THROW etc 45 46IntegerType ,///< Built in integer type 47 48Default ,/// default 49 50CountOf , 51}; 52 53typedef uint32_t IdentifierFlags ; 54struct IdentifierFlag 55{ 56enum Enum :IdentifierFlags 57 { 58StartScope = 0x1 ,///< namespace, struct or class 59ClassLike = 0x2 ,///< Struct or class 60Keyword = 0x4 , 61Reflection = 0x8 , 62 }; 63}; 64 65 66class IdentifierLookup 67{ 68public : 69struct Pair 70 { 71const char * name ; 72IdentifierStyle style ; 73 }; 74 75IdentifierStyle get ( const UnownedStringSlice & slice) const 76{ 77Index index = m_pool. findIndex (slice); 78return (index >= 0 ) ? m_styles[index] : IdentifierStyle::None; 79} 80 81void set ( const char * name, IdentifierStyle style) { set ( UnownedStringSlice (name), style); } 82 83void set ( const UnownedStringSlice & name, IdentifierStyle style); 84 85void set ( const char * const * names, size_t namesCount, IdentifierStyle style); 86 87void set ( const Pair * pairs, Index pairsCount); 88 89void reset () 90{ 91m_styles. clear (); 92m_pool. clear (); 93} 94 95void initDefault ( const UnownedStringSlice & markPrefix); 96 97IdentifierLookup () 98: m_pool ( StringSlicePool :: Style ::Empty) 99{ 100SLANG_ASSERT (m_pool. getSlicesCount () == 0 ); 101} 102 103static const IdentifierFlags kIdentifierFlags[ Index (IdentifierStyle::CountOf)]; 104 105protected : 106List < IdentifierStyle > m_styles; 107StringSlicePool m_pool; 108}; 109 110 111SLANG_FORCE_INLINE IdentifierFlags getFlags ( IdentifierStyle style) 112{ 113return IdentifierLookup::kIdentifierFlags[ Index (style)]; 114} 115 116SLANG_FORCE_INLINE bool hasFlag ( IdentifierStyle style, IdentifierFlag ::Enum flag) 117{ 118return ( getFlags (style) & flag) != 0 ; 119} 120 121} // namespace CppParse