# dmd.sideeffect

Find side-effects of expressions.

#### Authors

Walter Bright

#### License

Boost License 1.0

Source: sideeffect.d

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

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

- `isTrivialExp`

  #### Declaration

  `bool `isTrivialExp`(Expression `e`);`

  Front-end expression rewriting should create temporary variables for non trivial sub-expressions in order to:

  1. save evaluation order
  2. prevent sharing of sub-expression in AST
- `hasSideEffect`

  #### Declaration

  `bool `hasSideEffect`(Expression `e`);`

  Determine if Expression has any side effects.

- `callSideEffectLevel`

  #### Declaration

  `int `callSideEffectLevel`(FuncDeclaration `f`);`

  Determine if the call of `f`, or function type or delegate type t1, has any side effects.

  #### Return Value

  0 has any side effects 1 nothrow + constant purity 2 nothrow + strong purity

- `discardValue`

  #### Declaration

  `bool `discardValue`(Expression `e`);`

  The result of this expression will be discarded. Print error messages if the operation has no side effects (and hence is meaningless).

  #### Return Value

  `true` if expression has no side effects

- `copyToTemp`

  #### Declaration

  `VarDeclaration `copyToTemp`(StorageClass `stc`, const char[] `name`, Expression `e`);`

  Build a temporary variable to copy the value of `e` into.

  #### Parameters

  `StorageClass `stc`` | storage classes will be added to the made temporary variable
  `char[] `name`` | `name` for temporary variable
  `Expression `e`` | original expression

  #### Return Value

  Newly created temporary variable.

- `extractSideEffect`

  #### Declaration

  `Expression `extractSideEffect`(Scope* `sc`, const char[] `name`, ref Expression `e0`, Expression `e`, bool `alwaysCopy` = false);`

  Build a temporary variable to extract `e`'s evaluation, if `e` is not trivial.

  #### Parameters

  `Scope* `sc`` | scope
  `char[] `name`` | `name` for temporary variable
  `Expression `e0`` | a new side effect part will be appended to it.
  `Expression `e`` | original expression
  `bool `alwaysCopy`` | if `true`, build new temporary variable even if `e` is trivial.

  #### Return Value

  When `e` is trivial and `alwaysCopy` == `false`, `e` itself is returned. Otherwise, a new VarExp is returned.

  Note: `e`'s lvalue-ness will be handled well by STC.ref_ or STC.rvalue.