Signed-off-by: erick-alcachofa <erick@artichoke.dev> This commit refactors several AST nodes to use `Optional<T>` for fields that are not always present. This includes `attribute` in `ReflectionExpression`, `elseBranch` in `IfStatement` and `WhileStatement`, `defaultCase` in `MatchStatement` and `SwitchStatement`, and `preLoop` and `postLoop` in `CForStatement`. This change improves the robustness and clarity of the AST by explicitly modeling optionality.
206 lines
4.7 KiB
C++
206 lines
4.7 KiB
C++
#pragma once
|
|
|
|
#include <artichoke/Parser/AST/Common.hpp>
|
|
#include <artichoke/Parser/AST/Literals.hpp>
|
|
|
|
namespace arti::lang::ast {
|
|
|
|
namespace nodes {
|
|
/* Forward declaration of types */
|
|
|
|
/* Main declaration node types */
|
|
struct IdentifierExpression;
|
|
struct UnaryExpression;
|
|
struct BinaryExpression;
|
|
struct AssignExpression;
|
|
struct CompoundAssignExpression;
|
|
struct FunctionCallExpression;
|
|
struct SliceAccessExpression;
|
|
struct SliceRangeExpression;
|
|
struct MemberAccessExpression;
|
|
struct PointerAccessExpression;
|
|
struct ScopeAccessExpression;
|
|
struct ReflectionExpression;
|
|
struct SliceCreationExpression;
|
|
struct SliceLengthExpression;
|
|
struct SlicePtrExpression;
|
|
|
|
} // namespace nodes
|
|
|
|
/* Public Aliases */
|
|
using IdentifierExprNode = Ptr<nodes::IdentifierExpression>;
|
|
using UnaryExprNode = Ptr<nodes::UnaryExpression>;
|
|
using BinaryExprNode = Ptr<nodes::BinaryExpression>;
|
|
using AssignExprNode = Ptr<nodes::AssignExpression>;
|
|
using CompoundAssignExprNode = Ptr<nodes::CompoundAssignExpression>;
|
|
using FunctionCallExprNode = Ptr<nodes::FunctionCallExpression>;
|
|
using SliceAccessExprNode = Ptr<nodes::SliceAccessExpression>;
|
|
using SliceRangeExprNode = Ptr<nodes::SliceRangeExpression>;
|
|
using MemberAccessExprNode = Ptr<nodes::MemberAccessExpression>;
|
|
using PointerAccessExprNode = Ptr<nodes::PointerAccessExpression>;
|
|
using ScopeAccessExprNode = Ptr<nodes::ScopeAccessExpression>;
|
|
using ReflectionExprNode = Ptr<nodes::ReflectionExpression>;
|
|
using SliceCreationExprNode = Ptr<nodes::SliceCreationExpression>;
|
|
using SliceLengthExprNode = Ptr<nodes::SliceLengthExpression>;
|
|
using SlicePtrExprNode = Ptr<nodes::SlicePtrExpression>;
|
|
|
|
/* Variant nodes */
|
|
using ExpressionNode = Variant<
|
|
CharLtrlNode,
|
|
NullLtrlNode,
|
|
StringLtrlNode,
|
|
FloatLtrlNode,
|
|
IntegerLtrlNode,
|
|
BooleanLtrlNode,
|
|
StructLtrlNode,
|
|
SliceLtrlNode,
|
|
IdentifierExprNode,
|
|
UnaryExprNode,
|
|
BinaryExprNode,
|
|
AssignExprNode,
|
|
CompoundAssignExprNode,
|
|
FunctionCallExprNode,
|
|
SliceAccessExprNode,
|
|
SliceRangeExprNode,
|
|
MemberAccessExprNode,
|
|
PointerAccessExprNode,
|
|
ScopeAccessExprNode,
|
|
SliceCreationExprNode,
|
|
SliceLengthExprNode,
|
|
SlicePtrExprNode,
|
|
ReflectionExprNode
|
|
>;
|
|
|
|
/* Node definitions */
|
|
struct nodes::IdentifierExpression {
|
|
SourceLocation location;
|
|
String identifierName;
|
|
};
|
|
|
|
struct nodes::UnaryExpression {
|
|
SourceLocation location;
|
|
UnaryOperator op;
|
|
ExpressionNode right;
|
|
};
|
|
|
|
struct nodes::BinaryExpression {
|
|
SourceLocation location;
|
|
|
|
BinaryOperator op;
|
|
ExpressionNode left;
|
|
ExpressionNode right;
|
|
};
|
|
|
|
struct nodes::AssignExpression {
|
|
SourceLocation location;
|
|
|
|
ExpressionNode left;
|
|
ExpressionNode right;
|
|
};
|
|
|
|
struct nodes::CompoundAssignExpression {
|
|
SourceLocation location;
|
|
|
|
CompoundAssignOperator op;
|
|
ExpressionNode left;
|
|
ExpressionNode right;
|
|
};
|
|
|
|
struct nodes::FunctionCallExpression {
|
|
SourceLocation location;
|
|
|
|
ExpressionNode callee;
|
|
Vector<ExpressionNode> arguments;
|
|
};
|
|
|
|
struct nodes::SliceAccessExpression {
|
|
SourceLocation location;
|
|
|
|
ExpressionNode slice;
|
|
ExpressionNode index;
|
|
};
|
|
|
|
struct nodes::SliceRangeExpression {
|
|
SourceLocation location;
|
|
|
|
ExpressionNode slice;
|
|
Optional<ExpressionNode> start;
|
|
Optional<ExpressionNode> end;
|
|
};
|
|
|
|
struct nodes::MemberAccessExpression {
|
|
SourceLocation location;
|
|
|
|
String memberName;
|
|
ExpressionNode object;
|
|
};
|
|
|
|
struct nodes::PointerAccessExpression {
|
|
SourceLocation location;
|
|
|
|
String memberName;
|
|
ExpressionNode object;
|
|
};
|
|
|
|
struct nodes::ScopeAccessExpression {
|
|
SourceLocation location;
|
|
|
|
String memberName;
|
|
ExpressionNode scope;
|
|
Vector<TypeNode> genericParams;
|
|
};
|
|
|
|
struct nodes::ReflectionExpression {
|
|
SourceLocation location;
|
|
|
|
Optional<String> attribute;
|
|
ExpressionNode object;
|
|
};
|
|
|
|
struct nodes::SliceCreationExpression {
|
|
SourceLocation location;
|
|
|
|
ExpressionNode object;
|
|
ExpressionNode length;
|
|
};
|
|
|
|
struct nodes::SliceLengthExpression {
|
|
SourceLocation location;
|
|
|
|
ExpressionNode object;
|
|
};
|
|
|
|
struct nodes::SlicePtrExpression {
|
|
SourceLocation location;
|
|
|
|
ExpressionNode object;
|
|
};
|
|
|
|
struct nodes::StructLiteralNamedFieldInit {
|
|
SourceLocation location;
|
|
|
|
String fieldName;
|
|
ExpressionNode fieldValue;
|
|
};
|
|
|
|
struct nodes::StructLiteralPositionalInit {
|
|
SourceLocation location;
|
|
|
|
ExpressionNode fieldValue;
|
|
};
|
|
|
|
struct nodes::StructLiteralNamedInitializer {
|
|
SourceLocation location;
|
|
|
|
Vector<StructLtrlNamedFieldInitNode> fields;
|
|
};
|
|
|
|
struct nodes::StructLiteralPositionalInitializer {
|
|
SourceLocation location;
|
|
|
|
Vector<StructLtrlPositionalInitNode> fields;
|
|
};
|
|
|
|
} // namespace arti::lang::ast
|
|
|