erick-alcachofa c4c3d71cc4
feat(AST): Refactor AST nodes into a multi-file structure
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

This commit refactors the AST (Abstract Syntax Tree) to improve code
organization, clarity, and maintainability. The large single-file AST
definition has been split into multiple, logically grouped header files.

The key changes are:

- **New File Structure**: The single `Node.hpp` file is replaced by a
  modular structure consisting of `Common.hpp`, `Declarations.hpp`,
  `Expressions.hpp`, `Literals.hpp`, `Statements.hpp`, and a new central
  `AST.hpp` header.
- **Improved Naming**: All AST node structs and their aliases have been
  renamed to follow a consistent `[NodeName][NodeType]` convention, such
  as `StructDeclaration` and `StructDeclNode`.
- **Namespace Change**: The `node` namespace has been replaced by
  `arti::lang::ast::nodes` to provide better encapsulation and prevent
  naming conflicts.
- **Type Aliases**: Helper aliases like `String`, `Vector`, and
  `Variant` have been introduced to simplify the code.
2025-10-12 17:40:29 -06:00

110 lines
2.5 KiB
C++

#pragma once
#include <artichoke/Parser/AST/Common.hpp>
#include <artichoke/Parser/AST/Types.hpp>
namespace arti::lang::ast {
namespace nodes {
/* Forward declaration of types */
/* Main declaration node types */
struct CharLiteral;
struct NullLiteral;
struct StringLiteral;
struct FloatLiteral;
struct IntegerLiteral;
struct BooleanLiteral;
struct StructLiteral;
struct SliceLiteral;
/* Helper declaration node types */
struct StructLiteralNamedFieldInit;
struct StructLiteralPositionalInit;
struct StructLiteralNamedInitializer;
struct StructLiteralPositionalInitializer;
} // namespace nodes
/* Public Aliases */
using CharLtrlNode = Ptr<nodes::CharLiteral>;
using NullLtrlNode = Ptr<nodes::NullLiteral>;
using StringLtrlNode = Ptr<nodes::StringLiteral>;
using FloatLtrlNode = Ptr<nodes::FloatLiteral>;
using IntegerLtrlNode = Ptr<nodes::IntegerLiteral>;
using BooleanLtrlNode = Ptr<nodes::BooleanLiteral>;
using StructLtrlNode = Ptr<nodes::StructLiteral>;
using SliceLtrlNode = Ptr<nodes::SliceLiteral>;
using StructLtrlNamedFieldInitNode =
Ptr<nodes::StructLiteralNamedFieldInit>;
using StructLtrlPositionalInitNode =
Ptr<nodes::StructLiteralPositionalInit>;
using StructLtrlNamedInitializerNode =
Ptr<nodes::StructLiteralNamedInitializer>;
using StructLtrlPositionalInitializerNode =
Ptr<nodes::StructLiteralPositionalInitializer>;
/* Variant nodes */
using StructLtrlInitializerNode = Variant<
StructLtrlNamedInitializerNode,
StructLtrlPositionalInitializerNode
>;
/* Node definitions */
struct nodes::CharLiteral {
SourceLocation location;
uint8_t value;
};
struct nodes::NullLiteral {
SourceLocation location;
};
struct nodes::StringLiteral {
SourceLocation location;
String value;
};
struct nodes::FloatLiteral {
SourceLocation location;
double value;
};
struct nodes::IntegerLiteral {
SourceLocation location;
uint64_t value;
};
struct nodes::BooleanLiteral {
SourceLocation location;
Boolean value;
};
struct nodes::StructLiteral {
SourceLocation location;
TypeNode type;
Optional<StructLtrlInitializerNode> initializer;
};
struct nodes::SliceLiteral {
SourceLocation location;
TypeNode type;
Optional<StructLtrlPositionalInitializerNode> initializer;
};
/* INFO: Helper types definitions are on Expressions.hpp
* due to dependency in ExpressionNode variant. */
} // namespace arti::lang::ast