]> git.xonotic.org Git - xonotic/gmqcc.git/blob - parser.h
Testsuite now returns the correct value on test failures (also prints how many tests...
[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
41 typedef struct parser_s {
42     lex_file *lex;
43     int      tok;
44
45     bool     ast_cleaned;
46
47     ast_expression **globals;
48     ast_expression **fields;
49     ast_function **functions;
50     size_t         translated;
51
52     /* must be deleted first, they reference immediates and values */
53     ast_value    **accessors;
54
55     ast_value *nil;
56     ast_value *reserved_version;
57
58     size_t crc_globals;
59     size_t crc_fields;
60
61     ast_function *function;
62     ht            aliases;
63
64     /* All the labels the function defined...
65      * Should they be in ast_function instead?
66      */
67     ast_label  **labels;
68     ast_goto   **gotos;
69     const char **breaks;
70     const char **continues;
71
72     /* A list of hashtables for each scope */
73     ht *variables;
74     ht htfields;
75     ht htglobals;
76     ht *typedefs;
77
78     /* same as above but for the spelling corrector */
79     correct_trie_t  **correct_variables;
80     size_t         ***correct_variables_score;  /* vector of vector of size_t* */
81
82     /* not to be used directly, we use the hash table */
83     ast_expression **_locals;
84     size_t          *_blocklocals;
85     ast_value      **_typedefs;
86     size_t          *_blocktypedefs;
87     lex_ctx_t         *_block_ctx;
88
89     /* we store the '=' operator info */
90     const oper_info *assign_op;
91
92     /* magic values */
93     ast_value *const_vec[3];
94
95     /* pragma flags */
96     bool noref;
97
98     /* collected information */
99     size_t     max_param_count;
100
101     fold_t *fold;
102 } parser_t;
103
104
105 char *parser_strdup(const char *str);
106
107 /* fold.c */
108 fold_t         *fold_init           (parser_t *);
109 void            fold_cleanup        (fold_t *);
110 ast_expression *fold_constgen_float (fold_t *, qcfloat_t);
111 ast_expression *fold_constgen_vector(fold_t *, vec3_t);
112 ast_expression *fold_constgen_string(fold_t *, const char *, bool);
113 bool            fold_generate       (fold_t *, ir_builder *);
114 ast_expression *fold_op             (fold_t *, const oper_info *, ast_expression**);
115
116 int             fold_cond           (ir_value *, ast_function *, ast_ifthen *);
117
118 #endif