diff --git a/CHANGELOG.md b/CHANGELOG.md index 13538e34e..0e513f02f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,27 @@ To use development versions of Kipper download the - `kipper/core/compiler/ast/mapping`, which contains all AST mapping objects and the `ASTNodeMapper` class. - New class: - `ASTNodeMapper`, which handles the mapping between kind numbers, rule names, AST classes and parser context classes. + - `PrimaryExpression`, which is an abstract base class for all primary expressions. + - `PostfixExpression`, which is an abstract base class for all postfix expressions. +- New interfaces: + - `PrimaryExpressionSemantics`, which represents the semantics of a primary expression. + - `PrimaryExpressionTypeSemantics`, which represents the type semantics of a primary expression. + - `PostfixExpressionSemantics`, which represents the semantics of a postfix expression. + - `PostfixExpressionTypeSemantics`, which represents the type semantics of a postfix expression. + - `IterationStatementTypeSemantics`, which represents the type semantics of an iteration statement. + - `ExpressionStatementSemantics`, which represents the semantics of an expression statement. + - `ExpressionStatementTypeSemantics`, which represents the type semantics of an expression statement. + - `StatementSemantics`, which represents the semantics of a statement. + - `StatementTypeSemantics`, which represents the type semantics of a statement. + - `IfStatementTypeSemantics`, which represents the type semantics of an if statement. + - `CompoundStatementSemantics`, which represents the semantics of a compound statement. + - `CompoundStatementTypeSemantics`, which represents the type semantics of a compound statement. + - `ForLoopStatementTypeSemantics`, which represents the type semantics of a for loop statement. + - `DoWhileLoopIterationStatementTypeSemantics`, which represents the type semantics of a do-while loop statement. + - `WhileLoopStatementTypeSemantics`, which represents the type semantics of a while loop statement. + - `JumpStatementTypeSemantics`, which represents the type semantics of a jump statement. + - `SwitchStatementSemantics`, which represents the semantics of a switch statement. + - `SwitchStatementTypeSemantics`, which represents the type semantics of a switch statement. - New parameters: - `ignoreParams` in `genJSFunction()`, which, if true makes the function signature define no parameters. - `ignoreParams` in `createJSFunctionSignature()`, which, if true makes the function signature define no parameters. @@ -84,9 +105,14 @@ To use development versions of Kipper download the `DoWhileLoopStatement` to `DoWhileLoopIterationStatement`. This also includes changing the name in the `KipperTargetCodeGenerator`, `KipperTargetSemanticAnalyser` and `KipperTargetBuiltInGenerator` classes. - File `kipper/core/compiler/parser/parser-ast-mapping.ts` to `parse-rule-kind-mappings.ts`. + - Class `ArrayLiteralPrimaryExpression` to `ArrayPrimaryExpression`. + - Interface `ArrayLiteralPrimaryExpressionSemantics` to `ArrayPrimaryExpressionSemantics`. + - Interface `ArrayLiteralPrimaryExpressionTypeSemantics` to `ArrayPrimaryExpressionTypeSemantics`. + - Interface `TangledPrimaryTypeSemantics` to `TangledPrimaryExpressionTypeSemantics`. + - Interface `DoWhileLoopStatementSemantics` to `DoWhileLoopIterationStatementSemantics`. - Moved: - - `kipper/core/utils.ts` to `kipper/core/tools` and separated it into multiple files & modules. - - `kipper/core/compiler/ast/root-ast-node.ts` to the `kipper/core/compiler/ast/nodes` module. + - `kipper/core/utils.ts` to `kipper/core/tools` and separated it into multiple files & modules. + - `kipper/core/compiler/ast/root-ast-node.ts` to the `kipper/core/compiler/ast/nodes` module. - `kipper/core/compiler/ast/ast-types.ts` to the new `kipper/core/compiler/ast/common` module. ### Fixed diff --git a/kipper/core/src/compiler/analysis/analyser/semantic-checker.ts b/kipper/core/src/compiler/analysis/analyser/semantic-checker.ts index 71cc590c7..a5ec7d07e 100644 --- a/kipper/core/src/compiler/analysis/analyser/semantic-checker.ts +++ b/kipper/core/src/compiler/analysis/analyser/semantic-checker.ts @@ -14,7 +14,7 @@ import { IterationStatement, JumpStatement, ReturnStatement, - VariableDeclaration + VariableDeclaration, } from "../../ast"; import { KipperSemanticsAsserter } from "./err-handler"; import { @@ -22,7 +22,7 @@ import { Scope, ScopeDeclaration, ScopeFunctionDeclaration, - ScopeVariableDeclaration + ScopeVariableDeclaration, } from "../symbol-table"; import { BuiltInOrInternalGeneratorFunctionNotFoundError, @@ -37,7 +37,7 @@ import { MissingFunctionBodyError, UndefinedConstantError, UndefinedReferenceError, - UnknownReferenceError + UnknownReferenceError, } from "../../../errors"; /** diff --git a/kipper/core/src/compiler/analysis/analyser/type-checker.ts b/kipper/core/src/compiler/analysis/analyser/type-checker.ts index d5cc3f62f..dffcdd1a5 100644 --- a/kipper/core/src/compiler/analysis/analyser/type-checker.ts +++ b/kipper/core/src/compiler/analysis/analyser/type-checker.ts @@ -8,7 +8,7 @@ import type { KipperProgramContext } from "../../program-ctx"; import type { IncrementOrDecrementPostfixExpressionSemantics, ParameterDeclarationSemantics, - UnaryExpressionSemantics + UnaryExpressionSemantics, } from "../../ast"; import { AssignmentExpression, @@ -24,7 +24,7 @@ import { ReturnStatement, Statement, TangledPrimaryExpression, - UnaryExpression + UnaryExpression, } from "../../ast"; import { KipperSemanticsAsserter } from "./err-handler"; import { ScopeDeclaration, ScopeParameterDeclaration, ScopeVariableDeclaration } from "../symbol-table"; @@ -37,7 +37,7 @@ import { KipperReferenceable, KipperReferenceableFunction, kipperStrType, - kipperSupportedConversions + kipperSupportedConversions, } from "../../const"; import { ArgumentTypeError, @@ -55,7 +55,7 @@ import { KipperNotImplementedError, ReadOnlyWriteTypeError, UnknownTypeError, - ValueNotIndexableTypeError + ValueNotIndexableTypeError, } from "../../../errors"; import { CheckedType, UncheckedType, UndefinedCustomType } from "../type"; diff --git a/kipper/core/src/compiler/analysis/reference.ts b/kipper/core/src/compiler/analysis/reference.ts index e2df74711..e36cf92fe 100644 --- a/kipper/core/src/compiler/analysis/reference.ts +++ b/kipper/core/src/compiler/analysis/reference.ts @@ -13,7 +13,7 @@ import { InternalFunction } from "../runtime-built-ins"; * identifier's metadata and reference expression. * @since 0.8.0 */ -export interface Reference { +export interface Reference { /** * The target that this reference points to. * @since 0.8.0 diff --git a/kipper/core/src/compiler/analysis/symbol-table/entry/scope-function-declaration.ts b/kipper/core/src/compiler/analysis/symbol-table/entry/scope-function-declaration.ts index 2b9176e3b..c6f89146f 100644 --- a/kipper/core/src/compiler/analysis/symbol-table/entry/scope-function-declaration.ts +++ b/kipper/core/src/compiler/analysis/symbol-table/entry/scope-function-declaration.ts @@ -6,7 +6,7 @@ import { FunctionDeclaration, FunctionDeclarationSemantics, FunctionDeclarationTypeSemantics, - ParameterDeclaration + ParameterDeclaration, } from "../../../ast"; import { ScopeDeclaration } from "./scope-declaration"; import { CheckedType } from "../../type"; diff --git a/kipper/core/src/compiler/analysis/symbol-table/entry/scope-parameter-declaration.ts b/kipper/core/src/compiler/analysis/symbol-table/entry/scope-parameter-declaration.ts index 2934ad14a..5f55743e3 100644 --- a/kipper/core/src/compiler/analysis/symbol-table/entry/scope-parameter-declaration.ts +++ b/kipper/core/src/compiler/analysis/symbol-table/entry/scope-parameter-declaration.ts @@ -7,7 +7,7 @@ import type { FunctionDeclaration, ParameterDeclaration, ParameterDeclarationSemantics, - ParameterDeclarationTypeSemantics + ParameterDeclarationTypeSemantics, } from "../../../ast"; import type { LocalScope } from "../index"; import type { CheckedType } from "../../type"; diff --git a/kipper/core/src/compiler/ast/ast-generator.ts b/kipper/core/src/compiler/ast/ast-generator.ts index 7fb8ec135..54fa9ada6 100644 --- a/kipper/core/src/compiler/ast/ast-generator.ts +++ b/kipper/core/src/compiler/ast/ast-generator.ts @@ -6,7 +6,7 @@ import type { ASTNodeParserContext, ParserDeclarationContext, ParserExpressionContext, - ParserStatementContext + ParserStatementContext, } from "./common"; import type { ParseTreeListener } from "antlr4ts/tree/ParseTreeListener"; import type { @@ -19,7 +19,7 @@ import type { ActualLogicalOrExpressionContext, ActualMultiplicativeExpressionContext, ActualRelationalExpressionContext, - ArrayLiteralPrimaryExpressionContext, + ArrayPrimaryExpressionContext, BoolPrimaryExpressionContext, BracketNotationMemberAccessExpressionContext, CompilationUnitContext, @@ -65,7 +65,7 @@ import type { TypeSpecifierExpressionContext, VariableDeclarationContext, VoidOrNullOrUndefinedPrimaryExpressionContext, - WhileLoopIterationStatementContext + WhileLoopIterationStatementContext, } from "../parser"; import type { KipperProgramContext } from "../program-ctx"; import type { CompilableASTNode } from "./compilable-ast-node"; @@ -356,15 +356,13 @@ export class KipperFileASTGenerator implements KipperParserListener, ParseTreeLi * Enter a parse tree produced by `KipperParser.arrayLiteralPrimaryExpression`. * @param ctx The parse tree (instance of {@link KipperParserRuleContext}). */ - public enterArrayLiteralPrimaryExpression: (ctx: ArrayLiteralPrimaryExpressionContext) => void = - this.handleEnteringTreeNode; + public enterArrayPrimaryExpression: (ctx: ArrayPrimaryExpressionContext) => void = this.handleEnteringTreeNode; /** * Exit a parse tree produced by `KipperParser.arrayLiteralPrimaryExpression`. * @param ctx The parse tree (instance of {@link KipperParserRuleContext}). */ - public exitArrayLiteralPrimaryExpression: (ctx: ArrayLiteralPrimaryExpressionContext) => void = - this.handleExitingTreeNode; + public exitArrayPrimaryExpression: (ctx: ArrayPrimaryExpressionContext) => void = this.handleExitingTreeNode; /** * Enter a parse tree produced by `KipperParser.boolPrimaryExpression`. diff --git a/kipper/core/src/compiler/ast/common/ast-types.ts b/kipper/core/src/compiler/ast/common/ast-types.ts index 2f871a55f..17f5aea7d 100644 --- a/kipper/core/src/compiler/ast/common/ast-types.ts +++ b/kipper/core/src/compiler/ast/common/ast-types.ts @@ -4,7 +4,7 @@ */ import type { AdditiveExpressionContext, - ArrayLiteralPrimaryExpressionContext, + ArrayPrimaryExpressionContext, AssignmentExpressionContext, BoolPrimaryExpressionContext, BracketNotationMemberAccessExpressionContext, @@ -41,7 +41,7 @@ import type { TypeofTypeSpecifierExpressionContext, VariableDeclarationContext, VoidOrNullOrUndefinedPrimaryExpressionContext, - WhileLoopIterationStatementContext + WhileLoopIterationStatementContext, } from "../../parser"; import { KindParseRuleMapping } from "../../parser"; @@ -51,7 +51,7 @@ import { KindParseRuleMapping } from "../../parser"; */ export type ParserExpressionContext = | NumberPrimaryExpressionContext - | ArrayLiteralPrimaryExpressionContext + | ArrayPrimaryExpressionContext | IdentifierPrimaryExpressionContext | VoidOrNullOrUndefinedPrimaryExpressionContext | BoolPrimaryExpressionContext @@ -185,9 +185,9 @@ export type ConstructableASTKind = ASTDeclarationKind | ASTStatementKind | ASTEx * @since 0.11.0 */ export type ASTDeclarationRuleName = - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_functionDeclaration] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_parameterDeclaration] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_variableDeclaration]; + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_functionDeclaration] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_parameterDeclaration] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_variableDeclaration]; /** * Union type of all possible {@link ParserASTNode.ruleName} values that have a constructable {@link Statement} AST @@ -195,15 +195,15 @@ export type ASTDeclarationRuleName = * @since 0.11.0 */ export type ASTStatementRuleName = - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_compoundStatement] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_ifStatement] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_switchStatement] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_expressionStatement] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_doWhileLoopIterationStatement] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_whileLoopIterationStatement] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_forLoopIterationStatement] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_jumpStatement] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_returnStatement]; + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_compoundStatement] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_ifStatement] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_switchStatement] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_expressionStatement] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_doWhileLoopIterationStatement] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_whileLoopIterationStatement] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_forLoopIterationStatement] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_jumpStatement] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_returnStatement]; /** * Union type of all possible {@link ParserASTNode.ruleName} values that have a constructable {@link Expression} AST @@ -211,31 +211,31 @@ export type ASTStatementRuleName = * @since 0.11.0 */ export type ASTExpressionRuleName = - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_numberPrimaryExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_arrayLiteralPrimaryExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_identifierPrimaryExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_voidOrNullOrUndefinedPrimaryExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_boolPrimaryExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_stringPrimaryExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_fStringPrimaryExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_tangledPrimaryExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_incrementOrDecrementPostfixExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_functionCallExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_incrementOrDecrementUnaryExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_operatorModifiedUnaryExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_castOrConvertExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_multiplicativeExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_additiveExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_relationalExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_equalityExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_logicalAndExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_logicalOrExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_conditionalExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_assignmentExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_identifierTypeSpecifierExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_genericTypeSpecifierExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_typeofTypeSpecifierExpression] - | typeof KindParseRuleMapping[typeof ParseRuleKindMapping.RULE_memberAccessExpression]; + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_numberPrimaryExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_arrayLiteralPrimaryExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_identifierPrimaryExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_voidOrNullOrUndefinedPrimaryExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_boolPrimaryExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_stringPrimaryExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_fStringPrimaryExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_tangledPrimaryExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_incrementOrDecrementPostfixExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_functionCallExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_incrementOrDecrementUnaryExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_operatorModifiedUnaryExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_castOrConvertExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_multiplicativeExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_additiveExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_relationalExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_equalityExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_logicalAndExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_logicalOrExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_conditionalExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_assignmentExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_identifierTypeSpecifierExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_genericTypeSpecifierExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_typeofTypeSpecifierExpression] + | (typeof KindParseRuleMapping)[typeof ParseRuleKindMapping.RULE_memberAccessExpression]; /** * Union type of all possible {@link ParserASTNode.ruleName} values that have a constructable {@link CompilableASTNode}. diff --git a/kipper/core/src/compiler/ast/compilable-ast-node.ts b/kipper/core/src/compiler/ast/compilable-ast-node.ts index 5bcbedbb8..a6dde576e 100644 --- a/kipper/core/src/compiler/ast/compilable-ast-node.ts +++ b/kipper/core/src/compiler/ast/compilable-ast-node.ts @@ -7,7 +7,7 @@ import type { KipperCompileTarget, KipperTargetCodeGenerator, KipperTargetSemanticAnalyser, - TargetASTNodeCodeGenerator + TargetASTNodeCodeGenerator, } from "../target-presets"; import type { KipperParser, KipperParserRuleContext } from "../parser"; import type { TypeData } from "./ast-node"; diff --git a/kipper/core/src/compiler/ast/factories/declaration-ast-factory.ts b/kipper/core/src/compiler/ast/factories/declaration-ast-factory.ts index 3a5415ea1..ffb2acd82 100644 --- a/kipper/core/src/compiler/ast/factories/declaration-ast-factory.ts +++ b/kipper/core/src/compiler/ast/factories/declaration-ast-factory.ts @@ -57,7 +57,7 @@ export class DeclarationASTNodeFactory extends ASTNodeFactory( kind: T, - ): typeof ASTNodeMapper.declarationKindToClassMap[T] { + ): (typeof ASTNodeMapper.declarationKindToClassMap)[T] { return this.declarationKindToClassMap[kind]; } @@ -314,7 +314,7 @@ export class ASTNodeMapper { */ public static mapExpressionKindToClass( kind: T, - ): typeof ASTNodeMapper.expressionKindToClassMap[T] { + ): (typeof ASTNodeMapper.expressionKindToClassMap)[T] { return this.expressionKindToClassMap[kind]; } @@ -328,7 +328,7 @@ export class ASTNodeMapper { */ public static mapStatementKindToClass( kind: T, - ): typeof ASTNodeMapper.statementKindToClassMap[T] { + ): (typeof ASTNodeMapper.statementKindToClassMap)[T] { return this.statementKindToClassMap[kind]; } @@ -341,7 +341,7 @@ export class ASTNodeMapper { */ public static mapDeclarationKindToRuleContext( kind: T, - ): typeof ASTNodeMapper.declarationKindToRuleContextMap[T] { + ): (typeof ASTNodeMapper.declarationKindToRuleContextMap)[T] { return this.declarationKindToRuleContextMap[kind]; } @@ -354,7 +354,7 @@ export class ASTNodeMapper { */ public static mapExpressionKindToRuleContext( kind: T, - ): typeof ASTNodeMapper.expressionKindToRuleContextMap[T] { + ): (typeof ASTNodeMapper.expressionKindToRuleContextMap)[T] { return this.expressionKindToRuleContextMap[kind]; } @@ -367,7 +367,7 @@ export class ASTNodeMapper { */ public static mapStatementKindToRuleContext( kind: T, - ): typeof ASTNodeMapper.statementKindToRuleContextMap[T] { + ): (typeof ASTNodeMapper.statementKindToRuleContextMap)[T] { return this.statementKindToRuleContextMap[kind]; } @@ -380,7 +380,7 @@ export class ASTNodeMapper { */ public static mapDeclarationRuleNameToClass( name: T, - ): typeof ASTNodeMapper.declarationRuleNameToClassMap[T] { + ): (typeof ASTNodeMapper.declarationRuleNameToClassMap)[T] { return this.declarationRuleNameToClassMap[name]; } @@ -393,7 +393,7 @@ export class ASTNodeMapper { */ public static mapExpressionRuleNameToClass( name: T, - ): typeof ASTNodeMapper.expressionRuleNameToClassMap[T] { + ): (typeof ASTNodeMapper.expressionRuleNameToClassMap)[T] { return this.expressionRuleNameToClassMap[name]; } @@ -406,7 +406,7 @@ export class ASTNodeMapper { */ public static mapStatementRuleNameToClass( name: T, - ): typeof ASTNodeMapper.statementRuleNameToClassMap[T] { + ): (typeof ASTNodeMapper.statementRuleNameToClassMap)[T] { return this.statementRuleNameToClassMap[name]; } } diff --git a/kipper/core/src/compiler/ast/nodes/declarations/declaration-semantics.ts b/kipper/core/src/compiler/ast/nodes/declarations/declaration-semantics.ts new file mode 100644 index 000000000..5932142fc --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/declarations/declaration-semantics.ts @@ -0,0 +1,17 @@ +/** + * Semantics for a {@link Declaration}. + * @since 0.5.0 + */ +import type { SemanticData } from "../../ast-node"; + +/** + * Semantics for a {@link Declaration}. + * @since 0.5.0 + */ +export interface DeclarationSemantics extends SemanticData { + /** + * The identifier of the declaration. + * @since 0.5.0 + */ + identifier: string; +} diff --git a/kipper/core/src/compiler/ast/nodes/declarations/declaration-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/declarations/declaration-type-semantics.ts new file mode 100644 index 000000000..8e9572914 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/declarations/declaration-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for a {@link Declaration}. + * @since 0.10.0 + */ +import type { TypeData } from "../../ast-node"; + +/** + * Type semantics for a {@link Declaration}. + * @since 0.10.0 + */ +export interface DeclarationTypeSemantics extends TypeData {} diff --git a/kipper/core/src/compiler/ast/nodes/declarations/declaration.ts b/kipper/core/src/compiler/ast/nodes/declarations/declaration.ts index ed935d782..45afea8bd 100644 --- a/kipper/core/src/compiler/ast/nodes/declarations/declaration.ts +++ b/kipper/core/src/compiler/ast/nodes/declarations/declaration.ts @@ -9,8 +9,8 @@ * function and its local scope. * @since 0.1.0 */ -import type { DeclarationSemantics } from "../../semantic-data"; -import type { DeclarationTypeData } from "../../type-data"; +import type { DeclarationSemantics } from "./declaration-semantics"; +import type { DeclarationTypeSemantics } from "./declaration-type-semantics"; import type { TranslatedCodeLine } from "../../../const"; import type { ASTDeclarationKind, ASTDeclarationRuleName, ParserDeclarationContext } from "../../common"; import type { TargetASTNodeCodeGenerator, TargetASTNodeSemanticAnalyser } from "../../../target-presets"; @@ -31,7 +31,7 @@ import { MissingRequiredSemanticDataError, UndefinedDeclarationCtxError } from " */ export abstract class Declaration< Semantics extends DeclarationSemantics = DeclarationSemantics, - TypeData extends DeclarationTypeData = DeclarationTypeData, + TypeData extends DeclarationTypeSemantics = DeclarationTypeSemantics, > extends CompilableASTNode { /** * The private field '_antlrRuleCtx' that actually stores the variable data, diff --git a/kipper/core/src/compiler/ast/nodes/declarations/function-declaration/function-declaration-semantics.ts b/kipper/core/src/compiler/ast/nodes/declarations/function-declaration/function-declaration-semantics.ts new file mode 100644 index 000000000..7c5d20d73 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/declarations/function-declaration/function-declaration-semantics.ts @@ -0,0 +1,44 @@ +/** + * Semantics for AST Node {@link FunctionDeclaration}. + * @since 0.3.0 + */ +import type { UncheckedType } from "../../../../analysis"; +import type { CompoundStatement, IdentifierTypeSpecifierExpression, ParameterDeclaration } from "../../../nodes"; +import type { DeclarationSemantics } from "../declaration-semantics"; + +/** + * Semantics for AST Node {@link FunctionDeclaration}. + * @since 0.3.0 + */ +export interface FunctionDeclarationSemantics extends DeclarationSemantics { + /** + * The identifier of the function. + * @since 0.5.0 + */ + identifier: string; + /** + * The {@link KipperType return type} of the function. + * @since 0.5.0 + */ + returnType: UncheckedType; + /** + * The type specifier expression for the return type. + * @since 0.10.0 + */ + returnTypeSpecifier: IdentifierTypeSpecifierExpression; + /** + * Returns true if this declaration defines the function body for the function. + * @since 0.5.0 + */ + isDefined: boolean; + /** + * The available {@link ParameterDeclaration parameter} for the function invocation. + * @since 0.10.0 + */ + params: Array; + /** + * The body of the function. + * @since 0.10.0 + */ + functionBody: CompoundStatement; +} diff --git a/kipper/core/src/compiler/ast/nodes/declarations/function-declaration/function-declaration-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/declarations/function-declaration/function-declaration-type-semantics.ts new file mode 100644 index 000000000..b1a6fb123 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/declarations/function-declaration/function-declaration-type-semantics.ts @@ -0,0 +1,18 @@ +/** + * Type semantics for AST Node {@link FunctionDeclaration}. + * @since 0.10.0 + */ +import type { CheckedType } from "../../../../analysis"; +import { DeclarationTypeSemantics } from "../declaration-type-semantics"; + +/** + * Type semantics for AST Node {@link FunctionDeclaration}. + * @since 0.10.0 + */ +export interface FunctionDeclarationTypeSemantics extends DeclarationTypeSemantics { + /** + * The {@link KipperType return type} of the function. + * @since 0.10.0 + */ + returnType: CheckedType; +} diff --git a/kipper/core/src/compiler/ast/nodes/declarations/function-declaration.ts b/kipper/core/src/compiler/ast/nodes/declarations/function-declaration/function-declaration.ts similarity index 91% rename from kipper/core/src/compiler/ast/nodes/declarations/function-declaration.ts rename to kipper/core/src/compiler/ast/nodes/declarations/function-declaration/function-declaration.ts index af63aeec4..eec33d445 100644 --- a/kipper/core/src/compiler/ast/nodes/declarations/function-declaration.ts +++ b/kipper/core/src/compiler/ast/nodes/declarations/function-declaration/function-declaration.ts @@ -3,23 +3,23 @@ * language and is compilable using {@link translateCtxAndChildren}. * @since 0.1.2 */ -import type { ScopeNode } from "../../scope-node"; -import type { FunctionDeclarationSemantics } from "../../semantic-data"; -import type { FunctionDeclarationTypeSemantics } from "../../type-data"; -import type { CompilableNodeParent } from "../../compilable-ast-node"; -import type { CompoundStatement, Statement } from "../statements"; -import type { IdentifierTypeSpecifierExpression } from "../expressions"; -import { FunctionScope, ScopeFunctionDeclaration, UncheckedType } from "../../../analysis"; +import type { ScopeNode } from "../../../scope-node"; +import type { FunctionDeclarationSemantics } from "./function-declaration-semantics"; +import type { FunctionDeclarationTypeSemantics } from "./function-declaration-type-semantics"; +import type { CompilableNodeParent } from "../../../compilable-ast-node"; +import type { CompoundStatement, Statement } from "../../statements"; +import type { IdentifierTypeSpecifierExpression } from "../../expressions"; +import { FunctionScope, ScopeFunctionDeclaration, UncheckedType } from "../../../../analysis"; import { CompoundStatementContext, DeclaratorContext, FunctionDeclarationContext, KindParseRuleMapping, - ParseRuleKindMapping -} from "../../../parser"; -import { Declaration } from "./declaration"; -import { ParameterDeclaration } from "./parameter-declaration"; -import { UnableToDetermineSemanticDataError } from "../../../../errors"; + ParseRuleKindMapping, +} from "../../../../parser"; +import { Declaration } from "../declaration"; +import { ParameterDeclaration } from "../parameter-declaration"; +import { UnableToDetermineSemanticDataError } from "../../../../../errors"; /** * Function definition class, which represents the definition of a function in the Kipper diff --git a/kipper/core/src/compiler/ast/nodes/declarations/function-declaration/index.ts b/kipper/core/src/compiler/ast/nodes/declarations/function-declaration/index.ts new file mode 100644 index 000000000..5ab3e9922 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/declarations/function-declaration/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link FunctionDeclaration} and the related {@link FunctionDeclarationSemantics semantics} and + * {@link FunctionDeclarationTypeSemantics type semantics}. + */ +export * from "./function-declaration"; +export * from "./function-declaration-semantics"; +export * from "./function-declaration-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/declarations/index.ts b/kipper/core/src/compiler/ast/nodes/declarations/index.ts index 51654fb51..e782ff02e 100644 --- a/kipper/core/src/compiler/ast/nodes/declarations/index.ts +++ b/kipper/core/src/compiler/ast/nodes/declarations/index.ts @@ -4,6 +4,8 @@ * @since 0.11.0 */ export * from "./declaration"; -export * from "./parameter-declaration"; -export * from "./function-declaration"; -export * from "./variable-declaration"; +export * from "./declaration-semantics"; +export * from "./declaration-type-semantics"; +export * from "./parameter-declaration/"; +export * from "./function-declaration/"; +export * from "./variable-declaration/"; diff --git a/kipper/core/src/compiler/ast/nodes/declarations/parameter-declaration/index.ts b/kipper/core/src/compiler/ast/nodes/declarations/parameter-declaration/index.ts new file mode 100644 index 000000000..a8f320996 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/declarations/parameter-declaration/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link ParameterDeclaration} and the related {@link ParameterDeclarationSemantics semantics} and + * {@link ParameterDeclarationTypeSemantics type semantics}. + */ +export * from "./parameter-declaration"; +export * from "./parameter-declaration-semantics"; +export * from "./parameter-declaration-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/declarations/parameter-declaration/parameter-declaration-semantics.ts b/kipper/core/src/compiler/ast/nodes/declarations/parameter-declaration/parameter-declaration-semantics.ts new file mode 100644 index 000000000..2e4118c63 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/declarations/parameter-declaration/parameter-declaration-semantics.ts @@ -0,0 +1,34 @@ +/** + * Semantics for AST Node {@link FunctionDeclaration}. + * @since 0.3.0 + */ +import type { UncheckedType } from "../../../../analysis"; +import type { FunctionDeclaration, IdentifierTypeSpecifierExpression } from "../../../nodes"; +import type { DeclarationSemantics } from "../declaration-semantics"; + +/** + * Semantics for AST Node {@link ParameterDeclaration}. + * @since 0.5.0 + */ +export interface ParameterDeclarationSemantics extends DeclarationSemantics { + /** + * The identifier of the parameter. + * @since 0.5.0 + */ + identifier: string; + /** + * The {@link KipperType type} of the parameter. + * @since 0.5.0 + */ + valueType: UncheckedType; + /** + * The type specifier expression for the parameter type. + * @since 0.10.0 + */ + valueTypeSpecifier: IdentifierTypeSpecifierExpression; + /** + * The parent function of this parameter. + * @since 0.10.0 + */ + func: FunctionDeclaration; +} diff --git a/kipper/core/src/compiler/ast/nodes/declarations/parameter-declaration/parameter-declaration-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/declarations/parameter-declaration/parameter-declaration-type-semantics.ts new file mode 100644 index 000000000..49170ea1d --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/declarations/parameter-declaration/parameter-declaration-type-semantics.ts @@ -0,0 +1,18 @@ +/** + * Type semantics for AST Node {@link FunctionDeclaration}. + * @since 0.10.0 + */ +import type { CheckedType } from "../../../../analysis"; +import type { DeclarationTypeSemantics } from "../declaration-type-semantics"; + +/** + * Type semantics for AST Node {@link ParameterDeclaration}. + * @since 0.10.0 + */ +export interface ParameterDeclarationTypeSemantics extends DeclarationTypeSemantics { + /** + * The {@link KipperType type} of the parameter. + * @since 0.10.0 + */ + valueType: CheckedType; +} diff --git a/kipper/core/src/compiler/ast/nodes/declarations/parameter-declaration.ts b/kipper/core/src/compiler/ast/nodes/declarations/parameter-declaration/parameter-declaration.ts similarity index 91% rename from kipper/core/src/compiler/ast/nodes/declarations/parameter-declaration.ts rename to kipper/core/src/compiler/ast/nodes/declarations/parameter-declaration/parameter-declaration.ts index d88225858..9982e285c 100644 --- a/kipper/core/src/compiler/ast/nodes/declarations/parameter-declaration.ts +++ b/kipper/core/src/compiler/ast/nodes/declarations/parameter-declaration/parameter-declaration.ts @@ -2,15 +2,15 @@ * Function declaration class, which represents the definition of a parameter inside a {@link FunctionDeclaration}. * @since 0.1.2 */ -import type { ParameterDeclarationSemantics } from "../../semantic-data"; -import type { ParameterDeclarationTypeSemantics } from "../../type-data"; -import type { CompilableNodeParent } from "../../compilable-ast-node"; -import type { FunctionScope, ScopeParameterDeclaration } from "../../../analysis"; -import type { FunctionDeclaration } from "./function-declaration"; -import type { IdentifierTypeSpecifierExpression } from "../expressions"; -import { Declaration } from "./declaration"; -import { KindParseRuleMapping, ParameterDeclarationContext, ParseRuleKindMapping } from "../../../parser"; -import { getParseTreeSource } from "../../../../tools"; +import type { ParameterDeclarationSemantics } from "./parameter-declaration-semantics"; +import type { ParameterDeclarationTypeSemantics } from "./parameter-declaration-type-semantics"; +import type { CompilableNodeParent } from "../../../compilable-ast-node"; +import type { FunctionScope, ScopeParameterDeclaration } from "../../../../analysis"; +import type { FunctionDeclaration } from "../function-declaration"; +import type { IdentifierTypeSpecifierExpression } from "../../expressions"; +import { Declaration } from "../declaration"; +import { KindParseRuleMapping, ParameterDeclarationContext, ParseRuleKindMapping } from "../../../../parser"; +import { getParseTreeSource } from "../../../../../tools"; /** * Function declaration class, which represents the definition of a parameter inside a {@link FunctionDeclaration}. diff --git a/kipper/core/src/compiler/ast/nodes/declarations/variable-declaration/index.ts b/kipper/core/src/compiler/ast/nodes/declarations/variable-declaration/index.ts new file mode 100644 index 000000000..6f76c8c0d --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/declarations/variable-declaration/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link VariableDeclaration} and the related {@link VariableDeclarationSemantics semantics} and + * {@link VariableDeclarationTypeSemantics type semantics}. + */ +export * from "./variable-declaration"; +export * from "./variable-declaration-semantics"; +export * from "./variable-declaration-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/declarations/variable-declaration/variable-declaration-semantics.ts b/kipper/core/src/compiler/ast/nodes/declarations/variable-declaration/variable-declaration-semantics.ts new file mode 100644 index 000000000..f2f46ef42 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/declarations/variable-declaration/variable-declaration-semantics.ts @@ -0,0 +1,52 @@ +/** + * Semantics for AST Node {@link FunctionDeclaration}. + * @since 0.3.0 + */ +import type { KipperStorageType } from "../../../../const"; +import type { Scope, UncheckedType } from "../../../../analysis"; +import type { Expression, IdentifierTypeSpecifierExpression } from "../../../nodes"; +import type { DeclarationSemantics } from "../declaration-semantics"; + +/** + * Semantics for AST Node {@link VariableDeclaration}. + * @since 0.3.0 + */ +export interface VariableDeclarationSemantics extends DeclarationSemantics { + /** + * The identifier of this variable. + * @since 0.5.0 + */ + identifier: string; + /** + * The storage type option for this variable. + * @since 0.5.0 + */ + storageType: KipperStorageType; + /** + * The type of the value as a string. + * + * The identifier of the {@link valueTypeSpecifier.semanticData.identifier typeSpecifier}. + * @since 0.5.0 + */ + valueType: UncheckedType; + /** + * The type specifier expression for the variable type. + * @since 0.10.0 + */ + valueTypeSpecifier: IdentifierTypeSpecifierExpression; + /** + * If this is true then the variable has a defined value. + * @since 0.5.0 + */ + isDefined: boolean; + /** + * The scope of this variable. + * @since 0.5.0 + */ + scope: Scope; + /** + * The assigned value to this variable. If {@link isDefined} is false, then this value is undefined. + * @since 0.7.0 + */ + value: Expression | undefined; +} diff --git a/kipper/core/src/compiler/ast/nodes/declarations/variable-declaration/variable-declaration-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/declarations/variable-declaration/variable-declaration-type-semantics.ts new file mode 100644 index 000000000..52756c66b --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/declarations/variable-declaration/variable-declaration-type-semantics.ts @@ -0,0 +1,20 @@ +/** + * Type semantics for AST Node {@link FunctionDeclaration}. + * @since 0.10.0 + */ +import type { CheckedType } from "../../../../analysis"; +import { DeclarationTypeSemantics } from "../declaration-type-semantics"; + +/** + * Type semantics for AST Node {@link VariableDeclaration}. + * @since 0.10.0 + */ +export interface VariableDeclarationTypeSemantics extends DeclarationTypeSemantics { + /** + * The type of the value that may be stored in this variable. + * + * This is the type evaluated using the {@link VariableDeclarationSemantics.valueType valueType identifier}. + * @since 0.10.0 + */ + valueType: CheckedType; +} diff --git a/kipper/core/src/compiler/ast/nodes/declarations/variable-declaration.ts b/kipper/core/src/compiler/ast/nodes/declarations/variable-declaration/variable-declaration.ts similarity index 94% rename from kipper/core/src/compiler/ast/nodes/declarations/variable-declaration.ts rename to kipper/core/src/compiler/ast/nodes/declarations/variable-declaration/variable-declaration.ts index b25ce863c..162d80f3b 100644 --- a/kipper/core/src/compiler/ast/nodes/declarations/variable-declaration.ts +++ b/kipper/core/src/compiler/ast/nodes/declarations/variable-declaration/variable-declaration.ts @@ -5,23 +5,23 @@ * In case that {@link scope} is of type {@link KipperProgramContext}, then the scope is defined as global * (accessible for the entire program). */ -import type { VariableDeclarationSemantics } from "../../semantic-data"; -import type { VariableDeclarationTypeSemantics } from "../../type-data"; -import type { CompilableNodeParent } from "../../compilable-ast-node"; -import type { ScopeVariableDeclaration, UncheckedType } from "../../../analysis"; -import type { Expression, IdentifierTypeSpecifierExpression } from "../expressions"; +import type { VariableDeclarationSemantics } from "./variable-declaration-semantics"; +import type { VariableDeclarationTypeSemantics } from "./variable-declaration-type-semantics"; +import type { CompilableNodeParent } from "../../../compilable-ast-node"; +import type { ScopeVariableDeclaration, UncheckedType } from "../../../../analysis"; +import type { Expression, IdentifierTypeSpecifierExpression } from "../../expressions"; import type { ParseTree } from "antlr4ts/tree"; -import type { KipperStorageType } from "../../../const"; -import { Declaration } from "./declaration"; +import type { KipperStorageType } from "../../../../const"; +import { Declaration } from "../declaration"; import { DeclaratorContext, InitDeclaratorContext, KindParseRuleMapping, ParseRuleKindMapping, storageTypeSpecifierContext, - VariableDeclarationContext -} from "../../../parser"; -import { UnableToDetermineSemanticDataError } from "../../../../errors"; + VariableDeclarationContext, +} from "../../../../parser"; +import { UnableToDetermineSemanticDataError } from "../../../../../errors"; /** * Variable declaration class, which represents the declaration and or definition of a variable in the Kipper diff --git a/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/additive-expression/additive-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/additive-expression/additive-expression-semantics.ts new file mode 100644 index 000000000..99446bab0 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/additive-expression/additive-expression-semantics.ts @@ -0,0 +1,29 @@ +/** + * Semantics for AST Node {@link AdditiveExpression}. + * @since 0.5.0 + */ +import type { ArithmeticExpressionSemantics } from "../arithmetic-expression-semantics"; +import type { Expression } from "../../expression"; +import type { KipperAdditiveOperator } from "../../../../../const"; + +/** + * Semantics for AST Node {@link AdditiveExpression}. + * @since 0.5.0 + */ +export interface AdditiveExpressionSemantics extends ArithmeticExpressionSemantics { + /** + * The first expression. The left side of the expression. + * @since 0.6.0 + */ + leftOp: Expression; + /** + * The second expression. The right side of the expression. + * @since 0.6.0 + */ + rightOp: Expression; + /** + * The operator using the two values {@link this.leftOp leftOp} and {@link this.rightOp rightOp} to generate a result. + * @since 0.6.0 + */ + operator: KipperAdditiveOperator; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/additive-expression/additive-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/additive-expression/additive-expression-type-semantics.ts new file mode 100644 index 000000000..a2e60e879 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/additive-expression/additive-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link AdditiveExpression}. + * @since 0.10.0 + */ +import type { ArithmeticExpressionTypeSemantics } from "../arithmetic-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link AdditiveExpression}. + * @since 0.10.0 + */ +export interface AdditiveExpressionTypeSemantics extends ArithmeticExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/additive-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/additive-expression/additive-expression.ts similarity index 91% rename from kipper/core/src/compiler/ast/nodes/expressions/arithmetic/additive-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/arithmetic/additive-expression/additive-expression.ts index f872c4ae6..6e9c2cc86 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/additive-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/additive-expression/additive-expression.ts @@ -7,15 +7,15 @@ * 4 + 4 // 8 * 9 - 3 // 6 */ -import type { AdditiveExpressionSemantics } from "../../../semantic-data"; -import type { AdditiveExpressionTypeSemantics } from "../../../type-data"; -import type { Expression } from "../expression"; -import type { CompilableASTNode } from "../../../compilable-ast-node"; -import { AdditiveExpressionContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; -import { KipperAdditiveOperator, kipperAdditiveOperators } from "../../../../const"; +import type { AdditiveExpressionSemantics } from "./additive-expression-semantics"; +import type { AdditiveExpressionTypeSemantics } from "./additive-expression-type-semantics"; +import type { Expression } from "../../expression"; +import type { CompilableASTNode } from "../../../../compilable-ast-node"; +import { AdditiveExpressionContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../../parser"; +import { KipperAdditiveOperator, kipperAdditiveOperators } from "../../../../../const"; import { TerminalNode } from "antlr4ts/tree/TerminalNode"; -import { UnableToDetermineSemanticDataError } from "../../../../../errors"; -import { ArithmeticExpression } from "./arithmetic-expression"; +import { UnableToDetermineSemanticDataError } from "../../../../../../errors"; +import { ArithmeticExpression } from "../arithmetic-expression"; /** * Additive expression, which can be used add together or concatenate two expressions. diff --git a/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/additive-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/additive-expression/index.ts new file mode 100644 index 000000000..f15a3c75c --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/additive-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link AdditiveExpression} and the related {@link AdditiveExpressionSemantics semantics} and + * {@link AdditiveExpressionTypeSemantics type semantics}. + */ +export * from "./additive-expression"; +export * from "./additive-expression-semantics"; +export * from "./additive-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/arithmetic-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/arithmetic-expression-semantics.ts new file mode 100644 index 000000000..a1eac0d5b --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/arithmetic-expression-semantics.ts @@ -0,0 +1,29 @@ +/** + * Semantics for arithmetic expressions ({@link MultiplicativeExpression} and {@link AdditiveExpression}). + * @since 0.6.0 + */ +import type { ExpressionSemantics } from "../expression-semantics"; +import type { Expression } from "../expression"; +import type { KipperArithmeticOperator } from "../../../../const"; + +/** + * Semantics for arithmetic expressions ({@link MultiplicativeExpression} and {@link AdditiveExpression}). + * @since 0.6.0 + */ +export interface ArithmeticExpressionSemantics extends ExpressionSemantics { + /** + * The left operand of the expression. + * @since 0.10.0 + */ + leftOp: Expression; + /** + * The right operand of the expression. + * @since 0.10.0 + */ + rightOp: Expression; + /** + * The operator using the two values {@link this.leftOp leftOp} and {@link this.rightOp rightOp} to generate a result. + * @since 0.6.0 + */ + operator: KipperArithmeticOperator; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/arithmetic-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/arithmetic-expression-type-semantics.ts new file mode 100644 index 000000000..acdcf5c64 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/arithmetic-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for arithmetic expressions ({@link MultiplicativeExpression} and {@link AdditiveExpression}). + * @since 0.10.0 + */ +import { ExpressionTypeSemantics } from "../expression-type-semantics"; + +/** + * Type semantics for arithmetic expressions ({@link MultiplicativeExpression} and {@link AdditiveExpression}). + * @since 0.10.0 + */ +export interface ArithmeticExpressionTypeSemantics extends ExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/arithmetic-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/arithmetic-expression.ts index 0009d727d..32ed0d7e5 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/arithmetic-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/arithmetic-expression.ts @@ -4,8 +4,8 @@ * comparative expressions. * @since 0.9.0 */ -import type { ArithmeticExpressionSemantics } from "../../../semantic-data"; -import type { ArithmeticExpressionTypeSemantics } from "../../../type-data"; +import type { ArithmeticExpressionSemantics } from "./arithmetic-expression-semantics"; +import type { ArithmeticExpressionTypeSemantics } from "./arithmetic-expression-type-semantics"; import type { ParseRuleKindMapping } from "../../../../parser"; import { KindParseRuleMapping } from "../../../../parser"; import { Expression } from "../expression"; @@ -24,7 +24,7 @@ export type ASTArithmeticExpressionKind = * @since 0.10.0 */ export type ParserArithmeticExpressionContext = InstanceType< - typeof ASTNodeMapper.expressionKindToRuleContextMap[ASTArithmeticExpressionKind] + (typeof ASTNodeMapper.expressionKindToRuleContextMap)[ASTArithmeticExpressionKind] >; /** @@ -32,7 +32,7 @@ export type ParserArithmeticExpressionContext = InstanceType< * AST node. * @since 0.11.0 */ -export type ParserArithmeticExpressionRuleName = typeof KindParseRuleMapping[ASTArithmeticExpressionKind]; +export type ParserArithmeticExpressionRuleName = (typeof KindParseRuleMapping)[ASTArithmeticExpressionKind]; /** * Abstract arithmetic expression class representing an arithmetic expression, which can be used to perform calculations diff --git a/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/index.ts index c5aeffb12..4a26af6d8 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/index.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/index.ts @@ -3,5 +3,8 @@ * calculations based on two expressions. * @since 0.11.0 */ -export * from "./additive-expression"; -export * from "./multiplicative-expression"; +export * from "./arithmetic-expression"; +export * from "./arithmetic-expression-semantics"; +export * from "./arithmetic-expression-type-semantics"; +export * from "./additive-expression/"; +export * from "./multiplicative-expression/"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/multiplicative-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/multiplicative-expression/index.ts new file mode 100644 index 000000000..61d34d5e3 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/multiplicative-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link MultiplicativeExpression} and the related {@link MultiplicativeExpressionSemantics semantics} and + * {@link MultiplicativeExpressionTypeSemantics type semantics}. + */ +export * from "./multiplicative-expression"; +export * from "./multiplicative-expression-semantics"; +export * from "./multiplicative-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/multiplicative-expression/multiplicative-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/multiplicative-expression/multiplicative-expression-semantics.ts new file mode 100644 index 000000000..7cf74d3dd --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/multiplicative-expression/multiplicative-expression-semantics.ts @@ -0,0 +1,29 @@ +/** + * Semantics for AST Node {@link MultiplicativeExpression}. + * @since 0.5.0 + */ +import type { Expression } from "../../expression"; +import type { KipperMultiplicativeOperator } from "../../../../../const"; +import type { ArithmeticExpressionSemantics } from "../arithmetic-expression-semantics"; + +/** + * Semantics for AST Node {@link MultiplicativeExpression}. + * @since 0.5.0 + */ +export interface MultiplicativeExpressionSemantics extends ArithmeticExpressionSemantics { + /** + * The first expression. The left side of the expression. + * @since 0.6.0 + */ + leftOp: Expression; + /** + * The second expression. The right side of the expression. + * @since 0.6.0 + */ + rightOp: Expression; + /** + * The operator using the two values {@link this.leftOp leftOp} and {@link this.rightOp rightOp} to generate a result. + * @since 0.6.0 + */ + operator: KipperMultiplicativeOperator; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/multiplicative-expression/multiplicative-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/multiplicative-expression/multiplicative-expression-type-semantics.ts new file mode 100644 index 000000000..bf2e612fb --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/multiplicative-expression/multiplicative-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link MultiplicativeExpression}. + * @since 0.10.0 + */ +import type { ArithmeticExpressionTypeSemantics } from "../arithmetic-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link MultiplicativeExpression}. + * @since 0.10.0 + */ +export interface MultiplicativeTypeSemantics extends ArithmeticExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/multiplicative-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/multiplicative-expression/multiplicative-expression.ts similarity index 90% rename from kipper/core/src/compiler/ast/nodes/expressions/arithmetic/multiplicative-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/arithmetic/multiplicative-expression/multiplicative-expression.ts index 56fb22733..77c087d85 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/multiplicative-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/arithmetic/multiplicative-expression/multiplicative-expression.ts @@ -9,16 +9,16 @@ * 96 % 15 // 6 * 2 ** 8 // 256 */ -import type { MultiplicativeExpressionSemantics } from "../../../semantic-data"; -import type { MultiplicativeTypeSemantics } from "../../../type-data"; -import type { Expression } from "../expression"; -import type { CompilableASTNode } from "../../../compilable-ast-node"; -import { KindParseRuleMapping, MultiplicativeExpressionContext, ParseRuleKindMapping } from "../../../../parser"; -import { KipperMultiplicativeOperator, kipperMultiplicativeOperators } from "../../../../const"; +import type { MultiplicativeExpressionSemantics } from "./multiplicative-expression-semantics"; +import type { MultiplicativeTypeSemantics } from "./multiplicative-expression-type-semantics"; +import type { Expression } from "../../expression"; +import type { CompilableASTNode } from "../../../../compilable-ast-node"; +import { KindParseRuleMapping, MultiplicativeExpressionContext, ParseRuleKindMapping } from "../../../../../parser"; +import { KipperMultiplicativeOperator, kipperMultiplicativeOperators } from "../../../../../const"; import { TerminalNode } from "antlr4ts/tree/TerminalNode"; -import { UnableToDetermineSemanticDataError } from "../../../../../errors"; -import { CheckedType } from "../../../../analysis"; -import { ArithmeticExpression } from "./arithmetic-expression"; +import { UnableToDetermineSemanticDataError } from "../../../../../../errors"; +import { CheckedType } from "../../../../../analysis"; +import { ArithmeticExpression } from "../arithmetic-expression"; /** * Multiplicative expression, which can be used to perform multiplicative operations on two expressions. diff --git a/kipper/core/src/compiler/ast/nodes/expressions/assignment-expression/assignment-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/assignment-expression/assignment-expression-semantics.ts new file mode 100644 index 000000000..eec8fbd28 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/assignment-expression/assignment-expression-semantics.ts @@ -0,0 +1,41 @@ +/** + * Semantics for AST Node {@link AssignmentExpression}. + * @since 0.5.0 + */ +import type { Reference } from "../../../../analysis"; +import type { KipperAssignOperator } from "../../../../const"; +import type { Expression } from "../expression"; +import type { ExpressionSemantics } from "../expression-semantics"; +import type { IdentifierPrimaryExpression } from "../primary-expression"; + +/** + * Semantics for AST Node {@link AssignmentExpression}. + * @since 0.5.0 + */ +export interface AssignmentExpressionSemantics extends ExpressionSemantics { + /** + * The identifier expression that is being assigned to. + * @since 0.7.0 + */ + identifier: string; + /** + * The identifier AST node context that the {@link AssignmentExpressionSemantics.identifier identifier} points to. + * @since 0.10.0 + */ + identifierCtx: IdentifierPrimaryExpression; + /** + * The reference that is being assigned to. + * @since 0.10.0 + */ + assignTarget: Reference; + /** + * The assigned value to this variable. + * @since 0.7.0 + */ + value: Expression; + /** + * The operator of the assignment expression. + * @since 0.10.0 + */ + operator: KipperAssignOperator; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/assignment-expression/assignment-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/assignment-expression/assignment-expression-type-semantics.ts new file mode 100644 index 000000000..4ff450fac --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/assignment-expression/assignment-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link AssignmentExpression}. + * @since 0.10.0 + */ +import type { ExpressionTypeSemantics } from "../expression-type-semantics"; + +/** + * Type semantics for AST Node {@link AssignmentExpression}. + * @since 0.10.0 + */ +export interface AssignmentExpressionTypeSemantics extends ExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/assignment-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/assignment-expression/assignment-expression.ts similarity index 91% rename from kipper/core/src/compiler/ast/nodes/expressions/assignment-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/assignment-expression/assignment-expression.ts index 0ebecfbaa..3f6a12548 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/assignment-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/assignment-expression/assignment-expression.ts @@ -12,21 +12,21 @@ * x /= 5 * x %= 55 */ -import type { CompilableASTNode } from "../../compilable-ast-node"; -import type { AssignmentExpressionSemantics } from "../../semantic-data"; -import type { AssignmentExpressionTypeSemantics } from "../../type-data"; +import type { CompilableASTNode } from "../../../compilable-ast-node"; +import type { AssignmentExpressionSemantics } from "./assignment-expression-semantics"; +import type { AssignmentExpressionTypeSemantics } from "./assignment-expression-type-semantics"; import { AssignmentExpressionContext, KindParseRuleMapping, KipperParserRuleContext, - ParseRuleKindMapping -} from "../../../parser"; -import { Expression } from "./expression"; -import { IdentifierPrimaryExpression } from "./primary"; -import { UnableToDetermineSemanticDataError } from "../../../../errors"; -import { kipperArithmeticAssignOperators, KipperAssignOperator } from "../../../const"; -import { getParseRuleSource } from "../../../../tools"; -import { ScopeVariableDeclaration } from "../../../analysis"; + ParseRuleKindMapping, +} from "../../../../parser"; +import { Expression } from "../expression"; +import { IdentifierPrimaryExpression } from "../primary-expression"; +import { UnableToDetermineSemanticDataError } from "../../../../../errors"; +import { kipperArithmeticAssignOperators, KipperAssignOperator } from "../../../../const"; +import { getParseRuleSource } from "../../../../../tools"; +import { ScopeVariableDeclaration } from "../../../../analysis"; /** * Assignment expression, which assigns an expression to a variable. This class only represents assigning a value to diff --git a/kipper/core/src/compiler/ast/nodes/expressions/assignment-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/assignment-expression/index.ts new file mode 100644 index 000000000..6e6a7298b --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/assignment-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link AssignmentExpression} and the related {@link AssignmentExpressionSemantics semantics} and + * {@link AssignmentExpressionTypeSemantics type semantics}. + */ +export * from "./assignment-expression"; +export * from "./assignment-expression-semantics"; +export * from "./assignment-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/cast-or-convert-expression/cast-or-convert-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/cast-or-convert-expression/cast-or-convert-expression-semantics.ts new file mode 100644 index 000000000..b789929d9 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/cast-or-convert-expression/cast-or-convert-expression-semantics.ts @@ -0,0 +1,30 @@ +/** + * Semantics for AST Node {@link CastOrConvertExpression}. + * @since 0.5.0 + */ +import type { ExpressionSemantics } from "../expression-semantics"; +import type { Expression } from "../expression"; +import type { UncheckedType } from "../../../../analysis"; +import type { IdentifierTypeSpecifierExpression } from "../type-specifier-expression"; + +/** + * Semantics for AST Node {@link CastOrConvertExpression}. + * @since 0.5.0 + */ +export interface CastOrConvertExpressionSemantics extends ExpressionSemantics { + /** + * The expression to convert. + * @since 0.8.0 + */ + exp: Expression; + /** + * The type the {@link exp} should be converted to. + * @since 0.10.0 + */ + castType: UncheckedType; + /** + * The type specifier that determined {@link castType}. + * @since 0.10.0 + */ + castTypeSpecifier: IdentifierTypeSpecifierExpression; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/cast-or-convert-expression/cast-or-convert-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/cast-or-convert-expression/cast-or-convert-expression-type-semantics.ts new file mode 100644 index 000000000..c8518ff3b --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/cast-or-convert-expression/cast-or-convert-expression-type-semantics.ts @@ -0,0 +1,18 @@ +/** + * Type semantics for AST Node {@link CastOrConvertExpression}. + * @since 0.10.0 + */ +import type { CheckedType } from "../../../../analysis"; +import type { ExpressionTypeSemantics } from "../expression-type-semantics"; + +/** + * Type semantics for AST Node {@link CastOrConvertExpression}. + * @since 0.10.0 + */ +export interface CastOrConvertExpressionTypeSemantics extends ExpressionTypeSemantics { + /** + * The type the {@link CastOrConvertExpressionSemantics.exp} should be converted to. + * @since 0.10.0 + */ + castType: CheckedType; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/cast-or-convert-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/cast-or-convert-expression/cast-or-convert-expression.ts similarity index 88% rename from kipper/core/src/compiler/ast/nodes/expressions/cast-or-convert-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/cast-or-convert-expression/cast-or-convert-expression.ts index 40c7c09bd..0c403daea 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/cast-or-convert-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/cast-or-convert-expression/cast-or-convert-expression.ts @@ -7,16 +7,16 @@ * "4" as num // 4 * 39 as str // "39" */ -import type { CastOrConvertExpressionSemantics } from "../../semantic-data"; -import type { CastOrConvertExpressionTypeSemantics } from "../../type-data"; -import type { CompilableASTNode } from "../../compilable-ast-node"; -import type { IdentifierTypeSpecifierExpression } from "./type-specifier"; -import { Expression } from "./expression"; -import { CastOrConvertExpressionContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../parser"; -import { UncheckedType } from "../../../analysis"; -import { UnableToDetermineSemanticDataError } from "../../../../errors"; -import { getConversionFunctionIdentifier } from "../../../../tools"; -import { kipperInternalBuiltInFunctions } from "../../../runtime-built-ins"; +import type { CastOrConvertExpressionSemantics } from "./cast-or-convert-expression-semantics"; +import type { CastOrConvertExpressionTypeSemantics } from "./cast-or-convert-expression-type-semantics"; +import type { CompilableASTNode } from "../../../compilable-ast-node"; +import type { IdentifierTypeSpecifierExpression } from "../type-specifier-expression"; +import { Expression } from "../expression"; +import { CastOrConvertExpressionContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; +import { UncheckedType } from "../../../../analysis"; +import { UnableToDetermineSemanticDataError } from "../../../../../errors"; +import { getConversionFunctionIdentifier } from "../../../../../tools"; +import { kipperInternalBuiltInFunctions } from "../../../../runtime-built-ins"; /** * Convert expressions, which are used to convert a value to a different type. diff --git a/kipper/core/src/compiler/ast/nodes/expressions/cast-or-convert-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/cast-or-convert-expression/index.ts new file mode 100644 index 000000000..3ac767805 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/cast-or-convert-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link CastOrConvertExpression} and the related {@link CastOrConvertExpressionSemantics semantics} and + * {@link CastOrConvertExpressionTypeSemantics type semantics}. + */ +export * from "./cast-or-convert-expression"; +export * from "./cast-or-convert-expression-semantics"; +export * from "./cast-or-convert-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/comparative-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/comparative-expression-semantics.ts new file mode 100644 index 000000000..fcd57bdca --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/comparative-expression-semantics.ts @@ -0,0 +1,31 @@ +/** + * Semantics for a comparative expression, which compares two operands against each other using a specified + * operator. + * @since 0.9.0 + */ +import type { KipperComparativeOperator } from "../../../../const"; +import type { ExpressionSemantics } from "../expression-semantics"; +import type { Expression } from "../expression"; + +/** + * Semantics for a comparative expression, which compares two operands against each other using a specified + * operator. + * @since 0.9.0 + */ +export interface ComparativeExpressionSemantics extends ExpressionSemantics { + /** + * The operator used to compare the two expressions of this comparative expression. + * @since 0.9.0 + */ + operator: KipperComparativeOperator; + /** + * The left expression (left-hand side) used in this comparative expression. + * @since 0.9.0 + */ + leftOp: Expression; + /** + * The right expression (right-hand side) used in this comparative expression. + * @since 0.9.0 + */ + rightOp: Expression; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/comparative-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/comparative-expression-type-semantics.ts new file mode 100644 index 000000000..44c5f850f --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/comparative-expression-type-semantics.ts @@ -0,0 +1,13 @@ +/** + * Type semantics for a comparative expression, which compares two operands against each other using a specified + * operator. + * @since 0.10.0 + */ +import type { ExpressionTypeSemantics } from "../expression-type-semantics"; + +/** + * Type semantics for a comparative expression, which compares two operands against each other using a specified + * operator. + * @since 0.10.0 + */ +export interface ComparativeExpressionTypeSemantics extends ExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/comparative/comparative-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/comparative-expression.ts similarity index 79% rename from kipper/core/src/compiler/ast/nodes/expressions/comparative/comparative-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/comparative-expression.ts index 347df2c44..11633b8c9 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/comparative/comparative-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/comparative-expression.ts @@ -3,10 +3,9 @@ * expressions. This abstract class only exists to provide the commonality between the different comparative expressions. * @since 0.9.0 */ -import type { ParseRuleKindMapping } from "../../../../parser"; -import { KindParseRuleMapping } from "../../../../parser"; -import type { ComparativeExpressionSemantics } from "../../../semantic-data"; -import type { ComparativeExpressionTypeSemantics } from "../../../type-data"; +import type { KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; +import type { ComparativeExpressionSemantics } from "./comparative-expression-semantics"; +import type { ComparativeExpressionTypeSemantics } from "./comparative-expression-type-semantics"; import { Expression } from "../expression"; import { ASTNodeMapper } from "../../../mapping"; @@ -23,7 +22,7 @@ export type ASTComparativeExpressionKind = * @since 0.10.0 */ export type ParserComparativeExpressionContext = InstanceType< - typeof ASTNodeMapper.expressionKindToRuleContextMap[ASTComparativeExpressionKind] + (typeof ASTNodeMapper.expressionKindToRuleContextMap)[ASTComparativeExpressionKind] >; /** @@ -31,7 +30,7 @@ export type ParserComparativeExpressionContext = InstanceType< * AST node. * @since 0.11.0 */ -export type ParserComparativeExpressionRuleName = typeof KindParseRuleMapping[ASTComparativeExpressionKind]; +export type ParserComparativeExpressionRuleName = (typeof KindParseRuleMapping)[ASTComparativeExpressionKind]; /** * Abstract comparative expression class representing a comparative expression, which can be used to compare two diff --git a/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/equality-expression/equality-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/equality-expression/equality-expression-semantics.ts new file mode 100644 index 000000000..e014a380e --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/equality-expression/equality-expression-semantics.ts @@ -0,0 +1,29 @@ +/** + * Semantics for AST Node {@link EqualityExpressionSemantics}. + * @since 0.5.0 + */ +import type { KipperEqualityOperator } from "../../../../../const"; +import type { Expression } from "../../expression"; +import type { ComparativeExpressionSemantics } from "../comparative-expression-semantics"; + +/** + * Semantics for AST Node {@link EqualityExpressionSemantics}. + * @since 0.5.0 + */ +export interface EqualityExpressionSemantics extends ComparativeExpressionSemantics { + /** + * The operator used to compare the two expressions of this equality expression. + * @since 0.9.0 + */ + operator: KipperEqualityOperator; + /** + * The first expression (left-hand side) used in this equality expression. + * @since 0.9.0 + */ + leftOp: Expression; + /** + * The second expression (right-hand side) used in this equality expression. + * @since 0.9.0 + */ + rightOp: Expression; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/equality-expression/equality-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/equality-expression/equality-expression-type-semantics.ts new file mode 100644 index 000000000..d264f13f1 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/equality-expression/equality-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link EqualityExpressionSemantics}. + * @since 0.10.0 + */ +import type { ComparativeExpressionTypeSemantics } from "../comparative-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link EqualityExpressionSemantics}. + * @since 0.10.0 + */ +export interface EqualityExpressionTypeSemantics extends ComparativeExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/comparative/equality-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/equality-expression/equality-expression.ts similarity index 90% rename from kipper/core/src/compiler/ast/nodes/expressions/comparative/equality-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/equality-expression/equality-expression.ts index c487acc13..b8298dfb8 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/comparative/equality-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/equality-expression/equality-expression.ts @@ -7,16 +7,16 @@ * 32 != 9 // true * 59 != 59 // false */ -import type { EqualityExpressionSemantics } from "../../../semantic-data"; -import type { EqualityExpressionTypeSemantics } from "../../../type-data"; -import type { Expression } from "../expression"; -import { ComparativeExpression } from "./comparative-expression"; -import { CheckedType } from "../../../../analysis"; -import { EqualityExpressionContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; -import { UnableToDetermineSemanticDataError } from "../../../../../errors"; -import { KipperEqualityOperator, kipperEqualityOperators } from "../../../../const"; +import type { EqualityExpressionSemantics } from "./equality-expression-semantics"; +import type { EqualityExpressionTypeSemantics } from "./equality-expression-type-semantics"; +import type { Expression } from "../../expression"; +import { ComparativeExpression } from "../comparative-expression"; +import { CheckedType } from "../../../../../analysis"; +import { EqualityExpressionContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../../parser"; +import { UnableToDetermineSemanticDataError } from "../../../../../../errors"; +import { KipperEqualityOperator, kipperEqualityOperators } from "../../../../../const"; import { TerminalNode } from "antlr4ts/tree/TerminalNode"; -import { CompilableASTNode } from "../../../compilable-ast-node"; +import { CompilableASTNode } from "../../../../compilable-ast-node"; /** * Equality expression, which can be used to compare two expressions for equality. diff --git a/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/equality-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/equality-expression/index.ts new file mode 100644 index 000000000..193019ba6 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/equality-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link EqualityExpression} and the related {@link EqualityExpressionSemantics semantics} and + * {@link EqualityExpressionTypeSemantics type semantics}. + */ +export * from "./equality-expression"; +export * from "./equality-expression-semantics"; +export * from "./equality-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/comparative/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/index.ts similarity index 50% rename from kipper/core/src/compiler/ast/nodes/expressions/comparative/index.ts rename to kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/index.ts index e36344d23..63117053e 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/comparative/index.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/index.ts @@ -4,5 +4,7 @@ * @since 0.11.0 */ export * from "./comparative-expression"; -export * from "./equality-expression"; -export * from "./relational-expression"; +export * from "./comparative-expression-semantics"; +export * from "./comparative-expression-type-semantics"; +export * from "./equality-expression/"; +export * from "./relational-expression/"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/relational-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/relational-expression/index.ts new file mode 100644 index 000000000..15d259d3d --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/relational-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link RelationalExpression} and the related {@link RelationalExpressionSemantics semantics} and + * {@link RelationalExpressionTypeSemantics type semantics}. + */ +export * from "./relational-expression"; +export * from "./relational-expression-semantics"; +export * from "./relational-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/relational-expression/relational-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/relational-expression/relational-expression-semantics.ts new file mode 100644 index 000000000..2181dc6ca --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/relational-expression/relational-expression-semantics.ts @@ -0,0 +1,29 @@ +/** + * Semantics for AST Node {@link RelationalExpression}. + * @since 0.5.0 + */ +import type { KipperRelationalOperator } from "../../../../../const"; +import type { Expression } from "../../expression"; +import type { ComparativeExpressionSemantics } from "../comparative-expression-semantics"; + +/** + * Semantics for AST Node {@link RelationalExpression}. + * @since 0.5.0 + */ +export interface RelationalExpressionSemantics extends ComparativeExpressionSemantics { + /** + * The operator used to compare the two expressions of this relational expression. + * @since 0.9.0 + */ + operator: KipperRelationalOperator; + /** + * The first expression (left-hand side) used in this relational expression. + * @since 0.9.0 + */ + leftOp: Expression; + /** + * The second expression (right-hand side) used in this relational expression. + * @since 0.9.0 + */ + rightOp: Expression; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/relational-expression/relational-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/relational-expression/relational-expression-type-semantics.ts new file mode 100644 index 000000000..1a78942ff --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/relational-expression/relational-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link RelationalExpression}. + * @since 0.10.0 + */ +import type { ComparativeExpressionTypeSemantics } from "../comparative-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link RelationalExpression}. + * @since 0.10.0 + */ +export interface RelationalExpressionTypeSemantics extends ComparativeExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/comparative/relational-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/relational-expression/relational-expression.ts similarity index 90% rename from kipper/core/src/compiler/ast/nodes/expressions/comparative/relational-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/relational-expression/relational-expression.ts index 50c6870cb..171542f92 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/comparative/relational-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/comparative-expression/relational-expression/relational-expression.ts @@ -13,16 +13,16 @@ * 77 <= 77 // true * 36 <= 12 // false */ -import type { RelationalExpressionSemantics } from "../../../semantic-data"; -import type { RelationalExpressionTypeSemantics } from "../../../type-data"; -import type { Expression } from "../expression"; -import { ComparativeExpression } from "./comparative-expression"; -import { KindParseRuleMapping, ParseRuleKindMapping, RelationalExpressionContext } from "../../../../parser"; -import { CompilableASTNode } from "../../../compilable-ast-node"; -import { KipperRelationalOperator, kipperRelationalOperators } from "../../../../const"; +import type { RelationalExpressionSemantics } from "./relational-expression-semantics"; +import type { RelationalExpressionTypeSemantics } from "./relational-expression-type-semantics"; +import type { Expression } from "../../expression"; +import { ComparativeExpression } from "../comparative-expression"; +import { KindParseRuleMapping, ParseRuleKindMapping, RelationalExpressionContext } from "../../../../../parser"; +import { CompilableASTNode } from "../../../../compilable-ast-node"; +import { KipperRelationalOperator, kipperRelationalOperators } from "../../../../../const"; import { TerminalNode } from "antlr4ts/tree/TerminalNode"; -import { UnableToDetermineSemanticDataError } from "../../../../../errors"; -import { CheckedType } from "../../../../analysis"; +import { UnableToDetermineSemanticDataError } from "../../../../../../errors"; +import { CheckedType } from "../../../../../analysis"; /** * Relational expression, which can be used to compare two numeric expressions. diff --git a/kipper/core/src/compiler/ast/nodes/expressions/conditional-expression/conditional-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/conditional-expression/conditional-expression-semantics.ts new file mode 100644 index 000000000..792e0f15a --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/conditional-expression/conditional-expression-semantics.ts @@ -0,0 +1,11 @@ +/** + * Semantics for AST Node {@link ConditionalExpression}. + * @since 0.5.0 + */ +import type { ExpressionSemantics } from "../expression-semantics"; + +/** + * Semantics for AST Node {@link ConditionalExpression}. + * @since 0.5.0 + */ +export interface ConditionalExpressionSemantics extends ExpressionSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/conditional-expression/conditional-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/conditional-expression/conditional-expression-type-semantics.ts new file mode 100644 index 000000000..99a1c45d6 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/conditional-expression/conditional-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link ConditionalExpression}. + * @since 0.10.0 + */ +import type { ExpressionTypeSemantics } from "../expression-type-semantics"; + +/** + * Type semantics for AST Node {@link ConditionalExpression}. + * @since 0.10.0 + */ +export interface ConditionalExpressionTypeSemantics extends ExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/conditional-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/conditional-expression/conditional-expression.ts similarity index 90% rename from kipper/core/src/compiler/ast/nodes/expressions/conditional-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/conditional-expression/conditional-expression.ts index 261db0428..d2c98b8fc 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/conditional-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/conditional-expression/conditional-expression.ts @@ -6,12 +6,12 @@ * true ? 3 : 4; // 3 * false ? 3 : 4; // 4 */ -import type { ConditionalExpressionSemantics } from "../../semantic-data"; -import type { CompilableASTNode } from "../../compilable-ast-node"; -import type { ConditionalExpressionTypeSemantics } from "../../type-data"; -import { Expression } from "./expression"; -import { ConditionalExpressionContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../parser"; -import { KipperNotImplementedError } from "../../../../errors"; +import type { ConditionalExpressionSemantics } from "./conditional-expression-semantics"; +import type { ConditionalExpressionTypeSemantics } from "./conditional-expression-type-semantics"; +import type { CompilableASTNode } from "../../../compilable-ast-node"; +import { Expression } from "../expression"; +import { ConditionalExpressionContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; +import { KipperNotImplementedError } from "../../../../../errors"; /** * Conditional expression, which evaluates a condition and evaluates the left expression if it is true, or the right diff --git a/kipper/core/src/compiler/ast/nodes/expressions/conditional-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/conditional-expression/index.ts new file mode 100644 index 000000000..3e320efee --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/conditional-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link ConditionalExpression} and the related {@link ConditionalExpressionSemantics semantics} and + * {@link ConditionalExpressionTypeSemantics type semantics}. + */ +export * from "./conditional-expression"; +export * from "./conditional-expression-semantics"; +export * from "./conditional-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/expression-semantics.ts new file mode 100644 index 000000000..8afe06645 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/expression-semantics.ts @@ -0,0 +1,11 @@ +/** + * Static semantics for an expression class that must be evaluated during the Semantic Analysis. + * @since 0.10.0 + */ +import type { SemanticData } from "../../ast-node"; + +/** + * Static semantics for an expression class that must be evaluated during the Semantic Analysis. + * @since 0.10.0 + */ +export interface ExpressionSemantics extends SemanticData {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/expression-type-semantics.ts new file mode 100644 index 000000000..f0320c47c --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/expression-type-semantics.ts @@ -0,0 +1,21 @@ +/** + * Type semantics for an expression class that must be evaluated during Type Checking. + * @since 0.10.0 + */ +import type { CheckedType } from "../../../analysis"; +import type { TypeData } from "../../ast-node"; + +/** + * Type semantics for an expression class that must be evaluated during Type Checking. + * @since 0.10.0 + */ +export interface ExpressionTypeSemantics extends TypeData { + /** + * The value type that this expression evaluates to. This is used to properly represent the evaluated type of + * expressions that do not explicitly show their type. + * + * This will always evaluate to "type", as a type specifier will always be a type. + * @since 0.10.0 + */ + evaluatedType: CheckedType; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/expression.ts index 5f9715e78..88e016b35 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/expression.ts @@ -6,8 +6,8 @@ * @since 0.1.0 */ import type { TargetASTNodeCodeGenerator } from "../../../target-presets"; -import type { ExpressionSemantics } from "../../semantic-data"; -import type { ExpressionTypeSemantics } from "../../type-data"; +import type { ExpressionSemantics } from "./expression-semantics"; +import type { ExpressionTypeSemantics } from "./expression-type-semantics"; import { TranslatedExpression } from "../../../const"; import { MissingRequiredSemanticDataError } from "../../../../errors"; import { CompilableASTNode } from "../../compilable-ast-node"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/function-call-expression/function-call-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/function-call-expression/function-call-expression-semantics.ts new file mode 100644 index 000000000..498b27686 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/function-call-expression/function-call-expression-semantics.ts @@ -0,0 +1,30 @@ +/** + * Semantics for AST Node {@link FunctionCallExpression}. + * @since 0.5.0 + */ +import type { Reference } from "../../../../analysis"; +import type { KipperReferenceable } from "../../../../const"; +import type { Expression } from "../expression"; +import type { ExpressionSemantics } from "../expression-semantics"; + +/** + * Semantics for AST Node {@link FunctionCallExpression}. + * @since 0.5.0 + */ +export interface FunctionCallExpressionSemantics extends ExpressionSemantics { + /** + * The identifier of the function that is called. + * @since 0.5.0 + */ + identifier: string; + /** + * The function that is called by this expression. + * @since 0.5.0 + */ + callTarget: Reference; + /** + * The arguments that were passed to this function. + * @since 0.6.0 + */ + args: Array; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/function-call-expression/function-call-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/function-call-expression/function-call-expression-type-semantics.ts new file mode 100644 index 000000000..ef16b155b --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/function-call-expression/function-call-expression-type-semantics.ts @@ -0,0 +1,19 @@ +/** + * Type semantics for AST Node {@link FunctionCallExpression}. + * @since 0.5.0 + */ +import type { KipperFunction } from "../../../../const"; +import type { ExpressionTypeSemantics } from "../expression-type-semantics"; + +/** + * Type semantics for AST Node {@link FunctionCallExpression}. + * @since 0.5.0 + */ +export interface FunctionCallExpressionTypeSemantics extends ExpressionTypeSemantics { + /** + * The function that this expression calls. Can be either a {@link ScopeFunctionDeclaration function declaration} or + * a {@link ScopeVariableDeclaration function in a variable}. + * @since 0.10.0 + */ + func: KipperFunction; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/function-call-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/function-call-expression/function-call-expression.ts similarity index 90% rename from kipper/core/src/compiler/ast/nodes/expressions/function-call-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/function-call-expression/function-call-expression.ts index 3b8592a13..51131bf78 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/function-call-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/function-call-expression/function-call-expression.ts @@ -1,4 +1,3 @@ -import type { FunctionCallExpressionSemantics, IdentifierPrimaryExpressionSemantics } from "../../semantic-data"; /** * Function call class, which represents a function call expression in the Kipper language. * @since 0.1.0 @@ -7,13 +6,15 @@ import type { FunctionCallExpressionSemantics, IdentifierPrimaryExpressionSemant * // or * print("Hello world!") */ -import type { FunctionCallExpressionTypeSemantics } from "../../type-data"; -import type { CompilableASTNode } from "../../compilable-ast-node"; -import type { KipperReferenceableFunction } from "../../../const"; -import { Expression } from "./expression"; -import { FunctionCallExpressionContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../parser"; -import { UnableToDetermineSemanticDataError } from "../../../../errors"; -import { CheckedType } from "../../../analysis"; +import type { FunctionCallExpressionSemantics } from "./function-call-expression-semantics"; +import type { FunctionCallExpressionTypeSemantics } from "./function-call-expression-type-semantics"; +import type { CompilableASTNode } from "../../../compilable-ast-node"; +import type { KipperReferenceableFunction } from "../../../../const"; +import type { IdentifierPrimaryExpressionSemantics } from "../primary-expression"; +import { Expression } from "../expression"; +import { FunctionCallExpressionContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; +import { UnableToDetermineSemanticDataError } from "../../../../../errors"; +import { CheckedType } from "../../../../analysis"; /** * Function call class, which represents a function call expression in the Kipper language. diff --git a/kipper/core/src/compiler/ast/nodes/expressions/function-call-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/function-call-expression/index.ts new file mode 100644 index 000000000..5cdd05792 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/function-call-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link FunctionCallExpression} and the related {@link FunctionCallExpressionSemantics semantics} and + * {@link FunctionCallExpressionTypeSemantics type semantics}. + */ +export * from "./function-call-expression"; +export * from "./function-call-expression-semantics"; +export * from "./function-call-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/index.ts index 7eedf43f6..b845a0109 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/index.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/index.ts @@ -4,16 +4,18 @@ * @since 0.11.0 */ export * from "./expression"; +export * from "./expression-semantics"; +export * from "./expression-type-semantics"; +export * from "./primary-expression/"; export * from "./arithmetic/"; -export * from "./comparative/"; -export * from "./logical/"; -export * from "./postfix/"; -export * from "./primary/"; -export * from "./type-specifier/"; -export * from "./unary/"; -export * from "./assignment-expression"; -export * from "./cast-or-convert-expression"; -export * from "./conditional-expression"; -export * from "./function-call-expression"; -export * from "./member-access-expression"; -export * from "./tangled-primary-expression"; +export * from "./comparative-expression/"; +export * from "./logical-expression/"; +export * from "./postfix-expression/"; +export * from "./primary-expression/"; +export * from "./type-specifier-expression/"; +export * from "./unary-expression/"; +export * from "./assignment-expression/"; +export * from "./cast-or-convert-expression/"; +export * from "./conditional-expression/"; +export * from "./function-call-expression/"; +export * from "./member-access-expression/"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/logical/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/index.ts similarity index 55% rename from kipper/core/src/compiler/ast/nodes/expressions/logical/index.ts rename to kipper/core/src/compiler/ast/nodes/expressions/logical-expression/index.ts index f1d70947f..707594763 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/logical/index.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/index.ts @@ -4,5 +4,7 @@ * @since 0.11.0 */ export * from "./logical-expression"; -export * from "./logical-and-expression"; -export * from "./logical-or-expression"; +export * from "./logical-expression-semantics"; +export * from "./logical-expression-type-semantics"; +export * from "./logical-and-expression/"; +export * from "./logical-or-expression/"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-and-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-and-expression/index.ts new file mode 100644 index 000000000..cdfb5ba76 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-and-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link LogicalAndExpression} and the related {@link LogicalAndExpressionSemantics semantics} and + * {@link LogicalAndExpressionTypeSemantics type semantics}. + */ +export * from "./logical-and-expression"; +export * from "./logical-and-expression-semantics"; +export * from "./logical-and-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-and-expression/logical-and-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-and-expression/logical-and-expression-semantics.ts new file mode 100644 index 000000000..fdc6227f5 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-and-expression/logical-and-expression-semantics.ts @@ -0,0 +1,29 @@ +/** + * Semantics for AST Node {@link LogicalAndExpression}. + * @since 0.5.0 + */ +import type { KipperLogicalAndOperator } from "../../../../../const"; +import type { Expression } from "../../expression"; +import type { LogicalExpressionSemantics } from "../logical-expression-semantics"; + +/** + * Semantics for AST Node {@link LogicalAndExpression}. + * @since 0.5.0 + */ +export interface LogicalAndExpressionSemantics extends LogicalExpressionSemantics { + /** + * The operator used to combine the two expressions of this logical-and expression. + * @since 0.9.0 + */ + operator: KipperLogicalAndOperator; + /** + * The first expression (left-hand side) used in this logical-and expression. + * @since 0.9.0 + */ + leftOp: Expression; + /** + * The second expression (right-hand side) used in this logical-and expression. + * @since 0.9.0 + */ + rightOp: Expression; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-and-expression/logical-and-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-and-expression/logical-and-expression-type-semantics.ts new file mode 100644 index 000000000..d228318d1 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-and-expression/logical-and-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link LogicalAndExpression}. + * @since 0.10.0 + */ +import { LogicalExpressionTypeSemantics } from "../logical-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link LogicalAndExpression}. + * @since 0.10.0 + */ +export interface LogicalAndExpressionTypeSemantics extends LogicalExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/logical/logical-and-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-and-expression/logical-and-expression.ts similarity index 90% rename from kipper/core/src/compiler/ast/nodes/expressions/logical/logical-and-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-and-expression/logical-and-expression.ts index e1efe4186..41a704297 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/logical/logical-and-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-and-expression/logical-and-expression.ts @@ -8,14 +8,14 @@ * false && true // false * true && true // true */ -import type { LogicalAndExpressionSemantics } from "../../../semantic-data"; -import type { LogicalAndExpressionTypeSemantics } from "../../../type-data"; -import type { Expression } from "../expression"; -import { LogicalExpression } from "./logical-expression"; -import { KindParseRuleMapping, LogicalAndExpressionContext, ParseRuleKindMapping } from "../../../../parser"; -import { CompilableASTNode } from "../../../compilable-ast-node"; -import { UnableToDetermineSemanticDataError } from "../../../../../errors"; -import { CheckedType } from "../../../../analysis"; +import type { LogicalAndExpressionSemantics } from "./logical-and-expression-semantics"; +import type { LogicalAndExpressionTypeSemantics } from "./logical-and-expression-type-semantics"; +import type { Expression } from "../../expression"; +import { LogicalExpression } from "../logical-expression"; +import { KindParseRuleMapping, LogicalAndExpressionContext, ParseRuleKindMapping } from "../../../../../parser"; +import { CompilableASTNode } from "../../../../compilable-ast-node"; +import { UnableToDetermineSemanticDataError } from "../../../../../../errors"; +import { CheckedType } from "../../../../../analysis"; /** * Logical-and expression, representing an expression which can be used to combine multiple conditions. It will diff --git a/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-expression-semantics.ts new file mode 100644 index 000000000..6f03d5d47 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-expression-semantics.ts @@ -0,0 +1,31 @@ +/** + * Semantics for logical expressions, which combine two expressions/conditions and evaluate based on the input to a + * boolean value. + * @since 0.9.0 + */ +import type { KipperLogicalAndOperator, KipperLogicalOrOperator } from "../../../../const"; +import type { Expression } from "../expression"; +import type { ExpressionSemantics } from "../expression-semantics"; + +/** + * Semantics for logical expressions, which combine two expressions/conditions and evaluate based on the input to a + * boolean value. + * @since 0.9.0 + */ +export interface LogicalExpressionSemantics extends ExpressionSemantics { + /** + * The operator used to combine the two expressions of this logical expression. + * @since 0.9.0 + */ + operator: KipperLogicalAndOperator | KipperLogicalOrOperator; + /** + * The first expression (left-hand side) used in this logical expression. + * @since 0.9.0 + */ + leftOp: Expression; + /** + * The second expression (right-hand side) used in this logical expression. + * @since 0.9.0 + */ + rightOp: Expression; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-expression-type-semantics.ts new file mode 100644 index 000000000..7dcc42f2e --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-expression-type-semantics.ts @@ -0,0 +1,13 @@ +/** + * Type semantics for logical expressions, which combine two expressions/conditions and evaluate based on the input to a + * boolean value. + * @since 0.10.0 + */ +import type { ExpressionTypeSemantics } from "../expression-type-semantics"; + +/** + * Type semantics for logical expressions, which combine two expressions/conditions and evaluate based on the input to a + * boolean value. + * @since 0.10.0 + */ +export interface LogicalExpressionTypeSemantics extends ExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/logical/logical-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-expression.ts similarity index 80% rename from kipper/core/src/compiler/ast/nodes/expressions/logical/logical-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-expression.ts index 97885d643..249a6b18b 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/logical/logical-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-expression.ts @@ -4,10 +4,9 @@ * abstract class only exists to provide the commonality between the different logical expressions. * @abstract */ -import type { ParseRuleKindMapping } from "../../../../parser"; -import { KindParseRuleMapping } from "../../../../parser"; -import type { LogicalExpressionSemantics } from "../../../semantic-data"; -import type { LogicalExpressionTypeSemantics } from "../../../type-data"; +import type { LogicalExpressionSemantics } from "./logical-expression-semantics"; +import type { LogicalExpressionTypeSemantics } from "./logical-expression-type-semantics"; +import type { KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; import { Expression } from "../expression"; import { ASTNodeMapper } from "../../../mapping"; @@ -25,7 +24,7 @@ export type ASTLogicalExpressionKind = * @since 0.10.0 */ export type ParserLogicalExpressionContext = InstanceType< - typeof ASTNodeMapper.expressionKindToRuleContextMap[ASTLogicalExpressionKind] + (typeof ASTNodeMapper.expressionKindToRuleContextMap)[ASTLogicalExpressionKind] >; /** @@ -33,7 +32,7 @@ export type ParserLogicalExpressionContext = InstanceType< * AST node. * @since 0.11.0 */ -export type ParserLogicalExpressionRuleName = typeof KindParseRuleMapping[ASTLogicalExpressionKind]; +export type ParserLogicalExpressionRuleName = (typeof KindParseRuleMapping)[ASTLogicalExpressionKind]; /** * Logical expression, representing an expression which can be used to combine two expressions/conditions using diff --git a/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-or-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-or-expression/index.ts new file mode 100644 index 000000000..297e9131e --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-or-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link LogicalOrExpression} and the related {@link LogicalOrExpressionSemantics semantics} and + * {@link LogicalOrExpressionTypeSemantics type semantics}. + */ +export * from "./logical-or-expression"; +export * from "./logical-or-expression-semantics"; +export * from "./logical-or-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-or-expression/logical-or-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-or-expression/logical-or-expression-semantics.ts new file mode 100644 index 000000000..85ae2e09e --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-or-expression/logical-or-expression-semantics.ts @@ -0,0 +1,29 @@ +/** + * Semantics for AST Node {@link LogicalOrExpression}. + * @since 0.5.0 + */ +import type { KipperLogicalOrOperator } from "../../../../../const"; +import type { Expression } from "../../expression"; +import type { LogicalExpressionSemantics } from "../logical-expression-semantics"; + +/** + * Semantics for AST Node {@link LogicalOrExpression}. + * @since 0.5.0 + */ +export interface LogicalOrExpressionSemantics extends LogicalExpressionSemantics { + /** + * The operator used to combine the two expressions of this logical-or expression. + * @since 0.9.0 + */ + operator: KipperLogicalOrOperator; + /** + * The first expression (left-hand side) used in this logical-or expression. + * @since 0.9.0 + */ + leftOp: Expression; + /** + * The second expression (right-hand side) used in this logical-or expression. + * @since 0.9.0 + */ + rightOp: Expression; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-or-expression/logical-or-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-or-expression/logical-or-expression-type-semantics.ts new file mode 100644 index 000000000..ee68a4313 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-or-expression/logical-or-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link LogicalOrExpression}. + * @since 0.10.0 + */ +import type { LogicalExpressionTypeSemantics } from "../logical-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link LogicalOrExpression}. + * @since 0.10.0 + */ +export interface LogicalOrExpressionTypeSemantics extends LogicalExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/logical/logical-or-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-or-expression/logical-or-expression.ts similarity index 88% rename from kipper/core/src/compiler/ast/nodes/expressions/logical/logical-or-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-or-expression/logical-or-expression.ts index 7c3309749..4f06369ce 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/logical/logical-or-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/logical-expression/logical-or-expression/logical-or-expression.ts @@ -8,15 +8,15 @@ * false || true // true * true || true // true */ -import type { LogicalOrExpressionSemantics } from "../../../semantic-data"; -import type { LogicalOrExpressionTypeSemantics } from "../../../type-data"; -import type { Expression } from "../expression"; -import { LogicalExpression } from "./logical-expression"; -import { KindParseRuleMapping, LogicalOrExpressionContext, ParseRuleKindMapping } from "../../../../parser"; -import { CompilableASTNode } from "../../../compilable-ast-node"; -import { UnableToDetermineSemanticDataError } from "../../../../../errors"; -import { kipperLogicalOrOperator } from "../../../../const"; -import { CheckedType } from "../../../../analysis"; +import type { LogicalOrExpressionSemantics } from "./logical-or-expression-semantics"; +import type { LogicalOrExpressionTypeSemantics } from "./logical-or-expression-type-semantics"; +import type { Expression } from "../../expression"; +import { LogicalExpression } from "../logical-expression"; +import { KindParseRuleMapping, LogicalOrExpressionContext, ParseRuleKindMapping } from "../../../../../parser"; +import { CompilableASTNode } from "../../../../compilable-ast-node"; +import { UnableToDetermineSemanticDataError } from "../../../../../../errors"; +import { kipperLogicalOrOperator } from "../../../../../const"; +import { CheckedType } from "../../../../../analysis"; /** * Logical-or expression, representing an expression which can be used to combine multiple conditions. It returns true diff --git a/kipper/core/src/compiler/ast/nodes/expressions/member-access-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/member-access-expression/index.ts new file mode 100644 index 000000000..2bdc91352 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/member-access-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link MemberAccessExpression} and the related {@link MemberAccessExpressionSemantics semantics} and + * {@link MemberAccessExpressionTypeSemantics type semantics}. + */ +export * from "./member-access-expression"; +export * from "./member-access-expression-semantics"; +export * from "./member-access-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/member-access-expression/member-access-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/member-access-expression/member-access-expression-semantics.ts new file mode 100644 index 000000000..fe4e87bc6 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/member-access-expression/member-access-expression-semantics.ts @@ -0,0 +1,31 @@ +/** + * Semantics for AST Node {@link MemberAccessExpression}. + * @since 0.10.0 + */ +import type { Expression } from "../expression"; +import type { ExpressionSemantics } from "../expression-semantics"; + +/** + * Semantics for AST Node {@link MemberAccessExpression}. + * @since 0.10.0 + */ +export interface MemberAccessExpressionSemantics extends ExpressionSemantics { + /** + * The object or array that is accessed. + * @since 0.10.0 + */ + objectLike: Expression; + /** + * The member that is accessed. This can be in three different forms: + * - Dot Notation: object.member + * - Bracket Notation: object["member"] + * - Slice Notation: object[1:3] + * @since 0.10.0 + */ + propertyIndexOrKeyOrSlice: string | Expression | { start?: Expression; end?: Expression }; + /** + * The type of the member access expression. Represented using strings. + * @since 0.10.0 + */ + accessType: "dot" | "bracket" | "slice"; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/member-access-expression/member-access-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/member-access-expression/member-access-expression-type-semantics.ts new file mode 100644 index 000000000..bfb15287d --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/member-access-expression/member-access-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link MemberAccessExpression}. + * @since 0.10.0 + */ +import type { ExpressionTypeSemantics } from "../expression-type-semantics"; + +/** + * Type semantics for AST Node {@link MemberAccessExpression}. + * @since 0.10.0 + */ +export interface MemberAccessExpressionTypeSemantics extends ExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/member-access-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/member-access-expression/member-access-expression.ts similarity index 92% rename from kipper/core/src/compiler/ast/nodes/expressions/member-access-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/member-access-expression/member-access-expression.ts index 11f2eb0ac..f9054f55a 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/member-access-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/member-access-expression/member-access-expression.ts @@ -3,19 +3,19 @@ * object or array. * @since 0.10.0 */ -import type { SliceNotationContext, SliceNotationMemberAccessExpressionContext } from "../../../parser"; +import type { MemberAccessExpressionSemantics } from "./member-access-expression-semantics"; +import type { MemberAccessExpressionTypeSemantics } from "./member-access-expression-type-semantics"; +import type { SliceNotationContext, SliceNotationMemberAccessExpressionContext } from "../../../../parser"; import { BracketNotationMemberAccessExpressionContext, DotNotationMemberAccessExpressionContext, KindParseRuleMapping, - ParseRuleKindMapping -} from "../../../parser"; -import type { MemberAccessExpressionSemantics } from "../../semantic-data"; -import type { MemberAccessExpressionTypeSemantics } from "../../type-data"; -import type { CompilableASTNode } from "../../compilable-ast-node"; -import { Expression } from "./expression"; -import { KipperNotImplementedError, UnableToDetermineSemanticDataError } from "../../../../errors"; -import { kipperInternalBuiltInFunctions } from "../../../runtime-built-ins"; + ParseRuleKindMapping, +} from "../../../../parser"; +import type { CompilableASTNode } from "../../../compilable-ast-node"; +import { Expression } from "../expression"; +import { KipperNotImplementedError, UnableToDetermineSemanticDataError } from "../../../../../errors"; +import { kipperInternalBuiltInFunctions } from "../../../../runtime-built-ins"; /** * A union of all possible {@link KipperParserRuleContext} rule contexts that {@link MemberAccessExpression} implements. diff --git a/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/increment-or-decrement-postfix-expression/increment-or-decrement-postfix-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/increment-or-decrement-postfix-expression/increment-or-decrement-postfix-expression-semantics.ts new file mode 100644 index 000000000..90f607193 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/increment-or-decrement-postfix-expression/increment-or-decrement-postfix-expression-semantics.ts @@ -0,0 +1,24 @@ +/** + * Semantics for AST Node {@link IncrementOrDecrementPostfixExpression}. + * @since 0.5.0 + */ +import type { KipperIncrementOrDecrementOperator } from "../../../../../const"; +import type { Expression } from "../../expression"; +import type { PostfixExpressionSemantics } from "../postfix-expression-semantics"; + +/** + * Semantics for AST Node {@link IncrementOrDecrementPostfixExpression}. + * @since 0.5.0 + */ +export interface IncrementOrDecrementPostfixExpressionSemantics extends PostfixExpressionSemantics { + /** + * The operator that is used to modify the {@link operand}. + * @since 0.10.0 + */ + operator: KipperIncrementOrDecrementOperator; + /** + * The operand that is modified by the operator. + * @since 0.10.0 + */ + operand: Expression; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/increment-or-decrement-postfix-expression/increment-or-decrement-postfix-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/increment-or-decrement-postfix-expression/increment-or-decrement-postfix-expression-type-semantics.ts new file mode 100644 index 000000000..a6ecae8dc --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/increment-or-decrement-postfix-expression/increment-or-decrement-postfix-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link IncrementOrDecrementPostfixExpression}. + * @since 0.10.0 + */ +import type { PostfixExpressionTypeSemantics } from "../postfix-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link IncrementOrDecrementPostfixExpression}. + * @since 0.10.0 + */ +export interface IncrementOrDecrementPostfixExpressionTypeSemantics extends PostfixExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/postfix/increment-or-decrement-postfix-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/increment-or-decrement-postfix-expression/increment-or-decrement-postfix-expression.ts similarity index 89% rename from kipper/core/src/compiler/ast/nodes/expressions/postfix/increment-or-decrement-postfix-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/increment-or-decrement-postfix-expression/increment-or-decrement-postfix-expression.ts index ef375381d..b07e261cd 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/postfix/increment-or-decrement-postfix-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/increment-or-decrement-postfix-expression/increment-or-decrement-postfix-expression.ts @@ -1,4 +1,3 @@ -import type { IncrementOrDecrementPostfixExpressionSemantics } from "../../../semantic-data"; /** * Increment or Decrement expression, which represents a right-side -- or ++ expression modifying a numeric value. * @since 0.1.0 @@ -6,17 +5,19 @@ import type { IncrementOrDecrementPostfixExpressionSemantics } from "../../../se * 49++; // 49 will be incremented by 1 * 11--; // 11 will be decremented by 1 */ -import type { IncrementOrDecrementPostfixExpressionTypeSemantics } from "../../../type-data"; -import type { KipperIncrementOrDecrementOperator } from "../../../../const"; -import { Expression } from "../expression"; +import type { IncrementOrDecrementPostfixExpressionSemantics } from "./increment-or-decrement-postfix-expression-semantics"; +import type { IncrementOrDecrementPostfixExpressionTypeSemantics } from "./increment-or-decrement-postfix-expression-type-semantics"; +import type { KipperIncrementOrDecrementOperator } from "../../../../../const"; +import type { Expression } from "../../expression"; +import { PostfixExpression } from "../postfix-expression"; import { IncrementOrDecrementPostfixExpressionContext, KindParseRuleMapping, - ParseRuleKindMapping -} from "../../../../parser"; -import { CompilableASTNode } from "../../../compilable-ast-node"; -import { UnableToDetermineSemanticDataError } from "../../../../../errors"; -import { CheckedType } from "../../../../analysis"; + ParseRuleKindMapping, +} from "../../../../../parser"; +import { CompilableASTNode } from "../../../../compilable-ast-node"; +import { UnableToDetermineSemanticDataError } from "../../../../../../errors"; +import { CheckedType } from "../../../../../analysis"; /** * Increment or Decrement expression, which represents a right-side -- or ++ expression modifying a numeric value. @@ -25,7 +26,7 @@ import { CheckedType } from "../../../../analysis"; * 49++; // 49 will be incremented by 1 * 11--; // 11 will be decremented by 1 */ -export class IncrementOrDecrementPostfixExpression extends Expression< +export class IncrementOrDecrementPostfixExpression extends PostfixExpression< IncrementOrDecrementPostfixExpressionSemantics, IncrementOrDecrementPostfixExpressionTypeSemantics > { diff --git a/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/increment-or-decrement-postfix-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/increment-or-decrement-postfix-expression/index.ts new file mode 100644 index 000000000..80107be5b --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/increment-or-decrement-postfix-expression/index.ts @@ -0,0 +1,8 @@ +/** + * AST Node {@link IncrementOrDecrementPostfixExpression} and the related + * {@link IncrementOrDecrementPostfixExpressionSemantics semantics} and + * {@link IncrementOrDecrementPostfixExpressionTypeSemantics type semantics}. + */ +export * from "./increment-or-decrement-postfix-expression"; +export * from "./increment-or-decrement-postfix-expression-semantics"; +export * from "./increment-or-decrement-postfix-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/index.ts new file mode 100644 index 000000000..34b2b32cc --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/index.ts @@ -0,0 +1,9 @@ +/** + * Postfix expression module containing the classes representing expressions, which can be used to perform specific + * postfix operations using a specific operator. + * @since 0.11.0 + */ +export * from "./postfix-expression"; +export * from "./postfix-expression-semantics"; +export * from "./postfix-expression-type-semantics"; +export * from "./increment-or-decrement-postfix-expression/"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/postfix-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/postfix-expression-semantics.ts new file mode 100644 index 000000000..efc247154 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/postfix-expression-semantics.ts @@ -0,0 +1,18 @@ +/** + * Semantics for AST Node {@link PostfixExpression}. + * @since 0.11.0 + */ +import type { KipperIncrementOrDecrementOperator } from "../../../../const"; +import type { ExpressionSemantics } from "../expression-semantics"; + +/** + * Semantics for AST Node {@link PostfixExpression}. + * @since 0.11.0 + */ +export interface PostfixExpressionSemantics extends ExpressionSemantics { + /** + * The operator that is used to modify the {@link operand}. + * @since 0.11.0 + */ + operator: KipperIncrementOrDecrementOperator; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/postfix-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/postfix-expression-type-semantics.ts new file mode 100644 index 000000000..d3fe3f877 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/postfix-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link PostfixExpression}. + * @since 0.11.0 + */ +import type { ExpressionTypeSemantics } from "../expression-type-semantics"; + +/** + * Type semantics for AST Node {@link PostfixExpression}. + * @since 0.11.0 + */ +export interface PostfixExpressionTypeSemantics extends ExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/postfix-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/postfix-expression.ts new file mode 100644 index 000000000..da4f6024e --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/postfix-expression/postfix-expression.ts @@ -0,0 +1,48 @@ +/** + * Postfix expression, representing an expression which has a postfix operator modifying one or more operands. This + * abstract class only exists to provide the commonality between the different logical expressions. + * @abstract + * @since 0.11.0 + */ +import type { PostfixExpressionSemantics } from "./postfix-expression-semantics"; +import type { PostfixExpressionTypeSemantics } from "./postfix-expression-type-semantics"; +import type { KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; +import { Expression } from "../expression"; +import { ASTNodeMapper } from "../../../mapping"; + +/** + * Union type of all possible {@link ParserASTNode.kind} values for a constructable {@link PostfixExpression} AST node. + * @since 0.10.0 + */ +export type ASTPostfixExpressionKind = typeof ParseRuleKindMapping.RULE_incrementOrDecrementPostfixExpression; + +/** + * Union type of all possible {@link ParserASTNode.kind} context classes for a constructable + * {@link PostfixExpression} AST node. + * @since 0.10.0 + */ +export type ParserPostfixExpressionContext = InstanceType< + (typeof ASTNodeMapper.expressionKindToRuleContextMap)[ASTPostfixExpressionKind] +>; + +/** + * Union type of all possible {@link ParserASTNode.ruleName} values for a constructable {@link PostfixExpression} + * AST node. + * @since 0.11.0 + */ +export type ParserPostfixExpressionRuleName = (typeof KindParseRuleMapping)[ASTPostfixExpressionKind]; + +/** + * Postfix expression, representing an expression which has a postfix operator modifying one or more operands. This + * abstract class only exists to provide the commonality between the different logical expressions. + * @abstract + * @since 0.11.0 + */ +export abstract class PostfixExpression< + Semantics extends PostfixExpressionSemantics = PostfixExpressionSemantics, + TypeSemantics extends PostfixExpressionTypeSemantics = PostfixExpressionTypeSemantics, +> extends Expression { + protected abstract readonly _antlrRuleCtx: ParserPostfixExpressionContext; + public abstract get kind(): ASTPostfixExpressionKind; + public abstract get ruleName(): ParserPostfixExpressionRuleName; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/postfix/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/postfix/index.ts deleted file mode 100644 index e6b736a55..000000000 --- a/kipper/core/src/compiler/ast/nodes/expressions/postfix/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Postfix expression module containing the classes representing expressions, which can be used to perform specific - * postfix operations using a specific operator. - * @since 0.11.0 - */ -export * from "./increment-or-decrement-postfix-expression"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/array-primary-expression/array-primary-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/array-primary-expression/array-primary-expression-semantics.ts new file mode 100644 index 000000000..fec82d789 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/array-primary-expression/array-primary-expression-semantics.ts @@ -0,0 +1,18 @@ +/** + * Semantics for AST Node {@link ArrayPrimaryExpression}. + * @since 0.5.0 + */ +import type { Expression } from "../../../expression"; +import type { ConstantExpressionSemantics } from "../constant-expression-semantics"; + +/** + * Semantics for AST Node {@link ArrayPrimaryExpression}. + * @since 0.5.0 + */ +export interface ArrayPrimaryExpressionSemantics extends ConstantExpressionSemantics { + /** + * The value of the constant list expression. + * @since 0.5.0 + */ + value: Array; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/array-primary-expression/array-primary-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/array-primary-expression/array-primary-expression-type-semantics.ts new file mode 100644 index 000000000..782c21158 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/array-primary-expression/array-primary-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link ArrayPrimaryExpression}. + * @since 0.10.0 + */ +import { ConstantExpressionTypeSemantics } from "../constant-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link ArrayPrimaryExpression}. + * @since 0.10.0 + */ +export interface ArrayPrimaryExpressionTypeSemantics extends ConstantExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary/constant/array-primary-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/array-primary-expression/array-primary-expression.ts similarity index 75% rename from kipper/core/src/compiler/ast/nodes/expressions/primary/constant/array-primary-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/array-primary-expression/array-primary-expression.ts index 565021d11..f3decb468 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/primary/constant/array-primary-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/array-primary-expression/array-primary-expression.ts @@ -2,31 +2,27 @@ * List constant expression, which represents a list constant that was defined in the source code. * @since 0.1.0 */ -import type { ArrayLiteralPrimaryExpressionSemantics } from "../../../../semantic-data"; -import type { ArrayLiteralPrimaryExpressionTypeSemantics } from "../../../../type-data"; -import type { CompilableASTNode } from "../../../../compilable-ast-node"; -import { ConstantExpression } from "./constant-expression"; -import { - ArrayLiteralPrimaryExpressionContext, - KindParseRuleMapping, - ParseRuleKindMapping -} from "../../../../../parser"; -import { CheckedType } from "../../../../../analysis"; +import type { ArrayPrimaryExpressionSemantics } from "./array-primary-expression-semantics"; +import type { ArrayPrimaryExpressionTypeSemantics } from "./array-primary-expression-type-semantics"; +import type { CompilableASTNode } from "../../../../../compilable-ast-node"; +import { ConstantExpression } from "../constant-expression"; +import { ArrayPrimaryExpressionContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../../../parser"; +import { CheckedType } from "../../../../../../analysis"; /** * List constant expression, which represents a list constant that was defined in the source code. * @since 0.1.0 */ -export class ArrayLiteralPrimaryExpression extends ConstantExpression< - ArrayLiteralPrimaryExpressionSemantics, - ArrayLiteralPrimaryExpressionTypeSemantics +export class ArrayPrimaryExpression extends ConstantExpression< + ArrayPrimaryExpressionSemantics, + ArrayPrimaryExpressionTypeSemantics > { /** * The private field '_antlrRuleCtx' that actually stores the variable data, * which is returned inside the {@link this.antlrRuleCtx}. * @private */ - protected override readonly _antlrRuleCtx: ArrayLiteralPrimaryExpressionContext; + protected override readonly _antlrRuleCtx: ArrayPrimaryExpressionContext; /** * The static kind for this AST Node. @@ -43,7 +39,7 @@ export class ArrayLiteralPrimaryExpression extends ConstantExpression< * @since 0.10.0 */ public override get kind() { - return ArrayLiteralPrimaryExpression.kind; + return ArrayPrimaryExpression.kind; } /** @@ -61,10 +57,10 @@ export class ArrayLiteralPrimaryExpression extends ConstantExpression< * @since 0.11.0 */ public override get ruleName() { - return ArrayLiteralPrimaryExpression.ruleName; + return ArrayPrimaryExpression.ruleName; } - constructor(antlrRuleCtx: ArrayLiteralPrimaryExpressionContext, parent: CompilableASTNode) { + constructor(antlrRuleCtx: ArrayPrimaryExpressionContext, parent: CompilableASTNode) { super(antlrRuleCtx, parent); this._antlrRuleCtx = antlrRuleCtx; } @@ -108,7 +104,7 @@ export class ArrayLiteralPrimaryExpression extends ConstantExpression< /** * The antlr context containing the antlr4 metadata for this expression. */ - public override get antlrRuleCtx(): ArrayLiteralPrimaryExpressionContext { + public override get antlrRuleCtx(): ArrayPrimaryExpressionContext { return this._antlrRuleCtx; } diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/array-primary-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/array-primary-expression/index.ts new file mode 100644 index 000000000..e11cae76d --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/array-primary-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link ArrayPrimaryExpression} and the related {@link ArrayPrimaryExpressionSemantics semantics} and + * {@link ArrayPrimaryExpressionTypeSemantics type semantics}. + */ +export * from "./array-primary-expression"; +export * from "./array-primary-expression-semantics"; +export * from "./array-primary-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/bool-primary-expression/bool-primary-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/bool-primary-expression/bool-primary-expression-semantics.ts new file mode 100644 index 000000000..4aed9c3ff --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/bool-primary-expression/bool-primary-expression-semantics.ts @@ -0,0 +1,18 @@ +/** + * Semantics for AST Node {@link BoolPrimaryExpression}. + * @since 0.8.0 + */ +import type { KipperBoolTypeLiterals } from "../../../../../../const"; +import type { ConstantExpressionSemantics } from "../constant-expression-semantics"; + +/** + * Semantics for AST Node {@link BoolPrimaryExpression}. + * @since 0.8.0 + */ +export interface BoolPrimaryExpressionSemantics extends ConstantExpressionSemantics { + /** + * The value of this boolean constant expression. + * @since 0.8.0 + */ + value: KipperBoolTypeLiterals; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/bool-primary-expression/bool-primary-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/bool-primary-expression/bool-primary-expression-type-semantics.ts new file mode 100644 index 000000000..ff425f30a --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/bool-primary-expression/bool-primary-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link BoolPrimaryExpression}. + * @since 0.10.0 + */ +import type { ConstantExpressionTypeSemantics } from "../constant-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link BoolPrimaryExpression}. + * @since 0.10.0 + */ +export interface BoolPrimaryExpressionTypeSemantics extends ConstantExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary/constant/bool-primary-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/bool-primary-expression/bool-primary-expression.ts similarity index 87% rename from kipper/core/src/compiler/ast/nodes/expressions/primary/constant/bool-primary-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/bool-primary-expression/bool-primary-expression.ts index 7a4bff027..45683cd39 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/primary/constant/bool-primary-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/bool-primary-expression/bool-primary-expression.ts @@ -2,13 +2,13 @@ * Boolean constant expression representing the built-in constants {@link true} and {@link false}. * @since 0.8.0 */ -import type { BoolPrimaryExpressionSemantics } from "../../../../semantic-data"; -import type { BoolPrimaryExpressionTypeSemantics } from "../../../../type-data"; -import type { CompilableASTNode } from "../../../../compilable-ast-node"; -import type { KipperBoolTypeLiterals } from "../../../../../const"; -import { ConstantExpression } from "./constant-expression"; -import { BoolPrimaryExpressionContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../../parser"; -import { CheckedType } from "../../../../../analysis"; +import type { BoolPrimaryExpressionSemantics } from "./bool-primary-expression-semantics"; +import type { BoolPrimaryExpressionTypeSemantics } from "./bool-primary-expression-type-semantics"; +import type { CompilableASTNode } from "../../../../../compilable-ast-node"; +import type { KipperBoolTypeLiterals } from "../../../../../../const"; +import { ConstantExpression } from "../constant-expression"; +import { BoolPrimaryExpressionContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../../../parser"; +import { CheckedType } from "../../../../../../analysis"; /** * Boolean constant expression representing the built-in constants {@link true} and {@link false}. diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/bool-primary-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/bool-primary-expression/index.ts new file mode 100644 index 000000000..dfdd262e3 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/bool-primary-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link BoolPrimaryExpression} and the related {@link BoolPrimaryExpressionSemantics semantics} and + * {@link BoolPrimaryExpressionTypeSemantics type semantics}. + */ +export * from "./bool-primary-expression"; +export * from "./bool-primary-expression-semantics"; +export * from "./bool-primary-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/constant-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/constant-expression-semantics.ts new file mode 100644 index 000000000..016a5f15c --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/constant-expression-semantics.ts @@ -0,0 +1,17 @@ +/** + * Semantics for AST Node {@link ConstantExpression}. + * @since 0.5.0 + */ +import type { ExpressionSemantics } from "../../expression-semantics"; + +/** + * Semantics for AST Node {@link ConstantExpression}. + * @since 0.5.0 + */ +export interface ConstantExpressionSemantics extends ExpressionSemantics { + /** + * The value of the constant expression. This is usually either a {@link String} or {@link Number}. + * @since 0.5.0 + */ + value: any; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/constant-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/constant-expression-type-semantics.ts new file mode 100644 index 000000000..f8649f9db --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/constant-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link ConstantExpression}. + * @since 0.11.0 + */ +import type { ExpressionTypeSemantics } from "../../expression-type-semantics"; + +/** + * Type semantics for AST Node {@link ConstantExpression}. + * @since 0.11.0 + */ +export interface ConstantExpressionTypeSemantics extends ExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary/constant/constant-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/constant-expression.ts similarity index 76% rename from kipper/core/src/compiler/ast/nodes/expressions/primary/constant/constant-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/constant-expression.ts index a8161ed95..a02d0bb21 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/primary/constant/constant-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/constant-expression.ts @@ -3,12 +3,12 @@ * abstract class only exists to provide the commonality between the different constant expressions. * @since 0.10.0 */ -import type { ConstantExpressionSemantics } from "../../../../semantic-data"; -import type { ExpressionTypeSemantics } from "../../../../type-data"; +import type { ConstantExpressionTypeSemantics } from "./constant-expression-type-semantics"; +import type { ConstantExpressionSemantics } from "./constant-expression-semantics"; import type { ParseRuleKindMapping } from "../../../../../parser"; import { KindParseRuleMapping } from "../../../../../parser"; -import { Expression } from "../../expression"; import { ASTNodeMapper } from "../../../../mapping"; +import { PrimaryExpression } from "../primary-expression"; /** * Union type of all possible {@link ParserASTNode.kind} values for a constructable {@link ConstantExpression} AST node. @@ -26,7 +26,7 @@ export type ASTConstantExpressionKind = * @since 0.10.0 */ export type ParserConstantExpressionContext = InstanceType< - typeof ASTNodeMapper.expressionKindToRuleContextMap[ASTConstantExpressionKind] + (typeof ASTNodeMapper.expressionKindToRuleContextMap)[ASTConstantExpressionKind] >; /** @@ -34,7 +34,7 @@ export type ParserConstantExpressionContext = InstanceType< * AST node. * @since 0.11.0 */ -export type ParserConstantExpressionRuleName = typeof KindParseRuleMapping[ASTConstantExpressionKind]; +export type ParserConstantExpressionRuleName = (typeof KindParseRuleMapping)[ASTConstantExpressionKind]; /** * Abstract constant expression class representing a constant expression, which was defined in the source code. This @@ -43,8 +43,8 @@ export type ParserConstantExpressionRuleName = typeof KindParseRuleMapping[ASTCo */ export abstract class ConstantExpression< Semantics extends ConstantExpressionSemantics = ConstantExpressionSemantics, - TypeSemantics extends ExpressionTypeSemantics = ExpressionTypeSemantics, -> extends Expression { + TypeSemantics extends ConstantExpressionTypeSemantics = ConstantExpressionTypeSemantics, +> extends PrimaryExpression { protected abstract readonly _antlrRuleCtx: ParserConstantExpressionContext; public abstract get kind(): ASTConstantExpressionKind; public abstract get ruleName(): ParserConstantExpressionRuleName; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/index.ts new file mode 100644 index 000000000..ca19b3cf9 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/index.ts @@ -0,0 +1,13 @@ +/** + * Constant expression module containing the classes representing expressions, which represent a constant value in a + * specific data structure. + * @since 0.11.0 + */ +export * from "./constant-expression"; +export * from "./constant-expression-semantics"; +export * from "./constant-expression-type-semantics"; +export * from "./array-primary-expression/"; +export * from "./bool-primary-expression/"; +export * from "./number-primary-expression/"; +export * from "./string-primary-expression/"; +export * from "./void-or-null-or-undefined-primary-expression/"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/number-primary-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/number-primary-expression/index.ts new file mode 100644 index 000000000..bb939297d --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/number-primary-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link NumberPrimaryExpression} and the related {@link NumberPrimaryExpressionSemantics semantics} and + * {@link NumberPrimaryExpressionTypeSemantics type semantics}. + */ +export * from "./number-primary-expression"; +export * from "./number-primary-expression-semantics"; +export * from "./number-primary-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/number-primary-expression/number-primary-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/number-primary-expression/number-primary-expression-semantics.ts new file mode 100644 index 000000000..4e4e3e2c9 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/number-primary-expression/number-primary-expression-semantics.ts @@ -0,0 +1,26 @@ +/** + * Semantics for AST Node {@link NumberPrimaryExpression}. + * @since 0.5.0 + */ +import type { ConstantExpressionSemantics } from "../constant-expression-semantics"; + +/** + * Semantics for AST Node {@link NumberPrimaryExpression}. + * @since 0.5.0 + */ +export interface NumberPrimaryExpressionSemantics extends ConstantExpressionSemantics { + /** + * The value of the constant number expression. + * + * This can be either: + * - A Default 10-base number (N) + * - A Float 10-base number (N.N) + * - A Hex 16-base number (0xN) + * - A Octal 8-base number (0oN) + * - A Binary 2-base number (0bN) + * - An Exponent 10-base number (NeN) + * - An Exponent Float 10-base number (N.NeN) + * @since 0.5.0 + */ + value: string; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/number-primary-expression/number-primary-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/number-primary-expression/number-primary-expression-type-semantics.ts new file mode 100644 index 000000000..ef9fab12c --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/number-primary-expression/number-primary-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link NumberPrimaryExpression}. + * @since 0.10.0 + */ +import type { ConstantExpressionTypeSemantics } from "../constant-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link NumberPrimaryExpression}. + * @since 0.10.0 + */ +export interface NumberPrimaryExpressionTypeSemantics extends ConstantExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary/constant/number-primary-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/number-primary-expression/number-primary-expression.ts similarity index 89% rename from kipper/core/src/compiler/ast/nodes/expressions/primary/constant/number-primary-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/number-primary-expression/number-primary-expression.ts index d61b819f7..0923f9378 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/primary/constant/number-primary-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/number-primary-expression/number-primary-expression.ts @@ -2,12 +2,12 @@ * Integer constant expression, which represents a number constant that was defined in the source code. * @since 0.1.0 */ -import type { NumberPrimaryExpressionSemantics } from "../../../../semantic-data"; -import type { NumberPrimaryExpressionTypeSemantics } from "../../../../type-data"; -import type { CompilableASTNode } from "../../../../compilable-ast-node"; -import { ConstantExpression } from "./constant-expression"; -import { KindParseRuleMapping, NumberPrimaryExpressionContext, ParseRuleKindMapping } from "../../../../../parser"; -import { CheckedType } from "../../../../../analysis"; +import type { NumberPrimaryExpressionSemantics } from "./number-primary-expression-semantics"; +import type { NumberPrimaryExpressionTypeSemantics } from "./number-primary-expression-type-semantics"; +import type { CompilableASTNode } from "../../../../../compilable-ast-node"; +import { ConstantExpression } from "../constant-expression"; +import { KindParseRuleMapping, NumberPrimaryExpressionContext, ParseRuleKindMapping } from "../../../../../../parser"; +import { CheckedType } from "../../../../../../analysis"; /** * Number constant expression, which represents a number constant that was defined in the source code. diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/string-primary-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/string-primary-expression/index.ts new file mode 100644 index 000000000..e9982d1b0 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/string-primary-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link StringPrimaryExpression} and the related {@link StringPrimaryExpressionSemantics semantics} and + * {@link StringPrimaryExpressionTypeSemantics type semantics}. + */ +export * from "./string-primary-expression"; +export * from "./string-primary-expression-semantics"; +export * from "./string-primary-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/string-primary-expression/string-primary-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/string-primary-expression/string-primary-expression-semantics.ts new file mode 100644 index 000000000..54bf8a186 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/string-primary-expression/string-primary-expression-semantics.ts @@ -0,0 +1,25 @@ +/** + * Semantics for AST Node {@link StringPrimaryExpression}. + * @since 0.5.0 + */ +import type { ConstantExpressionSemantics } from "../constant-expression-semantics"; + +/** + * Semantics for AST Node {@link StringPrimaryExpression}. + * @since 0.5.0 + */ +export interface StringPrimaryExpressionSemantics extends ConstantExpressionSemantics { + /** + * The value of the constant string expression. + * @since 0.5.0 + */ + value: string; + /** + * The quotation marks that this string has used. + * + * This is important to keep track of, so that the translated string is valid and does not produce a syntax error + * due to unescaped quotation marks inside it. + * @since 0.10.0 + */ + quotationMarks: `"` | `'`; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/string-primary-expression/string-primary-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/string-primary-expression/string-primary-expression-type-semantics.ts new file mode 100644 index 000000000..6aed112b0 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/string-primary-expression/string-primary-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link StringPrimaryExpression}. + * @since 0.10.0 + */ +import type { ExpressionTypeSemantics } from "../../../expression-type-semantics"; + +/** + * Type semantics for AST Node {@link StringPrimaryExpression}. + * @since 0.10.0 + */ +export interface StringPrimaryExpressionTypeSemantics extends ExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary/constant/string-primary-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/string-primary-expression/string-primary-expression.ts similarity index 89% rename from kipper/core/src/compiler/ast/nodes/expressions/primary/constant/string-primary-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/string-primary-expression/string-primary-expression.ts index 25955dd8d..67dc82442 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/primary/constant/string-primary-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/string-primary-expression/string-primary-expression.ts @@ -2,12 +2,12 @@ * String constant expression, which represents a string constant that was defined in the source code. * @since 0.1.0 */ -import type { StringPrimaryExpressionSemantics } from "../../../../semantic-data"; -import type { StringPrimaryExpressionTypeSemantics } from "../../../../type-data"; -import type { CompilableASTNode } from "../../../../compilable-ast-node"; -import { ConstantExpression } from "./constant-expression"; -import { KindParseRuleMapping, ParseRuleKindMapping, StringPrimaryExpressionContext } from "../../../../../parser"; -import { CheckedType } from "../../../../../analysis"; +import type { StringPrimaryExpressionSemantics } from "./string-primary-expression-semantics"; +import type { StringPrimaryExpressionTypeSemantics } from "./string-primary-expression-type-semantics"; +import type { CompilableASTNode } from "../../../../../compilable-ast-node"; +import { ConstantExpression } from "../constant-expression"; +import { KindParseRuleMapping, ParseRuleKindMapping, StringPrimaryExpressionContext } from "../../../../../../parser"; +import { CheckedType } from "../../../../../../analysis"; /** * String constant expression, which represents a string constant that was defined in the source code. diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/void-or-null-or-undefined-primary-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/void-or-null-or-undefined-primary-expression/index.ts new file mode 100644 index 000000000..87058d6ad --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/void-or-null-or-undefined-primary-expression/index.ts @@ -0,0 +1,8 @@ +/** + * AST Node {@link VoidOrNullOrUndefinedPrimaryExpression} and the related + * {@link VoidOrNullOrUndefinedPrimaryExpressionSemantics semantics} and + * {@link VoidOrNullOrUndefinedPrimaryExpressionTypeSemantics type semantics}. + */ +export * from "./void-or-null-or-undefined-primary-expression"; +export * from "./void-or-null-or-undefined-primary-expression-semantics"; +export * from "./void-or-null-or-undefined-primary-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/void-or-null-or-undefined-primary-expression/void-or-null-or-undefined-primary-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/void-or-null-or-undefined-primary-expression/void-or-null-or-undefined-primary-expression-semantics.ts new file mode 100644 index 000000000..77e836ac7 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/void-or-null-or-undefined-primary-expression/void-or-null-or-undefined-primary-expression-semantics.ts @@ -0,0 +1,18 @@ +/** + * Semantics for AST Node {@link VoidOrNullOrUndefinedPrimaryExpression}. + * @since 0.10.0 + */ +import type { KipperNullType, KipperUndefinedType, KipperVoidType } from "../../../../../../const"; +import type { ConstantExpressionSemantics } from "../constant-expression-semantics"; + +/** + * Semantics for AST Node {@link VoidOrNullOrUndefinedPrimaryExpression}. + * @since 0.10.0 + */ +export interface VoidOrNullOrUndefinedPrimaryExpressionSemantics extends ConstantExpressionSemantics { + /** + * The constant identifier of this expression. + * @since 0.10.0 + */ + constantIdentifier: KipperVoidType | KipperNullType | KipperUndefinedType; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/void-or-null-or-undefined-primary-expression/void-or-null-or-undefined-primary-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/void-or-null-or-undefined-primary-expression/void-or-null-or-undefined-primary-expression-type-semantics.ts new file mode 100644 index 000000000..8cdd3f789 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/void-or-null-or-undefined-primary-expression/void-or-null-or-undefined-primary-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link VoidOrNullOrUndefinedPrimaryExpression}. + * @since 0.10.0 + */ +import type { ExpressionTypeSemantics } from "../../../expression-type-semantics"; + +/** + * Type semantics for AST Node {@link VoidOrNullOrUndefinedPrimaryExpression}. + * @since 0.10.0 + */ +export interface VoidOrNullOrUndefinedPrimaryExpressionTypeSemantics extends ExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary/constant/void-or-null-or-undefined-primary-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/void-or-null-or-undefined-primary-expression/void-or-null-or-undefined-primary-expression.ts similarity index 90% rename from kipper/core/src/compiler/ast/nodes/expressions/primary/constant/void-or-null-or-undefined-primary-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/void-or-null-or-undefined-primary-expression/void-or-null-or-undefined-primary-expression.ts index 427909023..fd37f2947 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/primary/constant/void-or-null-or-undefined-primary-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/constant/void-or-null-or-undefined-primary-expression/void-or-null-or-undefined-primary-expression.ts @@ -1,18 +1,18 @@ -import type { VoidOrNullOrUndefinedPrimaryExpressionSemantics } from "../../../../semantic-data"; -import type { VoidOrNullOrUndefinedPrimaryExpressionTypeSemantics } from "../../../../type-data"; /** * Constant expression, representing the void, null or undefined keyword. * @since 0.10.0 */ -import type { KipperNullType, KipperUndefinedType, KipperVoidType } from "../../../../../const"; -import type { CompilableASTNode } from "../../../../compilable-ast-node"; +import type { KipperNullType, KipperUndefinedType, KipperVoidType } from "../../../../../../const"; +import type { CompilableASTNode } from "../../../../../compilable-ast-node"; +import type { VoidOrNullOrUndefinedPrimaryExpressionSemantics } from "./void-or-null-or-undefined-primary-expression-semantics"; +import type { VoidOrNullOrUndefinedPrimaryExpressionTypeSemantics } from "./void-or-null-or-undefined-primary-expression-type-semantics"; import { KindParseRuleMapping, ParseRuleKindMapping, - VoidOrNullOrUndefinedPrimaryExpressionContext -} from "../../../../../parser"; -import { CheckedType } from "../../../../../analysis"; -import { ConstantExpression } from "./constant-expression"; + VoidOrNullOrUndefinedPrimaryExpressionContext, +} from "../../../../../../parser"; +import { CheckedType } from "../../../../../../analysis"; +import { ConstantExpression } from "../constant-expression"; /** * Constant expression, representing the void, null or undefined keyword. diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/fstring-primary-expression/fstring-primary-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/fstring-primary-expression/fstring-primary-expression-semantics.ts new file mode 100644 index 000000000..c10cdb9df --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/fstring-primary-expression/fstring-primary-expression-semantics.ts @@ -0,0 +1,19 @@ +/** + * Semantics for AST Node {@link FStringPrimaryExpression}. + * @since 0.5.0 + */ +import type { PrimaryExpressionSemantics } from "../primary-expression-semantics"; +import type { Expression } from "../../expression"; + +/** + * Semantics for AST Node {@link FStringPrimaryExpression}. + * @since 0.5.0 + */ +export interface FStringPrimaryExpressionSemantics extends PrimaryExpressionSemantics { + /** + * Returns the items of the f-strings, where each item represents one section of the string. The section may either be + * a {@link StringPrimaryExpression constant string} or {@link Expression evaluable runtime expression}. + * @since 0.10.0 + */ + atoms: Array; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/fstring-primary-expression/fstring-primary-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/fstring-primary-expression/fstring-primary-expression-type-semantics.ts new file mode 100644 index 000000000..e9fb0ea4a --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/fstring-primary-expression/fstring-primary-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Semantics for AST Node {@link FStringPrimaryExpression}. + * @since 0.5.0 + */ +import type { PrimaryExpressionTypeSemantics } from "../primary-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link FStringPrimaryExpression}. + * @since 0.10.0 + */ +export interface FStringPrimaryExpressionTypeSemantics extends PrimaryExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary/fstring-primary-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/fstring-primary-expression/fstring-primary-expression.ts similarity index 90% rename from kipper/core/src/compiler/ast/nodes/expressions/primary/fstring-primary-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/primary-expression/fstring-primary-expression/fstring-primary-expression.ts index 7963ef9c2..5752b9ff8 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/primary/fstring-primary-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/fstring-primary-expression/fstring-primary-expression.ts @@ -2,20 +2,20 @@ * F-String class, which represents an f-string expression in the Kipper language. * @since 0.1.0 */ -import type { FStringPrimaryExpressionSemantics } from "../../../semantic-data"; -import type { FStringPrimaryExpressionTypeSemantics } from "../../../type-data"; -import { Expression } from "../expression"; +import type { FStringPrimaryExpressionSemantics } from "./fstring-primary-expression-semantics"; +import type { FStringPrimaryExpressionTypeSemantics } from "./fstring-primary-expression-type-semantics"; +import { Expression } from "../../expression"; import { ExpressionContext, FStringDoubleQuoteAtomContext, FStringPrimaryExpressionContext, FStringSingleQuoteAtomContext, KindParseRuleMapping, - ParseRuleKindMapping -} from "../../../../parser"; -import { CompilableASTNode } from "../../../compilable-ast-node"; -import { CheckedType } from "../../../../analysis"; -import { getParseRuleSource } from "../../../../../tools"; + ParseRuleKindMapping, +} from "../../../../../parser"; +import { CompilableASTNode } from "../../../../compilable-ast-node"; +import { CheckedType } from "../../../../../analysis"; +import { getParseRuleSource } from "../../../../../../tools"; /** * F-String class, which represents an f-string expression in the Kipper language. F-Strings are a way to automatically diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/fstring-primary-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/fstring-primary-expression/index.ts new file mode 100644 index 000000000..2e6c6b181 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/fstring-primary-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link FStringPrimaryExpression} and the related {@link FStringPrimaryExpressionSemantics semantics} and + * {@link FStringPrimaryExpressionTypeSemantics type semantics}. + */ +export * from "./fstring-primary-expression"; +export * from "./fstring-primary-expression-semantics"; +export * from "./fstring-primary-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/identifier-primary-expression/identifier-primary-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/identifier-primary-expression/identifier-primary-expression-semantics.ts new file mode 100644 index 000000000..3d739a4c5 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/identifier-primary-expression/identifier-primary-expression-semantics.ts @@ -0,0 +1,23 @@ +/** + * Semantics for AST Node {@link IdentifierPrimaryExpression}. + * @since 0.5.0 + */ +import type { Reference } from "../../../../../analysis"; +import type { PrimaryExpressionSemantics } from "../primary-expression-semantics"; + +/** + * Semantics for AST Node {@link IdentifierPrimaryExpression}. + * @since 0.5.0 + */ +export interface IdentifierPrimaryExpressionSemantics extends PrimaryExpressionSemantics { + /** + * The identifier of the {@link IdentifierPrimaryExpressionSemantics.ref reference}. + * @since 0.5.0 + */ + identifier: string; + /** + * The reference that the {@link IdentifierPrimaryExpressionSemantics.identifier identifier} points to. + * @since 0.10.0 + */ + ref: Reference; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/identifier-primary-expression/identifier-primary-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/identifier-primary-expression/identifier-primary-expression-type-semantics.ts new file mode 100644 index 000000000..d75c90fdd --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/identifier-primary-expression/identifier-primary-expression-type-semantics.ts @@ -0,0 +1,21 @@ +/** + * Type semantics for AST Node {@link IdentifierPrimaryExpression}. + * @since 0.10.0 + */ +import type { CheckedType } from "../../../../../analysis"; +import type { PrimaryExpressionTypeSemantics } from "../primary-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link IdentifierPrimaryExpression}. + * @since 0.10.0 + */ +export interface IdentifierPrimaryExpressionTypeSemantics extends PrimaryExpressionTypeSemantics { + /** + * The value type that this expression evaluates to. + * + * This will always be the value type of the reference that the + * {@link IdentifierPrimaryExpressionSemantics.identifier identifier} points to. + * @since 0.10.0 + */ + evaluatedType: CheckedType; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary/identifier-primary-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/identifier-primary-expression/identifier-primary-expression.ts similarity index 89% rename from kipper/core/src/compiler/ast/nodes/expressions/primary/identifier-primary-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/primary-expression/identifier-primary-expression/identifier-primary-expression.ts index 0790a04d3..61b53c919 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/primary/identifier-primary-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/identifier-primary-expression/identifier-primary-expression.ts @@ -4,13 +4,13 @@ * This is only represents a reference and not a declaration/definition. * @since 0.1.0 */ -import type { IdentifierPrimaryExpressionSemantics } from "../../../semantic-data"; -import type { IdentifierPrimaryExpressionTypeSemantics } from "../../../type-data"; -import type { CompilableASTNode } from "../../../compilable-ast-node"; -import { Expression } from "../expression"; -import { IdentifierPrimaryExpressionContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; -import { CheckedType, ScopeDeclaration } from "../../../../analysis"; -import { AssignmentExpression } from "../assignment-expression"; +import type { IdentifierPrimaryExpressionSemantics } from "./identifier-primary-expression-semantics"; +import type { IdentifierPrimaryExpressionTypeSemantics } from "./identifier-primary-expression-type-semantics"; +import type { CompilableASTNode } from "../../../../compilable-ast-node"; +import { IdentifierPrimaryExpressionContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../../parser"; +import { CheckedType, ScopeDeclaration } from "../../../../../analysis"; +import { AssignmentExpression } from "../../assignment-expression/assignment-expression"; +import { PrimaryExpression } from "../primary-expression"; /** * Identifier expression, which represents an identifier referencing a variable, function or built-in identifier. @@ -18,7 +18,7 @@ import { AssignmentExpression } from "../assignment-expression"; * This is only represents a reference and not a declaration/definition. * @since 0.1.0 */ -export class IdentifierPrimaryExpression extends Expression< +export class IdentifierPrimaryExpression extends PrimaryExpression< IdentifierPrimaryExpressionSemantics, IdentifierPrimaryExpressionTypeSemantics > { @@ -33,7 +33,7 @@ export class IdentifierPrimaryExpression extends Expression< * The static kind for this AST Node. * @since 0.11.0 */ - public static readonly kind = ParseRuleKindMapping.RULE_identifierTypeSpecifierExpression; + public static readonly kind = ParseRuleKindMapping.RULE_identifierPrimaryExpression; /** * Returns the kind of this AST node. This represents the specific type of the {@link antlrRuleCtx} that this AST diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/identifier-primary-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/identifier-primary-expression/index.ts new file mode 100644 index 000000000..186b41b93 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/identifier-primary-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link IdentifierPrimaryExpression} and the related {@link IdentifierPrimaryExpressionSemantics semantics} + * and {@link IdentifierPrimaryExpressionTypeSemantics type semantics}. + */ +export * from "./identifier-primary-expression"; +export * from "./identifier-primary-expression-semantics"; +export * from "./identifier-primary-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/index.ts new file mode 100644 index 000000000..9d134f70f --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/index.ts @@ -0,0 +1,12 @@ +/** + * Primary expression module containing the classes representing expressions, which build up the fundamental building + * blocks of the language, such as constants and identifiers. + * @since 0.11.0 + */ +export * from "./primary-expression"; +export * from "./primary-expression-semantics"; +export * from "./primary-expression-type-semantics"; +export * from "./constant/"; +export * from "./fstring-primary-expression/"; +export * from "./identifier-primary-expression/"; +export * from "./tangled-primary-expression"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/primary-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/primary-expression-semantics.ts new file mode 100644 index 000000000..6326a5308 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/primary-expression-semantics.ts @@ -0,0 +1,11 @@ +/** + * Semantics for AST Node {@link PrimaryExpression}. + * @since 0.11.0 + */ +import type { ExpressionSemantics } from "../expression-semantics"; + +/** + * Semantics for AST Node {@link PrimaryExpression}. + * @since 0.11.0 + */ +export interface PrimaryExpressionSemantics extends ExpressionSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/primary-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/primary-expression-type-semantics.ts new file mode 100644 index 000000000..ff0e26b30 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/primary-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link PrimaryExpression}. + * @since 0.11.0 + */ +import type { ExpressionTypeSemantics } from "../expression-type-semantics"; + +/** + * Type semantics for AST Node {@link PrimaryExpression}. + * @since 0.11.0 + */ +export interface PrimaryExpressionTypeSemantics extends ExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/primary-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/primary-expression.ts new file mode 100644 index 000000000..f00e1a8c3 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/primary-expression.ts @@ -0,0 +1,53 @@ +/** + * Primary expression, which represents the most basic expressions in the language, such as constants, f-strings, + * identifiers and tangled expressions. + * @abstract + * @since 0.11.0 + */ +import type { PrimaryExpressionSemantics } from "./primary-expression-semantics"; +import type { PrimaryExpressionTypeSemantics } from "./primary-expression-type-semantics"; +import type { KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; +import { Expression } from "../expression"; +import { ASTNodeMapper } from "../../../mapping"; +import { ASTConstantExpressionKind } from "./constant"; + +/** + * Union type of all possible {@link ParserASTNode.kind} values for a constructable {@link PrimaryExpression} AST node. + * @since 0.10.0 + */ +export type ASTPrimaryExpressionKind = + | ASTConstantExpressionKind + | typeof ParseRuleKindMapping.RULE_fStringPrimaryExpression + | typeof ParseRuleKindMapping.RULE_identifierPrimaryExpression + | typeof ParseRuleKindMapping.RULE_tangledPrimaryExpression; + +/** + * Union type of all possible {@link ParserASTNode.kind} context classes for a constructable + * {@link PrimaryExpression} AST node. + * @since 0.10.0 + */ +export type ParserPrimaryExpressionContext = InstanceType< + (typeof ASTNodeMapper.expressionKindToRuleContextMap)[ASTPrimaryExpressionKind] +>; + +/** + * Union type of all possible {@link ParserASTNode.ruleName} values for a constructable {@link PrimaryExpression} + * AST node. + * @since 0.11.0 + */ +export type ParserPrimaryExpressionRuleName = (typeof KindParseRuleMapping)[ASTPrimaryExpressionKind]; + +/** + * Primary expression, which represents the most basic expressions in the language, such as constants, f-strings and + * tangled expressions. + * @abstract + * @since 0.11.0 + */ +export abstract class PrimaryExpression< + Semantics extends PrimaryExpressionSemantics = PrimaryExpressionSemantics, + TypeSemantics extends PrimaryExpressionTypeSemantics = PrimaryExpressionTypeSemantics, +> extends Expression { + protected abstract readonly _antlrRuleCtx: ParserPrimaryExpressionContext; + public abstract get kind(): ASTPrimaryExpressionKind; + public abstract get ruleName(): ParserPrimaryExpressionRuleName; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/tangled-primary-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/tangled-primary-expression/index.ts new file mode 100644 index 000000000..e70b34d25 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/tangled-primary-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link TangledPrimaryExpression} and the related {@link TangledPrimaryExpressionSemantics semantics} and + * {@link TangledPrimaryExpressionTypeSemantics type semantics}. + */ +export * from "./tangled-primary-expression"; +export * from "./tangled-primary-expression-semantics"; +export * from "./tangled-primary-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/tangled-primary-expression/tangled-primary-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/tangled-primary-expression/tangled-primary-expression-semantics.ts new file mode 100644 index 000000000..829b818d4 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/tangled-primary-expression/tangled-primary-expression-semantics.ts @@ -0,0 +1,18 @@ +/** + * Semantics for AST Node {@link TangledPrimaryExpression}. + * @since 0.5.0 + */ +import type { Expression } from "../../expression"; +import type { PrimaryExpressionSemantics } from "../primary-expression-semantics"; + +/** + * Semantics for AST Node {@link TangledPrimaryExpression}. + * @since 0.5.0 + */ +export interface TangledPrimaryExpressionSemantics extends PrimaryExpressionSemantics { + /** + * The child expression contained in this tangled expression. + * @since 0.10.0 + */ + childExp: Expression; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/tangled-primary-expression/tangled-primary-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/tangled-primary-expression/tangled-primary-expression-type-semantics.ts new file mode 100644 index 000000000..f80faf782 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/tangled-primary-expression/tangled-primary-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link TangledPrimaryExpression}. + * @since 0.5.0 + */ +import type { PrimaryExpressionTypeSemantics } from "../primary-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link TangledPrimaryExpression}. + * @since 0.5.0 + */ +export interface TangledPrimaryExpressionTypeSemantics extends PrimaryExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/tangled-primary-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/tangled-primary-expression/tangled-primary-expression.ts similarity index 88% rename from kipper/core/src/compiler/ast/nodes/expressions/tangled-primary-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/primary-expression/tangled-primary-expression/tangled-primary-expression.ts index 964e3c1ae..82c70614d 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/tangled-primary-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/primary-expression/tangled-primary-expression/tangled-primary-expression.ts @@ -5,12 +5,13 @@ * (4 + 5) * 5; // 4 + 5 will be evaluated first, then the multiplication will be performed * @since 0.1.0 */ -import type { TangledPrimaryExpressionSemantics } from "../../semantic-data"; -import type { TangledPrimaryTypeSemantics } from "../../type-data"; -import type { CompilableASTNode } from "../../compilable-ast-node"; -import { Expression } from "./expression"; -import { KindParseRuleMapping, ParseRuleKindMapping, TangledPrimaryExpressionContext } from "../../../parser"; -import { UnableToDetermineSemanticDataError } from "../../../../errors"; +import type { TangledPrimaryExpressionSemantics } from "./tangled-primary-expression-semantics"; +import type { TangledPrimaryExpressionTypeSemantics } from "./tangled-primary-expression-type-semantics"; +import type { CompilableASTNode } from "../../../../compilable-ast-node"; +import type { Expression } from "../../expression"; +import { KindParseRuleMapping, ParseRuleKindMapping, TangledPrimaryExpressionContext } from "../../../../../parser"; +import { UnableToDetermineSemanticDataError } from "../../../../../../errors"; +import { PrimaryExpression } from "../primary-expression"; /** * Tangled/Parenthesised expression, which represents a parenthesised expression that wraps another expression and @@ -19,9 +20,9 @@ import { UnableToDetermineSemanticDataError } from "../../../../errors"; * (4 + 5) * 5; // 4 + 5 will be evaluated first, then the multiplication will be performed * @since 0.1.0 */ -export class TangledPrimaryExpression extends Expression< +export class TangledPrimaryExpression extends PrimaryExpression< TangledPrimaryExpressionSemantics, - TangledPrimaryTypeSemantics + TangledPrimaryExpressionTypeSemantics > { /** * The private field '_antlrRuleCtx' that actually stores the variable data, diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary/constant/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary/constant/index.ts deleted file mode 100644 index f16c94616..000000000 --- a/kipper/core/src/compiler/ast/nodes/expressions/primary/constant/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Constant expression module containing the classes representing expressions, which represent a constant value in a - * specific data structure. - * @since 0.11.0 - */ -export * from "./constant-expression"; -export * from "./array-primary-expression"; -export * from "./bool-primary-expression"; -export * from "./number-primary-expression"; -export * from "./string-primary-expression"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/primary/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/primary/index.ts deleted file mode 100644 index 65978fb02..000000000 --- a/kipper/core/src/compiler/ast/nodes/expressions/primary/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Primary expression module containing the classes representing expressions, which build up the fundamental building - * blocks of the language, such as constants and identifiers. - * @since 0.11.0 - */ -export * from "./constant/"; -export * from "./fstring-primary-expression"; -export * from "./identifier-primary-expression"; -export * from "./constant/void-or-null-or-undefined-primary-expression"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/generic-type-specifier-expression/generic-type-specifier-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/generic-type-specifier-expression/generic-type-specifier-expression-semantics.ts new file mode 100644 index 000000000..395aa87f7 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/generic-type-specifier-expression/generic-type-specifier-expression-semantics.ts @@ -0,0 +1,13 @@ +/** + * Semantics for AST Node {@link GenericTypeSpecifierExpression}. + * @since 0.8.0 + */ +import type { TypeSpecifierExpressionSemantics } from "../type-specifier-expression-semantics"; + +/** + * Semantics for AST Node {@link GenericTypeSpecifierExpression}. + * @since 0.8.0 + */ +export interface GenericTypeSpecifierExpressionSemantics extends TypeSpecifierExpressionSemantics { + // Not implemented. +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/generic-type-specifier-expression/generic-type-specifier-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/generic-type-specifier-expression/generic-type-specifier-expression-type-semantics.ts new file mode 100644 index 000000000..259dc3bd6 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/generic-type-specifier-expression/generic-type-specifier-expression-type-semantics.ts @@ -0,0 +1,13 @@ +/** + * Semantics for AST Node {@link GenericTypeSpecifierExpression}. + * @since 0.10.0 + */ +import type { TypeSpecifierExpressionTypeSemantics } from "../type-specifier-expression-type-semantics"; + +/** + * Semantics for AST Node {@link GenericTypeSpecifierExpression}. + * @since 0.10.0 + */ +export interface GenericTypeSpecifierExpressionTypeSemantics extends TypeSpecifierExpressionTypeSemantics { + // Not implemented. +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier/generic-type-specifier-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/generic-type-specifier-expression/generic-type-specifier-expression.ts similarity index 88% rename from kipper/core/src/compiler/ast/nodes/expressions/type-specifier/generic-type-specifier-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/generic-type-specifier-expression/generic-type-specifier-expression.ts index 31951ce20..fdb7b10eb 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier/generic-type-specifier-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/generic-type-specifier-expression/generic-type-specifier-expression.ts @@ -1,15 +1,19 @@ -import type { GenericTypeSpecifierExpressionSemantics } from "../../../semantic-data"; /** * Generic type specifier expression, which represents a generic type specifier. * @example * list // List type with number as generic type * @since 0.8.0 */ -import type { GenericTypeSpecifierExpressionTypeSemantics } from "../../../type-data"; -import type { CompilableASTNode } from "../../../compilable-ast-node"; -import { TypeSpecifierExpression } from "./type-specifier-expression"; -import { GenericTypeSpecifierExpressionContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; -import { KipperNotImplementedError } from "../../../../../errors"; +import type { GenericTypeSpecifierExpressionSemantics } from "./generic-type-specifier-expression-semantics"; +import type { GenericTypeSpecifierExpressionTypeSemantics } from "./generic-type-specifier-expression-type-semantics"; +import type { CompilableASTNode } from "../../../../compilable-ast-node"; +import { TypeSpecifierExpression } from "../type-specifier-expression"; +import { + GenericTypeSpecifierExpressionContext, + KindParseRuleMapping, + ParseRuleKindMapping, +} from "../../../../../parser"; +import { KipperNotImplementedError } from "../../../../../../errors"; /** * Generic type specifier expression, which represents a generic type specifier. diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/generic-type-specifier-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/generic-type-specifier-expression/index.ts new file mode 100644 index 000000000..62a0924f5 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/generic-type-specifier-expression/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link GenericTypeSpecifierExpression} and the related {@link GenericTypeSpecifierExpressionSemantics + * semantics} and {@link GenericTypeSpecifierExpressionTypeSemantics type semantics}. + */ +export * from "./generic-type-specifier-expression"; +export * from "./generic-type-specifier-expression-semantics"; +export * from "./generic-type-specifier-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/identifier-type-specifier-expression/identifier-type-specifier-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/identifier-type-specifier-expression/identifier-type-specifier-expression-semantics.ts new file mode 100644 index 000000000..e48b6bf06 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/identifier-type-specifier-expression/identifier-type-specifier-expression-semantics.ts @@ -0,0 +1,19 @@ +/** + * Semantics for AST Node {@link IdentifierTypeSpecifierExpression}. + * @since 0.8.0 + */ +import type { UncheckedType } from "../../../../../analysis"; +import type { TypeSpecifierExpressionSemantics } from "../type-specifier-expression-semantics"; + +/** + * Semantics for AST Node {@link IdentifierTypeSpecifierExpression}. + * @since 0.8.0 + */ +export interface IdentifierTypeSpecifierExpressionSemantics extends TypeSpecifierExpressionSemantics { + /** + * The type specified by this expression, which per default is an unchecked type as the type is not yet known and + * therefore may be invalid/undefined. + * @since 0.8.0 + */ + typeIdentifier: UncheckedType; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/identifier-type-specifier-expression/identifier-type-specifier-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/identifier-type-specifier-expression/identifier-type-specifier-expression-type-semantics.ts new file mode 100644 index 000000000..aa361091a --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/identifier-type-specifier-expression/identifier-type-specifier-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link IdentifierTypeSpecifierExpression}. + * @since 0.10.0 + */ +import type { TypeSpecifierExpressionTypeSemantics } from "../type-specifier-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link IdentifierTypeSpecifierExpression}. + * @since 0.10.0 + */ +export interface IdentifierTypeSpecifierExpressionTypeSemantics extends TypeSpecifierExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier/identifier-type-specifier-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/identifier-type-specifier-expression/identifier-type-specifier-expression.ts similarity index 91% rename from kipper/core/src/compiler/ast/nodes/expressions/type-specifier/identifier-type-specifier-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/identifier-type-specifier-expression/identifier-type-specifier-expression.ts index e33562a57..bf2e15295 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier/identifier-type-specifier-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/identifier-type-specifier-expression/identifier-type-specifier-expression.ts @@ -7,16 +7,16 @@ * bool // Boolean type * @since 0.8.0 */ -import type { IdentifierTypeSpecifierExpressionSemantics } from "../../../semantic-data"; -import type { IdentifierTypeSpecifierExpressionTypeSemantics } from "../../../type-data"; -import type { CompilableASTNode } from "../../../compilable-ast-node"; -import { TypeSpecifierExpression } from "./type-specifier-expression"; +import type { IdentifierTypeSpecifierExpressionSemantics } from "./identifier-type-specifier-expression-semantics"; +import type { IdentifierTypeSpecifierExpressionTypeSemantics } from "./identifier-type-specifier-expression-type-semantics"; +import type { CompilableASTNode } from "../../../../compilable-ast-node"; +import { TypeSpecifierExpression } from "../type-specifier-expression"; import { IdentifierTypeSpecifierExpressionContext, KindParseRuleMapping, - ParseRuleKindMapping -} from "../../../../parser"; -import { CheckedType, UncheckedType } from "../../../../analysis"; + ParseRuleKindMapping, +} from "../../../../../parser"; +import { CheckedType, UncheckedType } from "../../../../../analysis"; /** * Type specifier expression, which represents a simple identifier type specifier. diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/identifier-type-specifier-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/identifier-type-specifier-expression/index.ts new file mode 100644 index 000000000..127cbff4d --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/identifier-type-specifier-expression/index.ts @@ -0,0 +1,8 @@ +/** + * AST Node {@link IdentifierTypeSpecifierExpression} and the related + * {@link IdentifierTypeSpecifierExpressionSemantics semantics} and + * {@link IdentifierTypeSpecifierExpressionTypeSemantics type semantics}. + */ +export * from "./identifier-type-specifier-expression"; +export * from "./identifier-type-specifier-expression-semantics"; +export * from "./identifier-type-specifier-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/index.ts new file mode 100644 index 000000000..fe9517cb9 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/index.ts @@ -0,0 +1,11 @@ +/** + * Type specifier expression module containing the classes representing expressions, which are used in declaration + * and type references, where a type specifier is required. + * @since 0.11.0 + */ +export * from "./type-specifier-expression"; +export * from "./type-specifier-expression-semantics"; +export * from "./type-specifier-expression-type-semantics"; +export * from "./identifier-type-specifier-expression/"; +export * from "./typeof-type-specifier-expression/"; +export * from "./generic-type-specifier-expression/"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/type-specifier-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/type-specifier-expression-semantics.ts new file mode 100644 index 000000000..1703316c9 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/type-specifier-expression-semantics.ts @@ -0,0 +1,9 @@ +/** + * Semantics for AST Node {@link TypeSpecifierExpression}. + */ +import type { ExpressionSemantics } from "../expression-semantics"; + +/** + * Semantics for AST Node {@link TypeSpecifierExpression}. + */ +export interface TypeSpecifierExpressionSemantics extends ExpressionSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/type-specifier-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/type-specifier-expression-type-semantics.ts new file mode 100644 index 000000000..284abeb1c --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/type-specifier-expression-type-semantics.ts @@ -0,0 +1,19 @@ +/** + * Type semantics for AST Node {@link TypeSpecifierExpression}. + * @since 0.10.0 + */ +import type { CheckedType } from "../../../../analysis"; +import type { ExpressionTypeSemantics } from "../expression-type-semantics"; + +/** + * Type semantics for AST Node {@link TypeSpecifierExpression}. + * @since 0.10.0 + */ +export interface TypeSpecifierExpressionTypeSemantics extends ExpressionTypeSemantics { + /** + * The type that is being stored by this type specifier. This is the type that would be used to determine what + * values should be stored in a variable. + * @since 0.10.0 + */ + storedType: CheckedType; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier/type-specifier-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/type-specifier-expression.ts similarity index 75% rename from kipper/core/src/compiler/ast/nodes/expressions/type-specifier/type-specifier-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/type-specifier-expression.ts index 762e4fbef..7ae60d42f 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier/type-specifier-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/type-specifier-expression.ts @@ -3,12 +3,11 @@ * different type specifier expressions. * @since 0.9.0 */ -import type { TypeSpecifierExpressionSemantics } from "../../../semantic-data"; -import type { ParseRuleKindMapping } from "../../../../parser"; -import { KindParseRuleMapping } from "../../../../parser"; -import type { TypeSpecifierExpressionTypeSemantics } from "../../../type-data"; +import type { TypeSpecifierExpressionSemantics } from "./type-specifier-expression-semantics"; +import type { TypeSpecifierExpressionTypeSemantics } from "./type-specifier-expression-type-semantics"; +import type { KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; +import type { ASTNodeMapper } from "../../../mapping"; import { Expression } from "../expression"; -import { ASTNodeMapper } from "../../../mapping"; /** * Union type of all possible {@link ParserASTNode.kind} values for a constructable {@link TypeSpecifierExpression} AST node. @@ -25,7 +24,7 @@ export type ASTTypeSpecifierExpressionKind = * @since 0.10.0 */ export type ParserTypeSpecifierExpressionContext = InstanceType< - typeof ASTNodeMapper.expressionKindToRuleContextMap[ASTTypeSpecifierExpressionKind] + (typeof ASTNodeMapper.expressionKindToRuleContextMap)[ASTTypeSpecifierExpressionKind] >; /** @@ -33,7 +32,7 @@ export type ParserTypeSpecifierExpressionContext = InstanceType< * AST node. * @since 0.11.0 */ -export type ParserTypeSpecifierExpressionRuleName = typeof KindParseRuleMapping[ASTTypeSpecifierExpressionKind]; +export type ParserTypeSpecifierExpressionRuleName = (typeof KindParseRuleMapping)[ASTTypeSpecifierExpressionKind]; /** * Abstract type class representing a type specifier. This abstract class only exists to provide the commonality between the diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/index.ts new file mode 100644 index 000000000..e1d9adc83 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/index.ts @@ -0,0 +1,8 @@ +/** + * AST Node {@link TypeofTypeSpecifierExpression} and the related + * {@link TypeofTypeSpecifierExpressionSemantics semantics} and + * {@link TypeofTypeSpecifierExpressionTypeSemantics type semantics}. + */ +export * from "./typeof-type-specifier-expression"; +export * from "./typeof-type-specifier-expression-semantics"; +export * from "./typeof-type-specifier-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression-semantics.ts new file mode 100644 index 000000000..ad479f29e --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression-semantics.ts @@ -0,0 +1,13 @@ +/** + * Semantics for AST Node {@link TypeofTypeSpecifierExpression}. + * @since 0.8.0 + */ +import type { TypeSpecifierExpressionSemantics } from "../type-specifier-expression-semantics"; + +/** + * Semantics for AST Node {@link TypeofTypeSpecifierExpression}. + * @since 0.8.0 + */ +export interface TypeofTypeSpecifierExpressionSemantics extends TypeSpecifierExpressionSemantics { + // Not implemented. +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression-type-semantics.ts new file mode 100644 index 000000000..570bc7741 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression-type-semantics.ts @@ -0,0 +1,13 @@ +/** + * Type semantics for AST Node {@link TypeofTypeSpecifierExpression}. + * @since 0.8.0 + */ +import type { TypeSpecifierExpressionTypeSemantics } from "../type-specifier-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link TypeofTypeSpecifierExpression}. + * @since 0.8.0 + */ +export interface TypeofTypeSpecifierExpressionTypeSemantics extends TypeSpecifierExpressionTypeSemantics { + // Not implemented. +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier/typeof-type-specifier-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression.ts similarity index 87% rename from kipper/core/src/compiler/ast/nodes/expressions/type-specifier/typeof-type-specifier-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression.ts index 46da4f391..d8b9c9d64 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier/typeof-type-specifier-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier-expression/typeof-type-specifier-expression/typeof-type-specifier-expression.ts @@ -2,12 +2,16 @@ * Typeof type specifier expression, which represents a runtime typeof expression evaluating the type of a value. * @since 0.8.0 */ -import type { TypeofTypeSpecifierExpressionSemantics } from "../../../semantic-data"; -import type { TypeofTypeSpecifierExpressionTypeSemantics } from "../../../type-data"; -import type { CompilableASTNode } from "../../../compilable-ast-node"; -import { TypeSpecifierExpression } from "./type-specifier-expression"; -import { KindParseRuleMapping, ParseRuleKindMapping, TypeofTypeSpecifierExpressionContext } from "../../../../parser"; -import { KipperNotImplementedError } from "../../../../../errors"; +import type { TypeofTypeSpecifierExpressionSemantics } from "./typeof-type-specifier-expression-semantics"; +import type { TypeofTypeSpecifierExpressionTypeSemantics } from "./typeof-type-specifier-expression-type-semantics"; +import type { CompilableASTNode } from "../../../../compilable-ast-node"; +import { TypeSpecifierExpression } from "../type-specifier-expression"; +import { + KindParseRuleMapping, + ParseRuleKindMapping, + TypeofTypeSpecifierExpressionContext, +} from "../../../../../parser"; +import { KipperNotImplementedError } from "../../../../../../errors"; /** * Typeof type specifier expression, which represents a runtime typeof expression evaluating the type of a value. diff --git a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/type-specifier/index.ts deleted file mode 100644 index fbd06eaa7..000000000 --- a/kipper/core/src/compiler/ast/nodes/expressions/type-specifier/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Type specifier expression module containing the classes representing expressions, which are used in declaration - * and type references, where a type specifier is required. - * @since 0.11.0 - */ -export * from "./type-specifier-expression"; -export * from "./identifier-type-specifier-expression"; -export * from "./typeof-type-specifier-expression"; -export * from "./generic-type-specifier-expression"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/increment-or-decrement-unary-expression/increment-or-decrement-unary-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/increment-or-decrement-unary-expression/increment-or-decrement-unary-expression-semantics.ts new file mode 100644 index 000000000..e3c11e180 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/increment-or-decrement-unary-expression/increment-or-decrement-unary-expression-semantics.ts @@ -0,0 +1,18 @@ +/** + * Semantics for AST Node {@link IncrementOrDecrementUnaryExpression}. + * @since 0.5.0 + */ +import type { KipperIncrementOrDecrementOperator } from "../../../../../const"; +import type { UnaryExpressionSemantics } from "../unary-expression-semantics"; + +/** + * Semantics for AST Node {@link IncrementOrDecrementUnaryExpression}. + * @since 0.5.0 + */ +export interface IncrementOrDecrementUnaryExpressionSemantics extends UnaryExpressionSemantics { + /** + * The operator that is used to modify the {@link operand}. + * @since 0.9.0 + */ + operator: KipperIncrementOrDecrementOperator; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/increment-or-decrement-unary-expression/increment-or-decrement-unary-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/increment-or-decrement-unary-expression/increment-or-decrement-unary-expression-type-semantics.ts new file mode 100644 index 000000000..d1b4ec7a0 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/increment-or-decrement-unary-expression/increment-or-decrement-unary-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link IncrementOrDecrementUnaryExpression}. + * @since 0.10.0 + */ +import type { UnaryExpressionTypeSemantics } from "../unary-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link IncrementOrDecrementUnaryExpression}. + * @since 0.10.0 + */ +export interface IncrementOrDecrementUnaryTypeSemantics extends UnaryExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/unary/increment-or-decrement-unary-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/increment-or-decrement-unary-expression/increment-or-decrement-unary-expression.ts similarity index 90% rename from kipper/core/src/compiler/ast/nodes/expressions/unary/increment-or-decrement-unary-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/unary-expression/increment-or-decrement-unary-expression/increment-or-decrement-unary-expression.ts index 6aaa95090..551a2799c 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/unary/increment-or-decrement-unary-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/increment-or-decrement-unary-expression/increment-or-decrement-unary-expression.ts @@ -5,19 +5,19 @@ * ++49; // 49 will be incremented by 1 * --11; // 11 will be decremented by 1 */ -import type { IncrementOrDecrementUnaryExpressionSemantics } from "../../../semantic-data"; -import type { IncrementOrDecrementUnaryTypeSemantics } from "../../../type-data"; -import type { CompilableASTNode } from "../../../compilable-ast-node"; -import type { Expression } from "../expression"; -import type { KipperIncrementOrDecrementOperator } from "../../../../const"; -import { UnaryExpression } from "./unary-expression"; +import type { IncrementOrDecrementUnaryExpressionSemantics } from "./increment-or-decrement-unary-expression-semantics"; +import type { IncrementOrDecrementUnaryTypeSemantics } from "./increment-or-decrement-unary-expression-type-semantics"; +import type { CompilableASTNode } from "../../../../compilable-ast-node"; +import type { Expression } from "../../expression"; +import type { KipperIncrementOrDecrementOperator } from "../../../../../const"; +import { UnaryExpression } from "../unary-expression"; import { IncrementOrDecrementUnaryExpressionContext, KindParseRuleMapping, - ParseRuleKindMapping -} from "../../../../parser"; -import { UnableToDetermineSemanticDataError } from "../../../../../errors"; -import { CheckedType } from "../../../../analysis"; + ParseRuleKindMapping, +} from "../../../../../parser"; +import { UnableToDetermineSemanticDataError } from "../../../../../../errors"; +import { CheckedType } from "../../../../../analysis"; /** * Increment or decrement expression class, which represents a left-side -- or ++ expression modifying a numeric value. diff --git a/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/increment-or-decrement-unary-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/increment-or-decrement-unary-expression/index.ts new file mode 100644 index 000000000..a1b23ccef --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/increment-or-decrement-unary-expression/index.ts @@ -0,0 +1,8 @@ +/** + * AST Node {@link IncrementOrDecrementUnaryExpression} and the related + * {@link IncrementOrDecrementUnaryExpressionSemantics semantics} and + * {@link IncrementOrDecrementUnaryExpressionTypeSemantics type semantics}. + */ +export * from "./increment-or-decrement-unary-expression"; +export * from "./increment-or-decrement-unary-expression-semantics"; +export * from "./increment-or-decrement-unary-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/unary/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/index.ts similarity index 51% rename from kipper/core/src/compiler/ast/nodes/expressions/unary/index.ts rename to kipper/core/src/compiler/ast/nodes/expressions/unary-expression/index.ts index 67817a3c9..18ee585e0 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/unary/index.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/index.ts @@ -4,5 +4,7 @@ * @since 0.11.0 */ export * from "./unary-expression"; -export * from "./operator-modified-unary-expression"; -export * from "./increment-or-decrement-unary-expression"; +export * from "./unary-expression-semantics"; +export * from "./unary-expression-type-semantics"; +export * from "./operator-modified-unary-expression/"; +export * from "./increment-or-decrement-unary-expression/"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/operator-modified-unary-expression/index.ts b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/operator-modified-unary-expression/index.ts new file mode 100644 index 000000000..c6ad51689 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/operator-modified-unary-expression/index.ts @@ -0,0 +1,8 @@ +/** + * AST Node {@link OperatorModifiedUnaryExpression} and the related + * {@link OperatorModifiedUnaryExpressionSemantics semantics} and + * {@link OperatorModifiedUnaryExpressionTypeSemantics type semantics}. + */ +export * from "./operator-modified-unary-expression"; +export * from "./operator-modified-unary-expression-semantics"; +export * from "./operator-modified-unary-expression-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/operator-modified-unary-expression/operator-modified-unary-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/operator-modified-unary-expression/operator-modified-unary-expression-semantics.ts new file mode 100644 index 000000000..470bb7551 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/operator-modified-unary-expression/operator-modified-unary-expression-semantics.ts @@ -0,0 +1,18 @@ +/** + * Semantics for AST Node {@link OperatorModifiedUnaryExpression}. + * @since 0.5.0 + */ +import type { KipperUnaryModifierOperator } from "../../../../../const"; +import type { UnaryExpressionSemantics } from "../unary-expression-semantics"; + +/** + * Semantics for AST Node {@link OperatorModifiedUnaryExpression}. + * @since 0.5.0 + */ +export interface OperatorModifiedUnaryExpressionSemantics extends UnaryExpressionSemantics { + /** + * The operator that is used to modify the {@link operand}. + * @since 0.9.0 + */ + operator: KipperUnaryModifierOperator; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/operator-modified-unary-expression/operator-modified-unary-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/operator-modified-unary-expression/operator-modified-unary-expression-type-semantics.ts new file mode 100644 index 000000000..d7bf35941 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/operator-modified-unary-expression/operator-modified-unary-expression-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link OperatorModifiedUnaryExpression}. + * @since 0.10.0 + */ +import type { UnaryExpressionTypeSemantics } from "../unary-expression-type-semantics"; + +/** + * Type semantics for AST Node {@link OperatorModifiedUnaryExpression}. + * @since 0.10.0 + */ +export interface OperatorModifiedUnaryTypeSemantics extends UnaryExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/unary/operator-modified-unary-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/operator-modified-unary-expression/operator-modified-unary-expression.ts similarity index 88% rename from kipper/core/src/compiler/ast/nodes/expressions/unary/operator-modified-unary-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/unary-expression/operator-modified-unary-expression/operator-modified-unary-expression.ts index 92eb22024..e42e17531 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/unary/operator-modified-unary-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/operator-modified-unary-expression/operator-modified-unary-expression.ts @@ -6,20 +6,21 @@ * -41 // -41 * +59 // 59 */ -import type { OperatorModifiedUnaryExpressionSemantics } from "../../../semantic-data"; -import type { OperatorModifiedUnaryTypeSemantics } from "../../../type-data"; -import type { CompilableASTNode } from "../../../compilable-ast-node"; -import type { Expression } from "../expression"; -import { UnaryExpression } from "./unary-expression"; +import type { OperatorModifiedUnaryExpressionSemantics } from "./operator-modified-unary-expression-semantics"; +import type { OperatorModifiedUnaryTypeSemantics } from "./operator-modified-unary-expression-type-semantics"; +import type { CompilableASTNode } from "../../../../compilable-ast-node"; +import type { Expression } from "../../expression"; +import type { KipperNegateOperator, KipperSignOperator } from "../../../../../const"; +import { kipperUnaryModifierOperators } from "../../../../../const"; +import { UnaryExpression } from "../unary-expression"; import { KindParseRuleMapping, OperatorModifiedUnaryExpressionContext, ParseRuleKindMapping, - UnaryOperatorContext -} from "../../../../parser"; -import { KipperNegateOperator, KipperSignOperator, kipperUnaryModifierOperators } from "../../../../const"; -import { UnableToDetermineSemanticDataError } from "../../../../../errors"; -import { CheckedType } from "../../../../analysis"; + UnaryOperatorContext, +} from "../../../../../parser"; +import { UnableToDetermineSemanticDataError } from "../../../../../../errors"; +import { CheckedType } from "../../../../../analysis"; /** * Operator modified expressions, which are used to modify the value of an expression based on an diff --git a/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/unary-expression-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/unary-expression-semantics.ts new file mode 100644 index 000000000..21a884b70 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/unary-expression-semantics.ts @@ -0,0 +1,26 @@ +/** + * Semantics for unary expressions, which can be used to modify an expression with + * a specified operator. + * @since 0.9.0 + */ +import type { KipperUnaryOperator } from "../../../../const"; +import type { Expression } from "../expression"; +import type { ExpressionSemantics } from "../expression-semantics"; + +/** + * Semantics for unary expressions, which can be used to modify an expression with + * a specified operator. + * @since 0.9.0 + */ +export interface UnaryExpressionSemantics extends ExpressionSemantics { + /** + * The operator that is used to modify the {@link operand}. + * @since 0.9.0 + */ + operator: KipperUnaryOperator; + /** + * The operand that is modified by the {@link operator}. + * @since 0.9.0 + */ + operand: Expression; +} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/unary-expression-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/unary-expression-type-semantics.ts new file mode 100644 index 000000000..e8ebf669b --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/unary-expression-type-semantics.ts @@ -0,0 +1,13 @@ +/** + * Semantics for {@link UnaryExpression unary expressions}, which can be used to modify an expression with + * a specified operator. + * @since 0.10.0 + */ +import type { ExpressionTypeSemantics } from "../expression-type-semantics"; + +/** + * Type semantics for {@link UnaryExpression unary expressions}, which can be used to modify an expression with + * a specified operator. + * @since 0.10.0 + */ +export interface UnaryExpressionTypeSemantics extends ExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/expressions/unary/unary-expression.ts b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/unary-expression.ts similarity index 84% rename from kipper/core/src/compiler/ast/nodes/expressions/unary/unary-expression.ts rename to kipper/core/src/compiler/ast/nodes/expressions/unary-expression/unary-expression.ts index f46bfeecd..02bab51e6 100644 --- a/kipper/core/src/compiler/ast/nodes/expressions/unary/unary-expression.ts +++ b/kipper/core/src/compiler/ast/nodes/expressions/unary-expression/unary-expression.ts @@ -4,8 +4,8 @@ * expressions. * @since 0.9.0 */ -import type { UnaryExpressionSemantics } from "../../../semantic-data"; -import type { UnaryExpressionTypeSemantics } from "../../../type-data"; +import type { UnaryExpressionSemantics } from "./unary-expression-semantics"; +import type { UnaryExpressionTypeSemantics } from "./unary-expression-type-semantics"; import type { ParseRuleKindMapping } from "../../../../parser"; import { KindParseRuleMapping } from "../../../../parser"; import { Expression } from "../expression"; @@ -24,7 +24,7 @@ export type ASTUnaryExpressionKind = * @since 0.10.0 */ export type ParserUnaryExpressionContext = InstanceType< - typeof ASTNodeMapper.expressionKindToRuleContextMap[ASTUnaryExpressionKind] + (typeof ASTNodeMapper.expressionKindToRuleContextMap)[ASTUnaryExpressionKind] >; /** @@ -32,7 +32,7 @@ export type ParserUnaryExpressionContext = InstanceType< * AST node. * @since 0.11.0 */ -export type ParserUnaryExpressionRuleName = typeof KindParseRuleMapping[ASTUnaryExpressionKind]; +export type ParserUnaryExpressionRuleName = (typeof KindParseRuleMapping)[ASTUnaryExpressionKind]; /** * Abstract unary expression class representing a unary expression, which can be used to modify an expression with diff --git a/kipper/core/src/compiler/ast/nodes/root-ast-node.ts b/kipper/core/src/compiler/ast/nodes/root-ast-node.ts index b2260cee7..4f6e87ebe 100644 --- a/kipper/core/src/compiler/ast/nodes/root-ast-node.ts +++ b/kipper/core/src/compiler/ast/nodes/root-ast-node.ts @@ -9,7 +9,7 @@ import type { KipperTargetCodeGenerator, KipperTargetSemanticAnalyser, TargetSetUpCodeGenerator, - TargetWrapUpCodeGenerator + TargetWrapUpCodeGenerator, } from "../../target-presets"; import type { EvaluatedCompileConfig } from "../../compile-config"; import type { KipperProgramContext } from "../../program-ctx"; diff --git a/kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement-semantics.ts new file mode 100644 index 000000000..164f3bc1d --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement-semantics.ts @@ -0,0 +1,11 @@ +/** + * Semantics for AST Node {@link CompoundStatement}. + * @since 0.11.0 + */ +import type { StatementSemantics } from "../statement-semantics"; + +/** + * Semantics for AST Node {@link CompoundStatement}. + * @since 0.11.0 + */ +export interface CompoundStatementSemantics extends StatementSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement-type-semantics.ts new file mode 100644 index 000000000..5055f172a --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Semantics for AST Node {@link CompoundStatement}. + * @since 0.11.0 + */ +import type { StatementTypeSemantics } from "../statement-type-semantics"; + +/** + * Type semantics for AST Node {@link CompoundStatement}. + * @since 0.11.0 + */ +export interface CompoundStatementTypeSemantics extends StatementTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/statements/compound-statement.ts b/kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts similarity index 87% rename from kipper/core/src/compiler/ast/nodes/statements/compound-statement.ts rename to kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts index aa17d79e4..5ee8d72a6 100644 --- a/kipper/core/src/compiler/ast/nodes/statements/compound-statement.ts +++ b/kipper/core/src/compiler/ast/nodes/statements/compound-statement/compound-statement.ts @@ -2,18 +2,22 @@ * Compound statement class, which represents a compound statement containing other items in the Kipper * language and is compilable using {@link translateCtxAndChildren}. */ -import type { NoSemantics, NoTypeSemantics } from "../../ast-node"; -import type { ScopeNode } from "../../scope-node"; -import type { CompilableNodeParent } from "../../compilable-ast-node"; -import { Statement } from "./statement"; -import { LocalScope } from "../../../analysis"; -import { CompoundStatementContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../parser"; +import type { ScopeNode } from "../../../scope-node"; +import type { CompilableNodeParent } from "../../../compilable-ast-node"; +import type { CompoundStatementSemantics } from "./compound-statement-semantics"; +import type { CompoundStatementTypeSemantics } from "./compound-statement-type-semantics"; +import { Statement } from "../statement"; +import { LocalScope } from "../../../../analysis"; +import { CompoundStatementContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; /** * Compound statement class, which represents a compound statement containing other items in the Kipper * language and is compilable using {@link translateCtxAndChildren}. */ -export class CompoundStatement extends Statement implements ScopeNode { +export class CompoundStatement + extends Statement + implements ScopeNode +{ /** * The private field '_antlrRuleCtx' that actually stores the variable data, * which is returned inside the {@link this.antlrRuleCtx}. diff --git a/kipper/core/src/compiler/ast/nodes/statements/compound-statement/index.ts b/kipper/core/src/compiler/ast/nodes/statements/compound-statement/index.ts new file mode 100644 index 000000000..cf87daffb --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/compound-statement/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link CompoundStatement} and the related {@link CompoundStatementSemantics semantics} and + * {@link CompoundStatementTypeSemantics type semantics}. + */ +export * from "./compound-statement"; +export * from "./compound-statement-semantics"; +export * from "./compound-statement-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/statements/expression-statement/expression-statement-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/expression-statement/expression-statement-semantics.ts new file mode 100644 index 000000000..12ceb06ce --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/expression-statement/expression-statement-semantics.ts @@ -0,0 +1,11 @@ +/** + * Semantics for AST Node {@link ExpressionStatement}. + * @since 0.11.0 + */ +import type { StatementSemantics } from "../statement-semantics"; + +/** + * Semantics for AST Node {@link ExpressionStatement}. + * @since 0.11.0 + */ +export interface ExpressionStatementSemantics extends StatementSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/statements/expression-statement/expression-statement-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/expression-statement/expression-statement-type-semantics.ts new file mode 100644 index 000000000..a0f5e2d2e --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/expression-statement/expression-statement-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Semantics for AST Node {@link ExpressionStatement}. + * @since 0.11.0 + */ +import type { StatementTypeSemantics } from "../statement-type-semantics"; + +/** + * Type semantics for AST Node {@link ExpressionStatement}. + * @since 0.11.0 + */ +export interface ExpressionStatementTypeSemantics extends StatementTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/statements/expression-statement.ts b/kipper/core/src/compiler/ast/nodes/statements/expression-statement/expression-statement.ts similarity index 87% rename from kipper/core/src/compiler/ast/nodes/statements/expression-statement.ts rename to kipper/core/src/compiler/ast/nodes/statements/expression-statement/expression-statement.ts index 6658cec0b..74fed1820 100644 --- a/kipper/core/src/compiler/ast/nodes/statements/expression-statement.ts +++ b/kipper/core/src/compiler/ast/nodes/statements/expression-statement/expression-statement.ts @@ -1,16 +1,17 @@ /** * Expression statement class, which represents a statement made up of an expression in the Kipper language. */ -import type { NoSemantics, NoTypeSemantics } from "../../ast-node"; -import type { CompilableNodeParent } from "../../compilable-ast-node"; -import { Statement } from "./statement"; -import { ExpressionStatementContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../parser"; -import { Expression } from "../expressions"; +import type { CompilableNodeParent } from "../../../compilable-ast-node"; +import type { ExpressionStatementSemantics } from "./expression-statement-semantics"; +import type { ExpressionStatementTypeSemantics } from "./expression-statement-type-semantics"; +import { Statement } from "../statement"; +import { ExpressionStatementContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; +import { Expression } from "../../expressions"; /** * Expression statement class, which represents a statement made up of an expression in the Kipper language. */ -export class ExpressionStatement extends Statement { +export class ExpressionStatement extends Statement { /** * The private field '_antlrRuleCtx' that actually stores the variable data, * which is returned inside the {@link this.antlrRuleCtx}. diff --git a/kipper/core/src/compiler/ast/nodes/statements/expression-statement/index.ts b/kipper/core/src/compiler/ast/nodes/statements/expression-statement/index.ts new file mode 100644 index 000000000..8b90ec0c6 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/expression-statement/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link ExpressionStatement} and the related {@link ExpressionStatementSemantics semantics} and + * {@link ExpressionStatementTypeSemantics type semantics}. + */ +export * from "./expression-statement"; +export * from "./expression-statement-semantics"; +export * from "./expression-statement-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/statements/if-statement/if-statement-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/if-statement/if-statement-semantics.ts new file mode 100644 index 000000000..8909b1283 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/if-statement/if-statement-semantics.ts @@ -0,0 +1,34 @@ +/** + * Semantics for AST Node {@link IfStatement}. + * @since 0.9.0 + */ +import type { SemanticData } from "../../../ast-node"; +import type { Expression } from "../../expressions"; +import type { Statement } from "../statement"; +import type { IfStatement } from "./if-statement"; + +/** + * Semantics for AST Node {@link IfStatement}. + * @since 0.9.0 + */ +export interface IfStatementSemantics extends SemanticData { + /** + * The condition of the if-statement. + * @since 0.9.0 + */ + condition: Expression; + /** + * The body of the if-statement. + * @since 0.9.0 + */ + ifBranch: Statement; + /** + * The alternative (optional) branch of the if-statement. This alternative branch can either be: + * - An else branch, if the type is a regular {@link Statement} (the statement that should be + * evaluated in the else branch). + * - An else-if branch, if the type is another {@link IfStatement}. + * - Nothing (undefined), if it wasn't specified and the if statement does not have any more branches. + * @since 0.9.0 + */ + elseBranch?: IfStatement | Statement; +} diff --git a/kipper/core/src/compiler/ast/nodes/statements/if-statement/if-statement-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/if-statement/if-statement-type-semantics.ts new file mode 100644 index 000000000..c5a30ddc3 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/if-statement/if-statement-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Semantics for AST Node {@link IfStatement}. + * @since 0.11.0 + */ +import type { StatementTypeSemantics } from "../statement-type-semantics"; + +/** + * Type semantics for AST Node {@link IfStatement}. + * @since 0.11.0 + */ +export interface IfStatementTypeSemantics extends StatementTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/statements/if-statement.ts b/kipper/core/src/compiler/ast/nodes/statements/if-statement/if-statement.ts similarity index 91% rename from kipper/core/src/compiler/ast/nodes/statements/if-statement.ts rename to kipper/core/src/compiler/ast/nodes/statements/if-statement/if-statement.ts index 81a666ed4..ddf790db9 100644 --- a/kipper/core/src/compiler/ast/nodes/statements/if-statement.ts +++ b/kipper/core/src/compiler/ast/nodes/statements/if-statement/if-statement.ts @@ -2,19 +2,19 @@ * If statement class, which represents if, else-if and else statements in the Kipper language and is compilable using * {@link translateCtxAndChildren}. */ -import type { NoTypeSemantics } from "../../ast-node"; -import type { CompilableNodeParent } from "../../compilable-ast-node"; -import type { IfStatementSemantics } from "../../semantic-data"; -import { Statement } from "./statement"; -import { IfStatementContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../parser"; -import { Expression } from "../expressions"; -import { UnableToDetermineSemanticDataError } from "../../../../errors"; +import type { CompilableNodeParent } from "../../../compilable-ast-node"; +import type { IfStatementSemantics } from "./if-statement-semantics"; +import type { IfStatementTypeSemantics } from "./if-statement-type-semantics"; +import type { Expression } from "../../expressions"; +import { Statement } from "../statement"; +import { IfStatementContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; +import { UnableToDetermineSemanticDataError } from "../../../../../errors"; /** * If statement class, which represents if, else-if and else statements in the Kipper language and is compilable using * {@link translateCtxAndChildren}. */ -export class IfStatement extends Statement { +export class IfStatement extends Statement { /** * The private field '_antlrRuleCtx' that actually stores the variable data, * which is returned inside the {@link this.antlrRuleCtx}. diff --git a/kipper/core/src/compiler/ast/nodes/statements/if-statement/index.ts b/kipper/core/src/compiler/ast/nodes/statements/if-statement/index.ts new file mode 100644 index 000000000..bf7b67cb2 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/if-statement/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link IfStatement} and the related {@link IfStatementSemantics semantics} and + * {@link IfStatementTypeSemantics type semantics}. + */ +export * from "./if-statement"; +export * from "./if-statement-semantics"; +export * from "./if-statement-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/statements/index.ts b/kipper/core/src/compiler/ast/nodes/statements/index.ts index ac4d8249e..f912b8241 100644 --- a/kipper/core/src/compiler/ast/nodes/statements/index.ts +++ b/kipper/core/src/compiler/ast/nodes/statements/index.ts @@ -4,10 +4,10 @@ * @since 0.11.0 */ export * from "./statement"; -export * from "./iteration/"; -export * from "./compound-statement"; -export * from "./expression-statement"; -export * from "./if-statement"; -export * from "./jump-statement"; -export * from "./return-statement"; -export * from "./switch-statement"; +export * from "./iteration-statement/"; +export * from "./compound-statement/"; +export * from "./expression-statement/"; +export * from "./if-statement/"; +export * from "./jump-statement/"; +export * from "./return-statement/"; +export * from "./switch-statement/"; diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/do-while-loop-iteration-statement/do-while-loop-iteration-statement-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/do-while-loop-iteration-statement/do-while-loop-iteration-statement-semantics.ts new file mode 100644 index 000000000..19ad872be --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/do-while-loop-iteration-statement/do-while-loop-iteration-statement-semantics.ts @@ -0,0 +1,11 @@ +/** + * Semantics for AST Node {@link DoWhileLoopIterationStatement}. + * @since 0.10.0 + */ +import type { IterationStatementSemantics } from "../iteration-statement-semantics"; + +/** + * Semantics for AST Node {@link DoWhileLoopIterationStatement}. + * @since 0.10.0 + */ +export interface DoWhileLoopIterationStatementSemantics extends IterationStatementSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/do-while-loop-iteration-statement/do-while-loop-iteration-statement-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/do-while-loop-iteration-statement/do-while-loop-iteration-statement-type-semantics.ts new file mode 100644 index 000000000..ed219991f --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/do-while-loop-iteration-statement/do-while-loop-iteration-statement-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link DoWhileLoopIterationStatement}. + * @since 0.10.0 + */ +import type { IterationStatementTypeSemantics } from "../iteration-statement-type-semantics"; + +/** + * Type semantics for AST Node {@link DoWhileLoopIterationStatement}. + * @since 0.11.0 + */ +export interface DoWhileLoopIterationStatementTypeSemantics extends IterationStatementTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration/do-while-loop-iteration-statement.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/do-while-loop-iteration-statement/do-while-loop-iteration-statement.ts similarity index 86% rename from kipper/core/src/compiler/ast/nodes/statements/iteration/do-while-loop-iteration-statement.ts rename to kipper/core/src/compiler/ast/nodes/statements/iteration-statement/do-while-loop-iteration-statement/do-while-loop-iteration-statement.ts index b58ad3868..0d1dbc27f 100644 --- a/kipper/core/src/compiler/ast/nodes/statements/iteration/do-while-loop-iteration-statement.ts +++ b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/do-while-loop-iteration-statement/do-while-loop-iteration-statement.ts @@ -2,17 +2,25 @@ * Do-While loop statement class, which represents a do-while loop statement in the Kipper language and is compilable * using {@link translateCtxAndChildren}. */ -import type { DoWhileLoopStatementSemantics } from "../../../semantic-data"; -import type { CompilableNodeChild, CompilableNodeParent } from "../../../compilable-ast-node"; -import { IterationStatement } from "./iteration-statement"; -import { DoWhileLoopIterationStatementContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; -import { KipperNotImplementedError } from "../../../../../errors"; +import type { DoWhileLoopIterationStatementSemantics } from "./do-while-loop-iteration-statement-semantics"; +import type { DoWhileLoopIterationStatementTypeSemantics } from "./do-while-loop-iteration-statement-type-semantics"; +import type { CompilableNodeChild, CompilableNodeParent } from "../../../../compilable-ast-node"; +import { IterationStatement } from "../iteration-statement"; +import { + DoWhileLoopIterationStatementContext, + KindParseRuleMapping, + ParseRuleKindMapping, +} from "../../../../../parser"; +import { KipperNotImplementedError } from "../../../../../../errors"; /** * Do-While loop statement class, which represents a do-while loop statement in the Kipper language and is compilable * using {@link translateCtxAndChildren}. */ -export class DoWhileLoopIterationStatement extends IterationStatement { +export class DoWhileLoopIterationStatement extends IterationStatement< + DoWhileLoopIterationStatementSemantics, + DoWhileLoopIterationStatementTypeSemantics +> { /** * The private field '_antlrRuleCtx' that actually stores the variable data, * which is returned inside the {@link this.antlrRuleCtx}. diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/do-while-loop-iteration-statement/index.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/do-while-loop-iteration-statement/index.ts new file mode 100644 index 000000000..b0c46b64b --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/do-while-loop-iteration-statement/index.ts @@ -0,0 +1,8 @@ +/** + * AST Node {@link DoWhileLoopIterationStatement} and the related + * {@link DoWhileLoopIterationStatementSemantics semantics} and + * {@link DoWhileLoopIterationStatementTypeSemantics type semantics}. + */ +export * from "./do-while-loop-iteration-statement"; +export * from "./do-while-loop-iteration-statement-semantics"; +export * from "./do-while-loop-iteration-statement-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/for-loop-iteration-statement/for-loop-iteration-statement-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/for-loop-iteration-statement/for-loop-iteration-statement-semantics.ts new file mode 100644 index 000000000..8a024e9b7 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/for-loop-iteration-statement/for-loop-iteration-statement-semantics.ts @@ -0,0 +1,39 @@ +/** + * Semantics for AST Node {@link ForLoopIterationStatement}. + * @since 0.10.0 + */ +import type { IterationStatementSemantics } from "../iteration-statement-semantics"; +import type { VariableDeclaration } from "../../../declarations"; +import type { Expression } from "../../../expressions"; +import type { Statement } from "../../statement"; + +/** + * Semantics for AST Node {@link ForLoopIterationStatement}. + * @since 0.10.0 + */ +export interface ForLoopStatementSemantics extends IterationStatementSemantics { + /** + * The declaration/first statement of the loop, which is executed before the loop condition is evaluated. + * + * This may also simply be a single expression, if the loop does not have a declaration. + * @since 0.10.0 + */ + forDeclaration: VariableDeclaration | Expression | undefined; + /** + * The for iteration expression of the loop, which is executed after the loop body is executed. This is used to + * update the loop variable or execute any other code that should be executed after each loop iteration. + * @since 0.10.0 + */ + forIterationExp: Expression | undefined; + /** + * The for condition of the loop, which is evaluated after the loop body is executed. If this evaluates to true, + * the loop will continue executing. + * @since 0.10.0 + */ + loopCondition: Expression | undefined; + /** + * The body of the loop, which is executed as long as {@link loopCondition} is true. + * @since 0.10.0 + */ + loopBody: Statement; +} diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/for-loop-iteration-statement/for-loop-iteration-statement-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/for-loop-iteration-statement/for-loop-iteration-statement-type-semantics.ts new file mode 100644 index 000000000..8ad0cbe4d --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/for-loop-iteration-statement/for-loop-iteration-statement-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link ForLoopIterationStatement}. + * @since 0.11.0 + */ +import type { IterationStatementTypeSemantics } from "../iteration-statement-type-semantics"; + +/** + * Type semantics for AST Node {@link ForLoopIterationStatement}. + * @since 0.11.0 + */ +export interface ForLoopStatementTypeSemantics extends IterationStatementTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration/for-loop-iteration-statement.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/for-loop-iteration-statement/for-loop-iteration-statement.ts similarity index 87% rename from kipper/core/src/compiler/ast/nodes/statements/iteration/for-loop-iteration-statement.ts rename to kipper/core/src/compiler/ast/nodes/statements/iteration-statement/for-loop-iteration-statement/for-loop-iteration-statement.ts index c86000ad0..59e061bb2 100644 --- a/kipper/core/src/compiler/ast/nodes/statements/iteration/for-loop-iteration-statement.ts +++ b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/for-loop-iteration-statement/for-loop-iteration-statement.ts @@ -1,24 +1,24 @@ -import type { ForLoopStatementSemantics } from "../../../semantic-data"; -import type { NoTypeSemantics } from "../../../ast-node"; -import type { CompilableNodeChild, CompilableNodeParent } from "../../../compilable-ast-node"; /** * For loop statement class, which represents a for loop statement in the Kipper language and is compilable * using {@link translateCtxAndChildren}. */ -import type { ScopeNode } from "../../../scope-node"; -import type { Statement } from "../statement"; -import type { VariableDeclaration } from "../../declarations"; -import { IterationStatement } from "./iteration-statement"; -import { ForLoopIterationStatementContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; -import { Expression } from "../../expressions"; -import { LocalScope } from "../../../../analysis"; +import type { ScopeNode } from "../../../../scope-node"; +import type { Statement } from "../../statement"; +import type { VariableDeclaration } from "../../../declarations"; +import type { ForLoopStatementSemantics } from "./for-loop-iteration-statement-semantics"; +import type { ForLoopStatementTypeSemantics } from "./for-loop-iteration-statement-type-semantics"; +import type { CompilableNodeChild, CompilableNodeParent } from "../../../../compilable-ast-node"; +import { IterationStatement } from "../iteration-statement"; +import { ForLoopIterationStatementContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../../parser"; +import { Expression } from "../../../expressions"; +import { LocalScope } from "../../../../../analysis"; /** * For loop statement class, which represents a for loop statement in the Kipper language and is compilable * using {@link translateCtxAndChildren}. */ export class ForLoopIterationStatement - extends IterationStatement + extends IterationStatement implements ScopeNode { /** diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/for-loop-iteration-statement/index.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/for-loop-iteration-statement/index.ts new file mode 100644 index 000000000..cb929a9f0 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/for-loop-iteration-statement/index.ts @@ -0,0 +1,8 @@ +/** + * AST Node {@link ForLoopIterationStatement} and the related + * {@link ForLoopIterationStatementSemantics semantics} and + * {@link ForLoopIterationStatementTypeSemantics type semantics}. + */ +export * from "./for-loop-iteration-statement"; +export * from "./for-loop-iteration-statement-semantics"; +export * from "./for-loop-iteration-statement-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/index.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/index.ts new file mode 100644 index 000000000..44d3646f7 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/index.ts @@ -0,0 +1,10 @@ +/** + * Iteration statement AST nodes, which are statements that execute a block of code repeatedly until a given + * condition is met. + */ +export * from "./iteration-statement"; +export * from "./iteration-statement-semantics"; +export * from "./iteration-statement-type-semantics"; +export * from "./while-loop-iteration-statement/"; +export * from "./do-while-loop-iteration-statement/"; +export * from "./for-loop-iteration-statement/"; diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/iteration-statement-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/iteration-statement-semantics.ts new file mode 100644 index 000000000..83a53c234 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/iteration-statement-semantics.ts @@ -0,0 +1,25 @@ +/** + * Semantics for AST Node {@link IterationStatement}. + * @since 0.10.0 + */ +import type { Expression } from "../../expressions"; +import type { Statement } from "../statement"; +import type { StatementSemantics } from "../statement-semantics"; + +/** + * Semantics for AST Node {@link IterationStatement}. + * @since 0.10.0 + */ +export interface IterationStatementSemantics extends StatementSemantics { + /** + * The loop condition, which, if it evaluates to true will trigger the loop to continue executing. + * @since 0.10.0 + */ + loopCondition: Expression | undefined; + /** + * The body of the loop, which is handled and executed depending on the loop type and the value of + * {@link loopCondition}. + * @since 0.10.0 + */ + loopBody: Statement; +} diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/iteration-statement-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/iteration-statement-type-semantics.ts new file mode 100644 index 000000000..52e8aa3b6 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/iteration-statement-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Semantics for AST Node {@link IterationStatement}. + * @since 0.10.0 + */ +import type { StatementTypeSemantics } from "../statement-type-semantics"; + +/** + * Type semantics for AST Node {@link IterationStatement}. + * @since 0.10.0 + */ +export interface IterationStatementTypeSemantics extends StatementTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration/iteration-statement.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/iteration-statement.ts similarity index 55% rename from kipper/core/src/compiler/ast/nodes/statements/iteration/iteration-statement.ts rename to kipper/core/src/compiler/ast/nodes/statements/iteration-statement/iteration-statement.ts index efb66e57e..40bab5da0 100644 --- a/kipper/core/src/compiler/ast/nodes/statements/iteration/iteration-statement.ts +++ b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/iteration-statement.ts @@ -1,12 +1,13 @@ /** - * Iteration statement class, which represents an iteration/loop statement in the Kipper language and is compilable - * using {@link translateCtxAndChildren}. + * Iteration statement class, which represents an iteration statement that repeats a statement until a condition is + * met. Provides the base class for all iteration statements. + * @abstract */ -import { KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; -import { IterationStatementSemantics } from "../../../semantic-data"; -import { NoTypeSemantics } from "../../../ast-node"; +import type { IterationStatementSemantics } from "./iteration-statement-semantics"; +import type { IterationStatementTypeSemantics } from "./iteration-statement-type-semantics"; +import type { KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; +import type { ASTNodeMapper } from "../../../mapping"; import { Statement } from "../statement"; -import { ASTNodeMapper } from "../../../mapping/ast-node-mapper"; /** * Union type of all possible {@link ParserASTNode.kind} values for a constructable {@link MemberAccessExpression} AST @@ -24,7 +25,7 @@ export type ParserIterationStatementKind = * @since 0.10.0 */ export type ParserIterationStatementContext = InstanceType< - typeof ASTNodeMapper.statementKindToRuleContextMap[ParserIterationStatementKind] + (typeof ASTNodeMapper.statementKindToRuleContextMap)[ParserIterationStatementKind] >; /** @@ -32,15 +33,16 @@ export type ParserIterationStatementContext = InstanceType< * AST node. * @since 0.11.0 */ -export type ParserIterationStatementRuleName = typeof KindParseRuleMapping[ParserIterationStatementKind]; +export type ParserIterationStatementRuleName = (typeof KindParseRuleMapping)[ParserIterationStatementKind]; /** - * Iteration statement class, which represents an iteration/loop statement in the Kipper language and is compilable - * using {@link translateCtxAndChildren}. + * Iteration statement class, which represents an iteration statement that repeats a statement until a condition is + * met. Provides the base class for all iteration statements. + * @abstract */ export abstract class IterationStatement< Semantics extends IterationStatementSemantics = IterationStatementSemantics, - TypeSemantics extends NoTypeSemantics = NoTypeSemantics, + TypeSemantics extends IterationStatementTypeSemantics = IterationStatementTypeSemantics, > extends Statement { protected abstract readonly _antlrRuleCtx: ParserIterationStatementContext; public abstract get kind(): ParserIterationStatementKind; diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/while-loop-iteration-statement/index.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/while-loop-iteration-statement/index.ts new file mode 100644 index 000000000..117d7bb1a --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/while-loop-iteration-statement/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link WhileLoopIterationStatement} and the related {@link WhileLoopIterationStatementSemantics semantics} + * and {@link WhileLoopIterationStatementTypeSemantics type semantics}. + */ +export * from "./while-loop-iteration-statement"; +export * from "./while-loop-iteration-statement-semantics"; +export * from "./while-loop-iteration-statement-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/while-loop-iteration-statement/while-loop-iteration-statement-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/while-loop-iteration-statement/while-loop-iteration-statement-semantics.ts new file mode 100644 index 000000000..7e7cb2707 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/while-loop-iteration-statement/while-loop-iteration-statement-semantics.ts @@ -0,0 +1,24 @@ +/** + * Semantics for AST Node {@link WhileLoopIterationStatement}. + * @since 0.10.0 + */ +import type { IterationStatementSemantics } from "../iteration-statement-semantics"; +import type { Statement } from "../../statement"; +import type { Expression } from "../../../expressions"; + +/** + * Semantics for AST Node {@link WhileLoopIterationStatement}. + * @since 0.10.0 + */ +export interface WhileLoopStatementSemantics extends IterationStatementSemantics { + /** + * The loop condition, which, if it evaluates to true will trigger the loop to continue executing. + * @since 0.10.0 + */ + loopCondition: Expression; + /** + * The body of the loop, which is executed as long as {@link loopCondition} is true. + * @since 0.10.0 + */ + loopBody: Statement; +} diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/while-loop-iteration-statement/while-loop-iteration-statement-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/while-loop-iteration-statement/while-loop-iteration-statement-type-semantics.ts new file mode 100644 index 000000000..7cd34d21e --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/while-loop-iteration-statement/while-loop-iteration-statement-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link WhileLoopIterationStatement}. + * @since 0.11.0 + */ +import type { IterationStatementTypeSemantics } from "../iteration-statement-type-semantics"; + +/** + * Type semantics for AST Node {@link WhileLoopIterationStatement}. + * @since 0.11.0 + */ +export interface WhileLoopStatementTypeSemantics extends IterationStatementTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration/while-loop-iteration-statement.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/while-loop-iteration-statement/while-loop-iteration-statement.ts similarity index 88% rename from kipper/core/src/compiler/ast/nodes/statements/iteration/while-loop-iteration-statement.ts rename to kipper/core/src/compiler/ast/nodes/statements/iteration-statement/while-loop-iteration-statement/while-loop-iteration-statement.ts index 7df65aa13..9ae089c37 100644 --- a/kipper/core/src/compiler/ast/nodes/statements/iteration/while-loop-iteration-statement.ts +++ b/kipper/core/src/compiler/ast/nodes/statements/iteration-statement/while-loop-iteration-statement/while-loop-iteration-statement.ts @@ -2,18 +2,22 @@ * While loop statement class, which represents a while loop statement in the Kipper language and is compilable * using {@link translateCtxAndChildren}. */ -import type { CompilableNodeChild, CompilableNodeParent } from "../../../compilable-ast-node"; -import type { WhileLoopStatementSemantics } from "../../../semantic-data"; -import { IterationStatement } from "./iteration-statement"; -import { KindParseRuleMapping, ParseRuleKindMapping, WhileLoopIterationStatementContext } from "../../../../parser"; -import { Expression } from "../../expressions"; -import { Statement } from "../statement"; +import type { CompilableNodeChild, CompilableNodeParent } from "../../../../compilable-ast-node"; +import type { WhileLoopStatementSemantics } from "./while-loop-iteration-statement-semantics"; +import type { WhileLoopStatementTypeSemantics } from "./while-loop-iteration-statement-type-semantics"; +import type { Expression } from "../../../expressions"; +import { IterationStatement } from "../iteration-statement"; +import { KindParseRuleMapping, ParseRuleKindMapping, WhileLoopIterationStatementContext } from "../../../../../parser"; +import { Statement } from "../../statement"; /** * While loop statement class, which represents a while loop statement in the Kipper language and is compilable * using {@link translateCtxAndChildren}. */ -export class WhileLoopIterationStatement extends IterationStatement { +export class WhileLoopIterationStatement extends IterationStatement< + WhileLoopStatementSemantics, + WhileLoopStatementTypeSemantics +> { /** * The private field '_antlrRuleCtx' that actually stores the variable data, * which is returned inside the {@link this.antlrRuleCtx}. diff --git a/kipper/core/src/compiler/ast/nodes/statements/iteration/index.ts b/kipper/core/src/compiler/ast/nodes/statements/iteration/index.ts deleted file mode 100644 index 8044cfb86..000000000 --- a/kipper/core/src/compiler/ast/nodes/statements/iteration/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from "./iteration-statement"; -export * from "./while-loop-iteration-statement"; -export * from "./do-while-loop-iteration-statement"; -export * from "./for-loop-iteration-statement"; diff --git a/kipper/core/src/compiler/ast/nodes/statements/jump-statement/index.ts b/kipper/core/src/compiler/ast/nodes/statements/jump-statement/index.ts new file mode 100644 index 000000000..48671ee4b --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/jump-statement/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link JumpStatement} and the related {@link JumpStatementSemantics semantics} and + * {@link JumpStatementTypeSemantics type semantics}. + */ +export * from "./jump-statement"; +export * from "./jump-statement-semantics"; +export * from "./jump-statement-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/statements/jump-statement/jump-statement-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/jump-statement/jump-statement-semantics.ts new file mode 100644 index 000000000..b419e2c81 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/jump-statement/jump-statement-semantics.ts @@ -0,0 +1,24 @@ +/** + * Semantics for AST Node {@link JumpStatement}. + * @since 0.10.0 + */ +import type { SemanticData } from "../../../ast-node"; +import type { JmpStatementType } from "../../../../const"; +import type { IterationStatement } from "../iteration-statement"; + +/** + * Semantics for AST Node {@link JumpStatement}. + * @since 0.10.0 + */ +export interface JumpStatementSemantics extends SemanticData { + /** + * The type of the {@link JumpStatement jump statement}. + * @since 0.10.0 + */ + jmpType: JmpStatementType; + /** + * The parent statement of the {@link JumpStatement jump statement}. + * @since 0.10.0 + */ + parent: IterationStatement; +} diff --git a/kipper/core/src/compiler/ast/nodes/statements/jump-statement/jump-statement-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/jump-statement/jump-statement-type-semantics.ts new file mode 100644 index 000000000..838cb5e5d --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/jump-statement/jump-statement-type-semantics.ts @@ -0,0 +1,7 @@ +import { StatementTypeSemantics } from "../statement-type-semantics"; + +/** + * Type semantics for AST Node {@link JumpStatement}. + * @since 0.10.0 + */ +export interface JumpStatementTypeSemantics extends StatementTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/statements/jump-statement.ts b/kipper/core/src/compiler/ast/nodes/statements/jump-statement/jump-statement.ts similarity index 90% rename from kipper/core/src/compiler/ast/nodes/statements/jump-statement.ts rename to kipper/core/src/compiler/ast/nodes/statements/jump-statement/jump-statement.ts index e76c12b11..f599b75b8 100644 --- a/kipper/core/src/compiler/ast/nodes/statements/jump-statement.ts +++ b/kipper/core/src/compiler/ast/nodes/statements/jump-statement/jump-statement.ts @@ -2,18 +2,18 @@ * Jump statement class, which represents a jump/break statement in the Kipper language and is compilable using * {@link translateCtxAndChildren}. */ -import type { NoTypeSemantics } from "../../ast-node"; -import type { CompilableNodeParent } from "../../compilable-ast-node"; -import type { JumpStatementSemantics } from "../../semantic-data"; -import { Statement } from "./statement"; -import { JumpStatementContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../parser"; -import { Expression } from "../expressions"; +import type { CompilableNodeParent } from "../../../compilable-ast-node"; +import type { JumpStatementSemantics } from "./jump-statement-semantics"; +import type { JumpStatementTypeSemantics } from "./jump-statement-type-semantics"; +import { Statement } from "../statement"; +import { JumpStatementContext, KindParseRuleMapping, ParseRuleKindMapping } from "../../../../parser"; +import { Expression } from "../../expressions"; /** * Jump statement class, which represents a jump/break statement in the Kipper language and is compilable using * {@link translateCtxAndChildren}. */ -export class JumpStatement extends Statement { +export class JumpStatement extends Statement { /** * The private field '_antlrRuleCtx' that actually stores the variable data, * which is returned inside the {@link this.antlrRuleCtx}. diff --git a/kipper/core/src/compiler/ast/nodes/statements/return-statement/index.ts b/kipper/core/src/compiler/ast/nodes/statements/return-statement/index.ts new file mode 100644 index 000000000..320da2e9d --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/return-statement/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link ReturnStatement} and the related {@link ReturnStatementSemantics semantics} and + * {@link ReturnStatementTypeSemantics type semantics}. + */ +export * from "./return-statement"; +export * from "./return-statement-semantics"; +export * from "./return-statement-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/statements/return-statement/return-statement-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/return-statement/return-statement-semantics.ts new file mode 100644 index 000000000..a9833ebeb --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/return-statement/return-statement-semantics.ts @@ -0,0 +1,24 @@ +/** + * Semantics for AST Node {@link ReturnStatement}. + * @since 0.10.0 + */ +import type { SemanticData } from "../../../ast-node"; +import type { Expression } from "../../expressions"; +import type { FunctionDeclaration } from "../../declarations"; + +/** + * Semantics for AST Node {@link ReturnStatement}. + * @since 0.10.0 + */ +export interface ReturnStatementSemantics extends SemanticData { + /** + * The value of the {@link ReturnStatement}, which is optional, if the return type is void. + * @since 0.10.0 + */ + returnValue: Expression | undefined; + /** + * The function that this return statement is in. + * @since 0.10.0 + */ + function: FunctionDeclaration; +} diff --git a/kipper/core/src/compiler/ast/nodes/statements/return-statement/return-statement-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/return-statement/return-statement-type-semantics.ts new file mode 100644 index 000000000..37d842f7b --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/return-statement/return-statement-type-semantics.ts @@ -0,0 +1,18 @@ +/** + * Type semantics for a {@link ReturnStatement}. + * @since 0.10.0 + */ +import type { CheckedType } from "../../../../analysis"; +import type { StatementTypeSemantics } from "../statement-type-semantics"; + +/** + * Type semantics for a {@link ReturnStatement}. + * @since 0.10.0 + */ +export interface ReturnStatementTypeSemantics extends StatementTypeSemantics { + /** + * The type of value returned by this return statement. + * @since 0.10.0 + */ + returnType: CheckedType | undefined; +} diff --git a/kipper/core/src/compiler/ast/nodes/statements/return-statement.ts b/kipper/core/src/compiler/ast/nodes/statements/return-statement/return-statement.ts similarity index 90% rename from kipper/core/src/compiler/ast/nodes/statements/return-statement.ts rename to kipper/core/src/compiler/ast/nodes/statements/return-statement/return-statement.ts index 93567f71c..258700801 100644 --- a/kipper/core/src/compiler/ast/nodes/statements/return-statement.ts +++ b/kipper/core/src/compiler/ast/nodes/statements/return-statement/return-statement.ts @@ -2,13 +2,13 @@ * Jump statement class, which represents a jump/break statement in the Kipper language and is compilable using * {@link translateCtxAndChildren}. */ -import type { CompilableNodeParent } from "../../compilable-ast-node"; -import type { ReturnStatementSemantics } from "../../semantic-data"; -import type { ReturnStatementTypeSemantics } from "../../type-data"; -import { Statement } from "./statement"; -import { CheckedType } from "../../../analysis"; -import { KindParseRuleMapping, ParseRuleKindMapping, ReturnStatementContext } from "../../../parser"; -import { Expression } from "../expressions"; +import type { CompilableNodeParent } from "../../../compilable-ast-node"; +import type { ReturnStatementSemantics } from "./return-statement-semantics"; +import type { ReturnStatementTypeSemantics } from "./return-statement-type-semantics"; +import type { Expression } from "../../expressions"; +import { Statement } from "../statement"; +import { CheckedType } from "../../../../analysis"; +import { KindParseRuleMapping, ParseRuleKindMapping, ReturnStatementContext } from "../../../../parser"; /** * Jump statement class, which represents a jump/break statement in the Kipper language and is compilable using diff --git a/kipper/core/src/compiler/ast/nodes/statements/statement-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/statement-semantics.ts new file mode 100644 index 000000000..dee574abe --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/statement-semantics.ts @@ -0,0 +1,11 @@ +/** + * Semantics for AST Node {@link Statement}. + * @since 0.11.0 + */ +import type { SemanticData } from "../../ast-node"; + +/** + * Semantics for AST Node {@link Statement}. + * @since 0.11.0 + */ +export interface StatementSemantics extends SemanticData {} diff --git a/kipper/core/src/compiler/ast/nodes/statements/statement-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/statement-type-semantics.ts new file mode 100644 index 000000000..4489d60d1 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/statement-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Semantics for AST Node {@link Statement}. + * @since 0.11.0 + */ +import type { TypeData } from "../../ast-node"; + +/** + * Type semantics for AST Node {@link Statement}. + * @since 0.11.0 + */ +export interface StatementTypeSemantics extends TypeData {} diff --git a/kipper/core/src/compiler/ast/nodes/statements/statement.ts b/kipper/core/src/compiler/ast/nodes/statements/statement.ts index f4bb98d0a..a05fcca8b 100644 --- a/kipper/core/src/compiler/ast/nodes/statements/statement.ts +++ b/kipper/core/src/compiler/ast/nodes/statements/statement.ts @@ -2,10 +2,12 @@ * AST Node Statement classes of the Kipper language. * @since 0.1.0 */ -import type { CompilableNodeParent, SemanticData, TypeData } from "../../index"; +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"; /** @@ -16,8 +18,8 @@ import { CompilableASTNode } from "../../compilable-ast-node"; * @since 0.1.0 */ export abstract class Statement< - Semantics extends SemanticData = SemanticData, - TypeSemantics extends TypeData = TypeData, + Semantics extends StatementSemantics = StatementSemantics, + TypeSemantics extends StatementTypeSemantics = StatementTypeSemantics, > extends CompilableASTNode { /** * The private field '_antlrRuleCtx' that actually stores the variable data, diff --git a/kipper/core/src/compiler/ast/nodes/statements/switch-statement/index.ts b/kipper/core/src/compiler/ast/nodes/statements/switch-statement/index.ts new file mode 100644 index 000000000..f883e5a80 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/switch-statement/index.ts @@ -0,0 +1,7 @@ +/** + * AST Node {@link SwitchStatement} and the related {@link SwitchStatementSemantics semantics} and + * {@link SwitchStatementTypeSemantics type semantics}. + */ +export * from "./switch-statement"; +export * from "./switch-statement-semantics"; +export * from "./switch-statement-type-semantics"; diff --git a/kipper/core/src/compiler/ast/nodes/statements/switch-statement/switch-statement-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/switch-statement/switch-statement-semantics.ts new file mode 100644 index 000000000..e887087df --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/switch-statement/switch-statement-semantics.ts @@ -0,0 +1,11 @@ +/** + * Semantics for AST Node {@link SwitchStatement}. + * @since 0.11.0 + */ +import type { StatementSemantics } from "../statement-semantics"; + +/** + * Semantics for AST Node {@link SwitchStatement}. + * @since 0.11.0 + */ +export interface SwitchStatementSemantics extends StatementSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/statements/switch-statement/switch-statement-type-semantics.ts b/kipper/core/src/compiler/ast/nodes/statements/switch-statement/switch-statement-type-semantics.ts new file mode 100644 index 000000000..7dfd5da84 --- /dev/null +++ b/kipper/core/src/compiler/ast/nodes/statements/switch-statement/switch-statement-type-semantics.ts @@ -0,0 +1,11 @@ +/** + * Type semantics for AST Node {@link SwitchStatement}. + * @since 0.11.0 + */ +import { StatementTypeSemantics } from "../statement-type-semantics"; + +/** + * Type semantics for AST Node {@link SwitchStatement}. + * @since 0.11.0 + */ +export interface SwitchStatementTypeSemantics extends StatementTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/nodes/statements/switch-statement.ts b/kipper/core/src/compiler/ast/nodes/statements/switch-statement/switch-statement.ts similarity index 88% rename from kipper/core/src/compiler/ast/nodes/statements/switch-statement.ts rename to kipper/core/src/compiler/ast/nodes/statements/switch-statement/switch-statement.ts index e9e9e5c8e..33c255ba1 100644 --- a/kipper/core/src/compiler/ast/nodes/statements/switch-statement.ts +++ b/kipper/core/src/compiler/ast/nodes/statements/switch-statement/switch-statement.ts @@ -1,16 +1,17 @@ /** * Switch statement class, which represents a switch selection statement in the Kipper language. */ -import type { NoSemantics, NoTypeSemantics } from "../../ast-node"; -import type { CompilableNodeParent } from "../../compilable-ast-node"; -import { Statement } from "./statement"; -import { KindParseRuleMapping, ParseRuleKindMapping, SwitchStatementContext } from "../../../parser"; -import { KipperNotImplementedError } from "../../../../errors"; +import type { CompilableNodeParent } from "../../../compilable-ast-node"; +import type { SwitchStatementSemantics } from "./switch-statement-semantics"; +import type { SwitchStatementTypeSemantics } from "./switch-statement-type-semantics"; +import { Statement } from "../statement"; +import { KindParseRuleMapping, ParseRuleKindMapping, SwitchStatementContext } from "../../../../parser"; +import { KipperNotImplementedError } from "../../../../../errors"; /** * Switch statement class, which represents a switch selection statement in the Kipper language. */ -export class SwitchStatement extends Statement { +export class SwitchStatement extends Statement { /** * The private field '_antlrRuleCtx' that actually stores the variable data, * which is returned inside the {@link this.antlrRuleCtx}. diff --git a/kipper/core/src/compiler/ast/semantic-data/definitions.ts b/kipper/core/src/compiler/ast/semantic-data/definitions.ts deleted file mode 100644 index 53cdfc8bd..000000000 --- a/kipper/core/src/compiler/ast/semantic-data/definitions.ts +++ /dev/null @@ -1,131 +0,0 @@ -/** - * Semantic data declarations for all definition AST nodes. - * @since 0.10.0 - */ -import type { SemanticData } from "../ast-node"; -import type { KipperStorageType } from "../../const"; -import type { Scope } from "../../analysis"; -import { UncheckedType } from "../../analysis"; -import type { CompoundStatement, Expression } from "../nodes"; -import { IdentifierTypeSpecifierExpression } from "../nodes"; -import type { FunctionDeclaration, ParameterDeclaration } from "../nodes"; - -/** - * Semantics for a {@link Declaration}. - * @since 0.5.0 - */ -export interface DeclarationSemantics extends SemanticData { - /** - * The identifier of the declaration. - * @since 0.5.0 - */ - identifier: string; -} - -/** - * Semantics for AST Node {@link FunctionDeclaration}. - * @since 0.3.0 - */ -export interface FunctionDeclarationSemantics extends SemanticData { - /** - * The identifier of the function. - * @since 0.5.0 - */ - identifier: string; - /** - * The {@link KipperType return type} of the function. - * @since 0.5.0 - */ - returnType: UncheckedType; - /** - * The type specifier expression for the return type. - * @since 0.10.0 - */ - returnTypeSpecifier: IdentifierTypeSpecifierExpression; - /** - * Returns true if this declaration defines the function body for the function. - * @since 0.5.0 - */ - isDefined: boolean; - /** - * The available {@link ParameterDeclaration parameter} for the function invocation. - * @since 0.10.0 - */ - params: Array; - /** - * The body of the function. - * @since 0.10.0 - */ - functionBody: CompoundStatement; -} - -/** - * Semantics for AST Node {@link VariableDeclaration}. - * @since 0.3.0 - */ -export interface VariableDeclarationSemantics extends SemanticData { - /** - * The identifier of this variable. - * @since 0.5.0 - */ - identifier: string; - /** - * The storage type option for this variable. - * @since 0.5.0 - */ - storageType: KipperStorageType; - /** - * The type of the value as a string. - * - * The identifier of the {@link valueTypeSpecifier.semanticData.identifier typeSpecifier}. - * @since 0.5.0 - */ - valueType: UncheckedType; - /** - * The type specifier expression for the variable type. - * @since 0.10.0 - */ - valueTypeSpecifier: IdentifierTypeSpecifierExpression; - /** - * If this is true then the variable has a defined value. - * @since 0.5.0 - */ - isDefined: boolean; - /** - * The scope of this variable. - * @since 0.5.0 - */ - scope: Scope; - /** - * The assigned value to this variable. If {@link isDefined} is false, then this value is undefined. - * @since 0.7.0 - */ - value: Expression | undefined; -} - -/** - * Semantics for AST Node {@link ParameterDeclaration}. - * @since 0.5.0 - */ -export interface ParameterDeclarationSemantics extends DeclarationSemantics { - /** - * The identifier of the parameter. - * @since 0.5.0 - */ - identifier: string; - /** - * The {@link KipperType type} of the parameter. - * @since 0.5.0 - */ - valueType: UncheckedType; - /** - * The type specifier expression for the parameter type. - * @since 0.10.0 - */ - valueTypeSpecifier: IdentifierTypeSpecifierExpression; - /** - * The parent function of this parameter. - * @since 0.10.0 - */ - func: FunctionDeclaration; -} diff --git a/kipper/core/src/compiler/ast/semantic-data/expressions.ts b/kipper/core/src/compiler/ast/semantic-data/expressions.ts deleted file mode 100644 index bb706f3fc..000000000 --- a/kipper/core/src/compiler/ast/semantic-data/expressions.ts +++ /dev/null @@ -1,563 +0,0 @@ -/** - * Semantic data declarations for all expression AST nodes. - * @since 0.10.0 - */ -import type { - KipperAdditiveOperator, - KipperArithmeticOperator, - KipperAssignOperator, - KipperBoolTypeLiterals, - KipperComparativeOperator, - KipperEqualityOperator, - KipperIncrementOrDecrementOperator, - KipperLogicalAndOperator, - KipperLogicalOrOperator, - KipperMultiplicativeOperator, - KipperNullType, - KipperReferenceable, - KipperRelationalOperator, - KipperUnaryModifierOperator, - KipperUnaryOperator, - KipperUndefinedType, - KipperVoidType -} from "../../const"; -import type { SemanticData } from "../ast-node"; -import type { Expression, IdentifierPrimaryExpression } from "../nodes"; -import { IdentifierTypeSpecifierExpression } from "../nodes"; -import type { Reference, UncheckedType } from "../../analysis"; - -/** - * Static semantics for an expression class that must be evaluated during the Semantic Analysis. - * @since 0.10.0 - */ -export interface ExpressionSemantics extends SemanticData {} - -/** - * Semantics for AST Node {@link ConstantExpression}. - * @since 0.5.0 - */ -export interface ConstantExpressionSemantics extends ExpressionSemantics { - /** - * The value of the constant expression. This is usually either a {@link String} or {@link Number}. - * @since 0.5.0 - */ - value: any; -} - -/** - * Semantics for AST Node {@link NumberPrimaryExpression}. - * @since 0.5.0 - */ -export interface NumberPrimaryExpressionSemantics extends ConstantExpressionSemantics { - /** - * The value of the constant number expression. - * - * This can be either: - * - A Default 10-base number (N) - * - A Float 10-base number (N.N) - * - A Hex 16-base number (0xN) - * - A Octal 8-base number (0oN) - * - A Binary 2-base number (0bN) - * - An Exponent 10-base number (NeN) - * - An Exponent Float 10-base number (N.NeN) - * @since 0.5.0 - */ - value: string; -} - -/** - * Semantics for AST Node {@link ArrayLiteralPrimaryExpression}. - * @since 0.5.0 - */ -export interface ArrayLiteralPrimaryExpressionSemantics extends ConstantExpressionSemantics { - /** - * The value of the constant list expression. - * @since 0.5.0 - */ - value: Array; -} - -/** - * Semantics for AST Node {@link StringPrimaryExpression}. - * @since 0.5.0 - */ -export interface StringPrimaryExpressionSemantics extends ConstantExpressionSemantics { - /** - * The value of the constant string expression. - * @since 0.5.0 - */ - value: string; - /** - * The quotation marks that this string has used. - * - * This is important to keep track of, so that the translated string is valid and does not produce a syntax error - * due to unescaped quotation marks inside it. - * @since 0.10.0 - */ - quotationMarks: `"` | `'`; -} - -/** - * Semantics for AST Node {@link BoolPrimaryExpression}. - * @since 0.8.0 - */ -export interface BoolPrimaryExpressionSemantics extends ConstantExpressionSemantics { - /** - * The value of this boolean constant expression. - * @since 0.8.0 - */ - value: KipperBoolTypeLiterals; -} - -/** - * Semantics for AST Node {@link VoidOrNullOrUndefinedPrimaryExpression}. - * @since 0.10.0 - */ -export interface VoidOrNullOrUndefinedPrimaryExpressionSemantics extends ConstantExpressionSemantics { - /** - * The constant identifier of this expression. - * @since 0.10.0 - */ - constantIdentifier: KipperVoidType | KipperNullType | KipperUndefinedType; -} - -/** - * Semantics for AST Node {@link FStringPrimaryExpression}. - * @since 0.5.0 - */ -export interface FStringPrimaryExpressionSemantics extends ExpressionSemantics { - /** - * Returns the items of the f-strings, where each item represents one section of the string. The section may either be - * a {@link StringPrimaryExpression constant string} or {@link Expression evaluable runtime expression}. - * @since 0.10.0 - */ - atoms: Array; -} - -/** - * Semantics for AST Node {@link IdentifierPrimaryExpression}. - * @since 0.5.0 - */ -export interface IdentifierPrimaryExpressionSemantics extends ExpressionSemantics { - /** - * The identifier of the {@link IdentifierPrimaryExpressionSemantics.ref reference}. - * @since 0.5.0 - */ - identifier: string; - /** - * The reference that the {@link IdentifierPrimaryExpressionSemantics.identifier identifier} points to. - * @since 0.10.0 - */ - ref: Reference; -} - -/** - * Semantics for AST Node {@link TypeSpecifierExpression}. - */ -export interface TypeSpecifierExpressionSemantics extends ExpressionSemantics {} - -/** - * Semantics for AST Node {@link IdentifierTypeSpecifierExpression}. - * @since 0.8.0 - */ -export interface IdentifierTypeSpecifierExpressionSemantics extends TypeSpecifierExpressionSemantics { - /** - * The type specified by this expression. - * @since 0.8.0 - */ - typeIdentifier: UncheckedType; -} - -/** - * Semantics for AST Node {@link GenericTypeSpecifierExpression}. - * @since 0.8.0 - */ -export interface GenericTypeSpecifierExpressionSemantics extends TypeSpecifierExpressionSemantics { - // Not implemented. -} - -/** - * Semantics for AST Node {@link TypeofTypeSpecifierExpression}. - * @since 0.8.0 - */ -export interface TypeofTypeSpecifierExpressionSemantics extends TypeSpecifierExpressionSemantics { - // Not implemented. -} - -/** - * Semantics for AST Node {@link TangledPrimaryExpression}. - * @since 0.5.0 - */ -export interface TangledPrimaryExpressionSemantics extends ExpressionSemantics { - /** - * The child expression contained in this tangled expression. - * @since 0.10.0 - */ - childExp: Expression; -} - -/** - * Semantics for AST Node {@link IncrementOrDecrementPostfixExpression}. - * @since 0.5.0 - */ -export interface IncrementOrDecrementPostfixExpressionSemantics extends ExpressionSemantics { - /** - * The operator that is used to modify the {@link operand}. - * @since 0.10.0 - */ - operator: KipperIncrementOrDecrementOperator; - /** - * The operand that is modified by the operator. - * @since 0.10.0 - */ - operand: Expression; -} - -/** - * Semantics for AST Node {@link MemberAccessExpression}. - * @since 0.10.0 - */ -export interface MemberAccessExpressionSemantics extends ExpressionSemantics { - /** - * The object or array that is accessed. - * @since 0.10.0 - */ - objectLike: Expression; - /** - * The member that is accessed. This can be in three different forms: - * - Dot Notation: object.member - * - Bracket Notation: object["member"] - * - Slice Notation: object[1:3] - * @since 0.10.0 - */ - propertyIndexOrKeyOrSlice: string | Expression | { start?: Expression; end?: Expression }; - /** - * The type of the member access expression. Represented using strings. - * @since 0.10.0 - */ - accessType: "dot" | "bracket" | "slice"; -} - -/** - * Semantics for AST Node {@link FunctionCallExpression}. - * @since 0.5.0 - */ -export interface FunctionCallExpressionSemantics extends ExpressionSemantics { - /** - * The identifier of the function that is called. - * @since 0.5.0 - */ - identifier: string; - /** - * The function that is called by this expression. - * @since 0.5.0 - */ - callTarget: Reference; - /** - * The arguments that were passed to this function. - * @since 0.6.0 - */ - args: Array; -} - -/** - * Semantics for unary expressions, which can be used to modify an expression with - * a specified operator. - * @since 0.9.0 - */ -export interface UnaryExpressionSemantics extends ExpressionSemantics { - /** - * The operator that is used to modify the {@link operand}. - * @since 0.9.0 - */ - operator: KipperUnaryOperator; - /** - * The operand that is modified by the {@link operator}. - * @since 0.9.0 - */ - operand: Expression; -} - -/** - * Semantics for AST Node {@link IncrementOrDecrementUnaryExpression}. - * @since 0.5.0 - */ -export interface IncrementOrDecrementUnaryExpressionSemantics extends UnaryExpressionSemantics { - /** - * The operator that is used to modify the {@link operand}. - * @since 0.9.0 - */ - operator: KipperIncrementOrDecrementOperator; -} - -/** - * Semantics for AST Node {@link OperatorModifiedUnaryExpression}. - * @since 0.5.0 - */ -export interface OperatorModifiedUnaryExpressionSemantics extends UnaryExpressionSemantics { - /** - * The operator that is used to modify the {@link operand}. - * @since 0.9.0 - */ - operator: KipperUnaryModifierOperator; -} - -/** - * Semantics for AST Node {@link CastOrConvertExpression}. - * @since 0.5.0 - */ -export interface CastOrConvertExpressionSemantics extends ExpressionSemantics { - /** - * The expression to convert. - * @since 0.8.0 - */ - exp: Expression; - /** - * The type the {@link exp} should be converted to. - * @since 0.10.0 - */ - castType: UncheckedType; - /** - * The type specifier that determined {@link castType}. - * @since 0.10.0 - */ - castTypeSpecifier: IdentifierTypeSpecifierExpression; -} - -/** - * Semantics for arithmetic expressions ({@link MultiplicativeExpression} and {@link AdditiveExpression}). - * @since 0.6.0 - */ -export interface ArithmeticExpressionSemantics extends ExpressionSemantics { - /** - * The left operand of the expression. - * @since 0.10.0 - */ - leftOp: Expression; - /** - * The right operand of the expression. - * @since 0.10.0 - */ - rightOp: Expression; - /** - * The operator using the two values {@link this.leftOp leftOp} and {@link this.rightOp rightOp} to generate a result. - * @since 0.6.0 - */ - operator: KipperArithmeticOperator; -} - -/** - * Semantics for AST Node {@link MultiplicativeExpression}. - * @since 0.5.0 - */ -export interface MultiplicativeExpressionSemantics extends ArithmeticExpressionSemantics { - /** - * The first expression. The left side of the expression. - * @since 0.6.0 - */ - leftOp: Expression; - /** - * The second expression. The right side of the expression. - * @since 0.6.0 - */ - rightOp: Expression; - /** - * The operator using the two values {@link this.leftOp leftOp} and {@link this.rightOp rightOp} to generate a result. - * @since 0.6.0 - */ - operator: KipperMultiplicativeOperator; -} - -/** - * Semantics for AST Node {@link AdditiveExpression}. - * @since 0.5.0 - */ -export interface AdditiveExpressionSemantics extends ArithmeticExpressionSemantics { - /** - * The first expression. The left side of the expression. - * @since 0.6.0 - */ - leftOp: Expression; - /** - * The second expression. The right side of the expression. - * @since 0.6.0 - */ - rightOp: Expression; - /** - * The operator using the two values {@link this.leftOp leftOp} and {@link this.rightOp rightOp} to generate a result. - * @since 0.6.0 - */ - operator: KipperAdditiveOperator; -} - -/** - * Semantics for a comparative expression, which compares two operands against each other using a specified - * operator. - * @since 0.9.0 - */ -export interface ComparativeExpressionSemantics extends ExpressionSemantics { - /** - * The operator used to compare the two expressions of this comparative expression. - * @since 0.9.0 - */ - operator: KipperComparativeOperator; - /** - * The left expression (left-hand side) used in this comparative expression. - * @since 0.9.0 - */ - leftOp: Expression; - /** - * The right expression (right-hand side) used in this comparative expression. - * @since 0.9.0 - */ - rightOp: Expression; -} - -/** - * Semantics for AST Node {@link RelationalExpression}. - * @since 0.5.0 - */ -export interface RelationalExpressionSemantics extends ComparativeExpressionSemantics { - /** - * The operator used to compare the two expressions of this relational expression. - * @since 0.9.0 - */ - operator: KipperRelationalOperator; - /** - * The first expression (left-hand side) used in this relational expression. - * @since 0.9.0 - */ - leftOp: Expression; - /** - * The second expression (right-hand side) used in this relational expression. - * @since 0.9.0 - */ - rightOp: Expression; -} - -/** - * Semantics for AST Node {@link EqualityExpressionSemantics}. - * @since 0.5.0 - */ -export interface EqualityExpressionSemantics extends ComparativeExpressionSemantics { - /** - * The operator used to compare the two expressions of this equality expression. - * @since 0.9.0 - */ - operator: KipperEqualityOperator; - /** - * The first expression (left-hand side) used in this equality expression. - * @since 0.9.0 - */ - leftOp: Expression; - /** - * The second expression (right-hand side) used in this equality expression. - * @since 0.9.0 - */ - rightOp: Expression; -} - -/** - * Semantics for logical expressions, which combine two expressions/conditions and evaluate based on the input to a - * boolean value. - * @since 0.9.0 - */ -export interface LogicalExpressionSemantics extends ExpressionSemantics { - /** - * The operator used to combine the two expressions of this logical expression. - * @since 0.9.0 - */ - operator: KipperLogicalAndOperator | KipperLogicalOrOperator; - /** - * The first expression (left-hand side) used in this logical expression. - * @since 0.9.0 - */ - leftOp: Expression; - /** - * The second expression (right-hand side) used in this logical expression. - * @since 0.9.0 - */ - rightOp: Expression; -} - -/** - * Semantics for AST Node {@link LogicalAndExpression}. - * @since 0.5.0 - */ -export interface LogicalAndExpressionSemantics extends LogicalExpressionSemantics { - /** - * The operator used to combine the two expressions of this logical-and expression. - * @since 0.9.0 - */ - operator: KipperLogicalAndOperator; - /** - * The first expression (left-hand side) used in this logical-and expression. - * @since 0.9.0 - */ - leftOp: Expression; - /** - * The second expression (right-hand side) used in this logical-and expression. - * @since 0.9.0 - */ - rightOp: Expression; -} - -/** - * Semantics for AST Node {@link LogicalOrExpression}. - * @since 0.5.0 - */ -export interface LogicalOrExpressionSemantics extends LogicalExpressionSemantics { - /** - * The operator used to combine the two expressions of this logical-or expression. - * @since 0.9.0 - */ - operator: KipperLogicalOrOperator; - /** - * The first expression (left-hand side) used in this logical-or expression. - * @since 0.9.0 - */ - leftOp: Expression; - /** - * The second expression (right-hand side) used in this logical-or expression. - * @since 0.9.0 - */ - rightOp: Expression; -} - -/** - * Semantics for AST Node {@link ConditionalExpression}. - * @since 0.5.0 - */ -export interface ConditionalExpressionSemantics extends ExpressionSemantics {} - -/** - * Semantics for AST Node {@link AssignmentExpression}. - * @since 0.5.0 - */ -export interface AssignmentExpressionSemantics extends ExpressionSemantics { - /** - * The identifier expression that is being assigned to. - * @since 0.7.0 - */ - identifier: string; - /** - * The identifier AST node context that the {@link AssignmentExpressionSemantics.identifier identifier} points to. - * @since 0.10.0 - */ - identifierCtx: IdentifierPrimaryExpression; - /** - * The reference that is being assigned to. - * @since 0.10.0 - */ - assignTarget: Reference; - /** - * The assigned value to this variable. - * @since 0.7.0 - */ - value: Expression; - /** - * The operator of the assignment expression. - * @since 0.10.0 - */ - operator: KipperAssignOperator; -} diff --git a/kipper/core/src/compiler/ast/semantic-data/index.ts b/kipper/core/src/compiler/ast/semantic-data/index.ts deleted file mode 100644 index e2a5d1e3c..000000000 --- a/kipper/core/src/compiler/ast/semantic-data/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Semantic data declarations for all AST nodes. - * @since 0.10.0 - */ -export * from "./definitions"; -export * from "./expressions"; -export * from "./statements"; diff --git a/kipper/core/src/compiler/ast/semantic-data/statements.ts b/kipper/core/src/compiler/ast/semantic-data/statements.ts deleted file mode 100644 index c8aee2d0d..000000000 --- a/kipper/core/src/compiler/ast/semantic-data/statements.ts +++ /dev/null @@ -1,141 +0,0 @@ -/** - * Semantic data declarations for all statement AST nodes. - * @since 0.10.0 - */ -import type { SemanticData } from "../ast-node"; -import type { Expression, IfStatement, Statement } from "../nodes"; -import { IterationStatement } from "../nodes"; -import type { JmpStatementType } from "../../const"; -import type { FunctionDeclaration, VariableDeclaration } from "../nodes"; - -/** - * Semantics for AST Node {@link IfStatement}. - * @since 0.9.0 - */ -export interface IfStatementSemantics extends SemanticData { - /** - * The condition of the if-statement. - * @since 0.9.0 - */ - condition: Expression; - /** - * The body of the if-statement. - * @since 0.9.0 - */ - ifBranch: Statement; - /** - * The alternative (optional) branch of the if-statement. This alternative branch can either be: - * - An else branch, if the type is a regular {@link Statement} (the statement that should be - * evaluated in the else branch). - * - An else-if branch, if the type is another {@link IfStatement}. - * - Nothing (undefined), if it wasn't specified and the if statement does not have any more branches. - * @since 0.9.0 - */ - elseBranch?: IfStatement | Statement; -} - -/** - * Semantics for AST Node {@link IterationStatement}. - * @since 0.10.0 - */ -export interface IterationStatementSemantics extends SemanticData { - /** - * The loop condition, which, if it evaluates to true will trigger the loop to continue executing. - * @since 0.10.0 - */ - loopCondition: Expression | undefined; - /** - * The body of the loop, which is handled and executed depending on the loop type and the value of - * {@link loopCondition}. - * @since 0.10.0 - */ - loopBody: Statement; -} - -/** - * Semantics for AST Node {@link DoWhileLoopStatement}. - * @since 0.10.0 - */ -export interface DoWhileLoopStatementSemantics extends IterationStatementSemantics {} - -/** - * Semantics for AST Node {@link WhileLoopStatement}. - * @since 0.10.0 - */ -export interface WhileLoopStatementSemantics extends IterationStatementSemantics { - /** - * The loop condition, which, if it evaluates to true will trigger the loop to continue executing. - * @since 0.10.0 - */ - loopCondition: Expression; - /** - * The body of the loop, which is executed as long as {@link loopCondition} is true. - * @since 0.10.0 - */ - loopBody: Statement; -} - -/** - * Semantics for AST Node {@link ForLoopStatement}. - * @since 0.10.0 - */ -export interface ForLoopStatementSemantics extends IterationStatementSemantics { - /** - * The declaration/first statement of the loop, which is executed before the loop condition is evaluated. - * - * This may also simply be a single expression, if the loop does not have a declaration. - * @since 0.10.0 - */ - forDeclaration: VariableDeclaration | Expression | undefined; - /** - * The for iteration expression of the loop, which is executed after the loop body is executed. This is used to - * update the loop variable or execute any other code that should be executed after each loop iteration. - * @since 0.10.0 - */ - forIterationExp: Expression | undefined; - /** - * The for condition of the loop, which is evaluated after the loop body is executed. If this evaluates to true, - * the loop will continue executing. - * @since 0.10.0 - */ - loopCondition: Expression | undefined; - /** - * The body of the loop, which is executed as long as {@link loopCondition} is true. - * @since 0.10.0 - */ - loopBody: Statement; -} - -/** - * Semantics for AST Node {@link JumpStatement}. - * @since 0.10.0 - */ -export interface JumpStatementSemantics extends SemanticData { - /** - * The type of the {@link JumpStatement jump statement}. - * @since 0.10.0 - */ - jmpType: JmpStatementType; - /** - * The parent statement of the {@link JumpStatement jump statement}. - * @since 0.10.0 - */ - parent: IterationStatement; -} - -/** - * Semantics for AST Node {@link ReturnStatement}. - * @since 0.10.0 - */ -export interface ReturnStatementSemantics extends SemanticData { - /** - * The value of the {@link ReturnStatement}, which is optional, if the return type is void. - * @since 0.10.0 - */ - returnValue: Expression | undefined; - /** - * The function that this return statement is in. - * @since 0.10.0 - */ - function: FunctionDeclaration; -} diff --git a/kipper/core/src/compiler/ast/type-data/definitions.ts b/kipper/core/src/compiler/ast/type-data/definitions.ts deleted file mode 100644 index b4271a9ba..000000000 --- a/kipper/core/src/compiler/ast/type-data/definitions.ts +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Semantic type data declarations for all definition AST nodes. - * @since 0.10.0 - */ -import type { TypeData } from "../../ast"; -import type { CheckedType } from "../../analysis"; - -/** - * Type Semantics for a {@link Declaration}. - * @since 0.10.0 - */ -export interface DeclarationTypeData extends TypeData {} - -/** - * Type Semantics for AST Node {@link FunctionDeclaration}. - * @since 0.10.0 - */ -export interface FunctionDeclarationTypeSemantics extends TypeData { - /** - * The {@link KipperType return type} of the function. - * @since 0.10.0 - */ - returnType: CheckedType; -} - -/** - * Type Semantics for AST Node {@link ParameterDeclaration}. - * @since 0.10.0 - */ -export interface ParameterDeclarationTypeSemantics extends TypeData { - /** - * The {@link KipperType type} of the parameter. - * @since 0.10.0 - */ - valueType: CheckedType; -} - -/** - * Type Semantics for AST Node {@link VariableDeclaration}. - * @since 0.10.0 - */ -export interface VariableDeclarationTypeSemantics extends TypeData { - /** - * The type of the value that may be stored in this variable. - * - * This is the type evaluated using the {@link VariableDeclarationSemantics.valueType valueType identifier}. - * @since 0.10.0 - */ - valueType: CheckedType; -} diff --git a/kipper/core/src/compiler/ast/type-data/expressions.ts b/kipper/core/src/compiler/ast/type-data/expressions.ts deleted file mode 100644 index 74934211b..000000000 --- a/kipper/core/src/compiler/ast/type-data/expressions.ts +++ /dev/null @@ -1,238 +0,0 @@ -/** - * Semantic type data declarations for all expression AST nodes. - * @since 0.10.0 - */ -import type { KipperFunction } from "../../const"; -import type { TypeData } from "../../ast"; -import type { CheckedType } from "../../analysis"; - -/** - * Type semantics for an expression class that must be evaluated during Type Checking. - * @since 0.10.0 - */ -export interface ExpressionTypeSemantics extends TypeData { - /** - * The value type that this expression evaluates to. This is used to properly represent the evaluated type of - * expressions that do not explicitly show their type. - * - * This will always evaluate to "type", as a type specifier will always be a type. - * @since 0.10.0 - */ - evaluatedType: CheckedType; -} - -/** - * Type Semantics for AST Node {@link NumberPrimaryExpression}. - * @since 0.10.0 - */ -export interface NumberPrimaryExpressionTypeSemantics extends ExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link ArrayLiteralPrimaryExpression}. - * @since 0.10.0 - */ -export interface ArrayLiteralPrimaryExpressionTypeSemantics extends ExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link StringPrimaryExpression}. - * @since 0.10.0 - */ -export interface StringPrimaryExpressionTypeSemantics extends ExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link BoolPrimaryExpression}. - * @since 0.10.0 - */ -export interface BoolPrimaryExpressionTypeSemantics extends ExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link FStringPrimaryExpression}. - * @since 0.10.0 - */ -export interface FStringPrimaryExpressionTypeSemantics extends ExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link IdentifierPrimaryExpression}. - * @since 0.10.0 - */ -export interface IdentifierPrimaryExpressionTypeSemantics extends ExpressionTypeSemantics { - /** - * The value type that this expression evaluates to. - * - * This will always be the value type of the reference that the - * {@link IdentifierPrimaryExpressionSemantics.identifier identifier} points to. - * @since 0.10.0 - */ - evaluatedType: CheckedType; -} - -/** - * Type Semantics for AST Node {@link TypeSpecifierExpression}. - * @since 0.10.0 - */ -export interface TypeSpecifierExpressionTypeSemantics extends ExpressionTypeSemantics { - /** - * The type that is being stored by this type specifier. This is the type that would be used to determine what - * values should be stored in a variable. - * @since 0.10.0 - */ - storedType: CheckedType; -} - -/** - * Type Semantics for AST Node {@link IdentifierTypeSpecifierExpression}. - * @since 0.10.0 - */ -export interface IdentifierTypeSpecifierExpressionTypeSemantics extends TypeSpecifierExpressionTypeSemantics {} - -/** - * Semantics for AST Node {@link GenericTypeSpecifierExpression}. - * @since 0.10.0 - */ -export interface GenericTypeSpecifierExpressionTypeSemantics extends TypeSpecifierExpressionTypeSemantics { - // Not implemented. -} - -/** - * Type Semantics for AST Node {@link TypeofTypeSpecifierExpression}. - * @since 0.8.0 - */ -export interface TypeofTypeSpecifierExpressionTypeSemantics extends TypeSpecifierExpressionTypeSemantics { - // Not implemented. -} - -/** - * Type Semantics for AST Node {@link TangledPrimaryExpression}. - * @since 0.5.0 - */ -export interface TangledPrimaryTypeSemantics extends ExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link VoidOrNullOrUndefinedPrimaryExpression}. - * @since 0.10.0 - */ -export interface VoidOrNullOrUndefinedPrimaryExpressionTypeSemantics extends ExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link IncrementOrDecrementPostfixExpression}. - * @since 0.10.0 - */ -export interface IncrementOrDecrementPostfixExpressionTypeSemantics extends ExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link MemberAccessExpression}. - * @since 0.10.0 - */ -export interface MemberAccessExpressionTypeSemantics extends ExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link FunctionCallExpression}. - * @since 0.5.0 - */ -export interface FunctionCallExpressionTypeSemantics extends ExpressionTypeSemantics { - /** - * The function that this expression calls. Can be either a {@link ScopeFunctionDeclaration function declaration} or - * a {@link ScopeVariableDeclaration function in a variable}. - * @since 0.10.0 - */ - func: KipperFunction; -} - -/** - * Semantics for unary expressions, which can be used to modify an expression with - * a specified operator. - * @since 0.10.0 - */ -export interface UnaryExpressionTypeSemantics extends ExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link IncrementOrDecrementUnaryExpression}. - * @since 0.10.0 - */ -export interface IncrementOrDecrementUnaryTypeSemantics extends UnaryExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link OperatorModifiedUnaryExpression}. - * @since 0.10.0 - */ -export interface OperatorModifiedUnaryTypeSemantics extends UnaryExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link CastOrConvertExpression}. - * @since 0.10.0 - */ -export interface CastOrConvertExpressionTypeSemantics extends ExpressionTypeSemantics { - /** - * The type the {@link CastOrConvertExpressionSemantics.exp} should be converted to. - * @since 0.10.0 - */ - castType: CheckedType; -} - -/** - * Type Semantics for arithmetic expressions ({@link MultiplicativeExpression} and {@link AdditiveExpression}). - * @since 0.10.0 - */ -export interface ArithmeticExpressionTypeSemantics extends ExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link MultiplicativeExpression}. - * @since 0.10.0 - */ -export interface MultiplicativeTypeSemantics extends ArithmeticExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link AdditiveExpression}. - * @since 0.10.0 - */ -export interface AdditiveExpressionTypeSemantics extends ArithmeticExpressionTypeSemantics {} - -/** - * Type Semantics for a comparative expression, which compares two operands against each other using a specified - * operator. - * @since 0.10.0 - */ -export interface ComparativeExpressionTypeSemantics extends ExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link RelationalExpression}. - * @since 0.10.0 - */ -export interface RelationalExpressionTypeSemantics extends ComparativeExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link EqualityExpressionSemantics}. - * @since 0.10.0 - */ -export interface EqualityExpressionTypeSemantics extends ComparativeExpressionTypeSemantics {} - -/** - * Type Semantics for logical expressions, which combine two expressions/conditions and evaluate based on the input to a - * boolean value. - * @since 0.10.0 - */ -export interface LogicalExpressionTypeSemantics extends ExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link LogicalAndExpression}. - * @since 0.10.0 - */ -export interface LogicalAndExpressionTypeSemantics extends LogicalExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link LogicalOrExpression}. - * @since 0.10.0 - */ -export interface LogicalOrExpressionTypeSemantics extends LogicalExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link ConditionalExpression}. - * @since 0.10.0 - */ -export interface ConditionalExpressionTypeSemantics extends ExpressionTypeSemantics {} - -/** - * Type Semantics for AST Node {@link AssignmentExpression}. - * @since 0.10.0 - */ -export interface AssignmentExpressionTypeSemantics extends ExpressionTypeSemantics {} diff --git a/kipper/core/src/compiler/ast/type-data/index.ts b/kipper/core/src/compiler/ast/type-data/index.ts deleted file mode 100644 index e2a5d1e3c..000000000 --- a/kipper/core/src/compiler/ast/type-data/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Semantic data declarations for all AST nodes. - * @since 0.10.0 - */ -export * from "./definitions"; -export * from "./expressions"; -export * from "./statements"; diff --git a/kipper/core/src/compiler/ast/type-data/statements.ts b/kipper/core/src/compiler/ast/type-data/statements.ts deleted file mode 100644 index 635780729..000000000 --- a/kipper/core/src/compiler/ast/type-data/statements.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Semantic type data declarations for all statement AST nodes. - * @since 0.10.0 - */ -import type { TypeData } from "../../ast"; -import type { CheckedType } from "../../analysis"; - -/** - * Type Semantics for a {@link ReturnStatement}. - * @since 0.10.0 - */ -export interface ReturnStatementTypeSemantics extends TypeData { - /** - * The type of value returned by this return statement. - * @since 0.10.0 - */ - returnType: CheckedType | undefined; -} diff --git a/kipper/core/src/compiler/compile-config.ts b/kipper/core/src/compiler/compile-config.ts index 8a3feba8e..655a3f48a 100644 --- a/kipper/core/src/compiler/compile-config.ts +++ b/kipper/core/src/compiler/compile-config.ts @@ -6,7 +6,7 @@ import { BuiltInFunction, BuiltInVariable, kipperRuntimeBuiltInFunctions, - kipperRuntimeBuiltInVariables + kipperRuntimeBuiltInVariables, } from "./runtime-built-ins"; import { KipperCompileTarget } from "./target-presets"; import { defaultOptimisationOptions, OptimisationOptions } from "./optimiser"; @@ -217,7 +217,7 @@ export class EvaluatedCompileConfig implements CompileConfig { * @since 0.10.0 * @private */ - private getConfigOption(option: keyof typeof EvaluatedCompileConfig["defaults"], rawConfig: CompileConfig): T { + private getConfigOption(option: keyof (typeof EvaluatedCompileConfig)["defaults"], rawConfig: CompileConfig): T { if (rawConfig[option] !== undefined) { return rawConfig[option] as T; } diff --git a/kipper/core/src/compiler/const.ts b/kipper/core/src/compiler/const.ts index b22d0d803..5018e01bb 100644 --- a/kipper/core/src/compiler/const.ts +++ b/kipper/core/src/compiler/const.ts @@ -7,7 +7,7 @@ import type { ScopeFunctionDeclaration, ScopeParameterDeclaration, ScopeVariableDeclaration, - UndefinedCustomType + UndefinedCustomType, } from "./analysis"; import type { BuiltInFunction, BuiltInVariable } from "./runtime-built-ins"; import { InternalFunction } from "./runtime-built-ins"; diff --git a/kipper/core/src/compiler/parser/antlr/KipperParser.ts b/kipper/core/src/compiler/parser/antlr/KipperParser.ts index 284a17991..f42932edd 100644 --- a/kipper/core/src/compiler/parser/antlr/KipperParser.ts +++ b/kipper/core/src/compiler/parser/antlr/KipperParser.ts @@ -2320,11 +2320,8 @@ export class KipperParser extends Parser { return _localctx; } // @RuleVersion(0) - public arrayLiteralPrimaryExpression(): ArrayLiteralPrimaryExpressionContext { - let _localctx: ArrayLiteralPrimaryExpressionContext = new ArrayLiteralPrimaryExpressionContext( - this._ctx, - this.state, - ); + public arrayLiteralPrimaryExpression(): ArrayPrimaryExpressionContext { + let _localctx: ArrayPrimaryExpressionContext = new ArrayPrimaryExpressionContext(this._ctx, this.state); this.enterRule(_localctx, 76, KipperParser.RULE_arrayLiteralPrimaryExpression); let _la: number; try { @@ -5609,8 +5606,8 @@ export class PrimaryExpressionContext extends KipperParserRuleContext { public numberPrimaryExpression(): NumberPrimaryExpressionContext | undefined { return this.tryGetRuleContext(0, NumberPrimaryExpressionContext); } - public arrayLiteralPrimaryExpression(): ArrayLiteralPrimaryExpressionContext | undefined { - return this.tryGetRuleContext(0, ArrayLiteralPrimaryExpressionContext); + public arrayLiteralPrimaryExpression(): ArrayPrimaryExpressionContext | undefined { + return this.tryGetRuleContext(0, ArrayPrimaryExpressionContext); } public voidOrNullOrUndefinedPrimaryExpression(): VoidOrNullOrUndefinedPrimaryExpressionContext | undefined { return this.tryGetRuleContext(0, VoidOrNullOrUndefinedPrimaryExpressionContext); @@ -6001,7 +5998,7 @@ export class NumberPrimaryExpressionContext extends KipperParserRuleContext { } } -export class ArrayLiteralPrimaryExpressionContext extends KipperParserRuleContext { +export class ArrayPrimaryExpressionContext extends KipperParserRuleContext { public LeftBracket(): TerminalNode { return this.getToken(KipperParser.LeftBracket, 0); } @@ -6035,20 +6032,20 @@ export class ArrayLiteralPrimaryExpressionContext extends KipperParserRuleContex } // @Override public enterRule(listener: KipperParserListener): void { - if (listener.enterArrayLiteralPrimaryExpression) { - listener.enterArrayLiteralPrimaryExpression(this); + if (listener.enterArrayPrimaryExpression) { + listener.enterArrayPrimaryExpression(this); } } // @Override public exitRule(listener: KipperParserListener): void { - if (listener.exitArrayLiteralPrimaryExpression) { - listener.exitArrayLiteralPrimaryExpression(this); + if (listener.exitArrayPrimaryExpression) { + listener.exitArrayPrimaryExpression(this); } } // @Override public accept(visitor: KipperParserVisitor): Result { - if (visitor.visitArrayLiteralPrimaryExpression) { - return visitor.visitArrayLiteralPrimaryExpression(this); + if (visitor.visitArrayPrimaryExpression) { + return visitor.visitArrayPrimaryExpression(this); } else { return visitor.visitChildren(this); } diff --git a/kipper/core/src/compiler/parser/antlr/KipperParserListener.ts b/kipper/core/src/compiler/parser/antlr/KipperParserListener.ts index 923b51e5b..13856ea89 100644 --- a/kipper/core/src/compiler/parser/antlr/KipperParserListener.ts +++ b/kipper/core/src/compiler/parser/antlr/KipperParserListener.ts @@ -17,7 +17,7 @@ import { ActualRelationalExpressionContext, AdditiveExpressionContext, ArgumentExpressionListContext, - ArrayLiteralPrimaryExpressionContext, + ArrayPrimaryExpressionContext, AssignmentExpressionContext, AssignmentOperatorContext, BlockItemContext, @@ -98,7 +98,7 @@ import { UnaryOperatorContext, VariableDeclarationContext, VoidOrNullOrUndefinedPrimaryExpressionContext, - WhileLoopIterationStatementContext + WhileLoopIterationStatementContext, } from "./KipperParser"; /** @@ -853,12 +853,12 @@ export interface KipperParserListener extends ParseTreeListener { * Enter a parse tree produced by `KipperParser.arrayLiteralPrimaryExpression`. * @param ctx the parse tree */ - enterArrayLiteralPrimaryExpression?: (ctx: ArrayLiteralPrimaryExpressionContext) => void; + enterArrayPrimaryExpression?: (ctx: ArrayPrimaryExpressionContext) => void; /** * Exit a parse tree produced by `KipperParser.arrayLiteralPrimaryExpression`. * @param ctx the parse tree */ - exitArrayLiteralPrimaryExpression?: (ctx: ArrayLiteralPrimaryExpressionContext) => void; + exitArrayPrimaryExpression?: (ctx: ArrayPrimaryExpressionContext) => void; /** * Enter a parse tree produced by `KipperParser.voidOrNullOrUndefinedPrimaryExpression`. diff --git a/kipper/core/src/compiler/parser/antlr/KipperParserVisitor.ts b/kipper/core/src/compiler/parser/antlr/KipperParserVisitor.ts index f2d3c3418..4801f1c0f 100644 --- a/kipper/core/src/compiler/parser/antlr/KipperParserVisitor.ts +++ b/kipper/core/src/compiler/parser/antlr/KipperParserVisitor.ts @@ -17,7 +17,7 @@ import { ActualRelationalExpressionContext, AdditiveExpressionContext, ArgumentExpressionListContext, - ArrayLiteralPrimaryExpressionContext, + ArrayPrimaryExpressionContext, AssignmentExpressionContext, AssignmentOperatorContext, BlockItemContext, @@ -98,7 +98,7 @@ import { UnaryOperatorContext, VariableDeclarationContext, VoidOrNullOrUndefinedPrimaryExpressionContext, - WhileLoopIterationStatementContext + WhileLoopIterationStatementContext, } from "./KipperParser"; /** @@ -580,7 +580,7 @@ export interface KipperParserVisitor extends ParseTreeVisitor { * @param ctx the parse tree * @return the visitor result */ - visitArrayLiteralPrimaryExpression?: (ctx: ArrayLiteralPrimaryExpressionContext) => Result; + visitArrayPrimaryExpression?: (ctx: ArrayPrimaryExpressionContext) => Result; /** * Visit a parse tree produced by `KipperParser.voidOrNullOrUndefinedPrimaryExpression`. diff --git a/kipper/core/src/compiler/parser/parse-rule-kind-mapping.ts b/kipper/core/src/compiler/parser/parse-rule-kind-mapping.ts index 97e7c4f31..bca0c11f7 100644 --- a/kipper/core/src/compiler/parser/parse-rule-kind-mapping.ts +++ b/kipper/core/src/compiler/parser/parse-rule-kind-mapping.ts @@ -106,4 +106,4 @@ export const KindParseRuleMapping = >inv * internal purposes inside the parser. For completion’s sake, all numbers are listed here regardless. * @since 0.10.0 */ -export type ASTKind = typeof ParseRuleKindMapping[keyof typeof ParseRuleKindMapping]; +export type ASTKind = (typeof ParseRuleKindMapping)[keyof typeof ParseRuleKindMapping]; diff --git a/kipper/core/src/compiler/target-presets/semantic-analyser.ts b/kipper/core/src/compiler/target-presets/semantic-analyser.ts index bc332e245..b868139e5 100644 --- a/kipper/core/src/compiler/target-presets/semantic-analyser.ts +++ b/kipper/core/src/compiler/target-presets/semantic-analyser.ts @@ -6,7 +6,7 @@ import type { AdditiveExpression, AnalysableASTNode, - ArrayLiteralPrimaryExpression, + ArrayPrimaryExpression, AssignmentExpression, BoolPrimaryExpression, CastOrConvertExpression, @@ -43,7 +43,7 @@ import type { TypeofTypeSpecifierExpression, VariableDeclaration, VoidOrNullOrUndefinedPrimaryExpression, - WhileLoopIterationStatement + WhileLoopIterationStatement, } from "../ast"; import { KipperSemanticErrorHandler } from "../analysis"; @@ -134,9 +134,9 @@ export abstract class KipperTargetSemanticAnalyser extends KipperSemanticErrorHa public abstract numberPrimaryExpression?: TargetASTNodeSemanticAnalyser; /** - * Performs translation-specific semantic analysis for {@link ArrayLiteralPrimaryExpression} instances. + * Performs translation-specific semantic analysis for {@link ArrayPrimaryExpression} instances. */ - public abstract listPrimaryExpression?: TargetASTNodeSemanticAnalyser; + public abstract listPrimaryExpression?: TargetASTNodeSemanticAnalyser; /** * Performs translation-specific semantic analysis for {@link IdentifierPrimaryExpression} instances. diff --git a/kipper/core/src/compiler/target-presets/translation/code-generator.ts b/kipper/core/src/compiler/target-presets/translation/code-generator.ts index ada344487..37267cfe1 100644 --- a/kipper/core/src/compiler/target-presets/translation/code-generator.ts +++ b/kipper/core/src/compiler/target-presets/translation/code-generator.ts @@ -4,7 +4,7 @@ */ import type { AdditiveExpression, - ArrayLiteralPrimaryExpression, + ArrayPrimaryExpression, AssignmentExpression, BoolPrimaryExpression, CastOrConvertExpression, @@ -40,7 +40,7 @@ import type { TypeofTypeSpecifierExpression, VariableDeclaration, VoidOrNullOrUndefinedPrimaryExpression, - WhileLoopIterationStatement + WhileLoopIterationStatement, } from "../../ast"; import type { TranslatedCodeLine, TranslatedExpression } from "../../const"; import type { KipperProgramContext } from "../../program-ctx"; @@ -180,13 +180,10 @@ export abstract class KipperTargetCodeGenerator { public abstract numberPrimaryExpression: TargetASTNodeCodeGenerator; /** - * Translates a {@link ArrayLiteralPrimaryExpression} into a specific language. + * Translates a {@link ArrayPrimaryExpression} into a specific language. * @since 0.10.0 */ - public abstract arrayLiteralExpression: TargetASTNodeCodeGenerator< - ArrayLiteralPrimaryExpression, - TranslatedExpression - >; + public abstract arrayLiteralExpression: TargetASTNodeCodeGenerator; /** * Translates a {@link IdentifierPrimaryExpression} into a specific language. diff --git a/kipper/target-js/src/code-generator.ts b/kipper/target-js/src/code-generator.ts index 01590dcf1..2f82c2945 100644 --- a/kipper/target-js/src/code-generator.ts +++ b/kipper/target-js/src/code-generator.ts @@ -29,7 +29,7 @@ import { IncrementOrDecrementUnaryExpression, JumpStatement, KipperProgramContext, - ArrayLiteralPrimaryExpression, + ArrayPrimaryExpression, LogicalAndExpression, LogicalExpression, LogicalOrExpression, @@ -374,9 +374,9 @@ export class JavaScriptTargetCodeGenerator extends KipperTargetCodeGenerator { }; /** - * Translates a {@link ArrayLiteralPrimaryExpression} into the JavaScript language. + * Translates a {@link ArrayPrimaryExpression} into the JavaScript language. */ - arrayLiteralExpression = async (node: ArrayLiteralPrimaryExpression): Promise => { + arrayLiteralExpression = async (node: ArrayPrimaryExpression): Promise => { return []; }; diff --git a/kipper/target-js/src/semantic-analyser.ts b/kipper/target-js/src/semantic-analyser.ts index 826467677..2e86f7572 100644 --- a/kipper/target-js/src/semantic-analyser.ts +++ b/kipper/target-js/src/semantic-analyser.ts @@ -114,7 +114,7 @@ export class JavaScriptTargetSemanticAnalyser extends KipperTargetSemanticAnalys numberPrimaryExpression = undefined; /** - * Performs typescript-specific semantic analysis for {@link ArrayLiteralPrimaryExpression} instances. + * Performs typescript-specific semantic analysis for {@link ArrayPrimaryExpression} instances. */ listPrimaryExpression = undefined;