effect_token.hpp (3950B)
1 /* 2 * Copyright (C) 2014 Patrick Mours 3 * SPDX-License-Identifier: BSD-3-Clause 4 */ 5 6 #pragma once 7 8 #include <cstdint> 9 #include <string> 10 #include <vector> 11 12 namespace reshadefx 13 { 14 /// <summary> 15 /// Structure which keeps track of a code location. 16 /// </summary> 17 struct location 18 { 19 location() : line(1), column(1) {} 20 explicit location(uint32_t line, uint32_t column = 1) : line(line), column(column) {} 21 explicit location(std::string source, uint32_t line, uint32_t column = 1) : source(std::move(source)), line(line), column(column) {} 22 23 std::string source; 24 uint32_t line, column; 25 }; 26 27 /// <summary> 28 /// A collection of identifiers for various possible tokens. 29 /// </summary> 30 enum class tokenid 31 { 32 unknown = -1, 33 end_of_file = 0, 34 end_of_line = '\n', 35 36 // operators 37 space = ' ', 38 exclaim = '!', 39 hash = '#', 40 dollar = '$', 41 percent = '%', 42 ampersand = '&', 43 parenthesis_open = '(', 44 parenthesis_close = ')', 45 star = '*', 46 plus = '+', 47 comma = ',', 48 minus = '-', 49 dot = '.', 50 slash = '/', 51 colon = ':', 52 semicolon = ';', 53 less = '<', 54 equal = '=', 55 greater = '>', 56 question = '?', 57 at = '@', 58 bracket_open = '[', 59 backslash = '\\', 60 bracket_close = ']', 61 caret = '^', 62 brace_open = '{', 63 pipe = '|', 64 brace_close = '}', 65 tilde = '~', 66 exclaim_equal = 256 /* != */, 67 percent_equal /* %= */, 68 ampersand_ampersand /* && */, 69 ampersand_equal /* &= */, 70 star_equal /* *= */, 71 plus_plus /* ++*/, 72 plus_equal /* += */, 73 minus_minus /* -- */, 74 minus_equal /* -= */, 75 arrow /* -> */, 76 ellipsis /* ... */, 77 slash_equal /* /= */, 78 colon_colon /* :: */, 79 less_less_equal /* <<= */, 80 less_less /* << */, 81 less_equal /* <= */, 82 equal_equal /* == */, 83 greater_greater_equal /* >>= */, 84 greater_greater /* >> */, 85 greater_equal /* >= */, 86 caret_equal /* ^= */, 87 pipe_equal /* |= */, 88 pipe_pipe /* || */, 89 90 // identifiers 91 reserved, 92 identifier, 93 94 // literals 95 true_literal, 96 false_literal, 97 int_literal, 98 uint_literal, 99 float_literal, 100 double_literal, 101 string_literal, 102 103 // keywords 104 namespace_, 105 struct_, 106 technique, 107 pass, 108 for_, 109 while_, 110 do_, 111 if_, 112 else_, 113 switch_, 114 case_, 115 default_, 116 break_, 117 continue_, 118 return_, 119 discard_, 120 extern_, 121 static_, 122 uniform_, 123 volatile_, 124 precise, 125 groupshared, 126 in, 127 out, 128 inout, 129 const_, 130 linear, 131 noperspective, 132 centroid, 133 nointerpolation, 134 135 void_, 136 bool_, 137 bool2, 138 bool3, 139 bool4, 140 bool2x2, 141 bool2x3, 142 bool2x4, 143 bool3x2, 144 bool3x3, 145 bool3x4, 146 bool4x2, 147 bool4x3, 148 bool4x4, 149 int_, 150 int2, 151 int3, 152 int4, 153 int2x2, 154 int2x3, 155 int2x4, 156 int3x2, 157 int3x3, 158 int3x4, 159 int4x2, 160 int4x3, 161 int4x4, 162 min16int, 163 min16int2, 164 min16int3, 165 min16int4, 166 uint_, 167 uint2, 168 uint3, 169 uint4, 170 uint2x2, 171 uint2x3, 172 uint2x4, 173 uint3x2, 174 uint3x3, 175 uint3x4, 176 uint4x2, 177 uint4x3, 178 uint4x4, 179 min16uint, 180 min16uint2, 181 min16uint3, 182 min16uint4, 183 float_, 184 float2, 185 float3, 186 float4, 187 float2x2, 188 float2x3, 189 float2x4, 190 float3x2, 191 float3x3, 192 float3x4, 193 float4x2, 194 float4x3, 195 float4x4, 196 min16float, 197 min16float2, 198 min16float3, 199 min16float4, 200 vector, 201 matrix, 202 string_, 203 texture1d, 204 texture2d, 205 texture3d, 206 sampler1d, 207 sampler2d, 208 sampler3d, 209 storage1d, 210 storage2d, 211 storage3d, 212 213 // preprocessor directives 214 hash_def, 215 hash_undef, 216 hash_if, 217 hash_ifdef, 218 hash_ifndef, 219 hash_else, 220 hash_elif, 221 hash_endif, 222 hash_error, 223 hash_warning, 224 hash_pragma, 225 hash_include, 226 hash_unknown, 227 228 single_line_comment, 229 multi_line_comment, 230 }; 231 232 /// <summary> 233 /// A structure describing a single token in the input string. 234 /// </summary> 235 struct token 236 { 237 tokenid id; 238 reshadefx::location location; 239 size_t offset, length; 240 union 241 { 242 int literal_as_int; 243 unsigned int literal_as_uint; 244 float literal_as_float; 245 double literal_as_double; 246 }; 247 std::string literal_as_string; 248 249 inline operator tokenid() const { return id; } 250 251 static std::string id_to_name(tokenid id); 252 }; 253 }