2 * Copyright (C) 2012, 2013, 2014
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:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
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
24 #ifndef GMQCC_PARSER_HDR
25 #define GMQCC_PARSER_HDR
30 typedef struct intrin_s intrin_t;
31 typedef struct parser_s parser_t;
34 struct parser_s *parser;
35 ast_value **imm_float; /* vector<ast_value*> */
36 ast_value **imm_vector; /* vector<ast_value*> */
37 ast_value **imm_string; /* vector<ast_value*> */
38 hash_table_t *imm_string_untranslate; /* map<string, ast_value*> */
39 hash_table_t *imm_string_dotranslate; /* map<string, ast_value*> */
43 ast_expression *(*intrin)(intrin_t *);
50 intrin_func_t *intrinsics; /* vector<intrin_func_t> */
51 ast_expression **generated; /* vector<ast_expression*> */
56 #define parser_ctx(p) ((p)->lex->tok.ctx)
64 ast_expression **globals;
65 ast_expression **fields;
66 ast_function **functions;
69 /* must be deleted first, they reference immediates and values */
70 ast_value **accessors;
73 ast_value *reserved_version;
78 ast_function *function;
81 /* All the labels the function defined...
82 * Should they be in ast_function instead?
87 const char **continues;
89 /* A list of hashtables for each scope */
95 /* same as above but for the spelling corrector */
96 correct_trie_t **correct_variables;
97 size_t ***correct_variables_score; /* vector of vector of size_t* */
99 /* not to be used directly, we use the hash table */
100 ast_expression **_locals;
101 size_t *_blocklocals;
102 ast_value **_typedefs;
103 size_t *_blocktypedefs;
104 lex_ctx_t *_block_ctx;
106 /* we store the '=' operator info */
107 const oper_info *assign_op;
110 ast_value *const_vec[3];
115 /* collected information */
116 size_t max_param_count;
124 char *parser_strdup (const char *str);
125 ast_expression *parser_find_global(parser_t *parser, const char *name);
128 fold_t *fold_init (parser_t *);
129 void fold_cleanup (fold_t *);
130 ast_expression *fold_constgen_float (fold_t *, qcfloat_t);
131 ast_expression *fold_constgen_vector(fold_t *, vec3_t);
132 ast_expression *fold_constgen_string(fold_t *, const char *, bool);
133 bool fold_generate (fold_t *, ir_builder *);
134 ast_expression *fold_op (fold_t *, const oper_info *, ast_expression **);
135 ast_expression *fold_intrin (fold_t *, const char *, ast_expression **);
137 ast_expression *fold_binary (lex_ctx_t ctx, int, ast_expression *, ast_expression *);
138 int fold_cond_ifthen (ir_value *, ast_function *, ast_ifthen *);
139 int fold_cond_ternary (ir_value *, ast_function *, ast_ternary *);
142 intrin_t *intrin_init (parser_t *parser);
143 void intrin_cleanup (intrin_t *intrin);
144 ast_expression *intrin_fold (intrin_t *intrin, ast_value *, ast_expression **);
145 ast_expression *intrin_func (intrin_t *intrin, const char *name);
146 ast_expression *intrin_debug_typestring(intrin_t *intrin);