| 1 |
|
| 2 |
/* Compiler implementation of the D programming language |
| 3 |
* Copyright (C) 1999-2025 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 |
| 9 |
*/ |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include "root/port.h" |
| 14 |
#include "dsymbol.h" |
| 15 |
|
| 16 |
class Expression; |
| 17 |
class Condition; |
| 18 |
class StaticForeach; |
| 19 |
|
| 20 |
namespace dmd |
| 21 |
{ |
| 22 |
Expressions *getAttributes(UserAttributeDeclaration *a); |
| 23 |
} |
| 24 |
|
| 25 |
/**************************************************************/ |
| 26 |
|
| 27 |
class AttribDeclaration : public Dsymbol |
| 28 |
{ |
| 29 |
public: |
| 30 |
Dsymbols *decl; // array of Dsymbol's |
| 31 |
const char *kind() const override; |
| 32 |
bool hasPointers() override final; |
| 33 |
void accept(Visitor *v) override { v->visit(this); } |
| 34 |
}; |
| 35 |
|
| 36 |
class StorageClassDeclaration : public AttribDeclaration |
| 37 |
{ |
| 38 |
public: |
| 39 |
StorageClass stc; |
| 40 |
|
| 41 |
StorageClassDeclaration *syntaxCopy(Dsymbol *s) override; |
| 42 |
|
| 43 |
void accept(Visitor *v) override { v->visit(this); } |
| 44 |
}; |
| 45 |
|
| 46 |
class DeprecatedDeclaration final : public StorageClassDeclaration |
| 47 |
{ |
| 48 |
public: |
| 49 |
Expression *msg; |
| 50 |
const char *msgstr; |
| 51 |
|
| 52 |
DeprecatedDeclaration *syntaxCopy(Dsymbol *s) override; |
| 53 |
void accept(Visitor *v) override { v->visit(this); } |
| 54 |
}; |
| 55 |
|
| 56 |
class LinkDeclaration final : public AttribDeclaration |
| 57 |
{ |
| 58 |
public: |
| 59 |
LINK linkage; |
| 60 |
|
| 61 |
static LinkDeclaration *create(Loc loc, LINK p, Dsymbols *decl); |
| 62 |
LinkDeclaration *syntaxCopy(Dsymbol *s) override; |
| 63 |
void accept(Visitor *v) override { v->visit(this); } |
| 64 |
}; |
| 65 |
|
| 66 |
class CPPMangleDeclaration final : public AttribDeclaration |
| 67 |
{ |
| 68 |
public: |
| 69 |
CPPMANGLE cppmangle; |
| 70 |
|
| 71 |
CPPMangleDeclaration *syntaxCopy(Dsymbol *s) override; |
| 72 |
void accept(Visitor *v) override { v->visit(this); } |
| 73 |
}; |
| 74 |
|
| 75 |
class CPPNamespaceDeclaration final : public AttribDeclaration |
| 76 |
{ |
| 77 |
public: |
| 78 |
Expression *exp; |
| 79 |
|
| 80 |
CPPNamespaceDeclaration *syntaxCopy(Dsymbol *s) override; |
| 81 |
void accept(Visitor *v) override { v->visit(this); } |
| 82 |
}; |
| 83 |
|
| 84 |
class VisibilityDeclaration final : public AttribDeclaration |
| 85 |
{ |
| 86 |
public: |
| 87 |
Visibility visibility; |
| 88 |
DArray<Identifier*> pkg_identifiers; |
| 89 |
|
| 90 |
VisibilityDeclaration *syntaxCopy(Dsymbol *s) override; |
| 91 |
const char *kind() const override; |
| 92 |
const char *toPrettyChars(bool unused) override; |
| 93 |
void accept(Visitor *v) override { v->visit(this); } |
| 94 |
}; |
| 95 |
|
| 96 |
class AlignDeclaration final : public AttribDeclaration |
| 97 |
{ |
| 98 |
public: |
| 99 |
Expressions *alignExps; |
| 100 |
structalign_t salign; |
| 101 |
|
| 102 |
AlignDeclaration *syntaxCopy(Dsymbol *s) override; |
| 103 |
void accept(Visitor *v) override { v->visit(this); } |
| 104 |
}; |
| 105 |
|
| 106 |
class AnonDeclaration final : public AttribDeclaration |
| 107 |
{ |
| 108 |
public: |
| 109 |
d_bool isunion; |
| 110 |
int sem; // 1 if successful semantic() |
| 111 |
unsigned anonoffset; // offset of anonymous struct |
| 112 |
unsigned anonstructsize; // size of anonymous struct |
| 113 |
unsigned anonalignsize; // size of anonymous struct for alignment purposes |
| 114 |
|
| 115 |
AnonDeclaration *syntaxCopy(Dsymbol *s) override; |
| 116 |
const char *kind() const override; |
| 117 |
void accept(Visitor *v) override { v->visit(this); } |
| 118 |
}; |
| 119 |
|
| 120 |
class PragmaDeclaration final : public AttribDeclaration |
| 121 |
{ |
| 122 |
public: |
| 123 |
Expressions *args; // array of Expression's |
| 124 |
|
| 125 |
PragmaDeclaration *syntaxCopy(Dsymbol *s) override; |
| 126 |
const char *kind() const override; |
| 127 |
void accept(Visitor *v) override { v->visit(this); } |
| 128 |
}; |
| 129 |
|
| 130 |
class ConditionalDeclaration : public AttribDeclaration |
| 131 |
{ |
| 132 |
public: |
| 133 |
Condition *condition; |
| 134 |
Dsymbols *elsedecl; // array of Dsymbol's for else block |
| 135 |
|
| 136 |
ConditionalDeclaration *syntaxCopy(Dsymbol *s) override; |
| 137 |
void accept(Visitor *v) override { v->visit(this); } |
| 138 |
}; |
| 139 |
|
| 140 |
class StaticIfDeclaration final : public ConditionalDeclaration |
| 141 |
{ |
| 142 |
public: |
| 143 |
ScopeDsymbol *scopesym; |
| 144 |
d_bool addisdone; |
| 145 |
d_bool onStack; |
| 146 |
|
| 147 |
StaticIfDeclaration *syntaxCopy(Dsymbol *s) override; |
| 148 |
const char *kind() const override; |
| 149 |
void accept(Visitor *v) override { v->visit(this); } |
| 150 |
}; |
| 151 |
|
| 152 |
class StaticForeachDeclaration final : public AttribDeclaration |
| 153 |
{ |
| 154 |
public: |
| 155 |
StaticForeach *sfe; |
| 156 |
ScopeDsymbol *scopesym; |
| 157 |
d_bool onStack; |
| 158 |
d_bool cached; |
| 159 |
Dsymbols *cache; |
| 160 |
|
| 161 |
StaticForeachDeclaration *syntaxCopy(Dsymbol *s) override; |
| 162 |
const char *kind() const override; |
| 163 |
void accept(Visitor *v) override { v->visit(this); } |
| 164 |
}; |
| 165 |
|
| 166 |
class ForwardingAttribDeclaration final : public AttribDeclaration |
| 167 |
{ |
| 168 |
public: |
| 169 |
ForwardingScopeDsymbol *sym; |
| 170 |
|
| 171 |
void accept(Visitor *v) override { v->visit(this); } |
| 172 |
}; |
| 173 |
|
| 174 |
// Mixin declarations |
| 175 |
|
| 176 |
class MixinDeclaration final : public AttribDeclaration |
| 177 |
{ |
| 178 |
public: |
| 179 |
Expressions *exps; |
| 180 |
|
| 181 |
ScopeDsymbol *scopesym; |
| 182 |
d_bool compiled; |
| 183 |
|
| 184 |
MixinDeclaration *syntaxCopy(Dsymbol *s) override; |
| 185 |
const char *kind() const override; |
| 186 |
void accept(Visitor *v) override { v->visit(this); } |
| 187 |
}; |
| 188 |
|
| 189 |
/** |
| 190 |
* User defined attributes look like: |
| 191 |
* @(args, ...) |
| 192 |
*/ |
| 193 |
class UserAttributeDeclaration final : public AttribDeclaration |
| 194 |
{ |
| 195 |
public: |
| 196 |
Expressions *atts; |
| 197 |
|
| 198 |
UserAttributeDeclaration *syntaxCopy(Dsymbol *s) override; |
| 199 |
const char *kind() const override; |
| 200 |
void accept(Visitor *v) override { v->visit(this); } |
| 201 |
}; |