Report a bug
		
				If you spot a problem with this page, click here to create a Bugzilla issue.
		
			Improve this page
		
			Quickly fork, edit online, and submit a pull request for this page.
			Requires a signed-in GitHub account. This works well for small changes.
			If you'd like to make larger changes you may want to consider using
			a local clone.
		
	dmd.attrib
Defines declarations of various attributes.
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)
Authors: 
License: 
Source attrib.d
Documentation https://dlang.org/phobos/dmd_attrib.html
- abstract classAttribDeclaration: dmd.dsymbol.Dsymbol;
- Abstract attribute applied to Dsymbol's used as a common ancestor for storage classes (StorageClassDeclaration), linkage (LinkageDeclaration) and others.- Dsymbols*decl;
- Dsymbol's affected by this AttribDeclaration
- static Scope*createNewScope(Scope*sc, STCstc, 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.
- final voidaddObjcSymbols(ClassDeclarations*classes, ClassDeclarations*categories);
 
- classStorageClassDeclaration: dmd.attrib.AttribDeclaration;
- Storage classes applied to Dsymbols, e.g. const int i;
- classDeprecatedDeclaration: dmd.attrib.StorageClassDeclaration;
- Deprecation with an additional message applied to Dsymbols, e.g. deprecated("Superseeded by foo") int bar;. (Note that deprecated int bar; is currently represented as a StorageClassDeclaration with STC.deprecated_)deprecated(<msg>) <decl...>- Expressionmsg;
- deprecation message
- const(char)*msgstr;
- cached string representation of msg
 
- classLinkDeclaration: dmd.attrib.AttribDeclaration;
- Linkage attribute applied to Dsymbols, e.g. extern(C) void foo().extern(<linkage>) <decl...>- LINKlinkage;
- either explicitly set or default_
 
- 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.extern(C++, <cppmangle>) <decl...>
- classCPPNamespaceDeclaration: dmd.attrib.AttribDeclaration;
- A node to represent an extern(C++) namespace attributeThere are two ways to declarate a symbol as member of a namespace: Nspace andCPPNamespaceDeclaration. 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. ACPPNamespaceDeclarationcan be created from an Identifier (already resolved) or from an Expression, which is CTFE-ed and can be either a TupleExp, in which can additionalCPPNamespaceDeclarationnodes are created, or a StringExp. Note that this class, like Nspace, matches only one identifier part of a namespace. For the namespace "foo::bar", the will be aCPPNamespaceDeclarationwith its ident set to "bar", and its namespace field pointing to anotherCPPNamespaceDeclarationwith its ident set to "foo".- Expressionexp;
- CTFE-able expression, resolving to TupleExp or StringExp
 
- classVisibilityDeclaration: dmd.attrib.AttribDeclaration;
- Visibility declaration for Dsymbols, e.g. public int i;<visibility> <decl...> or package(<pkg_identifiers>) <decl...> if pkg_identifiers !is null- Visibilityvisibility;
- the visibility
- Identifier[]pkg_identifiers;
- identifiers for package(foo.bar) or null
- @safe this(Locloc, Visibilityvisibility, Dsymbols*decl);
- Parameters:Loc locsource location of attribute token Visibility visibilityvisibility attribute data Dsymbols* decldeclarations which are affected by this visibility attribute 
- this(Locloc, Identifier[]pkg_identifiers, Dsymbols*decl);
- Parameters:Loc locsource location of attribute token Identifier[] pkg_identifierslist of identifiers for a qualified package name Dsymbols* decldeclarations which are affected by this visibility attribute 
 
- classAlignDeclaration: dmd.attrib.AttribDeclaration;
- Alignment attribute for aggregates, members and variables.align(<ealign>) <decl...> or align <decl...> if ealign is null- Expressions*exps;
- Expression(s) yielding the desired alignment,
- structalign_tsalign;
- the largest value wins the actual alignment is Unknown until it's either set to the value of ealign or the default if ealign is null ( / an error ocurred)
 
- classAnonDeclaration: dmd.attrib.AttribDeclaration;
- An anonymous struct/union (defined by isunion).- boolisunion;
- whether it's a union
- intsem;
- 1 if successful semantic()
- uintanonoffset;
- offset of anonymous struct
- uintanonstructsize;
- size of anonymous struct
- uintanonalignsize;
- size of anonymous struct for alignment purposes
 
- classPragmaDeclaration: dmd.attrib.AttribDeclaration;
- Pragma applied to Dsymbols, e.g. pragma(inline, true) void foo, but not PragmaStatement's like pragma(msg, "hello");.pragma(, ) - Expressions*args;
- parameters of this pragma
 
- classConditionalDeclaration: dmd.attrib.AttribDeclaration;
- A conditional compilation declaration, used for version / debug and specialized for static if.{ } else { } - Conditioncondition;
- condition deciding whether decl or elsedecl applies
- Dsymbols*elsedecl;
- array of Dsymbol's for else block
 
- classStaticIfDeclaration: dmd.attrib.ConditionalDeclaration;
- `{ static if ( ) { } else { } }` 
- ScopeDsymbolscopesym;
- enclosing symbol (e.g. module) where symbols will be inserted
- booladdisdone;
- true if members have been added to scope
- boolonStack;
- true if a call to include is currently active
class 
StaticForeachDeclaration: dmd.attrib.AttribDeclaration;
Static foreach at declaration scope, like:
     static foreach (i; [0, 1, 2]){ }
- StaticForeachsfe;
- contains static foreach expansion logic
- ScopeDsymbolscopesym;
- cached enclosing scope (mimics static if declaration)
- boolonStack;
- include can be called multiple times, but a static foreach should be expanded at most once. Achieved by caching the result of the first call. We need both cached and cache, because null is a valid value for cache.
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:
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.
class 
MixinDeclaration: dmd.attrib.AttribDeclaration;
Mixin declarations, like:
      mixin("int x");
 https://dlang.org/spec/module.html#mixin-declaration
class 
UserAttributeDeclaration: dmd.attrib.AttribDeclaration;
User defined attributes look like:
      @foo(args, ...)
      @(args, ...)
bool 
isCoreUda(Dsymbol sym, Identifier ident);
Returns true if the given symbol is a symbol declared in
 core.attribute and has the given identifier.
This is used to determine if a symbol is a UDA declared in
 core.attribute.
Parameters: 
| Dsymbol sym | the symbol to check | 
| Identifier ident | the name of the expected UDA | 
int 
foreachUdaNoSemantic(Dsymbol sym, int delegate(Expression) dg);
Iterates the UDAs attached to the given symbol, without performing semantic
 analysis.
Use this function instead of foreachUda if semantic analysis of 
sym is
 still in progress.
Parameters: 
| Dsymbol sym | the symbol to get the UDAs from | 
| int delegate(Expression) dg | called once for each UDA | 
Returns: 
If 
dg returns != 0, stops the iteration and returns that value.
  Otherwise, returns 0.bool 
isEnumAttribute(Expression e, Identifier id);
Returns: 
true if the given expression is an enum from core.attribute named 
idCopyright © 1999-2025 by the D Language Foundation | Page generated by
Ddoc on Mon Mar 31 10:27:46 2025