# dmd.frontend

Contains high-level interfaces for interacting with DMD as a library.

#### Authors

Walter Bright

#### License

Boost License 1.0

Source: id.d

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

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

- `Diagnostics`

  #### Declaration

  `struct `Diagnostics`;`

  Contains aggregated diagnostics information.

  - `errors`

    #### Declaration

    `immutable uint `errors`;`

    Number of `errors` diagnosed

  - `warnings`

    #### Declaration

    `immutable uint `warnings`;`

    Number of `warnings` diagnosed

  - `hasErrors`

    #### Declaration

    `immutable bool `hasErrors`();`

    #### Return Value

    `true` if errors have been diagnosed

  - `hasWarnings`

    #### Declaration

    `immutable bool `hasWarnings`();`

    #### Return Value

    `true` if warnings have been diagnosed

- `ContractChecking`

  #### Declaration

  `enum `ContractChecking`: CHECKENABLE;`

  Indicates the checking state of various contracts.

  - `default_`

    #### Declaration

    ``default_``

    Initial value

  - `disabled`

    #### Declaration

    ``disabled``

    Never do checking

  - `enabled`

    #### Declaration

    ``enabled``

    Always do checking

  - `enabledInSafe`

    #### Declaration

    ``enabledInSafe``

    Only do checking in `@safe` functions

- `ContractChecks`

  #### Declaration

  `struct `ContractChecks`;`

  Indicates which contracts should be checked or not.

  - `precondition`

    #### Declaration

    `ContractChecking `precondition`;`

    Precondition checks (in contract).

  - `invariant_`

    #### Declaration

    `ContractChecking `invariant_`;`

    Invariant checks.

  - `postcondition`

    #### Declaration

    `ContractChecking `postcondition`;`

    Postcondition checks (out contract).

  - `arrayBounds`

    #### Declaration

    `ContractChecking `arrayBounds`;`

    Array bound checks.

  - `assert_`

    #### Declaration

    `ContractChecking `assert_`;`

    Assert checks.

  - `switchError`

    #### Declaration

    `ContractChecking `switchError`;`

    Switch error checks.

- `deinitializeDMD`

  #### Declaration

  `void `deinitializeDMD`();`

  Deinitializes the global variables of the DMD compiler.

  #### Discussion

  This can be used to restore the state set by `initDMD` to its original state. Useful if there's a need for multiple sessions of the DMD compiler in the same application.

- `addImport`

  #### Declaration

  `void `addImport`(const(char)[] `path`);`

  Add import `path` to the `global.`path``.

  #### Parameters

  `const(char)[] `path`` | import to add

- `addStringImport`

  #### Declaration

  `void `addStringImport`(const(char)[] `path`);`

  Add string import `path` to `global.filePath`.

  #### Parameters

  `const(char)[] `path`` | string import to add

- `findDMDConfig`

  #### Declaration

  `string `findDMDConfig`(const(char)[] `dmdFilePath`);`

  Searches for a `dmd.conf`.

  #### Parameters

  `const(char)[] `dmdFilePath`` | path to the current DMD executable

  #### Return Value

  full path to the found `dmd.conf`, `null` otherwise.

- `findLDCConfig`

  #### Declaration

  `string `findLDCConfig`(const(char)[] `ldcFilePath`);`

  Searches for a `ldc2.conf`.

  #### Parameters

  `const(char)[] `ldcFilePath`` | path to the current LDC executable

  #### Return Value

  full path to the found `ldc2.conf`, `null` otherwise.

- `determineDefaultCompiler`

  #### Declaration

  `string `determineDefaultCompiler`();`

  Detect the currently active compiler.

  #### Return Value

  full path to the executable of the found compiler, `null` otherwise.

- `parseImportPathsFromConfig`

  #### Declaration

  `auto `parseImportPathsFromConfig`(const(char)[] `iniFile`, const(char)[] `execDir`);`

  Parses a `dmd.conf` or `ldc2.conf` config file and returns defined import paths.

  #### Parameters

  `const(char)[] `iniFile`` | `iniFile` to parse imports from
  `const(char)[] `execDir`` | directory of the compiler binary

  #### Return Value

  forward range of import paths found in ``iniFile``

- `findImportPaths`

  #### Declaration

  `auto `findImportPaths`();`

  Finds a `dmd.conf` and parses it for import paths. This depends on the `$DMD` environment variable. If `$DMD` is set to `ldmd`, it will try to detect and parse a `ldc2.conf` instead.

  #### Return Value

  A forward range of normalized import paths.

  #### See Also

  ,

- `parseModule`

  #### Declaration

  `Tuple!(Module, "module_", Diagnostics, "diagnostics") `parseModule`(AST = ASTCodegen)(const(char)[] `fileName`, const(char)[] `code` = null);`

  Parse a module from a string.

  #### Parameters

  `const(char)[] `fileName`` | file to parse
  `const(char)[] `code`` | text to use instead of opening the file

  #### Return Value

  the parsed module object

- `fullSemantic`

  #### Declaration

  `void `fullSemantic`(Module `m`);`

  Run full semantic analysis on a module.

