]> git.xonotic.org Git - xonotic/gmqcc.git/blob - parser.h
f9f0ab56e74c63f9ef8c994450c523c1ab8827b0
[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 #include "intrin.h"
7
8 struct parser_t;
9
10 struct fold_t {
11     parser_t *parser;
12     std::vector<ast_value*> imm_float;
13     std::vector<ast_value*> imm_vector;
14     std::vector<ast_value*> imm_string;
15     hash_table_t *imm_string_untranslate; /* map<string, ast_value*> */
16     hash_table_t *imm_string_dotranslate; /* map<string, ast_value*> */
17 };
18
19 #define parser_ctx(p) ((p)->lex->tok.ctx)
20
21 struct parser_t {
22     parser_t() { }
23
24     lex_file *lex;
25     int tok;
26
27     bool ast_cleaned;
28
29     std::vector<ast_expression *> globals;
30     std::vector<ast_expression *> fields;
31     std::vector<ast_function *> functions;
32     size_t translated;
33
34     /* must be deleted first, they reference immediates and values */
35     std::vector<ast_value *> accessors;
36
37     ast_value *nil;
38     ast_value *reserved_version;
39
40     size_t crc_globals;
41     size_t crc_fields;
42
43     ast_function *function;
44     ht aliases;
45
46     /* All the labels the function defined...
47      * Should they be in ast_function instead?
48      */
49     std::vector<ast_label*> labels;
50     std::vector<ast_goto*> gotos;
51     std::vector<const char *> breaks;
52     std::vector<const char *> continues;
53
54     /* A list of hashtables for each scope */
55     ht *variables;
56     ht htfields;
57     ht htglobals;
58     ht *typedefs;
59
60     /* not to be used directly, we use the hash table */
61     ast_expression **_locals;
62     size_t *_blocklocals;
63     ast_value **_typedefs;
64     size_t *_blocktypedefs;
65     lex_ctx_t *_block_ctx;
66
67     /* we store the '=' operator info */
68     const oper_info *assign_op;
69
70     /* magic values */
71     ast_value *const_vec[3];
72
73     /* pragma flags */
74     bool noref;
75
76     /* collected information */
77     size_t max_param_count;
78
79     fold_t *fold;
80     intrin m_intrin;
81 };
82
83
84 /* parser.c */
85 char           *parser_strdup     (const char *str);
86 ast_expression *parser_find_global(parser_t *parser, const char *name);
87
88 /* fold.c */
89 fold_t         *fold_init           (parser_t *);
90 void            fold_cleanup        (fold_t *);
91 ast_expression *fold_constgen_float (fold_t *, qcfloat_t, bool);
92 ast_expression *fold_constgen_vector(fold_t *, vec3_t);
93 ast_expression *fold_constgen_string(fold_t *, const char *, bool);
94 bool            fold_generate       (fold_t *, ir_builder *);
95 ast_expression *fold_op             (fold_t *, const oper_info *, ast_expression **);
96 ast_expression *fold_intrin         (fold_t *, const char      *, ast_expression **);
97
98 ast_expression *fold_binary         (lex_ctx_t ctx, int, ast_expression *, ast_expression *);
99 int             fold_cond_ifthen    (ir_value *, ast_function *, ast_ifthen  *);
100 int             fold_cond_ternary   (ir_value *, ast_function *, ast_ternary *);
101
102 #endif