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 classAttribDeclaration: 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, Visibilityvisibility, intexplicitVisibility, AlignDeclarationaligndecl, PragmaDeclarationinlining);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 voidaddLocalClass(ClassDeclarations*aclasses);
-
-
Declaration
classStorageClassDeclaration: dmd.attrib.AttribDeclaration;Storage classes applied to Dsymbols, e.g.
const int i;Discussion
-
Declaration
classDeprecatedDeclaration: 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
Expressionmsg;deprecation message
-
Declaration
const(char)*msgstr;cached string representation of msg
-
Declaration
Scope*newScope(Scope*sc);Provides a new scope with
STC.deprecated_andScope.depdeclsetDiscussion
Calls
StorageClassDeclaration.(as it must be called or copied in any function overridingnewScope), then set thenewScopeScope's depdecl.Return Value
Always a new scope, to use for this
DeprecatedDeclaration's members.
-
-
Declaration
classLinkDeclaration: dmd.attrib.AttribDeclaration;Linkage attribute applied to Dsymbols, e.g.
extern(C) void foo().Discussion
extern(<linkage>) <decl...>-
Declaration
LINKlinkage;either explicitly set or
default_
-
-
Declaration
classCPPMangleDeclaration: 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
classCPPNamespaceDeclaration: 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:
Nspaceand. 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
Acan be created from anCPPNamespaceDeclarationIdentifier(already resolved) or from anExpression, which is CTFE-ed and can be either aTupleExp, in which can additionalnodes are created, or aCPPNamespaceDeclarationStringExp.
Note that this class, likeNspace, matches only one identifier part of a namespace. For the namespace"foo::bar", the will be awith itsCPPNamespaceDeclarationidentset to"bar", and itsnamespacefield pointing to anotherwith itsCPPNamespaceDeclarationidentset to"foo".-
Declaration
Expressionexp;CTFE-able expression, resolving to
TupleExporStringExp -
Declaration
Scope*newScope(Scope*sc);Return Value
A copy of the parent scope, with
thisasnamespaceand C++ linkage
-
-
Declaration
classVisibilityDeclaration: dmd.attrib.AttribDeclaration;Visibility declaration for Dsymbols, e.g.
public int i;Discussion
<visibility> <decl...>orpackage(<pkg_identifiers>) <decl...>ifpkg_identifiers !is null-
Declaration
Visibilityvisibility;the
visibility -
Declaration
Identifier[]pkg_identifiers;identifiers for
package(foo.bar)ornull -
Declaration
this(ref const Locloc, Visibilityvisibility, Dsymbols*decl);Parameters
Loclocsource location of attribute token
Visibilityvisibilityvisibilityattribute dataDsymbols*decldeclarations which are affected by this
visibilityattribute -
Declaration
this(ref const Locloc, Identifier[]pkg_identifiers, Dsymbols*decl);Parameters
Loclocsource location of attribute token
Identifier[]pkg_identifierslist of identifiers for a qualified package name
Dsymbols*decldeclarations which are affected by this visibility attribute
-
-
Declaration
classAlignDeclaration: dmd.attrib.AttribDeclaration;Alignment attribute for aggregates, members and variables.
Discussion
align(<ealign>) <decl...>oralign <decl...>ifealignisnull-
Declaration
Expressionealign;expression yielding the actual alignment
-
Declaration
enum structalign_tUNKNOWN;alignment not yet computed
-
Declaration
structalign_tsalign;the actual alignment,
UNKNOWNuntil it's either set to the value ofealignorSTRUCTALIGN_DEFAULTifealignisnull( / an error ocurred)
-
-
Declaration
classAnonDeclaration: dmd.attrib.AttribDeclaration;An anonymous struct/union (defined by
isunion).-
Declaration
boolisunion;whether it's a union
-
Declaration
intsem;1 if successful semantic()
-
Declaration
uintanonoffset;offset of anonymous struct
-
Declaration
uintanonstructsize;size of anonymous struct
-
Declaration
uintanonalignsize;size of anonymous struct for alignment purposes
-
-
Declaration
classPragmaDeclaration: 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
classConditionalDeclaration: dmd.attrib.AttribDeclaration; -
Declaration
classStaticIfDeclaration: dmd.attrib.ConditionalDeclaration;`
{ static if ( ) { } else { } }` -
Declaration
ScopeDsymbolscopesym;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
StaticForeachsfe;contains
static foreachexpansion logic -
Declaration
ScopeDsymbolscopesym;cached enclosing scope (mimics
static ifdeclaration) -
Declaration
boolonStack;includecan be called multiple times, but astatic foreachshould be expanded at most once. Achieved by caching the result of the first call. We need bothcachedandcache, becausenullis 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
voidaddMember(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 boolisGNUABITag(Expressione);Check if the provided expression references
core.attribute.gnuAbiTagDiscussion
This should be called after semantic has been run on the expression. Semantic on UDA happens in semantic2 (see
dmd.semantic2).Parameters
ExpressioneExpression to check (usually from
UserAttributeDeclaration.atts)Return Value
trueif the expression references the compiler-recognizedgnuAbiTag -
Declaration
static voidcheckGNUABITag(Dsymbolsym, LINKlinkage);Called from a symbol's semantic to check if
gnuAbiTagUDA can be applied to themDiscussion
Directly emits an error if the UDA doesn't work with this symbol
Parameters
Dsymbolsymsymbol to check for
gnuAbiTagLINKlinkageLinkage of the symbol (Declaration.link or sc.link)