yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
eaa8dcfcc
master
1#include "identifier-lookup.h" 2 3namespace CppParse 4{ 5using namespace Slang ; 6 7/* static */ const IdentifierFlags 8IdentifierLookup ::kIdentifierFlags [Index (IdentifierStyle ::CountOf )]= { 90 ,/// None 100 ,/// Identifier 110 ,/// Declare type 120 ,/// Type set 13IdentifierFlag ::Keyword ,/// TypeModifier 14IdentifierFlag ::Keyword ,/// Keyword 15 16IdentifierFlag ::Keyword |IdentifierFlag ::StartScope |IdentifierFlag ::ClassLike ,/// Class 17IdentifierFlag ::Keyword |IdentifierFlag ::StartScope |IdentifierFlag ::ClassLike ,/// Struct 18IdentifierFlag ::Keyword |IdentifierFlag ::StartScope ,/// Namespace 19IdentifierFlag ::Keyword |IdentifierFlag ::StartScope ,/// Enum 20 21IdentifierFlag ::Keyword ,/// Typedef 22 23IdentifierFlag ::Keyword ,/// Access 24IdentifierFlag ::Reflection ,/// Reflected 25IdentifierFlag ::Reflection ,/// Unreflected 26 27IdentifierFlag ::Keyword ,/// virtual 280 ,/// Calling convention 29IdentifierFlag ::Keyword ,/// template 30IdentifierFlag ::Keyword ,/// static 31 32IdentifierFlag ::Keyword ,/// unsigned/signed 33 34IdentifierFlag ::Keyword ,/// extern 35 360 ,/// Callable misc 370 ,/// IntegerType int, short, char, long 38 39IdentifierFlag ::Keyword ,/// default 40}; 41 42void IdentifierLookup ::set (const UnownedStringSlice & name ,IdentifierStyle style ) 43{ 44StringSlicePool ::Handle handle ; 45if (m_pool .findOrAdd (name ,handle )) 46 { 47// Add the extra flags 48m_styles [Index (handle )]= style ; 49 } 50else 51 { 52Index index = Index (handle ); 53SLANG_ASSERT (index == m_styles .getCount ()); 54m_styles .add (style ); 55 } 56} 57 58void IdentifierLookup ::set (const char * const * names ,size_t namesCount ,IdentifierStyle style ) 59{ 60for (size_t i = 0 ;i < namesCount ;++ i ) 61 { 62set (UnownedStringSlice (names [i ]),style ); 63 } 64} 65 66void IdentifierLookup ::set (const Pair * pairs ,Index pairsCount ) 67{ 68for (Index i = 0 ;i < pairsCount ;++ i ) 69 { 70const auto & pair = pairs [i ]; 71set (UnownedStringSlice (pair .name ),pair .style ); 72 } 73} 74 75void IdentifierLookup ::initDefault (const UnownedStringSlice & markPrefix ) 76{ 77reset (); 78 79// Some keywords 80 { 81const char * names []= { 82"continue" , 83"if" , 84"case" , 85"break" , 86"catch" , 87"delete" , 88"do" , 89"else" , 90"for" , 91"new" , 92"goto" , 93"return" , 94"switch" , 95"throw" , 96"using" , 97"while" , 98"operator" , 99"explicit" }; 100set (names ,SLANG_COUNT_OF (names ),IdentifierStyle ::Keyword ); 101 } 102 103// Type modifier keywords 104 { 105const char * names []= {"const" ,"volatile" }; 106set (names ,SLANG_COUNT_OF (names ),IdentifierStyle ::TypeModifier ); 107 } 108 109// Special markers 110 { 111const char * names []= {"PRE_DECLARE" ,"TYPE_SET" ,"REFLECTED" ,"UNREFLECTED" }; 112const IdentifierStyle styles []= { 113IdentifierStyle ::PreDeclare , 114IdentifierStyle ::TypeSet , 115IdentifierStyle ::Reflected , 116IdentifierStyle ::Unreflected }; 117SLANG_COMPILE_TIME_ASSERT (SLANG_COUNT_OF (names )== SLANG_COUNT_OF (styles )); 118 119StringBuilder buf ; 120for (Index i = 0 ;i < SLANG_COUNT_OF (names );++ i ) 121 { 122buf .clear (); 123buf <<markPrefix <<names [i ]; 124set (buf .getUnownedSlice (),styles [i ]); 125 } 126 } 127 128 { 129set ("virtual" ,IdentifierStyle ::Virtual ); 130 131set ("template" ,IdentifierStyle ::Template ); 132set ("static" ,IdentifierStyle ::Static ); 133set ("extern" ,IdentifierStyle ::Extern ); 134set ("default" ,IdentifierStyle ::Default ); 135 } 136 137 { 138const char * names []= {"char" ,"short" ,"int" ,"long" }; 139set (names ,SLANG_COUNT_OF (names ),IdentifierStyle ::IntegerType ); 140 } 141 142 { 143const char * names []= {"SLANG_MCALL" }; 144set (names ,SLANG_COUNT_OF (names ),IdentifierStyle ::CallingConvention ); 145 } 146 147 { 148const char * names []= {"SLANG_NO_THROW" ,"inline" }; 149set (names ,SLANG_COUNT_OF (names ),IdentifierStyle ::CallableMisc ); 150 } 151 152// Keywords which introduce types/scopes 153 { 154const Pair pairs []= { 155 {"struct" ,IdentifierStyle ::Struct }, 156 {"class" ,IdentifierStyle ::Class }, 157 {"namespace" ,IdentifierStyle ::Namespace }, 158 {"enum" ,IdentifierStyle ::Enum }, 159 {"typedef" ,IdentifierStyle ::TypeDef }, 160 }; 161 162set (pairs ,SLANG_COUNT_OF (pairs )); 163 } 164 165// Keywords that control access 166 { 167const char * names []= {"private" ,"protected" ,"public" }; 168set (names ,SLANG_COUNT_OF (names ),IdentifierStyle ::Access ); 169 } 170 { 171const char * names []= {"signed" ,"unsigned" }; 172 173set (names ,SLANG_COUNT_OF (names ),IdentifierStyle ::IntegerModifier ); 174 } 175} 176 177}// namespace CppParse