All files / TRANSPILE/3-Render/codegen/types IPlannedArrayDeclaration.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67                                                                                                                                     
/**
 * The array half of a variable declaration (ADR-035/ADR-036).
 *
 * C-Next writes dimensions in the TYPE -- `u16[8] arr` -- and the grammar also
 * admits trailing `arrayDimension`s, so "is this an array" is the disjunction
 * of two places and both contribute text. That disjunction is decided here,
 * once, rather than re-asked at each of the four sites that used to ask it.
 *
 * ## What is eager, and the one that surprises
 *
 * `arrayTypeDimensions` is a STRING, not a thunk, and that is deliberate.
 * Rendering it can generate a dimension expression, and today it is rendered
 * unconditionally once `isArray` holds -- BEFORE the initializer branch chooses
 * whether to use it. One sub-branch (`hasEmptyArrayTypeDimension`, where size
 * inference has already produced the suffix) then discards it. Making it a
 * thunk would skip the render on exactly that sub-branch, which drops whatever
 * effects the dimension expression raised. Preserved as eager so the effects
 * are raised the same number of times.
 *
 * `renderCStyleDimensions` IS a thunk, for the mirror reason: today it runs
 * only on the branch that uses it.
 */
interface IPlannedArrayDeclaration {
  /** True when the type carries dimensions, or the declaration trails them. */
  readonly isArray: boolean;
 
  /** Any dimension, in either position, written as `[]`. */
  readonly hasEmptyDimension: boolean;
 
  /**
   * The empty dimension is in the TYPE rather than trailing.
   *
   * ADR-035 size inference fills that one from the initializer, so the
   * inferred suffix already carries it and the declared dimensions must not be
   * prepended a second time.
   */
  readonly hasEmptyArrayTypeDimension: boolean;
 
  /** The first declared dimension when it folds, else null. */
  readonly declaredSize: number | null;
 
  /** The type's own dimensions, already rendered -- see above. */
  readonly arrayTypeDimensions: string;
 
  /** The declaration's trailing dimensions. */
  readonly renderCStyleDimensions: () => string;
 
  /** Null when the declaration has no initializer. */
  readonly init: IPlannedArrayInitializer | null;
}
 
/**
 * What ADR-035's array-initializer processing needs, unevaluated.
 *
 * All three are thunks because `ArrayInitHelper.processArrayInit` opens a
 * `withExpectedType` window and they must render inside it -- a value rendered
 * before the window loses the MISRA C:2012 Rule 7.2 suffix the window exists to
 * apply.
 */
interface IPlannedArrayInitializer {
  readonly renderExpression: () => string;
  readonly renderTypeName: () => string;
  readonly renderDimensions: () => string;
}
 
export default IPlannedArrayDeclaration;