Luma 0.1.0
A low-level compiled alternative to C, C++, and more!
Loading...
Searching...
No Matches
ast_utils.h
Go to the documentation of this file.
1#pragma once
2
3#include "ast.h"
4#include <stdio.h>
5
6#define IS_EXPR(node) ((node)->type >= AST_EXPR_LITERAL && (node)->type <= AST_EXPR_GROUPING)
7#define IS_STMT(node) ((node)->type >= AST_STMT_EXPRESSION && (node)->type <= AST_STMT_STRUCT)
8#define IS_TYPE(node) ((node)->type >= AST_TYPE_BASIC && (node)->type <= AST_TYPE_ENUM)
9
10#define IS_PROGRAM(node) ((node)->type == AST_PROGRAM)
11#define IS_EXPR_STMT(node) ((node)->type == AST_STMT_EXPRESSION)
12#define IS_LITERAL(node) ((node)->type == AST_EXPR_LITERAL)
13#define IS_BINARY(node) ((node)->type == AST_EXPR_BINARY)
14#define IS_GROUPING(node) ((node)->type == AST_EXPR_GROUPING)
15#define IS_UNARY(node) ((node)->type == AST_EXPR_UNARY)
16#define IS_CALL(node) ((node)->type == AST_EXPR_CALL)
17#define IS_VAR_DECL(node) ((node)->type == AST_STMT_VAR_DECL)
18#define IS_FUNC_DECL(node) ((node)->type == AST_STMT_FUNCTION)
19#define IS_BLOCK(node) ((node)->type == AST_STMT_BLOCK)
20#define IS_IF(node) ((node)->type == AST_STMT_IF)
21#define IS_LOOP(node) ((node)->type == AST_STMT_LOOP)
22#define IS_RETURN(node) ((node)->type == AST_STMT_RETURN)
23
24const char *node_type_to_string(NodeType type);
25const char *binop_to_string(BinaryOp op);
26const char *unop_to_string(UnaryOp op);
27const char *literal_type_to_string(LiteralType type);
28
29void print_prefix(const char *prefix, bool is_last);
30void print_ast(const AstNode *node, const char *prefix, bool is_last, bool root);
Abstract Syntax Tree definitions with documentation comment support.
LiteralType
Definition ast.h:85
BinaryOp
Definition ast.h:97
UnaryOp
Definition ast.h:121
NodeType
Definition ast.h:18
void print_prefix(const char *prefix, bool is_last)
Definition ast_utils.c:201
const char * literal_type_to_string(LiteralType type)
Definition ast_utils.c:182
const char * node_type_to_string(NodeType type)
Definition ast_utils.c:13
void print_ast(const AstNode *node, const char *prefix, bool is_last, bool root)
Definition ast_utils.c:219
const char * unop_to_string(UnaryOp op)
Definition ast_utils.c:155
const char * binop_to_string(BinaryOp op)
Definition ast_utils.c:108
Definition ast.h:142