/** * What the translators share while they work through one script. * * A translation is kept or refused per top level statement, never per line * inside one: a block with one line missing is a block that means something * the original did not, so the unit that is kept as a comment is the whole * statement at the top level. `Node` is that unit, and everything a refusal or * a warning needs to point at is recorded against it rather than decided on the * spot, because a statement translated now can still be refused later: by the * compiler, or because an earlier statement it reads was refused. */ import type { Diagnostic } from '../diagnostics/index.js'; import type { SourceFile } from '../source/index.js'; import type { Span } from '../span/index.js'; import { Namer, Scope } from './names.js'; import type { Binding } from './names.js'; import type { Expr, Lines, Named, Place, Stmt } from './syntax.js'; export interface OutLine { readonly depth: number; readonly text: string; } /** A finding on a statement that is kept, and the key that makes it once per script where it is once per built-in. */ export interface Note { readonly diagnostic: Diagnostic; readonly once: string | undefined; } export interface Node { readonly stmt: Stmt; readonly lines: Lines; /** Top level names the statement declares, so what reads them can follow it. */ readonly declares: readonly Named[]; /** Top level names it reads, in source order, with where. */ readonly reads: Named[]; output: OutLine[]; /** Why its translation was refused, if it was. */ refusal: Diagnostic | undefined; /** Why the compiler refused the translation, if it did. */ failed: Diagnostic | undefined; /** Why it reads a name a refused statement declared, recomputed on every pass. */ lost: Diagnostic | undefined; readonly notes: Note[]; /** The declaration, which is placed first and is never kept as a comment. */ readonly declaration: boolean; } export declare function isKept(node: Node): boolean; /** The first reason a node is not kept, in the order the reasons are found. */ export declare function reasonOf(node: Node): Diagnostic | undefined; export type Version = 5 | 6; export interface Reassignment { readonly op: string; readonly value: Expr; } /** Everything about the script the translators need before they start. */ export interface Facts { readonly file: SourceFile; readonly version: Version; /** Every identifier the source writes. */ readonly used: ReadonlySet; /** * Every reassignment the source makes, by name, anywhere in the file. A name * with any is never a constant, and is present only if every value it is * given is. */ readonly reassigned: ReadonlyMap; /** * Every name the file declares at the top level, wherever. OpenScript lets a * block or a function see one declared below it, so an inner declaration of * the same name is renamed, which the source dialect's meaning allows. */ readonly globals: ReadonlySet; /** The side each literal entry id opens, from the script's entry calls. */ readonly entries: ReadonlyMap; } export declare class Context { readonly namer: Namer; readonly fileScope: Scope; scope: Scope; /** The statement being translated. */ node: Node | undefined; /** Lines a statement needs evaluated before it, and whether it may have them. */ hoisted: OutLine[]; mayHoist: boolean; /** Inside a ternary arm, where the source dialect evaluates lazily as OpenScript does. */ lazy: number; depth: number; /** The declaration's pyramiding, read as the source dialect reads it: 0 is 1. */ pyramiding: number; /** * Whether the declaration sizes orders in units. The source dialect counts a * quantity written on an entry in contracts whatever the declaration says, * and OpenScript counts it in the declaration's own unit. */ qtyInUnits: boolean; readonly titles: Map>; readonly facts: Facts; constructor(facts: Facts); span(at: Place): Span; /** Records the first reason the current statement cannot be translated. */ refuse(diagnostic: Diagnostic): void; get refused(): boolean; note(diagnostic: Diagnostic, once?: string): void; /** Whether declaring `name` in the current scope needs a new spelling to keep it apart. */ hides(name: string): boolean; /** The binding a source name has here, recording a read of a top level one. */ lookup(name: string, at: Place): Binding | undefined; /** Enters a block scope for the length of `work`. */ within(work: () => T): T; /** * Moves an expression to its own line before the current statement, and * returns the name it is read under, or undefined where it cannot be moved. */ hoist(text: string): string | undefined; /** A title for a declared output that no other output of its kind has. */ title(kind: string, wanted: string): string; } /** A string literal in OpenScript's spelling of it (`language.md` 3.6). */ export declare function quoted(value: string): string; //# sourceMappingURL=context.d.ts.map