# dmd.ctfeexpr

CTFE for expressions involving pointers, slices, array concatenation etc.

#### Authors

Walter Bright

#### License

Boost License 1.0

Source: ctfeexpr.d

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

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

- `ClassReferenceExp`

  #### Declaration

  `class `ClassReferenceExp`: dmd.expression.Expression;`

  A reference to a class, or an interface. We need this when we point to a base class (we must record what the type is).

- `findFieldIndexByName`

  #### Declaration

  `pure int `findFieldIndexByName`(const StructDeclaration `sd`, const VarDeclaration `v`);`

  Same as getFieldIndex, but checks for a direct match with the VarDeclaration

  #### Return Value

  index of the field, or -1 if not found

- `ThrownExceptionExp`

  #### Declaration

  `class `ThrownExceptionExp`: dmd.expression.Expression;`

  Fake class which holds the thrown exception. Used for implementing exception handling.

- `CTFEExp`

  #### Declaration

  `class `CTFEExp`: dmd.expression.Expression;`

  This type is only used by the interpreter.

- `needToCopyLiteral`

  #### Declaration

  `bool `needToCopyLiteral`(const Expression `expr`);`

  Aggregate literals (AA/string/array/struct)

- `resolveSlice`

  #### Declaration

  `Expression `resolveSlice`(Expression `e`, UnionExp* `pue` = null);`

  If `e` is a SliceExp, constant fold it.

  #### Parameters

  `Expression `e`` | expression to resolve
  `UnionExp* `pue`` | if not `null`, store resulting expression here

  #### Return Value

  resulting expression

- `createBlockDuplicatedArrayLiteral`

  #### Declaration

  `ArrayLiteralExp `createBlockDuplicatedArrayLiteral`(UnionExp* `pue`, const ref Loc `loc`, Type `type`, Expression `elem`, size_t `dim`);`

  Helper for NewExp Create an array literal consisting of '`elem`' duplicated '`dim`' times.

  #### Parameters

  `UnionExp* `pue`` | where to store result
  `Loc `loc`` | source location where the interpretation occurs
  `Type `type`` | target `type` of the result
  `Expression `elem`` | the source of array element, it will be owned by the result
  `size_t `dim`` | element number of the result

  #### Return Value

  Constructed ArrayLiteralExp

- `createBlockDuplicatedStringLiteral`

  #### Declaration

  `StringExp `createBlockDuplicatedStringLiteral`(UnionExp* `pue`, const ref Loc `loc`, Type `type`, dchar `value`, size_t `dim`, ubyte `sz`);`

  Helper for NewExp Create a string literal consisting of '`value`' duplicated '`dim`' times.

- `isTypeInfo_Class`

  #### Declaration

  `bool `isTypeInfo_Class`(const Type `type`);`

  TypeInfo operations

- `isPointer`

  #### Declaration

  `bool `isPointer`(Type `t`);`

  Pointer operations

- `pointToSameMemoryBlock`

  #### Declaration

  `bool `pointToSameMemoryBlock`(Expression `agg1`, Expression `agg2`);`

  Return `true` if `agg1` and `agg2` are pointers to the same memory block

- `isCtfeComparable`

  #### Declaration

  `bool `isCtfeComparable`(Expression `e`);`

  Constant folding, with support for CTFE Return `true` if non-pointer expression `e` can be compared with >,is, ==, etc, using ctfeCmp, ctfeEqual, ctfeIdentity

- `specificCmp`

  #### Declaration

  `bool `specificCmp`(TOK `op`, int `rawCmp`);`

  Returns cmp OP 0; where OP is ==, !=, <, >=, etc. Result is 0 or 1

- `intUnsignedCmp`

  #### Declaration

  `bool `intUnsignedCmp`(TOK `op`, dinteger_t `n1`, dinteger_t `n2`);`

  Returns e1 OP e2; where OP is ==, !=, <, >=, etc. Result is 0 or 1

- `intSignedCmp`

  #### Declaration

  `bool `intSignedCmp`(TOK `op`, sinteger_t `n1`, sinteger_t `n2`);`

  Returns e1 OP e2; where OP is ==, !=, <, >=, etc. Result is 0 or 1

- `realCmp`

  #### Declaration

  `bool `realCmp`(TOK `op`, real_t `r1`, real_t `r2`);`

  Returns e1 OP e2; where OP is ==, !=, <, >=, etc. Result is 0 or 1

- `ctfeEqual`

  #### Declaration

  `bool `ctfeEqual`(const ref Loc `loc`, TOK `op`, Expression `e1`, Expression `e2`);`

  Evaluate ==, !=. Resolves slices before comparing. Returns 0 or 1

- `ctfeIdentity`

  #### Declaration

  `bool `ctfeIdentity`(const ref Loc `loc`, TOK `op`, Expression `e1`, Expression `e2`);`

  Evaluate is, !is. Resolves slices before comparing. Returns 0 or 1

- `ctfeCmp`

  #### Declaration

  `bool `ctfeCmp`(const ref Loc `loc`, TOK `op`, Expression `e1`, Expression `e2`);`

  Evaluate >,<=, etc. Resolves slices before comparing. Returns 0 or 1

- `assignInPlace`

  #### Declaration

  `void `assignInPlace`(Expression `dest`, Expression `src`);`

  Assignment helper functions

- `changeArrayLiteralLength`

  #### Declaration

  `UnionExp `changeArrayLiteralLength`(const ref Loc `loc`, TypeArray `arrayType`, Expression `oldval`, size_t `oldlen`, size_t `newlen`);`

  Given array literal `oldval` of type ArrayLiteralExp or StringExp, of length `oldlen`, change its length to `newlen`. If the `newlen` is longer than `oldlen`, all new elements will be set to the default initializer for the element type.

- `isCtfeValueValid`

  #### Declaration

  `bool `isCtfeValueValid`(Expression `newval`);`

  CTFE Sanity Checks

- `voidInitLiteral`

  #### Declaration

  `UnionExp `voidInitLiteral`(Type `t`, VarDeclaration `var`);`

  Void initialization