]>
Commit | Line | Data |
---|---|---|
b4c522fa IB |
1 | |
2 | /* Compiler implementation of the D programming language | |
a3b38b77 | 3 | * Copyright (C) 1999-2021 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/attrib.h | |
9 | */ | |
10 | ||
11 | #pragma once | |
12 | ||
13 | #include "dsymbol.h" | |
14 | ||
15 | class Expression; | |
16 | class Statement; | |
17 | class LabelDsymbol; | |
18 | class Initializer; | |
19 | class Module; | |
20 | class Condition; | |
21 | class StaticForeach; | |
22 | ||
23 | /**************************************************************/ | |
24 | ||
25 | class AttribDeclaration : public Dsymbol | |
26 | { | |
27 | public: | |
28 | Dsymbols *decl; // array of Dsymbol's | |
29 | ||
30 | AttribDeclaration(Dsymbols *decl); | |
d3da83f6 | 31 | virtual Dsymbols *include(Scope *sc); |
b4c522fa IB |
32 | int apply(Dsymbol_apply_ft_t fp, void *param); |
33 | static Scope *createNewScope(Scope *sc, | |
34 | StorageClass newstc, LINK linkage, CPPMANGLE cppmangle, Prot protection, | |
35 | int explicitProtection, AlignDeclaration *aligndecl, PINLINE inlining); | |
36 | virtual Scope *newScope(Scope *sc); | |
37 | void addMember(Scope *sc, ScopeDsymbol *sds); | |
38 | void setScope(Scope *sc); | |
39 | void importAll(Scope *sc); | |
b4c522fa IB |
40 | void addComment(const utf8_t *comment); |
41 | const char *kind() const; | |
42 | bool oneMember(Dsymbol **ps, Identifier *ident); | |
43 | void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion); | |
44 | bool hasPointers(); | |
45 | bool hasStaticCtorOrDtor(); | |
46 | void checkCtorConstInit(); | |
47 | void addLocalClass(ClassDeclarations *); | |
48 | AttribDeclaration *isAttribDeclaration() { return this; } | |
49 | ||
50 | void accept(Visitor *v) { v->visit(this); } | |
51 | }; | |
52 | ||
53 | class StorageClassDeclaration : public AttribDeclaration | |
54 | { | |
55 | public: | |
56 | StorageClass stc; | |
57 | ||
58 | StorageClassDeclaration(StorageClass stc, Dsymbols *decl); | |
59 | Dsymbol *syntaxCopy(Dsymbol *s); | |
60 | Scope *newScope(Scope *sc); | |
61 | bool oneMember(Dsymbol **ps, Identifier *ident); | |
62 | void addMember(Scope *sc, ScopeDsymbol *sds); | |
63 | StorageClassDeclaration *isStorageClassDeclaration() { return this; } | |
64 | ||
65 | void accept(Visitor *v) { v->visit(this); } | |
66 | }; | |
67 | ||
68 | class DeprecatedDeclaration : public StorageClassDeclaration | |
69 | { | |
70 | public: | |
71 | Expression *msg; | |
72 | const char *msgstr; | |
73 | ||
74 | DeprecatedDeclaration(Expression *msg, Dsymbols *decl); | |
75 | Dsymbol *syntaxCopy(Dsymbol *s); | |
76 | Scope *newScope(Scope *sc); | |
77 | void setScope(Scope *sc); | |
b4c522fa IB |
78 | const char *getMessage(); |
79 | void accept(Visitor *v) { v->visit(this); } | |
80 | }; | |
81 | ||
82 | class LinkDeclaration : public AttribDeclaration | |
83 | { | |
84 | public: | |
85 | LINK linkage; | |
86 | ||
87 | LinkDeclaration(LINK p, Dsymbols *decl); | |
88 | static LinkDeclaration *create(LINK p, Dsymbols *decl); | |
89 | Dsymbol *syntaxCopy(Dsymbol *s); | |
90 | Scope *newScope(Scope *sc); | |
91 | const char *toChars(); | |
92 | void accept(Visitor *v) { v->visit(this); } | |
93 | }; | |
94 | ||
95 | class CPPMangleDeclaration : public AttribDeclaration | |
96 | { | |
97 | public: | |
98 | CPPMANGLE cppmangle; | |
99 | ||
100 | CPPMangleDeclaration(CPPMANGLE p, Dsymbols *decl); | |
101 | Dsymbol *syntaxCopy(Dsymbol *s); | |
102 | Scope *newScope(Scope *sc); | |
103 | const char *toChars(); | |
104 | void accept(Visitor *v) { v->visit(this); } | |
105 | }; | |
106 | ||
107 | class ProtDeclaration : public AttribDeclaration | |
108 | { | |
109 | public: | |
110 | Prot protection; | |
111 | Identifiers* pkg_identifiers; | |
112 | ||
113 | ProtDeclaration(Loc loc, Prot p, Dsymbols *decl); | |
114 | ProtDeclaration(Loc loc, Identifiers* pkg_identifiers, Dsymbols *decl); | |
115 | ||
116 | Dsymbol *syntaxCopy(Dsymbol *s); | |
117 | Scope *newScope(Scope *sc); | |
118 | void addMember(Scope *sc, ScopeDsymbol *sds); | |
119 | const char *kind() const; | |
120 | const char *toPrettyChars(bool unused); | |
121 | void accept(Visitor *v) { v->visit(this); } | |
122 | }; | |
123 | ||
124 | class AlignDeclaration : public AttribDeclaration | |
125 | { | |
126 | public: | |
127 | Expression *ealign; | |
128 | structalign_t salign; | |
129 | ||
130 | AlignDeclaration(Loc loc, Expression *ealign, Dsymbols *decl); | |
131 | Dsymbol *syntaxCopy(Dsymbol *s); | |
132 | Scope *newScope(Scope *sc); | |
b4c522fa IB |
133 | structalign_t getAlignment(Scope *sc); |
134 | void accept(Visitor *v) { v->visit(this); } | |
135 | }; | |
136 | ||
137 | class AnonDeclaration : public AttribDeclaration | |
138 | { | |
139 | public: | |
140 | bool isunion; | |
141 | int sem; // 1 if successful semantic() | |
142 | unsigned anonoffset; // offset of anonymous struct | |
143 | unsigned anonstructsize; // size of anonymous struct | |
144 | unsigned anonalignsize; // size of anonymous struct for alignment purposes | |
145 | ||
146 | AnonDeclaration(Loc loc, bool isunion, Dsymbols *decl); | |
147 | Dsymbol *syntaxCopy(Dsymbol *s); | |
148 | void setScope(Scope *sc); | |
b4c522fa IB |
149 | void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion); |
150 | const char *kind() const; | |
151 | AnonDeclaration *isAnonDeclaration() { return this; } | |
152 | void accept(Visitor *v) { v->visit(this); } | |
153 | }; | |
154 | ||
155 | class PragmaDeclaration : public AttribDeclaration | |
156 | { | |
157 | public: | |
158 | Expressions *args; // array of Expression's | |
159 | ||
160 | PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Dsymbols *decl); | |
161 | Dsymbol *syntaxCopy(Dsymbol *s); | |
162 | Scope *newScope(Scope *sc); | |
b4c522fa IB |
163 | const char *kind() const; |
164 | void accept(Visitor *v) { v->visit(this); } | |
165 | }; | |
166 | ||
167 | class ConditionalDeclaration : public AttribDeclaration | |
168 | { | |
169 | public: | |
170 | Condition *condition; | |
171 | Dsymbols *elsedecl; // array of Dsymbol's for else block | |
172 | ||
173 | ConditionalDeclaration(Condition *condition, Dsymbols *decl, Dsymbols *elsedecl); | |
174 | Dsymbol *syntaxCopy(Dsymbol *s); | |
175 | bool oneMember(Dsymbol **ps, Identifier *ident); | |
d3da83f6 | 176 | Dsymbols *include(Scope *sc); |
b4c522fa IB |
177 | void addComment(const utf8_t *comment); |
178 | void setScope(Scope *sc); | |
179 | void accept(Visitor *v) { v->visit(this); } | |
180 | }; | |
181 | ||
182 | class StaticIfDeclaration : public ConditionalDeclaration | |
183 | { | |
184 | public: | |
185 | ScopeDsymbol *scopesym; | |
186 | bool addisdone; | |
5b74dd0a | 187 | bool onStack; |
b4c522fa IB |
188 | |
189 | StaticIfDeclaration(Condition *condition, Dsymbols *decl, Dsymbols *elsedecl); | |
190 | Dsymbol *syntaxCopy(Dsymbol *s); | |
d3da83f6 | 191 | Dsymbols *include(Scope *sc); |
b4c522fa IB |
192 | void addMember(Scope *sc, ScopeDsymbol *sds); |
193 | void setScope(Scope *sc); | |
194 | void importAll(Scope *sc); | |
b4c522fa IB |
195 | const char *kind() const; |
196 | void accept(Visitor *v) { v->visit(this); } | |
197 | }; | |
198 | ||
5b74dd0a | 199 | class StaticForeachDeclaration : public AttribDeclaration |
b4c522fa IB |
200 | { |
201 | public: | |
202 | StaticForeach *sfe; | |
203 | ScopeDsymbol *scopesym; | |
5b74dd0a | 204 | bool onStack; |
b4c522fa IB |
205 | bool cached; |
206 | Dsymbols *cache; | |
207 | ||
5b74dd0a | 208 | StaticForeachDeclaration(StaticForeach *sfe, Dsymbols *decl); |
b4c522fa | 209 | Dsymbol *syntaxCopy(Dsymbol *s); |
f9ab59ff | 210 | bool oneMember(Dsymbol **ps, Identifier *ident); |
d3da83f6 | 211 | Dsymbols *include(Scope *sc); |
b4c522fa | 212 | void addMember(Scope *sc, ScopeDsymbol *sds); |
f9ab59ff | 213 | void addComment(const utf8_t *comment); |
b4c522fa IB |
214 | void setScope(Scope *sc); |
215 | void importAll(Scope *sc); | |
b4c522fa IB |
216 | const char *kind() const; |
217 | void accept(Visitor *v) { v->visit(this); } | |
218 | }; | |
219 | ||
5b74dd0a | 220 | class ForwardingAttribDeclaration : public AttribDeclaration |
b4c522fa IB |
221 | { |
222 | public: | |
223 | ForwardingScopeDsymbol *sym; | |
224 | ||
5b74dd0a | 225 | ForwardingAttribDeclaration(Dsymbols *decl); |
b4c522fa IB |
226 | Scope *newScope(Scope *sc); |
227 | void addMember(Scope *sc, ScopeDsymbol *sds); | |
228 | ForwardingAttribDeclaration *isForwardingAttribDeclaration() { return this; } | |
5b74dd0a | 229 | void accept(Visitor *v) { v->visit(this); } |
b4c522fa IB |
230 | }; |
231 | ||
232 | // Mixin declarations | |
233 | ||
234 | class CompileDeclaration : public AttribDeclaration | |
235 | { | |
236 | public: | |
237 | Expression *exp; | |
238 | ||
239 | ScopeDsymbol *scopesym; | |
240 | bool compiled; | |
241 | ||
242 | CompileDeclaration(Loc loc, Expression *exp); | |
243 | Dsymbol *syntaxCopy(Dsymbol *s); | |
244 | void addMember(Scope *sc, ScopeDsymbol *sds); | |
245 | void setScope(Scope *sc); | |
b4c522fa IB |
246 | const char *kind() const; |
247 | void accept(Visitor *v) { v->visit(this); } | |
248 | }; | |
249 | ||
250 | /** | |
251 | * User defined attributes look like: | |
252 | * @(args, ...) | |
253 | */ | |
254 | class UserAttributeDeclaration : public AttribDeclaration | |
255 | { | |
256 | public: | |
257 | Expressions *atts; | |
258 | ||
259 | UserAttributeDeclaration(Expressions *atts, Dsymbols *decl); | |
260 | Dsymbol *syntaxCopy(Dsymbol *s); | |
261 | Scope *newScope(Scope *sc); | |
262 | void setScope(Scope *sc); | |
b4c522fa IB |
263 | static Expressions *concat(Expressions *udas1, Expressions *udas2); |
264 | Expressions *getAttributes(); | |
265 | const char *kind() const; | |
266 | void accept(Visitor *v) { v->visit(this); } | |
267 | }; |