/** * Bitwise and expression AST node. * @since 0.11.0 * @example * 1 & 1 // 1 * 1 & 0 // 0 * 0 & 1 // 0 * 0 & 0 // 0 */ import type { BitwiseAndExpressionSemantics } from "./bitwise-and-expression-semantics"; import type { BitwiseAndExpressionTypeSemantics } from "./bitwise-and-expression-type-semantics"; import { BitwiseExpression } from "../bitwise-expression"; import type { BitwiseAndExpressionContext } from "../../../../../lexer-parser"; import { KindParseRuleMapping, ParseRuleKindMapping } from "../../../../../lexer-parser"; import type { CompilableASTNode } from "../../../../compilable-ast-node"; import type { Expression } from "../../expression"; import { UnableToDetermineSemanticDataError } from "../../../../../../errors"; import { BuiltInTypes } from "../../../../../semantics"; /** * Bitwise and expression AST node. * @since 0.11.0 * @example * 1 & 1 // 1 * 1 & 0 // 0 * 0 & 1 // 0 * 0 & 0 // 0 */ export class BitwiseAndExpression extends BitwiseExpression< BitwiseAndExpressionSemantics, BitwiseAndExpressionTypeSemantics > { /** * The static kind for this AST Node. * @since 0.11.0 */ public static readonly kind = ParseRuleKindMapping.RULE_bitwiseAndExpression; /** * The static rule name for this AST Node. * @since 0.11.0 */ public static readonly ruleName = KindParseRuleMapping[this.kind]; /** * The private field '_antlrRuleCtx' that actually stores the variable data, * which is returned inside the {@link this.antlrRuleCtx}. * @private */ protected override readonly _antlrRuleCtx: BitwiseAndExpressionContext; constructor(antlrRuleCtx: BitwiseAndExpressionContext, parent: CompilableASTNode) { super(antlrRuleCtx, parent); this._antlrRuleCtx = antlrRuleCtx; } /** * 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_expression}. * @since 0.10.0 */ public override get kind() { return BitwiseAndExpression.kind; } public override get ruleName() { return BitwiseAndExpression.ruleName; } /** * The primary code generation for this AST node. * @since 0.11.0 */ public override get antlrRuleCtx(): BitwiseAndExpressionContext { return this._antlrRuleCtx; } /** * The primary semantic analysis for this AST node. * @since 0.11.0 */ public async primarySemanticAnalysis(): Promise { const leftOp: Expression = this.children[0]; const rightOp: Expression = this.children[1]; if (!leftOp || !rightOp) { throw new UnableToDetermineSemanticDataError(); } this.semanticData = { leftOp: leftOp, rightOp: rightOp, operator: "&", }; } /** * The primary semantic type checking for this AST node. * @since 0.11.0 */ public async primarySemanticTypeChecking(): Promise { const semanticData = this.getSemanticData(); this.programCtx .typeCheck(this) .validBitwiseExpression(semanticData.leftOp, semanticData.rightOp, semanticData.operator); this.typeSemantics = { evaluatedType: BuiltInTypes.num, }; } /** * The primary code generation for this AST node. * @since 0.11.0 */ public checkForWarnings = undefined; readonly targetSemanticAnalysis = this.semanticAnalyser.bitwiseAndExpression; readonly targetCodeGenerator = this.codeGenerator.bitwiseAndExpression; }