All files / TRANSPILE/3-Render/codegen/types TPlannedVariableDecl.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 68 69 70                                                                                                                                           
import type IPlannedArrayDeclaration from "./IPlannedArrayDeclaration";
import type IRenderedModifiers from "./IRenderedModifiers";
import type TPlannedStringDecl from "./TPlannedStringDecl";
import type TPlannedVariableInitializer from "./TPlannedVariableInitializer";
 
/**
 * One variable declaration, reduced to which of three forms it takes.
 *
 * #1445 box 3: `VariableDeclHelper` was handed a `VariableDeclarationContext`
 * and asked it the same questions repeatedly -- is there an initializer, is
 * there an arrayType, what are the trailing dimensions -- across four helpers
 * and four callback interfaces, each naming its own subset of grammar types.
 * The questions are answered once now, by `CodeGenerator.planVariableDecl`.
 *
 * ## The planner writes state, and it has to
 *
 * Building this plan registers the variable's type info, marks it as a pointer
 * when its type was inferred as one, and resolves its EMITTED name. Those are
 * writes, and they are ordered against each other and against the reads that
 * follow: `emittedLocalName` is only correct after registration, and ADR-045's
 * string discrimination reads the type registry that registration filled --
 * which is why `string<32> s <- s + "x"` is detected as a concatenation at all.
 *
 * So this is not a pure description computed ahead of time. It is built
 * immediately before it is rendered, in the same call, and the ordering inside
 * the planner is the ordering the renderer used to perform.
 */
type TPlannedVariableDecl =
  /**
   * Issue #375: `Type name(arg, arg);` -- C++ constructor syntax.
   *
   * `emittedName` is the post-registration name (ADR-057): the planner
   * registers the variable in the type registry as an external C++ type and,
   * inside a function body, as a local, and only then asks what it is emitted
   * as. Those writes are the reason this arm is planned rather than described.
   */
  | {
      readonly kind: "constructor";
      readonly type: string;
      readonly emittedName: string;
      readonly args: readonly string[];
    }
  /** ADR-045: a string declaration, in one of its own three forms. */
  | {
      readonly kind: "string";
      readonly string: TPlannedStringDecl;
      readonly emittedName: string;
      readonly modifiers: IRenderedModifiers;
      readonly isConst: boolean;
    }
  /** Everything else. */
  | {
      readonly kind: "plain";
      /**
       * The name AS WRITTEN.
       *
       * ADR-057: every registry keys on this, because it is what references in
       * the source say. Only the emitted text moves.
       */
      readonly sourceName: string;
      /** The identifier this declaration is emitted under (ADR-057). */
      readonly emittedName: string;
      readonly modifierPrefix: string;
      readonly type: string;
      readonly array: IPlannedArrayDeclaration;
      readonly initializer: TPlannedVariableInitializer;
    };
 
export default TPlannedVariableDecl;