]> git.xonotic.org Git - xonotic/gmqcc.git/blob - parser.h
search for funciton param first before function locals, this fixes #163
[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 struct parser_t;
11
12 #define parser_ctx(p) ((p)->lex->tok.ctx)
13
14 struct parser_t {
15     parser_t();
16     ~parser_t();
17
18     void remove_ast();
19
20     lex_file *lex;
21     int tok;
22
23     bool ast_cleaned;
24
25     std::vector<ast_expression *> globals;
26     std::vector<ast_expression *> fields;
27     std::vector<ast_function *> functions;
28     size_t translated;
29
30     /* must be deleted first, they reference immediates and values */
31     std::vector<ast_value *> accessors;
32
33     ast_value *nil;
34     ast_value *reserved_version;
35
36     size_t crc_globals;
37     size_t crc_fields;
38
39     ast_function *function;
40     ht aliases;
41
42     /* All the labels the function defined...
43      * Should they be in ast_function instead?
44      */
45     std::vector<ast_label*> labels;
46     std::vector<ast_goto*> gotos;
47     std::vector<const char *> breaks;
48     std::vector<const char *> continues;
49
50     /* A list of hashtables for each scope */
51     std::vector<ht> variables;
52     ht htfields;
53     ht htglobals;
54     std::vector<ht> typedefs;
55
56     /* not to be used directly, we use the hash table */
57     std::vector<ast_expression*> _locals;
58     std::vector<size_t> _blocklocals;
59     std::vector<std::unique_ptr<ast_value>> _typedefs;
60     std::vector<size_t> _blocktypedefs;
61     std::vector<lex_ctx_t> _block_ctx;
62
63     /* we store the '=' operator info */
64     const oper_info *assign_op;
65
66     /* magic values */
67     ast_value *const_vec[3];
68
69     /* pragma flags */
70     bool noref;
71
72     /* collected information */
73     size_t max_param_count;
74
75     fold m_fold;
76     intrin m_intrin;
77 };
78
79
80 /* parser.c */
81 char           *parser_strdup     (const char *str);
82 ast_expression *parser_find_global(parser_t *parser, const char *name);
83
84 #endif