Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
epidemian
GitHub Repository: epidemian/gravity
Path: blob/master/src/compiler/gravity_visitor.h
1214 views
1
//
2
// gravity_visitor.h
3
// gravity
4
//
5
// Created by Marco Bambini on 08/09/14.
6
// Copyright (c) 2014 CreoLabs. All rights reserved.
7
//
8
9
#ifndef __GRAVITY_VISITOR__
10
#define __GRAVITY_VISITOR__
11
12
#include "gravity_ast.h"
13
14
#define visit(node) gvisit(self, node)
15
16
typedef struct gvisitor {
17
uint32_t nerr; // to store err counter state
18
void *data; // to store a ptr state
19
void *delegate; // delegate callback
20
21
// count must be equal to enum gnode_n defined in gravity_ast.h less 3
22
23
// STATEMENTS: 7
24
void (* visit_list_stmt)(struct gvisitor *self, gnode_compound_stmt_t *node);
25
void (* visit_compound_stmt)(struct gvisitor *self, gnode_compound_stmt_t *node);
26
void (* visit_label_stmt)(struct gvisitor *self, gnode_label_stmt_t *node);
27
void (* visit_flow_stmt)(struct gvisitor *self, gnode_flow_stmt_t *node);
28
void (* visit_jump_stmt)(struct gvisitor *self, gnode_jump_stmt_t *node);
29
void (* visit_loop_stmt)(struct gvisitor *self, gnode_loop_stmt_t *node);
30
void (* visit_empty_stmt)(struct gvisitor *self, gnode_empty_stmt_t *node);
31
32
// DECLARATIONS: 5+1 (NODE_VARIABLE handled by NODE_VARIABLE_DECL case)
33
void (* visit_function_decl)(struct gvisitor *self, gnode_function_decl_t *node);
34
void (* visit_variable_decl)(struct gvisitor *self, gnode_variable_decl_t *node);
35
void (* visit_enum_decl)(struct gvisitor *self, gnode_enum_decl_t *node);
36
void (* visit_class_decl)(struct gvisitor *self, gnode_class_decl_t *node);
37
void (* visit_module_decl)(struct gvisitor *self, gnode_module_decl_t *node);
38
39
// EXPRESSIONS: 7+3 (CALL EXPRESSIONS handled by one callback)
40
void (* visit_binary_expr)(struct gvisitor *self, gnode_binary_expr_t *node);
41
void (* visit_unary_expr)(struct gvisitor *self, gnode_unary_expr_t *node);
42
void (* visit_file_expr)(struct gvisitor *self, gnode_file_expr_t *node);
43
void (* visit_literal_expr)(struct gvisitor *self, gnode_literal_expr_t *node);
44
void (* visit_identifier_expr)(struct gvisitor *self, gnode_identifier_expr_t *node);
45
void (* visit_keyword_expr)(struct gvisitor *self, gnode_keyword_expr_t *node);
46
void (* visit_list_expr)(struct gvisitor *self, gnode_list_expr_t *node);
47
void (* visit_postfix_expr)(struct gvisitor *self, gnode_postfix_expr_t *node);
48
} gvisitor_t;
49
50
void gvisit(gvisitor_t *self, gnode_t *node);
51
52
#endif
53
54