dmd.attrib
Defines declarations of various attributes.
Discussion
The term 'attribute' refers to things that can apply to a larger scope than a single declaration. Among them are:
- Alignment (
align(8)
) - User defined attributes (
@UDA
) - Function Attributes (
@safe
) - Storage classes (
static
,__gshared
) - Mixin declarations (
mixin("int x;")
) - Conditional compilation (
static if
,static foreach
) - Linkage (
extern(C)
) - Anonymous structs / unions
- Protection (
private
,public
) - Deprecated declarations (
@deprecated
)
License
Source: attrib.d
Documentation: https://dlang.org/phobos/dmd_attrib.html
-
Declaration
abstract class
AttribDeclaration
: dmd.dsymbol.Dsymbol;Abstract attribute applied to Dsymbol's used as a common ancestor for storage classes (StorageClassDeclaration), linkage (LinkageDeclaration) and others.
-
Declaration
Dsymbols*
decl
;Dsymbol's affected by this AttribDeclaration
-
Declaration
static Scope*
createNewScope
(Scope*sc
, StorageClassstc
, LINKlinkage
, CPPMANGLEcppmangle
, Protprotection
, intexplicitProtection
, AlignDeclarationaligndecl
, PINLINEinlining
);Create a new scope if one or more given attributes are different from the
sc
's. If the returned scope !=sc
, the caller should pop the scope after it used. -
Declaration
Scope*
newScope
(Scope*sc
);A hook point to supply scope for members. addMember, setScope, importAll, semantic, semantic2 and semantic3 will use this.
-
Declaration
final void
addLocalClass
(ClassDeclarations*aclasses
);
-
-
Declaration
class
StorageClassDeclaration
: dmd.attrib.AttribDeclaration;Storage classes applied to Dsymbols, e.g.
const int i;
Discussion
-
Declaration
class
DeprecatedDeclaration
: dmd.attrib.StorageClassDeclaration;Deprecation with an additional message applied to Dsymbols, e.g.
deprecated("Superseeded by foo") int bar;
. (Note thatdeprecated int bar;
is currently represented as a StorageClassDeclaration with STC.deprecated_)Discussion
deprecated(<msg>) <decl...>
-
Declaration
Expression
msg
;deprecation message
-
Declaration
const(char)*
msgstr
;cached string representation of msg
-
Declaration
Scope*
newScope
(Scope*sc
);Provides a new scope with
STC.deprecated_
andScope.depdecl
setDiscussion
Calls
StorageClassDeclaration.
(as it must be called or copied in any function overridingnewScope
), then set thenewScope
Scope
's depdecl.Return Value
Always a new scope, to use for this
DeprecatedDeclaration
's members.
-
-
Declaration
class
LinkDeclaration
: dmd.attrib.AttribDeclaration;Linkage attribute applied to Dsymbols, e.g.
extern(C) void foo()
.Discussion
extern(<linkage>) <decl...>
-
Declaration
LINK
linkage
;either explicitly set or
default_
-
-
Declaration
class
CPPMangleDeclaration
: dmd.attrib.AttribDeclaration;Attribute declaring whether an external aggregate should be mangled as a struct or class in C++, e.g.
extern(C++, struct) class C { ... }
. This is required for correct name mangling on MSVC targets, see cppmanglewin.d for details.Discussion
extern(C++, <cppmangle>) <decl...>
-
Declaration
class
CPPNamespaceDeclaration
: dmd.attrib.AttribDeclaration;A node to represent an
extern(C++)
namespace attributeDiscussion
There are two ways to declarate a symbol as member of a namespace:
Nspace
and
. The former creates a scope for the symbol, and inject them in the parent scope at the same time. The later, this class, has no semantic implications and is only used for mangling. Additionally, this class allows one to use reserved identifiers (D keywords) in the namespace.CPPNamespaceDeclaration
A
can be created from anCPPNamespaceDeclaration
Identifier
(already resolved) or from anExpression
, which is CTFE-ed and can be either aTupleExp
, in which can additional
nodes are created, or aCPPNamespaceDeclaration
StringExp
.
Note that this class, likeNspace
, matches only one identifier part of a namespace. For the namespace"foo::bar"
, the will be a
with itsCPPNamespaceDeclaration
ident
set to"bar"
, and itsnamespace
field pointing to another
with itsCPPNamespaceDeclaration
ident
set to"foo"
.-
Declaration
Expression
exp
;CTFE-able expression, resolving to
TupleExp
orStringExp
-
Declaration
Scope*
newScope
(Scope*sc
);Return Value
A copy of the parent scope, with
this
asnamespace
and C++ linkage
-
-
Declaration
class
ProtDeclaration
: dmd.attrib.AttribDeclaration;Visibility declaration for Dsymbols, e.g.
public int i;
Discussion
<protection> <decl...>
orpackage(<pkg_identifiers>) <decl...>
ifpkg_identifiers !is null
-
Declaration
Prot
protection
;the visibility
-
Declaration
Identifiers*
pkg_identifiers
;identifiers for
package(foo.bar)
ornull
-
Declaration
this(ref const Loc
loc
, Protprotection
, Dsymbols*decl
);Parameters
Loc
loc
source location of attribute token
Prot
protection
protection
attribute dataDsymbols*
decl
declarations which are affected by this
protection
attribute -
Declaration
this(ref const Loc
loc
, Identifiers*pkg_identifiers
, Dsymbols*decl
);Parameters
Loc
loc
source location of attribute token
Identifiers*
pkg_identifiers
list of identifiers for a qualified package name
Dsymbols*
decl
declarations which are affected by this protection attribute
-
-
Declaration
class
AlignDeclaration
: dmd.attrib.AttribDeclaration;Alignment attribute for aggregates, members and variables.
Discussion
align(<ealign>) <decl...>
oralign <decl...>
ifealign
isnull
-
Declaration
Expression
ealign
;expression yielding the actual alignment
-
Declaration
enum structalign_t
UNKNOWN
;alignment not yet computed
-
Declaration
structalign_t
salign
;the actual alignment,
UNKNOWN
until it's either set to the value ofealign
orSTRUCTALIGN_DEFAULT
ifealign
isnull
( / an error ocurred)
-
-
Declaration
class
AnonDeclaration
: dmd.attrib.AttribDeclaration;An anonymous struct/union (defined by
isunion
).-
Declaration
bool
isunion
;whether it's a union
-
Declaration
int
sem
;1 if successful semantic()
-
Declaration
uint
anonoffset
;offset of anonymous struct
-
Declaration
uint
anonstructsize
;size of anonymous struct
-
Declaration
uint
anonalignsize
;size of anonymous struct for alignment purposes
-
-
Declaration
class
PragmaDeclaration
: dmd.attrib.AttribDeclaration;Pragma applied to Dsymbols, e.g.
pragma(inline, true) void foo
, but not PragmaStatement's likepragma(msg, "hello");
.Discussion
pragma(
, ) -
Declaration
Expressions*
args
;parameters of this pragma
-
-
Declaration
class
ConditionalDeclaration
: dmd.attrib.AttribDeclaration; -
Declaration
class
StaticIfDeclaration
: dmd.attrib.ConditionalDeclaration;`
{ static if ( ) { } else { } }` -
Declaration
ScopeDsymbol
scopesym
;enclosing symbol (e.g. module) where symbols will be inserted
-
Declaration
Dsymbols*
include
(Scope*sc
);Different from other AttribDeclaration subclasses,
include
() call requires the completion of addMember and setScope phases.
-
Declaration
class
StaticForeachDeclaration
: dmd.attrib.AttribDeclaration;
Static foreach at declaration scope, like: static foreach (i; [0, 1, 2]){ }
-
Declaration
StaticForeach
sfe
;contains
static foreach
expansion logic -
Declaration
ScopeDsymbol
scopesym
;cached enclosing scope (mimics
static if
declaration) -
Declaration
bool
onStack
;include
can be called multiple times, but astatic foreach
should be expanded at most once. Achieved by caching the result of the first call. We need bothcached
andcache
, becausenull
is a valid value forcache
.
Declaration
class
ForwardingAttribDeclaration
: dmd.attrib.AttribDeclaration;
Collection of declarations that stores foreach index variables in a local symbol table. Other symbols declared within are forwarded to another scope, like:
Discussion
static foreach (i; 0 .. 10) // loop variables for different indices do not conflict.
{ // this body is expanded into 10 ForwardingAttribDeclarations, where i
has storage class STC.local
mixin("enum x" ~ to!string(i) ~ " = i"); // ok, can access current loop variable
}
static foreach (i; 0.. 10)
{
pragma(msg, mixin("x" ~ to!string(i))); // ok, all 10 symbols are visible as they were forwarded to the global scope
}
static assert (!is(typeof(i))); // loop index variable is not visible outside of the static foreach loop
A StaticForeachDeclaration generates one
ForwardingAttribDeclaration
for each expansion of its body. The
AST of the ForwardingAttribDeclaration
contains both the `static
foreach variables and the respective copy of the
static foreach`
body. The functionality is achieved by using a
ForwardingScopeDsymbol as the parent symbol for the generated
declarations.
-
Declaration
Scope*
newScope
(Scope*sc
);Use the ForwardingScopeDsymbol as the parent symbol for members.
-
Declaration
void
addMember
(Scope*sc
, ScopeDsymbolsds
);Lazily initializes the scope to forward to.
Declaration
class
CompileDeclaration
: dmd.attrib.AttribDeclaration;
Mixin declarations, like: mixin("int x"); https://dlang.org/spec/module.html#mixin-declaration
Declaration
class
UserAttributeDeclaration
: dmd.attrib.AttribDeclaration;
User defined attributes look like: @foo(args, ...) @(args, ...)
-
Declaration
static bool
isGNUABITag
(Expressione
);Check if the provided expression references
core.attribute.gnuAbiTag
Discussion
This should be called after semantic has been run on the expression. Semantic on UDA happens in semantic2 (see
dmd.semantic2
).Parameters
Expression
e
Expression to check (usually from
UserAttributeDeclaration.atts
)Return Value
true
if the expression references the compiler-recognizedgnuAbiTag
-
Declaration
static void
checkGNUABITag
(Dsymbolsym
, LINKlinkage
);Called from a symbol's semantic to check if
gnuAbiTag
UDA can be applied to themDiscussion
Directly emits an error if the UDA doesn't work with this symbol
Parameters
Dsymbol
sym
symbol to check for
gnuAbiTag
LINK
linkage
Linkage of the symbol (Declaration.link or sc.link)