# dmd.location

Encapsulates file/line/column locations.

#### Authors

Walter Bright

#### License

Boost License 1.0

Source: location.d

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

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

- `MessageStyle`

  #### Declaration

  `enum `MessageStyle`: ubyte;`

  How code locations are formatted for diagnostic reporting

  - `digitalmars`

    #### Declaration

    ``digitalmars``

    filename.d(line): message

  - `gnu`

    #### Declaration

    ``gnu``

    filename.d:line: message, see https://www.gnu.org/prep/standards/html_node/Errors.html

- `Loc`

  #### Declaration

  `struct `Loc`;`

  A source code location

  #### Discussion

  Used for error messages, `__FILE__` and `__LINE__` tokens, `__traits(getLocation, XXX)`, debug info etc.

  - `filename`

    #### Declaration

    `const(char)* `filename`;`

    zero-terminated `filename` string, either absolute or relative to cwd

  - `linnum`

    #### Declaration

    `uint `linnum`;`

    line number, starting from 1

  - `charnum`

    #### Declaration

    `uint `charnum`;`

    utf8 code unit index relative to start of line, starting from 1

  - `initial`

    #### Declaration

    `static immutable Loc `initial`;`

    use for default initialization of const ref Loc's

  - `set`

    #### Declaration

    `static nothrow void `set`(bool `showColumns`, MessageStyle `messageStyle`);`

    Configure how display is done

    #### Parameters

    `bool `showColumns`` | when to display columns
    `MessageStyle `messageStyle`` | digitalmars or gnu style messages

  - `equals`

    #### Declaration

    `const nothrow bool `equals`(ref const(Loc) `loc`);`

    Checks for equivalence by comparing the filename contents (not the pointer) and character location.

    Note:

    - Uses case-insensitive comparison on Windows
    - Ignores `charnum` if `Columns` is `false`.
  - `opEquals`

    #### Declaration

    `const pure nothrow @nogc @trusted bool `opEquals`(ref const(Loc) `loc`);
    const pure nothrow @trusted size_t `toHash`();`

    ``opEquals`()` / ``toHash`()` for AA key usage

    #### Discussion

    Compare filename contents (case-sensitively on Windows too), not the pointer - a static foreach loop repeatedly mixing in a mixin may lead to multiple equivalent filenames (`foo.d-mixin-<line>`), e.g., for test/runnable/test18880.d.

  - `isValid`

    #### Declaration

    `const pure nothrow bool `isValid`();`

    #### Return Value

    `true` if Loc has been set to other than the default initialization