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