mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-18 22:31:36 +00:00
Get rid of some code duplication
This commit is contained in:
parent
77ef7f516d
commit
02ec45363e
3 changed files with 32 additions and 50 deletions
37
ast.c
37
ast.c
|
@ -1391,18 +1391,8 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
|
||||||
v->cvq = self->cvq;
|
v->cvq = self->cvq;
|
||||||
self->ir_v = v;
|
self->ir_v = v;
|
||||||
|
|
||||||
if (self->setter) {
|
if (!ast_generate_accessors(self, func->owner))
|
||||||
if (!ast_global_codegen(self->setter, func->owner, false) ||
|
return false;
|
||||||
!ast_function_codegen(self->setter->constval.vfunc, func->owner) ||
|
|
||||||
!ir_function_finalize(self->setter->constval.vfunc->ir_func))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (self->getter) {
|
|
||||||
if (!ast_global_codegen(self->getter, func->owner, false) ||
|
|
||||||
!ast_function_codegen(self->getter->constval.vfunc, func->owner) ||
|
|
||||||
!ir_function_finalize(self->getter->constval.vfunc->ir_func))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
error: /* clean up */
|
error: /* clean up */
|
||||||
|
@ -1410,6 +1400,29 @@ error: /* clean up */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ast_generate_accessors(ast_value *asvalue, ir_builder *ir)
|
||||||
|
{
|
||||||
|
if (asvalue->setter) {
|
||||||
|
if (!ast_global_codegen (asvalue->setter, ir, false) ||
|
||||||
|
!ast_function_codegen(asvalue->setter->constval.vfunc, ir) ||
|
||||||
|
!ir_function_finalize(asvalue->setter->constval.vfunc->ir_func))
|
||||||
|
{
|
||||||
|
compile_error(ast_ctx(asvalue), "internal error: failed to generate setter for `%s`", asvalue->name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (asvalue->getter) {
|
||||||
|
if (!ast_global_codegen (asvalue->getter, ir, false) ||
|
||||||
|
!ast_function_codegen(asvalue->getter->constval.vfunc, ir) ||
|
||||||
|
!ir_function_finalize(asvalue->getter->constval.vfunc->ir_func))
|
||||||
|
{
|
||||||
|
compile_error(ast_ctx(asvalue), "internal error: failed to generate getter for `%s`", asvalue->name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool ast_function_codegen(ast_function *self, ir_builder *ir)
|
bool ast_function_codegen(ast_function *self, ir_builder *ir)
|
||||||
{
|
{
|
||||||
ir_function *irf;
|
ir_function *irf;
|
||||||
|
|
1
ast.h
1
ast.h
|
@ -626,6 +626,7 @@ void ast_function_delete(ast_function*);
|
||||||
const char* ast_function_label(ast_function*, const char *prefix);
|
const char* ast_function_label(ast_function*, const char *prefix);
|
||||||
|
|
||||||
bool ast_function_codegen(ast_function *self, ir_builder *builder);
|
bool ast_function_codegen(ast_function *self, ir_builder *builder);
|
||||||
|
bool ast_generate_accessors(ast_value *asvalue, ir_builder *ir);
|
||||||
|
|
||||||
/* Expression union
|
/* Expression union
|
||||||
*/
|
*/
|
||||||
|
|
44
parser.c
44
parser.c
|
@ -4591,25 +4591,9 @@ bool parser_finish(const char *output)
|
||||||
if (!ast_istype(parser->globals[i], ast_value))
|
if (!ast_istype(parser->globals[i], ast_value))
|
||||||
continue;
|
continue;
|
||||||
asvalue = (ast_value*)(parser->globals[i]);
|
asvalue = (ast_value*)(parser->globals[i]);
|
||||||
if (asvalue->setter) {
|
if (!ast_generate_accessors(asvalue, ir)) {
|
||||||
if (!ast_global_codegen(asvalue->setter, ir, false) ||
|
ir_builder_delete(ir);
|
||||||
!ast_function_codegen(asvalue->setter->constval.vfunc, ir) ||
|
return false;
|
||||||
!ir_function_finalize(asvalue->setter->constval.vfunc->ir_func))
|
|
||||||
{
|
|
||||||
printf("failed to generate setter for %s\n", asvalue->name);
|
|
||||||
ir_builder_delete(ir);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (asvalue->getter) {
|
|
||||||
if (!ast_global_codegen(asvalue->getter, ir, false) ||
|
|
||||||
!ast_function_codegen(asvalue->getter->constval.vfunc, ir) ||
|
|
||||||
!ir_function_finalize(asvalue->getter->constval.vfunc->ir_func))
|
|
||||||
{
|
|
||||||
printf("failed to generate getter for %s\n", asvalue->name);
|
|
||||||
ir_builder_delete(ir);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < vec_size(parser->fields); ++i) {
|
for (i = 0; i < vec_size(parser->fields); ++i) {
|
||||||
|
@ -4620,25 +4604,9 @@ bool parser_finish(const char *output)
|
||||||
continue;
|
continue;
|
||||||
if (asvalue->expression.vtype != TYPE_ARRAY)
|
if (asvalue->expression.vtype != TYPE_ARRAY)
|
||||||
continue;
|
continue;
|
||||||
if (asvalue->setter) {
|
if (!ast_generate_accessors(asvalue, ir)) {
|
||||||
if (!ast_global_codegen(asvalue->setter, ir, false) ||
|
ir_builder_delete(ir);
|
||||||
!ast_function_codegen(asvalue->setter->constval.vfunc, ir) ||
|
return false;
|
||||||
!ir_function_finalize(asvalue->setter->constval.vfunc->ir_func))
|
|
||||||
{
|
|
||||||
printf("failed to generate setter for %s\n", asvalue->name);
|
|
||||||
ir_builder_delete(ir);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (asvalue->getter) {
|
|
||||||
if (!ast_global_codegen(asvalue->getter, ir, false) ||
|
|
||||||
!ast_function_codegen(asvalue->getter->constval.vfunc, ir) ||
|
|
||||||
!ir_function_finalize(asvalue->getter->constval.vfunc->ir_func))
|
|
||||||
{
|
|
||||||
printf("failed to generate getter for %s\n", asvalue->name);
|
|
||||||
ir_builder_delete(ir);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < vec_size(parser->functions); ++i) {
|
for (i = 0; i < vec_size(parser->functions); ++i) {
|
||||||
|
|
Loading…
Reference in a new issue