Skip to content

Commit

Permalink
Split up semantic-data and type-data into individual files
Browse files Browse the repository at this point in the history
These semantic data and type data interfaces are now grouped together with their corresponding AST node in their own directory. This is to help make the AST structure more clear and finish the AST update.
  • Loading branch information
Luna-Klatzer committed Oct 17, 2023
1 parent c3ee71a commit 886627f
Show file tree
Hide file tree
Showing 234 changed files with 2,756 additions and 1,710 deletions.
30 changes: 28 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import {
IterationStatement,
JumpStatement,
ReturnStatement,
VariableDeclaration
VariableDeclaration,
} from "../../ast";
import { KipperSemanticsAsserter } from "./err-handler";
import {
LocalScope,
Scope,
ScopeDeclaration,
ScopeFunctionDeclaration,
ScopeVariableDeclaration
ScopeVariableDeclaration,
} from "../symbol-table";
import {
BuiltInOrInternalGeneratorFunctionNotFoundError,
Expand All @@ -37,7 +37,7 @@ import {
MissingFunctionBodyError,
UndefinedConstantError,
UndefinedReferenceError,
UnknownReferenceError
UnknownReferenceError,
} from "../../../errors";

/**
Expand Down
8 changes: 4 additions & 4 deletions kipper/core/src/compiler/analysis/analyser/type-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { KipperProgramContext } from "../../program-ctx";
import type {
IncrementOrDecrementPostfixExpressionSemantics,
ParameterDeclarationSemantics,
UnaryExpressionSemantics
UnaryExpressionSemantics,
} from "../../ast";
import {
AssignmentExpression,
Expand All @@ -24,7 +24,7 @@ import {
ReturnStatement,
Statement,
TangledPrimaryExpression,
UnaryExpression
UnaryExpression,
} from "../../ast";
import { KipperSemanticsAsserter } from "./err-handler";
import { ScopeDeclaration, ScopeParameterDeclaration, ScopeVariableDeclaration } from "../symbol-table";
Expand All @@ -37,7 +37,7 @@ import {
KipperReferenceable,
KipperReferenceableFunction,
kipperStrType,
kipperSupportedConversions
kipperSupportedConversions,
} from "../../const";
import {
ArgumentTypeError,
Expand All @@ -55,7 +55,7 @@ import {
KipperNotImplementedError,
ReadOnlyWriteTypeError,
UnknownTypeError,
ValueNotIndexableTypeError
ValueNotIndexableTypeError,
} from "../../../errors";
import { CheckedType, UncheckedType, UndefinedCustomType } from "../type";

Expand Down
2 changes: 1 addition & 1 deletion kipper/core/src/compiler/analysis/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { InternalFunction } from "../runtime-built-ins";
* identifier's metadata and reference expression.
* @since 0.8.0
*/
export interface Reference<T extends KipperReferenceable> {
export interface Reference<T extends KipperReferenceable = KipperReferenceable> {
/**
* The target that this reference points to.
* @since 0.8.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
FunctionDeclaration,
FunctionDeclarationSemantics,
FunctionDeclarationTypeSemantics,
ParameterDeclaration
ParameterDeclaration,
} from "../../../ast";
import { ScopeDeclaration } from "./scope-declaration";
import { CheckedType } from "../../type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
FunctionDeclaration,
ParameterDeclaration,
ParameterDeclarationSemantics,
ParameterDeclarationTypeSemantics
ParameterDeclarationTypeSemantics,
} from "../../../ast";
import type { LocalScope } from "../index";
import type { CheckedType } from "../../type";
Expand Down
12 changes: 5 additions & 7 deletions kipper/core/src/compiler/ast/ast-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
ASTNodeParserContext,
ParserDeclarationContext,
ParserExpressionContext,
ParserStatementContext
ParserStatementContext,
} from "./common";
import type { ParseTreeListener } from "antlr4ts/tree/ParseTreeListener";
import type {
Expand All @@ -19,7 +19,7 @@ import type {
ActualLogicalOrExpressionContext,
ActualMultiplicativeExpressionContext,
ActualRelationalExpressionContext,
ArrayLiteralPrimaryExpressionContext,
ArrayPrimaryExpressionContext,
BoolPrimaryExpressionContext,
BracketNotationMemberAccessExpressionContext,
CompilationUnitContext,
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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`.
Expand Down
80 changes: 40 additions & 40 deletions kipper/core/src/compiler/ast/common/ast-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
import type {
AdditiveExpressionContext,
ArrayLiteralPrimaryExpressionContext,
ArrayPrimaryExpressionContext,
AssignmentExpressionContext,
BoolPrimaryExpressionContext,
BracketNotationMemberAccessExpressionContext,
Expand Down Expand Up @@ -41,7 +41,7 @@ import type {
TypeofTypeSpecifierExpressionContext,
VariableDeclarationContext,
VoidOrNullOrUndefinedPrimaryExpressionContext,
WhileLoopIterationStatementContext
WhileLoopIterationStatementContext,
} from "../../parser";
import { KindParseRuleMapping } from "../../parser";

Expand All @@ -51,7 +51,7 @@ import { KindParseRuleMapping } from "../../parser";
*/
export type ParserExpressionContext =
| NumberPrimaryExpressionContext
| ArrayLiteralPrimaryExpressionContext
| ArrayPrimaryExpressionContext
| IdentifierPrimaryExpressionContext
| VoidOrNullOrUndefinedPrimaryExpressionContext
| BoolPrimaryExpressionContext
Expand Down Expand Up @@ -185,57 +185,57 @@ 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
* node.
* @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
* node.
* @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}.
Expand Down
2 changes: 1 addition & 1 deletion kipper/core/src/compiler/ast/compilable-ast-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class DeclarationASTNodeFactory extends ASTNodeFactory<Declaration, Parse
* A union of all construable Declaration AST node classes.
* @since 0.10.0
*/
export type ConstructableASTDeclarationClass = typeof DeclarationASTNodeFactory.ruleMapping[ASTDeclarationKind];
export type ConstructableASTDeclarationClass = (typeof DeclarationASTNodeFactory.ruleMapping)[ASTDeclarationKind];

/**
* A union of all construable Declaration AST nodes. Uses {@link ConstructableASTDeclarationClass} to infer the type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class ExpressionASTNodeFactory extends ASTNodeFactory<Expression, ParserE
* A union of all construable Expression AST node classes.
* @since 0.10.0
*/
export type ConstructableASTExpressionClass = typeof ExpressionASTNodeFactory.ruleMapping[ASTExpressionKind];
export type ConstructableASTExpressionClass = (typeof ExpressionASTNodeFactory.ruleMapping)[ASTExpressionKind];

/**
* A union of all construable Expression AST nodes. Uses {@link ConstructableASTExpressionClass} to infer the type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class StatementASTNodeFactory extends ASTNodeFactory<Statement, ParserExp
* A union of all construable Statement AST node classes.
* @since 0.10.0
*/
export type ConstructableASTStatementClass = typeof StatementASTNodeFactory.ruleMapping[ASTStatementKind];
export type ConstructableASTStatementClass = (typeof StatementASTNodeFactory.ruleMapping)[ASTStatementKind];

/**
* A union of all construable Statement AST nodes. Uses {@link ConstructableASTStatementClass} to infer the type.
Expand Down
2 changes: 0 additions & 2 deletions kipper/core/src/compiler/ast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ export * from "./compilable-ast-node";
export * from "./scope-node";
export * from "./mapping/";
export * from "./factories/";
export * from "./semantic-data/";
export * from "./type-data/";
export * from "./nodes/";
Loading

0 comments on commit 886627f

Please sign in to comment.