Merge dmd upstream 6243fa6d2
[official-gcc.git] / gcc / d / dmd / attrib.h
bloba491605fc1303ec99e3d9bbc5b77d5a244f02984
2 /* Compiler implementation of the D programming language
3 * Copyright (C) 1999-2018 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/attrib.h
9 */
11 #pragma once
13 #include "dsymbol.h"
15 class Expression;
16 class Statement;
17 class LabelDsymbol;
18 class Initializer;
19 class Module;
20 class Condition;
21 class StaticForeach;
23 /**************************************************************/
25 class AttribDeclaration : public Dsymbol
27 public:
28 Dsymbols *decl; // array of Dsymbol's
30 AttribDeclaration(Dsymbols *decl);
31 virtual Dsymbols *include(Scope *sc, ScopeDsymbol *sds);
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);
40 void semantic(Scope *sc);
41 void semantic2(Scope *sc);
42 void semantic3(Scope *sc);
43 void addComment(const utf8_t *comment);
44 const char *kind() const;
45 bool oneMember(Dsymbol **ps, Identifier *ident);
46 void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion);
47 bool hasPointers();
48 bool hasStaticCtorOrDtor();
49 void checkCtorConstInit();
50 void addLocalClass(ClassDeclarations *);
51 AttribDeclaration *isAttribDeclaration() { return this; }
53 void accept(Visitor *v) { v->visit(this); }
56 class StorageClassDeclaration : public AttribDeclaration
58 public:
59 StorageClass stc;
61 StorageClassDeclaration(StorageClass stc, Dsymbols *decl);
62 Dsymbol *syntaxCopy(Dsymbol *s);
63 Scope *newScope(Scope *sc);
64 bool oneMember(Dsymbol **ps, Identifier *ident);
65 void addMember(Scope *sc, ScopeDsymbol *sds);
66 StorageClassDeclaration *isStorageClassDeclaration() { return this; }
68 void accept(Visitor *v) { v->visit(this); }
71 class DeprecatedDeclaration : public StorageClassDeclaration
73 public:
74 Expression *msg;
75 const char *msgstr;
77 DeprecatedDeclaration(Expression *msg, Dsymbols *decl);
78 Dsymbol *syntaxCopy(Dsymbol *s);
79 Scope *newScope(Scope *sc);
80 void setScope(Scope *sc);
81 void semantic2(Scope *sc);
82 const char *getMessage();
83 void accept(Visitor *v) { v->visit(this); }
86 class LinkDeclaration : public AttribDeclaration
88 public:
89 LINK linkage;
91 LinkDeclaration(LINK p, Dsymbols *decl);
92 static LinkDeclaration *create(LINK p, Dsymbols *decl);
93 Dsymbol *syntaxCopy(Dsymbol *s);
94 Scope *newScope(Scope *sc);
95 const char *toChars();
96 void accept(Visitor *v) { v->visit(this); }
99 class CPPMangleDeclaration : public AttribDeclaration
101 public:
102 CPPMANGLE cppmangle;
104 CPPMangleDeclaration(CPPMANGLE p, Dsymbols *decl);
105 Dsymbol *syntaxCopy(Dsymbol *s);
106 Scope *newScope(Scope *sc);
107 const char *toChars();
108 void accept(Visitor *v) { v->visit(this); }
111 class ProtDeclaration : public AttribDeclaration
113 public:
114 Prot protection;
115 Identifiers* pkg_identifiers;
117 ProtDeclaration(Loc loc, Prot p, Dsymbols *decl);
118 ProtDeclaration(Loc loc, Identifiers* pkg_identifiers, Dsymbols *decl);
120 Dsymbol *syntaxCopy(Dsymbol *s);
121 Scope *newScope(Scope *sc);
122 void addMember(Scope *sc, ScopeDsymbol *sds);
123 const char *kind() const;
124 const char *toPrettyChars(bool unused);
125 void accept(Visitor *v) { v->visit(this); }
128 class AlignDeclaration : public AttribDeclaration
130 public:
131 Expression *ealign;
132 structalign_t salign;
134 AlignDeclaration(Loc loc, Expression *ealign, Dsymbols *decl);
135 Dsymbol *syntaxCopy(Dsymbol *s);
136 Scope *newScope(Scope *sc);
137 void semantic2(Scope *sc);
138 structalign_t getAlignment(Scope *sc);
139 void accept(Visitor *v) { v->visit(this); }
142 class AnonDeclaration : public AttribDeclaration
144 public:
145 bool isunion;
146 int sem; // 1 if successful semantic()
147 unsigned anonoffset; // offset of anonymous struct
148 unsigned anonstructsize; // size of anonymous struct
149 unsigned anonalignsize; // size of anonymous struct for alignment purposes
151 AnonDeclaration(Loc loc, bool isunion, Dsymbols *decl);
152 Dsymbol *syntaxCopy(Dsymbol *s);
153 void setScope(Scope *sc);
154 void semantic(Scope *sc);
155 void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion);
156 const char *kind() const;
157 AnonDeclaration *isAnonDeclaration() { return this; }
158 void accept(Visitor *v) { v->visit(this); }
161 class PragmaDeclaration : public AttribDeclaration
163 public:
164 Expressions *args; // array of Expression's
166 PragmaDeclaration(Loc loc, Identifier *ident, Expressions *args, Dsymbols *decl);
167 Dsymbol *syntaxCopy(Dsymbol *s);
168 Scope *newScope(Scope *sc);
169 void semantic(Scope *sc);
170 const char *kind() const;
171 void accept(Visitor *v) { v->visit(this); }
174 class ConditionalDeclaration : public AttribDeclaration
176 public:
177 Condition *condition;
178 Dsymbols *elsedecl; // array of Dsymbol's for else block
180 ConditionalDeclaration(Condition *condition, Dsymbols *decl, Dsymbols *elsedecl);
181 Dsymbol *syntaxCopy(Dsymbol *s);
182 bool oneMember(Dsymbol **ps, Identifier *ident);
183 Dsymbols *include(Scope *sc, ScopeDsymbol *sds);
184 void addComment(const utf8_t *comment);
185 void setScope(Scope *sc);
186 void accept(Visitor *v) { v->visit(this); }
189 class StaticIfDeclaration : public ConditionalDeclaration
191 public:
192 ScopeDsymbol *scopesym;
193 bool addisdone;
195 StaticIfDeclaration(Condition *condition, Dsymbols *decl, Dsymbols *elsedecl);
196 Dsymbol *syntaxCopy(Dsymbol *s);
197 Dsymbols *include(Scope *sc, ScopeDsymbol *sds);
198 void addMember(Scope *sc, ScopeDsymbol *sds);
199 void setScope(Scope *sc);
200 void importAll(Scope *sc);
201 void semantic(Scope *sc);
202 const char *kind() const;
203 void accept(Visitor *v) { v->visit(this); }
206 class StaticForeachDeclaration : public ConditionalDeclaration
208 public:
209 StaticForeach *sfe;
210 ScopeDsymbol *scopesym;
211 bool cached;
212 Dsymbols *cache;
214 Dsymbol *syntaxCopy(Dsymbol *s);
215 bool oneMember(Dsymbol **ps, Identifier *ident);
216 Dsymbols *include(Scope *sc, ScopeDsymbol *sds);
217 void addMember(Scope *sc, ScopeDsymbol *sds);
218 void addComment(const utf8_t *comment);
219 void setScope(Scope *sc);
220 void importAll(Scope *sc);
221 void semantic(Scope *sc);
222 const char *kind() const;
223 void accept(Visitor *v) { v->visit(this); }
226 class ForwardingAttribDeclaration : AttribDeclaration
228 public:
229 ForwardingScopeDsymbol *sym;
231 Scope *newScope(Scope *sc);
232 void addMember(Scope *sc, ScopeDsymbol *sds);
233 ForwardingAttribDeclaration *isForwardingAttribDeclaration() { return this; }
236 // Mixin declarations
238 class CompileDeclaration : public AttribDeclaration
240 public:
241 Expression *exp;
243 ScopeDsymbol *scopesym;
244 bool compiled;
246 CompileDeclaration(Loc loc, Expression *exp);
247 Dsymbol *syntaxCopy(Dsymbol *s);
248 void addMember(Scope *sc, ScopeDsymbol *sds);
249 void setScope(Scope *sc);
250 void compileIt(Scope *sc);
251 void semantic(Scope *sc);
252 const char *kind() const;
253 void accept(Visitor *v) { v->visit(this); }
257 * User defined attributes look like:
258 * @(args, ...)
260 class UserAttributeDeclaration : public AttribDeclaration
262 public:
263 Expressions *atts;
265 UserAttributeDeclaration(Expressions *atts, Dsymbols *decl);
266 Dsymbol *syntaxCopy(Dsymbol *s);
267 Scope *newScope(Scope *sc);
268 void setScope(Scope *sc);
269 void semantic(Scope *sc);
270 void semantic2(Scope *sc);
271 static Expressions *concat(Expressions *udas1, Expressions *udas2);
272 Expressions *getAttributes();
273 const char *kind() const;
274 void accept(Visitor *v) { v->visit(this); }