Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AST Restructuring & Mapping Update #507

Merged
merged 7 commits into from
Oct 17, 2023

Conversation

Luna-Klatzer
Copy link
Member

What type of change does this PR perform?

  • Development or internal changes (These changes do not add new features or fix bugs, but update the code in other ways)
  • New feature (Non-breaking change which adds functionality)

Summary

Cleaned up internal AST structure and added additional mapping functionality, allowing more seamless mappings between kind and ruleName, and their associated AST class.

Summary of Changes

  • Renamed many items to be more clear and fit the given naming scheme.
  • Added new class ASTNodeMapper for handling mappings.
  • Restructured internal AST module structure in @kipper/core.
  • Added new required field ruleName for all AST node classes.

Does this PR create new warnings?

No.

Detailed Changelog

Not present for website/docs changes

  • New modules:
    • kipper/core/tools, which contains all tools and utilities used by the compiler.
    • kipper/core/tools/decorators, which contains all decorators used by the compiler.
    • kipper/core/tools/functions, which contains all functions used by the compiler.
    • kipper/core/tools/types, which contains all types used by the compiler.
    • kipper/core/compiler/ast/common, which contains commonly used types and functions.
    • kipper/core/compiler/ast/factories, which replaces the old file factories.ts and contains all AST factory
      classes and types.
    • 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 field:
    • ParserASTNode.ruleName, which contains the rule name of the node.
  • New functions:
    • KipperTargetBuiltInGenerator.voidToStr(), for the built-in conversion from void to str.
    • KipperTargetBuiltInGenerator.nullToStr(), for the built-in conversion from null to str.
    • KipperTargetBuiltInGenerator.undefinedToStr(), for the built-in conversion from undefined to str.
    • replaceObjKeys(), which replaces the keys of an object with the values returned by a function.
    • inverseMap(), which inverts a map by swapping the keys and values.

Changed

  • Renamed:
    • Class FunctionCallPostfixTypeSemantics to FunctionCallExpressionTypeSemantics.
    • Field FStringPrimaryExpressionSemantics.items to atoms.
    • Function getTSFunction() to genTSFunction().
    • Grammar Rule typeSpecifier to typeSpecifierExpression and its AST class TypeSpecifier to TypeSpecifierExpression. This also includes changing the name in the KipperTargetCodeGenerator, KipperTargetSemanticAnalyser and KipperTargetBuiltInGenerator classes.
    • Grammar Rule identifierTypeSpecifier to identifierTypeSpecifierExpression and its AST class IdentifierTypeSpecifier to IdentifierTypeSpecifierExpression. This also includes changing the name in the KipperTargetCodeGenerator, KipperTargetSemanticAnalyser and KipperTargetBuiltInGenerator classes.
    • Grammar Rule genericTypeSpecifier to genericTypeSpecifierExpression and its AST class GenericTypeSpecifier to GenericTypeSpecifierExpression. This also includes changing the name in the KipperTargetCodeGenerator, KipperTargetSemanticAnalyser and KipperTargetBuiltInGenerator classes.
    • Grammar Rule typeofTypeSpecifier to typeofTypeSpecifierExpression and its AST class TypeofTypeSpecifier to TypeofTypeSpecifierExpression. This also includes changing the name in the KipperTargetCodeGenerator, KipperTargetSemanticAnalyser and KipperTargetBuiltInGenerator classes.
    • Grammar Rule forLoopStatement to forLoopIterationStatement and its AST class ForLoopStatement to ForLoopIterationStatement. This also includes changing the name in the KipperTargetCodeGenerator, KipperTargetSemanticAnalyser and KipperTargetBuiltInGenerator classes.
    • Grammar Rule whileLoopStatement to whileLoopIterationStatement and its AST class WhileLoopStatement to WhileLoopIterationStatement. This also includes changing the name in the KipperTargetCodeGenerator, KipperTargetSemanticAnalyser and KipperTargetBuiltInGenerator classes.
    • Grammar Rule doWhileLoopStatement to doWhileLoopIterationStatement and its AST class 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/compiler/ast/ast-types.ts to the new kipper/core/compiler/ast/common module.

Linked issues or PRs

No linked issues.

This primarily helps improve security by having more strict type inference and clearness navigating the code, as things should be more directly accessible now. In addition with the improved mapping of kind ids and rule names the connection between the AST and the parser is more streamlined and clear.
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.
@Luna-Klatzer Luna-Klatzer added feature New feature or enhancement other Other development related change or issue labels Oct 17, 2023
@Luna-Klatzer Luna-Klatzer added this to the v0.11.0 milestone Oct 17, 2023
@Luna-Klatzer Luna-Klatzer self-assigned this Oct 17, 2023
@Luna-Klatzer Luna-Klatzer changed the base branch from main to dev-next October 17, 2023 14:03
@codecov
Copy link

codecov bot commented Oct 17, 2023

Codecov Report

Attention: 92 lines in your changes are missing coverage. Please review.

Files Coverage Δ
kipper/cli/src/commands/compile.ts 81.25% <ø> (ø)
kipper/cli/src/commands/run.ts 32.50% <ø> (ø)
...nalysis/analyser/err-handler/semantics-asserter.ts 100.00% <100.00%> (ø)
...is/analyser/err-handler/semantics-error-handler.ts 45.45% <100.00%> (ø)
...src/compiler/analysis/analyser/semantic-checker.ts 92.00% <100.00%> (ø)
...ore/src/compiler/analysis/analyser/type-checker.ts 70.81% <ø> (ø)
...e/src/compiler/analysis/analyser/warning-issuer.ts 80.00% <100.00%> (ø)
...c/compiler/analysis/symbol-table/function-scope.ts 90.00% <ø> (ø)
.../src/compiler/analysis/symbol-table/local-scope.ts 95.00% <ø> (ø)
...ipper/core/src/compiler/ast/analysable-ast-node.ts 85.48% <ø> (ø)
... and 130 more

📢 Thoughts on this report? Let us know!.

@Luna-Klatzer Luna-Klatzer merged commit 7458beb into dev-next Oct 17, 2023
29 of 31 checks passed
@Luna-Klatzer Luna-Klatzer deleted the ast-restructuring-and-mapping-update branch October 21, 2023 10:28
@Luna-Klatzer Luna-Klatzer restored the ast-restructuring-and-mapping-update branch October 21, 2023 11:54
@Luna-Klatzer Luna-Klatzer deleted the ast-restructuring-and-mapping-update branch October 21, 2023 12:00
@Luna-Klatzer Luna-Klatzer mentioned this pull request Feb 10, 2024
16 tasks
@Luna-Klatzer Luna-Klatzer removed the feature New feature or enhancement label Jul 5, 2024
@Luna-Klatzer Luna-Klatzer mentioned this pull request Jul 10, 2024
41 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
other Other development related change or issue
Projects
Development

Successfully merging this pull request may close these issues.

1 participant