]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/d/dmd/attrib.h
d: Merge upstream dmd 7132b3537
[thirdparty/gcc.git] / gcc / d / dmd / attrib.h
CommitLineData
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
15class Expression;
16class Statement;
17class LabelDsymbol;
18class Initializer;
19class Module;
20class Condition;
21class StaticForeach;
22
23/**************************************************************/
24
25class AttribDeclaration : public Dsymbol
26{
27public:
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
53class StorageClassDeclaration : public AttribDeclaration
54{
55public:
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
68class DeprecatedDeclaration : public StorageClassDeclaration
69{
70public:
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
82class LinkDeclaration : public AttribDeclaration
83{
84public:
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
95class CPPMangleDeclaration : public AttribDeclaration
96{
97public:
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
107class ProtDeclaration : public AttribDeclaration
108{
109public:
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
124class AlignDeclaration : public AttribDeclaration
125{
126public:
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
137class AnonDeclaration : public AttribDeclaration
138{
139public:
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
155class PragmaDeclaration : public AttribDeclaration
156{
157public:
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
167class ConditionalDeclaration : public AttribDeclaration
168{
169public:
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
182class StaticIfDeclaration : public ConditionalDeclaration
183{
184public:
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 199class StaticForeachDeclaration : public AttribDeclaration
b4c522fa
IB
200{
201public:
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 220class ForwardingAttribDeclaration : public AttribDeclaration
b4c522fa
IB
221{
222public:
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
234class CompileDeclaration : public AttribDeclaration
235{
236public:
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 */
254class UserAttributeDeclaration : public AttribDeclaration
255{
256public:
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};