]> git.xonotic.org Git - xonotic/gmqcc.git/blob - parser.h
08692107b93dcf061cccff5032c095e77ee14cf9
[xonotic/gmqcc.git] / parser.h
1 /*
2  * Copyright (C) 2012, 2013
3  *     Wolfgang Bumiller
4  *     Dale Weiler
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy of
7  * this software and associated documentation files (the "Software"), to deal in
8  * the Software without restriction, including without limitation the rights to
9  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is furnished to do
11  * so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef GMQCC_PARSER_HDR
25 #define GMQCC_PARSER_HDR
26 #include "gmqcc.h"
27 #include "lexer.h"
28 #include "ast.h"
29
30 typedef struct {
31     struct parser_s *parser;
32     ast_value      **imm_float;              /* vector<ast_value*> */
33     ast_value      **imm_vector;             /* vector<ast_value*> */
34     ast_value      **imm_string;             /* vector<ast_value*> */
35     hash_table_t    *imm_string_untranslate; /* map<string, ast_value*> */
36     hash_table_t    *imm_string_dotranslate; /* map<string, ast_value*> */
37 } fold_t;
38
39 #define parser_ctx(p)    ((p)->lex->tok.ctx)
40 typedef struct parser_s {
41     lex_file *lex;
42     int      tok;
43
44     bool     ast_cleaned;
45
46     ast_expression **globals;
47     ast_expression **fields;
48     ast_function **functions;
49     size_t         translated;
50
51     /* must be deleted first, they reference immediates and values */
52     ast_value    **accessors;
53
54     ast_value *nil;
55     ast_value *reserved_version;
56
57     size_t crc_globals;
58     size_t crc_fields;
59
60     ast_function *function;
61     ht            aliases;
62
63     /* All the labels the function defined...
64      * Should they be in ast_function instead?
65      */
66     ast_label  **labels;
67     ast_goto   **gotos;
68     const char **breaks;
69     const char **continues;
70
71     /* A list of hashtables for each scope */
72     ht *variables;
73     ht htfields;
74     ht htglobals;
75     ht *typedefs;
76
77     /* same as above but for the spelling corrector */
78     correct_trie_t  **correct_variables;
79     size_t         ***correct_variables_score;  /* vector of vector of size_t* */
80
81     /* not to be used directly, we use the hash table */
82     ast_expression **_locals;
83     size_t          *_blocklocals;
84     ast_value      **_typedefs;
85     size_t          *_blocktypedefs;
86     lex_ctx_t         *_block_ctx;
87
88     /* we store the '=' operator info */
89     const oper_info *assign_op;
90
91     /* magic values */
92     ast_value *const_vec[3];
93
94     /* pragma flags */
95     bool noref;
96
97     /* collected information */
98     size_t     max_param_count;
99
100     fold_t *fold;
101 } parser_t;
102
103
104 char *parser_strdup(const char *str);
105
106 /* fold.c */
107 fold_t         *fold_init           (parser_t *);
108 void            fold_cleanup        (fold_t *);
109 ast_expression *fold_constgen_float (fold_t *, qcfloat_t);
110 ast_expression *fold_constgen_vector(fold_t *, vec3_t);
111 ast_expression *fold_constgen_string(fold_t *, const char *, bool);
112 bool            fold_generate       (fold_t *, ir_builder *);
113 ast_expression *fold_op             (fold_t *, const oper_info *, ast_expression**);
114 #endif