fix memleak; initialization boilerplate

This commit is contained in:
2025-01-01 23:09:50 +02:00
parent 85dfbe9d09
commit 49c910b8b2
4 changed files with 239 additions and 21 deletions

32
ast.h
View File

@@ -33,15 +33,15 @@ typedef enum {
AST_NODE_TAG_ALIGNED_VAR_DECL,
/// lhs is the identifier token payload if any,
/// rhs is the deferred expression.
AST_NODE_TAG_AST_NODE_TAG_ERRDEFER,
AST_NODE_TAG_ERRDEFER,
/// lhs is unused.
/// rhs is the deferred expression.
AST_NODE_TAG_AST_NODE_TAG_DEFER,
AST_NODE_TAG_DEFER,
/// lhs catch rhs
/// lhs catch |err| rhs
/// main_token is the `catch` keyword.
/// payload is determined by looking at the next token after the `catch` keyword.
AST_NODE_TAG_AST_NODE_TAG_CATCH,
AST_NODE_TAG_CATCH,
/// `lhs.a`. main_token is the dot. rhs is the identifier token index.
AST_NODE_TAG_FIELD_ACCESS,
/// `lhs.?`. main_token is the dot. rhs is the `?` token index.
@@ -149,7 +149,7 @@ typedef enum {
/// `lhs | rhs`. main_token is the `|`.
AST_NODE_TAG_BIT_OR,
/// `lhs orelse rhs`. main_token is the `orelse`.
AST_NODE_TAG_AST_NODE_TAG_ORELSE,
AST_NODE_TAG_ORELSE,
/// `lhs and rhs`. main_token is the `and`.
AST_NODE_TAG_BOOL_AND,
/// `lhs or rhs`. main_token is the `or`.
@@ -165,9 +165,9 @@ typedef enum {
/// `op lhs`. rhs unused. main_token is op.
AST_NODE_TAG_ADDRESS_OF,
/// `op lhs`. rhs unused. main_token is op.
AST_NODE_TAG_AST_NODE_TAG_TRY,
AST_NODE_TAG_TRY,
/// `op lhs`. rhs unused. main_token is op.
AST_NODE_TAG_AST_NODE_TAG_AWAIT,
AST_NODE_TAG_AWAIT,
/// `?lhs`. rhs unused. main_token is the `?`.
AST_NODE_TAG_OPTIONAL_TYPE,
/// `[lhs]rhs`.
@@ -284,7 +284,7 @@ typedef enum {
AST_NODE_TAG_ASYNC_CALL_COMMA,
/// `switch(lhs) {}`. `SubRange[rhs]`.
/// `main_token` is the identifier of a preceding label, if any; otherwise `switch`.
AST_NODE_TAG_AST_NODE_TAG_SWITCH,
AST_NODE_TAG_SWITCH,
/// Same as switch except there is known to be a trailing comma
/// before the final rbrace
AST_NODE_TAG_SWITCH_COMMA,
@@ -310,32 +310,32 @@ typedef enum {
/// `while (lhs) |x| : (a) b else c`. `While[rhs]`.
/// `while (lhs) |x| : (a) b else |y| c`. `While[rhs]`.
/// The cont expression part `: (a)` may be omitted.
AST_NODE_TAG_AST_NODE_TAG_WHILE,
AST_NODE_TAG_WHILE,
/// `for (lhs) rhs`.
AST_NODE_TAG_FOR_SIMPLE,
/// `for (lhs[0..inputs]) lhs[inputs + 1] else lhs[inputs + 2]`. `For[rhs]`.
AST_NODE_TAG_AST_NODE_TAG_AST_NODE_TAG_FOR,
AST_NODE_TAG_FOR,
/// `lhs..rhs`. rhs can be omitted.
AST_NODE_TAG_AST_NODE_TAG_FOR_RANGE,
AST_NODE_TAG_FOR_RANGE,
/// `if (lhs) rhs`.
/// `if (lhs) |a| rhs`.
AST_NODE_TAG_IF_SIMPLE,
/// `if (lhs) a else b`. `If[rhs]`.
/// `if (lhs) |x| a else b`. `If[rhs]`.
/// `if (lhs) |x| a else |y| b`. `If[rhs]`.
AST_NODE_TAG_AST_NODE_TAG_AST_NODE_TAG_IF,
AST_NODE_TAG_IF,
/// `suspend lhs`. lhs can be omitted. rhs is unused.
AST_NODE_TAG_AST_NODE_TAG_AST_NODE_TAG_SUSPEND,
AST_NODE_TAG_SUSPEND,
/// `resume lhs`. rhs is unused.
AST_NODE_TAG_AST_NODE_TAG_AST_NODE_TAG_RESUME,
AST_NODE_TAG_RESUME,
/// `continue :lhs rhs`
/// both lhs and rhs may be omitted.
AST_NODE_TAG_AST_NODE_TAG_AST_NODE_TAG_CONTINUE,
AST_NODE_TAG_CONTINUE,
/// `break :lhs rhs`
/// both lhs and rhs may be omitted.
AST_NODE_TAG_AST_NODE_TAG_AST_NODE_TAG_BREAK,
AST_NODE_TAG_BREAK,
/// `return lhs`. lhs can be omitted. rhs is unused.
AST_NODE_TAG_AST_NODE_TAG_RETURN,
AST_NODE_TAG_RETURN,
/// `fn (a: lhs) rhs`. lhs can be omitted.
/// anytype and ... parameters are omitted from the AST tree.
/// main_token is the `fn` keyword.