Skip to content

Commit 8dff898

Browse files
refactor(wheel_parser): add null assertions to node constructors
Add not_null assertions in Node and StatementNode constructors to validate that token pointers are not null during construction. This improves defensive programming by catching invalid inputs early.
1 parent 80f538b commit 8dff898

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

wheel_parser/nodes.cxx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include <vector>
22
#include "wheel_parser/ast/nodes.hxx"
33
#include "wheel_parser/ast/symbol.hxx"
4+
#include <wheel_utils/logging.hxx>
5+
6+
USE_WHEEL_ASSERTION
47

58
using wheel_parser::ast::Node;
69
using wheel_parser::ast::StatementNode;
@@ -13,10 +16,14 @@ using wheel_parser::ast::IdentifierExpression;
1316
using wheel_parser::ast::VariableDeclaration;
1417

1518
Node::Node(NodeKind node_kind,
16-
const Token* token) noexcept : node_kind(node_kind), token(token) {}
19+
const Token* token) noexcept : node_kind(node_kind), token(token) {
20+
not_null<const Token*>(token);
21+
}
1722

1823
StatementNode::StatementNode(NodeKind node_kind,
19-
const Token *token) noexcept : Node(node_kind, token) {}
24+
const Token *token) noexcept : Node(node_kind, token) {
25+
not_null<const Token*>(token);
26+
}
2027

2128
FunctionDeclaration::FunctionDeclaration(const Token *token,
2229
SymbolID func_name,

0 commit comments

Comments
 (0)