refactor(AST): Make optional some fields in AST nodes
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.
This commit is contained in:
parent
d979b10bee
commit
9626ac07c8
@ -36,7 +36,7 @@ namespace arti::lang::ast {
|
||||
using FunctionParamNode = Ptr<nodes::FunctionParam>;
|
||||
using EnumMemberNode = Ptr<nodes::EnumMember>;
|
||||
using StructMemberNode = Ptr<nodes::StructMember>;
|
||||
|
||||
|
||||
/* Variant nodes */
|
||||
using TopLevelDeclNode = Variant<
|
||||
ModuleDeclNode,
|
||||
@ -81,7 +81,7 @@ namespace arti::lang::ast {
|
||||
String name;
|
||||
Vector<GenericParamNode> genericParams;
|
||||
Vector<EnumMemberNode> enumMembers;
|
||||
};
|
||||
};
|
||||
|
||||
struct nodes::FunctionDeclaration {
|
||||
SourceLocation location;
|
||||
@ -121,7 +121,7 @@ namespace arti::lang::ast {
|
||||
String name;
|
||||
Optional<TypeNode> type;
|
||||
};
|
||||
|
||||
|
||||
struct nodes::GenericParam {
|
||||
SourceLocation location;
|
||||
|
||||
@ -130,7 +130,7 @@ namespace arti::lang::ast {
|
||||
|
||||
struct nodes::FunctionParam {
|
||||
SourceLocation location;
|
||||
|
||||
|
||||
Boolean isThis;
|
||||
String name;
|
||||
TypeNode type;
|
||||
|
||||
@ -153,7 +153,7 @@ namespace arti::lang::ast {
|
||||
struct nodes::ReflectionExpression {
|
||||
SourceLocation location;
|
||||
|
||||
String attribute;
|
||||
Optional<String> attribute;
|
||||
ExpressionNode object;
|
||||
};
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ namespace arti::lang::ast {
|
||||
struct WhileStatement;
|
||||
struct DoWhileStatement;
|
||||
struct InfLoopStatement;
|
||||
struct ExpressionStatement;
|
||||
struct ExpressionStatement;
|
||||
|
||||
/* Helper declaration node types */
|
||||
struct MatchCase;
|
||||
@ -54,7 +54,7 @@ namespace arti::lang::ast {
|
||||
using ExpressionStmtNode = Ptr<nodes::ExpressionStatement>;
|
||||
using MatchCaseNode = Ptr<nodes::MatchCase>;
|
||||
using SwitchCaseNode = Ptr<nodes::SwitchCase>;
|
||||
|
||||
|
||||
/* Variant nodes */
|
||||
using StatementNode = Variant<
|
||||
VariableStmtNode,
|
||||
@ -71,7 +71,7 @@ namespace arti::lang::ast {
|
||||
WhileStmtNode,
|
||||
DoWhileStmtNode,
|
||||
InfLoopStmtNode,
|
||||
ExpressionStmtNode
|
||||
ExpressionStmtNode
|
||||
>;
|
||||
|
||||
using ElseBranchNode = Variant<
|
||||
@ -88,7 +88,7 @@ namespace arti::lang::ast {
|
||||
VariableStmtNode,
|
||||
ExpressionStmtNode
|
||||
>;
|
||||
|
||||
|
||||
/* Node definitions */
|
||||
|
||||
struct nodes::CodeBlockStatement {
|
||||
@ -112,7 +112,7 @@ namespace arti::lang::ast {
|
||||
Optional<String> unwrappedVar;
|
||||
ExpressionNode condition;
|
||||
CodeBlockStmtNode body;
|
||||
ElseBranchNode elseBranch;
|
||||
Optional<ElseBranchNode> elseBranch;
|
||||
};
|
||||
|
||||
struct nodes::ElseStatement {
|
||||
@ -157,7 +157,7 @@ namespace arti::lang::ast {
|
||||
|
||||
ExpressionNode value;
|
||||
Vector<MatchCaseNode> matchCases;
|
||||
CodeBlockStmtNode defaultCase;
|
||||
Optional<CodeBlockStmtNode> defaultCase;
|
||||
};
|
||||
|
||||
struct nodes::SwitchStatement {
|
||||
@ -165,16 +165,16 @@ namespace arti::lang::ast {
|
||||
|
||||
ExpressionNode value;
|
||||
Vector<SwitchCaseNode> switchCases;
|
||||
CodeBlockStmtNode defaultCase;
|
||||
Optional<CodeBlockStmtNode> defaultCase;
|
||||
};
|
||||
|
||||
struct nodes::CForStatement {
|
||||
SourceLocation location;
|
||||
|
||||
Optional<String> label;
|
||||
PreLoopStmtNode preLoop;
|
||||
Optional<PreLoopStmtNode> preLoop;
|
||||
ExpressionNode condition;
|
||||
ExpressionNode postLoop;
|
||||
Optional<ExpressionNode> postLoop;
|
||||
CodeBlockStmtNode body;
|
||||
};
|
||||
|
||||
@ -195,7 +195,7 @@ namespace arti::lang::ast {
|
||||
Optional<String> unwrappedVar;
|
||||
ExpressionNode condition;
|
||||
CodeBlockStmtNode body;
|
||||
ElseBranchNode elseBranch;
|
||||
Optional<ElseBranchNode> elseBranch;
|
||||
};
|
||||
|
||||
struct nodes::DoWhileStatement {
|
||||
@ -218,7 +218,7 @@ namespace arti::lang::ast {
|
||||
|
||||
ExpressionNode expression;
|
||||
};
|
||||
|
||||
|
||||
struct nodes::MatchCase {
|
||||
SourceLocation location;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user