]> git.xonotic.org Git - xonotic/gmqcc.git/blob - parser.h
Stuff
[xonotic/gmqcc.git] / parser.h
1 #ifndef GMQCC_PARSER_HDR
2 #define GMQCC_PARSER_HDR
3 #include "gmqcc.h"
4 #include "lexer.h"
5 #include "ast.h"
6
7 #include "intrin.h"
8 #include "fold.h"
9
10 #define parser_ctx(p) ((p).lex->tok.ctx)
11
12 struct parser_t {
13     parser_t();
14     ~parser_t();
15
16     void remove_ast();
17
18     lex_file *lex;
19     Token tok;
20
21     bool ast_cleaned;
22
23     std::vector<ast_expression *> globals;
24     std::vector<ast_expression *> fields;
25     std::vector<ast_function *> functions;
26     size_t translated;
27
28     /* must be deleted first, they reference immediates and values */
29     std::vector<ast_value *> accessors;
30
31     ast_value *nil;
32     ast_value *reserved_version;
33
34     size_t crc_globals;
35     size_t crc_fields;
36
37     ast_function *function;
38     ht aliases;
39
40     /* All the labels the function defined...
41      * Should they be in ast_function instead?
42      */
43     std::vector<ast_label*> labels;
44     std::vector<ast_goto*> gotos;
45     std::vector<const char *> breaks;
46     std::vector<const char *> continues;
47
48     /* A list of hashtables for each scope */
49     std::vector<ht> variables;
50     ht htfields;
51     ht htglobals;
52     std::vector<ht> typedefs;
53
54     /* not to be used directly, we use the hash table */
55     std::vector<ast_expression*> _locals;
56     std::vector<size_t> _blocklocals;
57     std::vector<std::unique_ptr<ast_value>> _typedefs;
58     std::vector<size_t> _blocktypedefs;
59     std::vector<lex_ctx_t> _block_ctx;
60
61     /* we store the '=' operator info */
62     const oper_info *assign_op;
63
64     /* magic values */
65     ast_value *const_vec[3];
66
67     /* pragma flags */
68     bool noref;
69
70     /* collected information */
71     size_t max_param_count;
72
73     fold m_fold;
74     intrin m_intrin;
75 };
76
77 /* parser.c */
78 inline char *parser_strdup(const char *str)
79 {
80     if (str && !*str) {
81         /* actually dup empty strings */
82         auto *out = reinterpret_cast<char*>(mem_a(1));
83         *out = 0;
84         return out;
85     }
86     return util_strdup(str);
87 }
88 ast_expression *parser_find_global(parser_t &parser, const char *name);
89 parser_t *parser_create();
90 bool parser_compile_file(parser_t &parser, const char *);
91 bool parser_compile_string(parser_t &parser, const char *, const char *, size_t);
92 bool parser_finish(parser_t &parser, const char *);
93
94 #endif