- `prettyPrint`

  #### Declaration

  `string `prettyPrint`(Module `m`);`

  Pretty print a module.

  #### Return Value

  Pretty printed module as string.

- `DiagnosticReporter`

  #### Declaration

  `abstract class `DiagnosticReporter`;`

  Interface for diagnostic reporting.

  - `errorCount`

    #### Declaration

    `abstract nothrow int `errorCount`();`

    #### Return Value

    the number of errors that occurred during lexing or parsing.

  - `warningCount`

    #### Declaration

    `abstract nothrow int `warningCount`();`

    #### Return Value

    the number of warnings that occurred during lexing or parsing.

  - `deprecationCount`

    #### Declaration

    `abstract nothrow int `deprecationCount`();`

    #### Return Value

    the number of deprecations that occurred during lexing or parsing.

  - `error`

    #### Declaration

    `abstract nothrow bool `error`(ref const Loc `loc`, const(char)* `format`, va_list `args`, const(char)* `p1`, const(char)* `p2`);`

    Reports an `error` message.

    #### Parameters

    `Loc `loc`` | Location of `error`
    `const(char)* `format`` | `format` string for `error`
    `va_list `args`` | printf-style variadic arguments
    `const(char)* `p1`` | additional message prefix
    `const(char)* `p2`` | additional message prefix

    #### Return Value

    `false` if the message should also be printed to stderr, `true` otherwise

  - `errorSupplemental`

    #### Declaration

    `abstract nothrow bool `errorSupplemental`(ref const Loc `loc`, const(char)* `format`, va_list `args`, const(char)* `p1`, const(char)* `p2`);`

    Reports additional details about an error message.

    #### Parameters

    `Loc `loc`` | Location of error
    `const(char)* `format`` | `format` string for supplemental message
    `va_list `args`` | printf-style variadic arguments
    `const(char)* `p1`` | additional message prefix
    `const(char)* `p2`` | additional message prefix

    #### Return Value

    `false` if the message should also be printed to stderr, `true` otherwise

  - `warning`

    #### Declaration

    `abstract nothrow bool `warning`(ref const Loc `loc`, const(char)* `format`, va_list `args`, const(char)* `p1`, const(char)* `p2`);`

    Reports a `warning` message.

    #### Parameters

    `Loc `loc`` | Location of `warning`
    `const(char)* `format`` | `format` string for `warning`
    `va_list `args`` | printf-style variadic arguments
    `const(char)* `p1`` | additional message prefix
    `const(char)* `p2`` | additional message prefix

    #### Return Value

    `false` if the message should also be printed to stderr, `true` otherwise

  - `warningSupplemental`

    #### Declaration

    `abstract nothrow bool `warningSupplemental`(ref const Loc `loc`, const(char)* `format`, va_list `args`, const(char)* `p1`, const(char)* `p2`);`

    Reports additional details about a warning message.

    #### Parameters

    `Loc `loc`` | Location of warning
    `const(char)* `format`` | `format` string for supplemental message
    `va_list `args`` | printf-style variadic arguments
    `const(char)* `p1`` | additional message prefix
    `const(char)* `p2`` | additional message prefix

    #### Return Value

    `false` if the message should also be printed to stderr, `true` otherwise

  - `deprecation`

    #### Declaration

    `abstract nothrow bool `deprecation`(ref const Loc `loc`, const(char)* `format`, va_list `args`, const(char)* `p1`, const(char)* `p2`);`

    Reports a `deprecation` message.

    #### Parameters

    `Loc `loc`` | Location of the `deprecation`
    `const(char)* `format`` | `format` string for the `deprecation`
    `va_list `args`` | printf-style variadic arguments
    `const(char)* `p1`` | additional message prefix
    `const(char)* `p2`` | additional message prefix

    #### Return Value

    `false` if the message should also be printed to stderr, `true` otherwise

  - `deprecationSupplemental`

    #### Declaration

    `abstract nothrow bool `deprecationSupplemental`(ref const Loc `loc`, const(char)* `format`, va_list `args`, const(char)* `p1`, const(char)* `p2`);`

    Reports additional details about a deprecation message.

    #### Parameters

    `Loc `loc`` | Location of deprecation
    `const(char)* `format`` | `format` string for supplemental message
    `va_list `args`` | printf-style variadic arguments
    `const(char)* `p1`` | additional message prefix
    `const(char)* `p2`` | additional message prefix

    #### Return Value

    `false` if the message should also be printed to stderr, `true` otherwise

- `StderrDiagnosticReporter`

  #### Declaration

  `class `StderrDiagnosticReporter`: dmd.frontend.DiagnosticReporter;`

  Diagnostic reporter which prints the diagnostic messages to stderr.

  #### Discussion

  This is usually the default diagnostic reporter.

  - `this`

    #### Declaration

    `nothrow this(DiagnosticReporting `useDeprecated`);`

    Initializes this object.

    #### Parameters

    `DiagnosticReporting `useDeprecated`` | indicates how deprecation diagnostics should be handled