xref: /netbsd/external/gpl3/gcc.old/dist/gcc/d/dmd/tokens.h (revision 760c2415)
1 
2 /* Compiler implementation of the D programming language
3  * Copyright (C) 1999-2019 by The D Language Foundation, All Rights Reserved
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 
16 class Identifier;
17 
18 /* Tokens:
19         (       )
20         [       ]
21         {       }
22         <       >       <=      >=      ==      !=      ===     !==
23         <<      >>      <<=     >>=     >>>     >>>=
24         +       -       +=      -=
25         *       /       %       *=      /=      %=
26         &       |       ^       &=      |=      ^=
27         =       !       ~       @
28         ^^      ^^=
29         ++      --
30         .       ->      :       ,       =>
31         ?       &&      ||
32  */
33 
34 enum 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         TOKvectorarray,
183 
184         TOKMAX
185 };
186 
187 #define TOKwild TOKinout
188 
189 // Token has an anonymous struct, which is not strict ISO C++.
190 #if defined(__GNUC__)
191 #pragma GCC diagnostic push
192 #pragma GCC diagnostic ignored "-Wpedantic"
193 #endif
194 
195 struct Token
196 {
197     Token *next;
198     Loc loc;
199     const utf8_t *ptr;         // pointer to first character of this token within buffer
200     TOK value;
201     const utf8_t *blockComment; // doc comment string prior to this token
202     const utf8_t *lineComment;  // doc comment for previous token
203     union
204     {
205         // Integers
206         d_int64 int64value;
207         d_uns64 uns64value;
208 
209         // Floats
210         real_t floatvalue;
211 
212         struct
213         {   utf8_t *ustring;     // UTF8 string
214             unsigned len;
215             unsigned char postfix;      // 'c', 'w', 'd'
216         };
217 
218         Identifier *ident;
219     };
220 
221     static const char *tochars[TOKMAX];
222 
223     static Token *freelist;
224     static Token *alloc();
225     void free();
226 
TokenToken227     Token() : next(NULL) {}
228     int isKeyword();
229     const char *toChars() const;
230     static const char *toChars(TOK);
231 };
232 
233 #if defined(__GNUC__)
234 #pragma GCC diagnostic pop
235 #endif
236