/** * AST Node Statement classes of the Kipper language. * @since 0.1.0 */ import type { CompilableNodeParent } from "../../index"; import type { ASTStatementKind, ASTStatementRuleName, ParserStatementContext } from "../../common"; import type { TranslatedCodeLine } from "../../../const"; import type { TargetASTNodeCodeGenerator } from "../../../target-presets"; import type { StatementSemantics } from "./statement-semantics"; import type { StatementTypeSemantics } from "./statement-type-semantics"; import { CompilableASTNode } from "../../compilable-ast-node"; /** * The base abstract AST node class for all statements, which wrap their corresponding * {@link KipperParserRuleContext} rule context classes that were generated by the {@link KipperParser}. * * These AST nodes can be created with the {@link StatementASTNodeFactory} class. * @since 0.1.0 */ export abstract class Statement< Semantics extends StatementSemantics = StatementSemantics, TypeSemantics extends StatementTypeSemantics = StatementTypeSemantics, > extends CompilableASTNode { public abstract targetCodeGenerator: TargetASTNodeCodeGenerator>; /** * The private field '_antlrRuleCtx' that actually stores the variable data, * which is returned inside the {@link this.antlrRuleCtx}. * @private */ protected override readonly _antlrRuleCtx: ParserStatementContext; protected constructor(antlrRuleCtx: ParserStatementContext, parent: CompilableNodeParent) { super(antlrRuleCtx, parent); this._antlrRuleCtx = antlrRuleCtx; // Manually add the child to the parent parent.addNewChild(this); } /** * Returns the kind of this AST node. This represents the specific type of the {@link antlrRuleCtx} that this AST * node wraps. * * This may be compared using the {@link ParseRuleKindMapping rule fields}, for example * {@link ParseRuleKindMapping.RULE_statement}. * @since 0.10.0 */ public abstract get kind(): ASTStatementKind; /** * Returns the rule name of this AST Node. This represents the specific type of the {@link antlrRuleCtx} that this * AST node wraps. * * This may be compared using the {@link ParseRuleKindMapping rule fields}, for example * {@link ParseRuleKindMapping.RULE_statement}. * @since 0.11.0 */ public abstract get ruleName(): ASTStatementRuleName; /** * The antlr context containing the antlr4 metadata for this statement. */ public override get antlrRuleCtx(): ParserStatementContext { return this._antlrRuleCtx; } /** * Generates the typescript code for this item, and all children (if they exist). * * Every item in the array represents a single line of code. */ public async translateCtxAndChildren(): Promise> { return await this.targetCodeGenerator(this); } }