2 * Copyright (C) 2012, 2013
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
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*> */
39 #define parser_ctx(p) ((p)->lex->tok.ctx)
40 typedef struct parser_s {
46 ast_expression **globals;
47 ast_expression **fields;
48 ast_function **functions;
51 /* must be deleted first, they reference immediates and values */
52 ast_value **accessors;
55 ast_value *reserved_version;
60 ast_function *function;
63 /* All the labels the function defined...
64 * Should they be in ast_function instead?
69 const char **continues;
71 /* A list of hashtables for each scope */
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* */
81 /* not to be used directly, we use the hash table */
82 ast_expression **_locals;
84 ast_value **_typedefs;
85 size_t *_blocktypedefs;
86 lex_ctx_t *_block_ctx;
88 /* we store the '=' operator info */
89 const oper_info *assign_op;
92 ast_value *const_vec[3];
97 /* collected information */
98 size_t max_param_count;
104 char *parser_strdup(const char *str);
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**);