# dmd.aggregate

Defines a `Dsymbol` representing an `aggregate`, which is a `struct`, `union` or `class`.

Specification: Structs, Unions, Class.

#### Authors

Walter Bright

#### License

Boost License 1.0

Source: aggregate.d

Documentation: https://dlang.org/phobos/dmd_aggregate.html

Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/aggregate.d

- `ClassKind`

  #### Declaration

  `enum `ClassKind`: ubyte;`

  The `ClassKind` enum is used in AggregateDeclaration AST nodes to specify the linkage type of the struct/class/interface or if it is an anonymous class. If the class is anonymous it is also considered to be a D class.

  - `d`

    #### Declaration

    ``d``

    the aggregate is a `d`(efault) class

  - `cpp`

    #### Declaration

    ``cpp``

    the aggregate is a C++ struct/class/interface

  - `objc`

    #### Declaration

    ``objc``

    the aggregate is an Objective-C class/interface

- `AggregateDeclaration`

  #### Declaration

  `abstract class `AggregateDeclaration`: dmd.dsymbol.ScopeDsymbol;`

  Abstract aggregate as a common ancestor for Class- and StructDeclaration.

  - `type`

    #### Declaration

    `Type `type`;`

  - `storage_class`

    #### Declaration

    `StorageClass `storage_class`;`

  - `structsize`

    #### Declaration

    `uint `structsize`;`

    size of struct

  - `alignsize`

    #### Declaration

    `uint `alignsize`;`

    size of struct for alignment purposes

  - `fields`

    #### Declaration

    `VarDeclarations `fields`;`

    VarDeclaration `fields`

  - `deferred`

    #### Declaration

    `Dsymbol `deferred`;`

    any `deferred` semantic2() or semantic3() symbol

  - `classKind`

    #### Declaration

    `ClassKind `classKind`;`

    specifies whether this is a D, C++, Objective-C or anonymous struct/class/interface

  - `cppmangle`

    #### Declaration

    `CPPMANGLE `cppmangle`;`

    Specify whether to mangle the aggregate as a `class` or a `struct` This information is used by the MSVC mangler Only valid for class and struct. TODO: Merge with ClassKind ?

  - `enclosing`

    #### Declaration

    `Dsymbol `enclosing`;`

    !=`null` if is nested pointing to the dsymbol that directly `enclosing` it.

    1. The function that `enclosing` it (nested struct and class)
    2. The class that `enclosing` it (nested class only)
    3. If `enclosing` aggregate is template, its `enclosing` dsymbol.

    #### Discussion

    See AggregateDeclaraton::makeNested for the details.

  - `vthis`

    #### Declaration

    `VarDeclaration `vthis`;`

    'this' parameter if this aggregate is nested

  - `vthis2`

    #### Declaration

    `VarDeclaration `vthis2`;`

    'this' parameter if this aggregate is a template and is nested

  - `invs`

    #### Declaration

    `FuncDeclarations `invs`;`

    Array of invariants

  - `inv`

    #### Declaration

    `FuncDeclaration `inv`;`

    Merged invariant calling all members of invs

  - `aggNew`

    #### Declaration

    `NewDeclaration `aggNew`;`

    allocator

  - `ctor`

    #### Declaration

    `Dsymbol `ctor`;`

    CtorDeclaration or TemplateDeclaration

  - `defaultCtor`

    #### Declaration

    `CtorDeclaration `defaultCtor`;`

    default constructor - should have no arguments, because it would be stored in TypeInfo_Class.defaultConstructor

  - `aliasthis`

    #### Declaration

    `AliasThis `aliasthis`;`

    forward unresolved lookups to `aliasthis`

  - `dtors`

    #### Declaration

    `DtorDeclarations `dtors`;`

    Array of destructors

  - `dtor`

    #### Declaration

    `DtorDeclaration `dtor`;`

    aggregate destructor calling dtors and member constructors

  - `primaryDtor`

    #### Declaration

    `DtorDeclaration `primaryDtor`;`

    non-deleting C++ destructor, same as dtor for D

  - `tidtor`

    #### Declaration

    `DtorDeclaration `tidtor`;`

    aggregate destructor used in TypeInfo (must have extern(D) ABI)

  - `fieldDtor`

    #### Declaration

    `FuncDeclaration `fieldDtor`;`

    aggregate destructor for just the fields

  - `getRTInfo`

    #### Declaration

    `Expression `getRTInfo`;`

    pointer to GC info generated by object.RTInfo(this)

  - `visibility`

    #### Declaration

    `Visibility `visibility`;`

  - `noDefaultCtor`

    #### Declaration

    `bool `noDefaultCtor`;`

    no default construction

  - `sizeok`

    #### Declaration

    `Sizeok `sizeok`;`

    set when structsize contains valid data

  - `newScope`

    #### Declaration

    `Scope* `newScope`(Scope* `sc`);`

    Create a new scope from `sc`. semantic, semantic2 and semantic3 will use this for aggregate members.

  - `determineFields`

    #### Declaration

    `final bool `determineFields`();`

    Find all instance fields, then push them into `fields`.

    #### Discussion

    Runs semantic() for all instance field variables, but also the field types can remain yet not resolved forward references, except direct recursive definitions. After the process sizeok is set to Sizeok.fwd.

    #### Return Value

    `false` if any errors occur.

  - `nonHiddenFields`

    #### Declaration

    `final size_t `nonHiddenFields`();`

    #### Return Value

    The total number of fields minus the number of hidden fields.

  - `determineSize`

    #### Declaration

    `final bool `determineSize`(Loc `loc`);`

    Collect all instance fields, then determine instance size.

    #### Return Value

    `false` if failed to determine the size.

  - `checkOverlappedFields`

    #### Declaration

    `final bool `checkOverlappedFields`();`

    Calculate field[i].overlapped and overlapUnsafe, and check that all of explicit field initializers have unique memory space on instance.

    #### Return Value

    `true` if any errors happen.

  - `fill`

    #### Declaration

    `final bool `fill`(Loc `loc`, Expressions* `elements`, bool `ctorinit`);`

    Fill out remainder of `elements`[] with default initializers for fields[].

    #### Parameters

    `Loc `loc`` | location
    `Expressions* `elements`` | explicit arguments which given to construct object.
    `bool `ctorinit`` | `true` if the `elements` will be used for default initialization.

    #### Return Value

    `false` if any errors occur. Otherwise, returns `true` and the missing arguments will be pushed in `elements`[].

  - `alignmember`

    #### Declaration

    `static pure nothrow @safe void `alignmember`(structalign_t `alignment`, uint `size`, uint* `poffset`);`

    Do byte or word `alignment` as necessary. Align sizes of 0, as we may not know array sizes yet.

    #### Parameters

    `structalign_t `alignment`` | struct `alignment` that is in effect
    `uint `size`` | `alignment` requirement of field
    `uint* `poffset`` | pointer to offset to be aligned

  - `placeField`

    #### Declaration

    `static uint `placeField`(uint* `nextoffset`, uint `memsize`, uint `memalignsize`, structalign_t `alignment`, uint* `paggsize`, uint* `paggalignsize`, bool `isunion`);`

    Place a member (mem) into an aggregate (agg), which can be a struct, union or class

    #### Return Value

    offset to place field at
    `nextoffset`: next location in aggregate `memsize`: size of member `memalignsize`: natural `alignment` of member `alignment`: `alignment` in effect for this member `paggsize`: size of aggregate (updated) `paggalignsize`: `alignment` of aggregate (updated) `isunion`: the aggregate is a union

  - `setDeprecated`

    #### Declaration

    `final void `setDeprecated`();`

    Flag this aggregate as deprecated

  - `isNested`

    #### Declaration

    `final const bool `isNested`();`

    Returns `true` if there's an extra member which is the 'this' pointer to the enclosing context (enclosing aggregate or function)

  - `searchCtor`

    #### Declaration

    `final Dsymbol `searchCtor`();`

    Look for constructor declaration.

  - `stag`

    #### Declaration

    `Symbol* `stag`;`

    tag symbol for debug data

  - `sinit`

    #### Declaration

    `Symbol* `sinit`;`

    initializer symbol