1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SKSL_TOKEN
#define SKSL_TOKEN
#include "SkSLPosition.h"
#include "SkSLUtil.h"
namespace SkSL {
#undef IN
#undef OUT
#undef CONST
/**
* Represents a lexical analysis token. Token is generally only used during the parse process, but
* Token::Kind is also used to represent operator kinds.
*/
struct Token {
enum Kind {
END_OF_FILE,
IDENTIFIER,
INT_LITERAL,
FLOAT_LITERAL,
TRUE_LITERAL,
FALSE_LITERAL,
LPAREN,
RPAREN,
LBRACE,
RBRACE,
LBRACKET,
RBRACKET,
DOT,
COMMA,
PLUSPLUS,
MINUSMINUS,
PLUS,
MINUS,
STAR,
SLASH,
PERCENT,
SHL,
SHR,
BITWISEOR,
BITWISEXOR,
BITWISEAND,
LOGICALOR,
LOGICALXOR,
LOGICALAND,
NOT,
QUESTION,
COLON,
EQ,
EQEQ,
NEQ,
GT,
LT,
GTEQ,
LTEQ,
PLUSEQ,
MINUSEQ,
STAREQ,
SLASHEQ,
PERCENTEQ,
SHLEQ,
SHREQ,
BITWISEOREQ,
BITWISEXOREQ,
BITWISEANDEQ,
LOGICALOREQ,
LOGICALXOREQ,
LOGICALANDEQ,
SEMICOLON,
IF,
ELSE,
FOR,
WHILE,
DO,
RETURN,
BREAK,
CONTINUE,
DISCARD,
IN,
OUT,
INOUT,
CONST,
LOWP,
MEDIUMP,
HIGHP,
UNIFORM,
FLAT,
NOPERSPECTIVE,
STRUCT,
LAYOUT,
DIRECTIVE,
PRECISION,
INVALID_TOKEN
};
static std::string OperatorName(Kind kind) {
switch (kind) {
case Token::PLUS: return "+";
case Token::MINUS: return "-";
case Token::STAR: return "*";
case Token::SLASH: return "/";
case Token::PERCENT: return "%";
case Token::SHL: return "<<";
case Token::SHR: return ">>";
case Token::LOGICALAND: return "&&";
case Token::LOGICALOR: return "||";
case Token::LOGICALXOR: return "^^";
case Token::BITWISEAND: return "&";
case Token::BITWISEOR: return "|";
case Token::BITWISEXOR: return "^";
case Token::EQ: return "=";
case Token::EQEQ: return "==";
case Token::NEQ: return "!=";
case Token::LT: return "<";
case Token::GT: return ">";
case Token::LTEQ: return "<=";
case Token::GTEQ: return ">=";
case Token::PLUSEQ: return "+=";
case Token::MINUSEQ: return "-=";
case Token::STAREQ: return "*=";
case Token::SLASHEQ: return "/=";
case Token::PERCENTEQ: return "%=";
case Token::SHLEQ: return "<<=";
case Token::SHREQ: return ">>=";
case Token::LOGICALANDEQ: return "&&=";
case Token::LOGICALOREQ: return "||=";
case Token::LOGICALXOREQ: return "^^=";
case Token::BITWISEANDEQ: return "&=";
case Token::BITWISEOREQ: return "|=";
case Token::BITWISEXOREQ: return "^=";
case Token::PLUSPLUS: return "++";
case Token::MINUSMINUS: return "--";
case Token::NOT: return "!";
default:
ABORT("unsupported operator: %d\n", kind);
}
}
Token() {
}
Token(Position position, Kind kind, std::string text)
: fPosition(position)
, fKind(kind)
, fText(std::move(text)) {}
Position fPosition;
Kind fKind;
std::string fText;
};
} // namespace
#endif
|