All files / TRANSPILE/3-Render/codegen/types IPlannedType.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                                                                                                                                   
import type INamedTypeResolution from "../../../../types/INamedTypeResolution";
 
/**
 * A C-Next type, reduced to what 2.3 Render asks of it.
 *
 * #1445: `TypeGenerationHelper` used to take a `TypeContext` and re-walk the
 * six type alternatives itself. That was the seventh ladder #1285 set out to
 * collapse -- `TypeBinding`'s own header names this helper as one of the seven
 * -- and it was still standing. The named branches come from that one ladder
 * now, so the renderer receives a classification instead of re-deriving one.
 *
 * The three non-named alternatives stay separate fields rather than joining
 * the union, because 1.3 Declare and 2.3 Render want DIFFERENT answers for
 * them: `TypeBinding.resolveStringType` yields `string<32>`, where the
 * renderer wants `char`; `resolveNamedOrPrimitiveType` yields a primitive's
 * written name, where the renderer wants it through `TYPE_MAP`. Folding them
 * in would force one of the two to re-derive, which is the thing this replaces.
 */
interface IPlannedType {
  /**
   * The named-type branch `TypeBinding` classified -- `this.T`, `global.T`,
   * `Scope.T` or a bare `T` -- or null for every other alternative.
   *
   * For an array type this describes the ELEMENT: the renderer emits the
   * element type and the dimensions are appended by whoever declares the
   * variable.
   */
  readonly named: INamedTypeResolution | null;
 
  /** `string<N>` or a bare `string`, whose element type is `char`. */
  readonly isString: boolean;
 
  /**
   * The string type's source text -- `string<32>`, or `string` unbounded.
   *
   * Undefined unless `isString`. Present because 2.3's two readers want
   * different answers from the same node: the renderer emits `char`, and the
   * parameter context reports the written text for an ARRAY element while
   * reporting a bare `"string"` for a top-level one. That asymmetry is
   * load-bearing -- a top-level string's capacity travels separately -- so the
   * text is carried rather than either reader re-deriving it.
   */
  readonly stringTypeText: string | undefined;
 
  /** A primitive's WRITTEN name; the renderer maps it through `TYPE_MAP`. */
  readonly primitiveName: string | null;
 
  /** True when the alternatives above describe an array's element type. */
  readonly isArray: boolean;
 
  /**
   * The line a bare `userType` sits on, for `AdrProvenance`. Undefined for
   * every other branch, and for a `userType` whose token carries no position.
   */
  readonly userTypeLine: number | undefined;
 
  /**
   * The type's source text. This is what an unrecognized alternative renders
   * as -- a C++ `templateType` passes through unchanged, and `void` is its own
   * text, which is why the renderer needs no special case for it.
   */
  readonly text: string;
}
 
export default IPlannedType;