]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/d/dmd/tokens.h
Merge dmd upstream 6d5b853d3
[thirdparty/gcc.git] / gcc / d / dmd / tokens.h
CommitLineData
b4c522fa
IB
1
2/* Compiler implementation of the D programming language
f3ed896c 3 * Copyright (C) 1999-2019 by The D Language Foundation, All Rights Reserved
b4c522fa
IB
4 * written by Walter Bright
5 * http://www.digitalmars.com
6 * Distributed under the Boost Software License, Version 1.0.
7 * http://www.boost.org/LICENSE_1_0.txt
8 * https://github.com/dlang/dmd/blob/master/src/dmd/tokens.h
9 */
10
11#pragma once
12
13#include "root/port.h"
14#include "globals.h"
15
16class Identifier;
17
18/* Tokens:
19 ( )
20 [ ]
21 { }
22 < > <= >= == != === !==
23 << >> <<= >>= >>> >>>=
24 + - += -=
25 * / % *= /= %=
26 & | ^ &= |= ^=
27 = ! ~ @
28 ^^ ^^=
29 ++ --
30 . -> : , =>
31 ? && ||
32 */
33
34enum TOK
35{
36 TOKreserved,
37
38 // Other
39 TOKlparen, TOKrparen,
40 TOKlbracket, TOKrbracket,
41 TOKlcurly, TOKrcurly,
42 TOKcolon, TOKneg,
43 TOKsemicolon, TOKdotdotdot,
44 TOKeof, TOKcast,
45 TOKnull, TOKassert,
46 TOKtrue, TOKfalse,
47 TOKarray, TOKcall,
48 TOKaddress,
49 TOKtype, TOKthrow,
50 TOKnew, TOKdelete,
51 TOKstar, TOKsymoff,
52 TOKvar, TOKdotvar,
53 TOKdotid, TOKdotti,
54 TOKdottype, TOKslice,
55 TOKarraylength, TOKversion,
56 TOKmodule, TOKdollar,
57 TOKtemplate, TOKdottd,
58 TOKdeclaration, TOKtypeof,
59 TOKpragma, TOKdsymbol,
60 TOKtypeid, TOKuadd,
61 TOKremove,
62 TOKnewanonclass, TOKcomment,
63 TOKarrayliteral, TOKassocarrayliteral,
64 TOKstructliteral,
65 TOKclassreference,
66 TOKthrownexception,
67 TOKdelegateptr,
68 TOKdelegatefuncptr,
69
70// 54
71 // Operators
72 TOKlt, TOKgt,
73 TOKle, TOKge,
74 TOKequal, TOKnotequal,
75 TOKidentity, TOKnotidentity,
76 TOKindex, TOKis,
77
78// 64
79 // NCEG floating point compares
80 // !<>= <> <>= !> !>= !< !<= !<>
81 TOKunord,TOKlg,TOKleg,TOKule,TOKul,TOKuge,TOKug,TOKue,
82
83// 72
84 TOKshl, TOKshr,
85 TOKshlass, TOKshrass,
86 TOKushr, TOKushrass,
87 TOKcat, TOKcatass, // ~ ~=
88 TOKadd, TOKmin, TOKaddass, TOKminass,
89 TOKmul, TOKdiv, TOKmod,
90 TOKmulass, TOKdivass, TOKmodass,
91 TOKand, TOKor, TOKxor,
92 TOKandass, TOKorass, TOKxorass,
93 TOKassign, TOKnot, TOKtilde,
94 TOKplusplus, TOKminusminus, TOKconstruct, TOKblit,
95 TOKdot, TOKarrow, TOKcomma,
96 TOKquestion, TOKandand, TOKoror,
97 TOKpreplusplus, TOKpreminusminus,
98
99// 111
100 // Numeric literals
101 TOKint32v, TOKuns32v,
102 TOKint64v, TOKuns64v,
103 TOKint128v, TOKuns128v,
104 TOKfloat32v, TOKfloat64v, TOKfloat80v,
105 TOKimaginary32v, TOKimaginary64v, TOKimaginary80v,
106
107 // Char constants
108 TOKcharv, TOKwcharv, TOKdcharv,
109
110 // Leaf operators
111 TOKidentifier, TOKstring, TOKxstring,
112 TOKthis, TOKsuper,
113 TOKhalt, TOKtuple,
114 TOKerror,
115
116 // Basic types
117 TOKvoid,
118 TOKint8, TOKuns8,
119 TOKint16, TOKuns16,
120 TOKint32, TOKuns32,
121 TOKint64, TOKuns64,
122 TOKint128, TOKuns128,
123 TOKfloat32, TOKfloat64, TOKfloat80,
124 TOKimaginary32, TOKimaginary64, TOKimaginary80,
125 TOKcomplex32, TOKcomplex64, TOKcomplex80,
126 TOKchar, TOKwchar, TOKdchar, TOKbool,
127
128// 158
129 // Aggregates
130 TOKstruct, TOKclass, TOKinterface, TOKunion, TOKenum, TOKimport,
131 TOKalias, TOKoverride, TOKdelegate, TOKfunction,
132 TOKmixin,
133
134 TOKalign, TOKextern, TOKprivate, TOKprotected, TOKpublic, TOKexport,
135 TOKstatic, TOKfinal, TOKconst, TOKabstract,
136 TOKdebug, TOKdeprecated, TOKin, TOKout, TOKinout, TOKlazy,
137 TOKauto, TOKpackage, TOKmanifest, TOKimmutable,
138
139 // Statements
140 TOKif, TOKelse, TOKwhile, TOKfor, TOKdo, TOKswitch,
141 TOKcase, TOKdefault, TOKbreak, TOKcontinue, TOKwith,
142 TOKsynchronized, TOKreturn, TOKgoto, TOKtry, TOKcatch, TOKfinally,
143 TOKasm, TOKforeach, TOKforeach_reverse,
144 TOKscope,
145 TOKon_scope_exit, TOKon_scope_failure, TOKon_scope_success,
146
147 // Contracts
148 TOKinvariant,
149
150 // Testing
151 TOKunittest,
152
153 // Added after 1.0
154 TOKargTypes,
155 TOKref,
156 TOKmacro,
157
158 TOKparameters,
159 TOKtraits,
160 TOKoverloadset,
161 TOKpure,
162 TOKnothrow,
163 TOKgshared,
164 TOKline,
165 TOKfile,
166 TOKfilefullpath,
167 TOKmodulestring,
168 TOKfuncstring,
169 TOKprettyfunc,
170 TOKshared,
171 TOKat,
172 TOKpow,
173 TOKpowass,
174 TOKgoesto,
175 TOKvector,
176 TOKpound,
177
178 TOKinterval,
179 TOKvoidexp,
180 TOKcantexp,
181
182 TOKMAX
183};
184
185#define TOKwild TOKinout
186
187// Token has an anonymous struct, which is not strict ISO C++.
188#if defined(__GNUC__)
189#pragma GCC diagnostic push
190#pragma GCC diagnostic ignored "-Wpedantic"
191#endif
192
193struct Token
194{
195 Token *next;
196 Loc loc;
197 const utf8_t *ptr; // pointer to first character of this token within buffer
198 TOK value;
199 const utf8_t *blockComment; // doc comment string prior to this token
200 const utf8_t *lineComment; // doc comment for previous token
201 union
202 {
203 // Integers
204 d_int64 int64value;
205 d_uns64 uns64value;
206
207 // Floats
208 real_t floatvalue;
209
210 struct
211 { utf8_t *ustring; // UTF8 string
212 unsigned len;
213 unsigned char postfix; // 'c', 'w', 'd'
214 };
215
216 Identifier *ident;
217 };
218
219 static const char *tochars[TOKMAX];
220
221 static Token *freelist;
222 static Token *alloc();
223 void free();
224
225 Token() : next(NULL) {}
226 int isKeyword();
227 const char *toChars() const;
228 static const char *toChars(TOK);
229};
230
231#if defined(__GNUC__)
232#pragma GCC diagnostic pop
233#endif