xref: /netbsd/external/gpl3/gcc/dist/gcc/d/dmd/tokens.h (revision f0fbc68b)
1 
2 /* Compiler implementation of the D programming language
3  * Copyright (C) 1999-2022 by The D Language Foundation, All Rights Reserved
4  * written by Walter Bright
5  * https://www.digitalmars.com
6  * Distributed under the Boost Software License, Version 1.0.
7  * https://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/dcompat.h"
14 #include "root/port.h"
15 #include "globals.h"
16 
17 class Identifier;
18 
19 /* Tokens:
20         (       )
21         [       ]
22         {       }
23         <       >       <=      >=      ==      !=      ===     !==
24         <<      >>      <<=     >>=     >>>     >>>=
25         +       -       +=      -=
26         *       /       %       *=      /=      %=
27         &       |       ^       &=      |=      ^=
28         =       !       ~       @
29         ^^      ^^=
30         ++      --
31         .       ->      :       ,       =>
32         ?       &&      ||
33  */
34 
35 enum class TOK : unsigned char
36 {
37     reserved,
38 
39     // Other
40     leftParenthesis,
41     rightParenthesis,
42     leftBracket,
43     rightBracket,
44     leftCurly,
45     rightCurly,
46     colon,
47     semicolon,
48     dotDotDot,
49     endOfFile,
50     cast_,
51     null_,
52     assert_,
53     true_,
54     false_,
55     throw_,
56     new_,
57     delete_,
58     variable,
59     slice,
60     version_,
61     module_,
62     dollar,
63     template_,
64     typeof_,
65     pragma_,
66     typeid_,
67     comment,
68 
69     // Operators
70     lessThan,
71     greaterThan,
72     lessOrEqual,
73     greaterOrEqual,
74     equal,
75     notEqual,
76     identity,
77     notIdentity,
78     is_,
79 
80     leftShift,
81     rightShift,
82     leftShiftAssign,
83     rightShiftAssign,
84     unsignedRightShift,
85     unsignedRightShiftAssign,
86     concatenateAssign, // ~=
87     add,
88     min,
89     addAssign,
90     minAssign,
91     mul,
92     div,
93     mod,
94     mulAssign,
95     divAssign,
96     modAssign,
97     and_,
98     or_,
99     xor_,
100     andAssign,
101     orAssign,
102     xorAssign,
103     assign,
104     not_,
105     tilde,
106     plusPlus,
107     minusMinus,
108     dot,
109     comma,
110     question,
111     andAnd,
112     orOr,
113 
114     // Numeric literals
115     int32Literal,
116     uns32Literal,
117     int64Literal,
118     uns64Literal,
119     int128Literal,
120     uns128Literal,
121     float32Literal,
122     float64Literal,
123     float80Literal,
124     imaginary32Literal,
125     imaginary64Literal,
126     imaginary80Literal,
127 
128     // Char constants
129     charLiteral,
130     wcharLiteral,
131     dcharLiteral,
132 
133     // Leaf operators
134     identifier,
135     string_,
136     this_,
137     super_,
138     error,
139 
140     // Basic types
141     void_,
142     int8,
143     uns8,
144     int16,
145     uns16,
146     int32,
147     uns32,
148     int64,
149     uns64,
150     int128,
151     uns128,
152     float32,
153     float64,
154     float80,
155     imaginary32,
156     imaginary64,
157     imaginary80,
158     complex32,
159     complex64,
160     complex80,
161     char_,
162     wchar_,
163     dchar_,
164     bool_,
165 
166     // Aggregates
167     struct_,
168     class_,
169     interface_,
170     union_,
171     enum_,
172     import_,
173     alias_,
174     override_,
175     delegate_,
176     function_,
177     mixin_,
178     align_,
179     extern_,
180     private_,
181     protected_,
182     public_,
183     export_,
184     static_,
185     final_,
186     const_,
187     abstract_,
188     debug_,
189     deprecated_,
190     in_,
191     out_,
192     inout_,
193     lazy_,
194     auto_,
195     package_,
196     immutable_,
197 
198     // Statements
199     if_,
200     else_,
201     while_,
202     for_,
203     do_,
204     switch_,
205     case_,
206     default_,
207     break_,
208     continue_,
209     with_,
210     synchronized_,
211     return_,
212     goto_,
213     try_,
214     catch_,
215     finally_,
216     asm_,
217     foreach_,
218     foreach_reverse_,
219     scope_,
220     onScopeExit,
221     onScopeFailure,
222     onScopeSuccess,
223 
224     // Contracts
225     invariant_,
226 
227     // Testing
228     unittest_,
229 
230     // Added after 1.0
231     argumentTypes,
232     ref_,
233     macro_,
234 
235     parameters,
236     traits,
237     pure_,
238     nothrow_,
239     gshared,
240     line,
241     file,
242     fileFullPath,
243     moduleString,   // __MODULE__
244     functionString, // __FUNCTION__
245     prettyFunction, // __PRETTY_FUNCTION__
246     shared_,
247     at,
248     pow,
249     powAssign,
250     goesTo,
251     vector,
252     pound,
253 
254     arrow,      // ->
255     colonColon, // ::
256     wchar_tLiteral,
257     endOfLine,  // \n, \r, \u2028, \u2029
258     whitespace,
259 
260     // C only keywords
261     inline_,
262     register_,
263     restrict_,
264     signed_,
265     sizeof_,
266     typedef_,
267     unsigned_,
268     volatile_,
269     _Alignas_,
270     _Alignof_,
271     _Atomic_,
272     _Bool_,
273     _Complex_,
274     _Generic_,
275     _Imaginary_,
276     _Noreturn_,
277     _Static_assert_,
278     _Thread_local_,
279 
280     // C only extended keywords
281     _import,
282     cdecl_,
283     declspec,
284     stdcall,
285     attribute__,
286 
287     MAX,
288 };
289 
290 enum class EXP : unsigned char
291 {
292     reserved,
293 
294     // Other
295     negate,
296     cast_,
297     null_,
298     assert_,
299     true_,
300     false_,
301     array,
302     call,
303     address,
304     type,
305     throw_,
306     new_,
307     delete_,
308     star,
309     symbolOffset,
310     variable,
311     dotVariable,
312     dotIdentifier,
313     dotTemplateInstance,
314     dotType,
315     slice,
316     arrayLength,
317     version_,
318     dollar,
319     template_,
320     dotTemplateDeclaration,
321     declaration,
322     typeof_,
323     pragma_,
324     dSymbol,
325     typeid_,
326     uadd,
327     remove,
328     newAnonymousClass,
329     arrayLiteral,
330     assocArrayLiteral,
331     structLiteral,
332     classReference,
333     thrownException,
334     delegatePointer,
335     delegateFunctionPointer,
336 
337     // Operators
338     lessThan,
339     greaterThan,
340     lessOrEqual,
341     greaterOrEqual,
342     equal,
343     notEqual,
344     identity,
345     notIdentity,
346     index,
347     is_,
348 
349     leftShift,
350     rightShift,
351     leftShiftAssign,
352     rightShiftAssign,
353     unsignedRightShift,
354     unsignedRightShiftAssign,
355     concatenate,
356     concatenateAssign, // ~=
357     concatenateElemAssign,
358     concatenateDcharAssign,
359     add,
360     min,
361     addAssign,
362     minAssign,
363     mul,
364     div,
365     mod,
366     mulAssign,
367     divAssign,
368     modAssign,
369     and_,
370     or_,
371     xor_,
372     andAssign,
373     orAssign,
374     xorAssign,
375     assign,
376     not_,
377     tilde,
378     plusPlus,
379     minusMinus,
380     construct,
381     blit,
382     dot,
383     comma,
384     question,
385     andAnd,
386     orOr,
387     prePlusPlus,
388     preMinusMinus,
389 
390     // Leaf operators
391     identifier,
392     string_,
393     this_,
394     super_,
395     halt,
396     tuple,
397     error,
398 
399     // Basic types
400     void_,
401     int64,
402     float64,
403     complex80,
404     char_,
405     import_,
406     delegate_,
407     function_,
408     mixin_,
409     in_,
410     default_,
411     break_,
412     continue_,
413     goto_,
414     scope_,
415 
416     traits,
417     overloadSet,
418     line,
419     file,
420     fileFullPath,
421     moduleString,   // __MODULE__
422     functionString, // __FUNCTION__
423     prettyFunction, // __PRETTY_FUNCTION__
424     shared_,
425     pow,
426     powAssign,
427     vector,
428 
429     voidExpression,
430     cantExpression,
431     showCtfeContext,
432     objcClassReference,
433     vectorArray,
434     arrow,      // ->
435     compoundLiteral, // ( type-name ) { initializer-list }
436     _Generic_,
437     interval,
438 
439     MAX
440 };
441 
442 #define TOKwild TOKinout
443 
444 // Token has an anonymous struct, which is not strict ISO C++.
445 #if defined(__GNUC__)
446 #pragma GCC diagnostic push
447 #pragma GCC diagnostic ignored "-Wpedantic"
448 #endif
449 
450 struct Token
451 {
452     Token *next;
453     Loc loc;
454     const utf8_t *ptr;    // pointer to first character of this token within buffer
455     TOK value;
456     DString blockComment; // doc comment string prior to this token
457     DString lineComment;  // doc comment for previous token
458     union
459     {
460         // Integers
461         sinteger_t intvalue;
462         uinteger_t unsvalue;
463 
464         // Floats
465         real_t floatvalue;
466 
467         struct
468         {   utf8_t *ustring;     // UTF8 string
469             unsigned len;
470             unsigned char postfix;      // 'c', 'w', 'd'
471         };
472 
473         Identifier *ident;
474     };
475 
476     void free();
477 
TokenToken478     Token() : next(NULL) {}
479     int isKeyword();
480     const char *toChars() const;
481 
482     static const char *toChars(TOK value);
483 };
484 
485 #if defined(__GNUC__)
486 #pragma GCC diagnostic pop
487 #endif
488