29 lines
484 B
C
29 lines
484 B
C
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include "rifle/ast.h"
|
|
|
|
int
|
|
ast_alloc_node(struct rifle_state *state, ast_type_t type, struct ast_node **res)
|
|
{
|
|
struct ast_node *node;
|
|
|
|
if (state == NULL) {
|
|
return -1;
|
|
}
|
|
|
|
node = ptrbox_alloc(&state->ptrbox, sizeof(*node));
|
|
if (node == NULL) {
|
|
return -1;
|
|
}
|
|
|
|
memset(node, 0, sizeof(*node));
|
|
node->type = type;
|
|
|
|
if (res != NULL) {
|
|
*res = node;
|
|
}
|
|
|
|
return 0;
|
|
}
|