* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#include <stdio.h>
-#include <stdarg.h>
+#include <string.h>
#include <math.h>
#include "gmqcc.h"
lex_file *lex;
int tok;
+ bool ast_cleaned;
+
ast_expression **globals;
ast_expression **fields;
ast_function **functions;
char name[32];
util_snprintf(name, sizeof(name), "dotranslate_%lu", (unsigned long)(parser->translated++));
out = ast_value_new(parser_ctx(parser), name, TYPE_STRING);
+ out->expression.flags |= AST_FLAG_INCLUDE_DEF;
} else
out = ast_value_new(parser_ctx(parser), "#IMMEDIATE", TYPE_STRING);
out->cvq = CV_CONST;
out->hasvalue = true;
out->isimm = true;
- out->expression.flags |= AST_FLAG_INCLUDE_DEF;
out->constval.vstring = parser_strdup(str);
vec_push(parser->imm_string, out);
util_htseth(parser->ht_imm_string, str, hash, out);
/* for the sake of less code we parse-in in this function */
if (!parser_next(parser)) {
+ ast_delete(var);
parseerror(parser, "expected parameter list");
return NULL;
}
/* parse on */
if (!parser_next(parser)) {
ast_delete(var);
+ mem_d(name);
parseerror(parser, "error after variable or field declaration");
return NULL;
}
if (parser->tok == '[') {
wasarray = true;
var = parse_arraysize(parser, var);
- if (!var)
+ if (!var) {
+ if (name) mem_d(name);
return NULL;
+ }
}
/* This is the point where we can turn it into a field */
while (parser->tok == '(') {
var = parse_parameter_list(parser, var);
if (!var) {
- if (name)
- mem_d((void*)name);
+ if (name) mem_d(name);
return NULL;
}
}
if (name) {
if (!ast_value_set_name(var, name)) {
ast_delete(var);
+ mem_d(name);
parseerror(parser, "internal error: failed to set name");
return NULL;
}
/* free the name, ast_value_set_name duplicates */
- mem_d((void*)name);
+ mem_d(name);
}
return var;
return parser_compile(parser);
}
-void parser_cleanup(parser_t *parser)
+static void parser_remove_ast(parser_t *parser)
{
size_t i;
+ if (parser->ast_cleaned)
+ return;
+ parser->ast_cleaned = true;
for (i = 0; i < vec_size(parser->accessors); ++i) {
ast_delete(parser->accessors[i]->constval.vfunc);
parser->accessors[i]->constval.vfunc = NULL;
ast_value_delete(parser->const_vec[2]);
util_htdel(parser->aliases);
-
intrin_intrinsics_destroy(parser);
+}
+void parser_cleanup(parser_t *parser)
+{
+ parser_remove_ast(parser);
code_cleanup(parser->code);
mem_d(parser);
return false;
}
}
+
+ generate_checksum(parser);
if (OPTS_OPTION_BOOL(OPTION_DUMP))
ir_builder_dump(ir, con_out);
for (i = 0; i < vec_size(parser->functions); ++i) {
return false;
}
}
+ parser_remove_ast(parser);
if (compile_Werrors) {
con_out("*** there were warnings treated as errors\n");
if (OPTS_OPTION_BOOL(OPTION_DUMPFIN))
ir_builder_dump(ir, con_out);
- generate_checksum(parser);
-
if (!ir_builder_generate(parser->code, ir, output)) {
con_out("*** failed to generate output file\n");
ir_builder_delete(ir);
return false;
}
}
-
ir_builder_delete(ir);
return retval;
}