2 /* Compiler implementation of the D programming language
3 * Copyright (C) 1999-2023 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/attrib.h
13 #include "root/port.h"
20 /**************************************************************/
22 class AttribDeclaration
: public Dsymbol
25 Dsymbols
*decl
; // array of Dsymbol's
27 virtual Dsymbols
*include(Scope
*sc
);
28 virtual Scope
*newScope(Scope
*sc
);
29 void addMember(Scope
*sc
, ScopeDsymbol
*sds
) override
;
30 void setScope(Scope
*sc
) override
;
31 void importAll(Scope
*sc
) override
;
32 void addComment(const utf8_t
*comment
) override
;
33 const char *kind() const override
;
34 bool oneMember(Dsymbol
**ps
, Identifier
*ident
) override
;
35 void setFieldOffset(AggregateDeclaration
*ad
, FieldState
& fieldState
, bool isunion
) override
;
36 bool hasPointers() override final
;
37 bool hasStaticCtorOrDtor() override final
;
38 void checkCtorConstInit() override final
;
39 AttribDeclaration
*isAttribDeclaration() override
{ return this; }
41 void accept(Visitor
*v
) override
{ v
->visit(this); }
44 class StorageClassDeclaration
: public AttribDeclaration
49 StorageClassDeclaration
*syntaxCopy(Dsymbol
*s
) override
;
50 Scope
*newScope(Scope
*sc
) override
;
51 bool oneMember(Dsymbol
**ps
, Identifier
*ident
) override final
;
52 void addMember(Scope
*sc
, ScopeDsymbol
*sds
) override
;
53 StorageClassDeclaration
*isStorageClassDeclaration() override
{ return this; }
55 void accept(Visitor
*v
) override
{ v
->visit(this); }
58 class DeprecatedDeclaration final
: public StorageClassDeclaration
64 DeprecatedDeclaration
*syntaxCopy(Dsymbol
*s
) override
;
65 Scope
*newScope(Scope
*sc
) override
;
66 void setScope(Scope
*sc
) override
;
67 void accept(Visitor
*v
) override
{ v
->visit(this); }
70 class LinkDeclaration final
: public AttribDeclaration
75 static LinkDeclaration
*create(const Loc
&loc
, LINK p
, Dsymbols
*decl
);
76 LinkDeclaration
*syntaxCopy(Dsymbol
*s
) override
;
77 Scope
*newScope(Scope
*sc
) override
;
78 const char *toChars() const override
;
79 void accept(Visitor
*v
) override
{ v
->visit(this); }
82 class CPPMangleDeclaration final
: public AttribDeclaration
87 CPPMangleDeclaration
*syntaxCopy(Dsymbol
*s
) override
;
88 Scope
*newScope(Scope
*sc
) override
;
89 void setScope(Scope
*sc
) override
;
90 const char *toChars() const override
;
91 void accept(Visitor
*v
) override
{ v
->visit(this); }
94 class CPPNamespaceDeclaration final
: public AttribDeclaration
99 CPPNamespaceDeclaration
*syntaxCopy(Dsymbol
*s
) override
;
100 Scope
*newScope(Scope
*sc
) override
;
101 const char *toChars() const override
;
102 void accept(Visitor
*v
) override
{ v
->visit(this); }
105 class VisibilityDeclaration final
: public AttribDeclaration
108 Visibility visibility
;
109 DArray
<Identifier
*> pkg_identifiers
;
111 VisibilityDeclaration
*syntaxCopy(Dsymbol
*s
) override
;
112 Scope
*newScope(Scope
*sc
) override
;
113 void addMember(Scope
*sc
, ScopeDsymbol
*sds
) override
;
114 const char *kind() const override
;
115 const char *toPrettyChars(bool unused
) override
;
116 VisibilityDeclaration
*isVisibilityDeclaration() override
{ return this; }
117 void accept(Visitor
*v
) override
{ v
->visit(this); }
120 class AlignDeclaration final
: public AttribDeclaration
123 Expressions
*alignExps
;
124 structalign_t salign
;
126 AlignDeclaration(const Loc
&loc
, Expression
*ealign
, Dsymbols
*decl
);
127 AlignDeclaration
*syntaxCopy(Dsymbol
*s
) override
;
128 Scope
*newScope(Scope
*sc
) override
;
129 void accept(Visitor
*v
) override
{ v
->visit(this); }
132 class AnonDeclaration final
: public AttribDeclaration
136 int sem
; // 1 if successful semantic()
137 unsigned anonoffset
; // offset of anonymous struct
138 unsigned anonstructsize
; // size of anonymous struct
139 unsigned anonalignsize
; // size of anonymous struct for alignment purposes
141 AnonDeclaration
*syntaxCopy(Dsymbol
*s
) override
;
142 void setScope(Scope
*sc
) override
;
143 void setFieldOffset(AggregateDeclaration
*ad
, FieldState
& fieldState
, bool isunion
) override
;
144 const char *kind() const override
;
145 AnonDeclaration
*isAnonDeclaration() override
{ return this; }
146 void accept(Visitor
*v
) override
{ v
->visit(this); }
149 class PragmaDeclaration final
: public AttribDeclaration
152 Expressions
*args
; // array of Expression's
154 PragmaDeclaration
*syntaxCopy(Dsymbol
*s
) override
;
155 Scope
*newScope(Scope
*sc
) override
;
156 const char *kind() const override
;
157 void accept(Visitor
*v
) override
{ v
->visit(this); }
160 class ConditionalDeclaration
: public AttribDeclaration
163 Condition
*condition
;
164 Dsymbols
*elsedecl
; // array of Dsymbol's for else block
166 ConditionalDeclaration
*syntaxCopy(Dsymbol
*s
) override
;
167 bool oneMember(Dsymbol
**ps
, Identifier
*ident
) override final
;
168 Dsymbols
*include(Scope
*sc
) override
;
169 void addComment(const utf8_t
*comment
) override final
;
170 void setScope(Scope
*sc
) override
;
171 void accept(Visitor
*v
) override
{ v
->visit(this); }
174 class StaticIfDeclaration final
: public ConditionalDeclaration
177 ScopeDsymbol
*scopesym
;
181 StaticIfDeclaration
*syntaxCopy(Dsymbol
*s
) override
;
182 Dsymbols
*include(Scope
*sc
) override
;
183 void addMember(Scope
*sc
, ScopeDsymbol
*sds
) override
;
184 void setScope(Scope
*sc
) override
;
185 void importAll(Scope
*sc
) override
;
186 StaticIfDeclaration
*isStaticIfDeclaration() override
{ return this; }
187 const char *kind() const override
;
188 void accept(Visitor
*v
) override
{ v
->visit(this); }
191 class StaticForeachDeclaration final
: public AttribDeclaration
195 ScopeDsymbol
*scopesym
;
200 StaticForeachDeclaration
*syntaxCopy(Dsymbol
*s
) override
;
201 bool oneMember(Dsymbol
**ps
, Identifier
*ident
) override
;
202 Dsymbols
*include(Scope
*sc
) override
;
203 void addMember(Scope
*sc
, ScopeDsymbol
*sds
) override
;
204 void addComment(const utf8_t
*comment
) override
;
205 void setScope(Scope
*sc
) override
;
206 void importAll(Scope
*sc
) override
;
207 const char *kind() const override
;
208 void accept(Visitor
*v
) override
{ v
->visit(this); }
211 class ForwardingAttribDeclaration final
: public AttribDeclaration
214 ForwardingScopeDsymbol
*sym
;
216 Scope
*newScope(Scope
*sc
) override
;
217 void addMember(Scope
*sc
, ScopeDsymbol
*sds
) override
;
218 ForwardingAttribDeclaration
*isForwardingAttribDeclaration() override
{ return this; }
219 void accept(Visitor
*v
) override
{ v
->visit(this); }
222 // Mixin declarations
224 class CompileDeclaration final
: public AttribDeclaration
229 ScopeDsymbol
*scopesym
;
232 CompileDeclaration
*syntaxCopy(Dsymbol
*s
) override
;
233 void addMember(Scope
*sc
, ScopeDsymbol
*sds
) override
;
234 void setScope(Scope
*sc
) override
;
235 const char *kind() const override
;
236 void accept(Visitor
*v
) override
{ v
->visit(this); }
240 * User defined attributes look like:
243 class UserAttributeDeclaration final
: public AttribDeclaration
248 UserAttributeDeclaration
*syntaxCopy(Dsymbol
*s
) override
;
249 Scope
*newScope(Scope
*sc
) override
;
250 void setScope(Scope
*sc
) override
;
251 Expressions
*getAttributes();
252 const char *kind() const override
;
253 void accept(Visitor
*v
) override
{ v
->visit(this); }