mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-02-18 17:41:47 +00:00
More std::vector
This commit is contained in:
parent
35a8c3c9af
commit
b5d8b44503
3 changed files with 61 additions and 82 deletions
12
intrin.cpp
12
intrin.cpp
|
@ -23,8 +23,8 @@ static GMQCC_INLINE ast_function *intrin_value(intrin_t *intrin, ast_value **out
|
||||||
}
|
}
|
||||||
|
|
||||||
static GMQCC_INLINE void intrin_reg(intrin_t *intrin, ast_value *const value, ast_function *const func) {
|
static GMQCC_INLINE void intrin_reg(intrin_t *intrin, ast_value *const value, ast_function *const func) {
|
||||||
vec_push(intrin->parser->functions, func);
|
intrin->parser->functions.push_back(func);
|
||||||
vec_push(intrin->parser->globals, (ast_expression*)value);
|
intrin->parser->globals.push_back((ast_expression*)value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define QC_POW_EPSILON 0.00001f
|
#define QC_POW_EPSILON 0.00001f
|
||||||
|
@ -2056,13 +2056,11 @@ static GMQCC_INLINE ast_expression *intrin_func_try(intrin_t *intrin, size_t off
|
||||||
}
|
}
|
||||||
|
|
||||||
static ast_expression *intrin_func_self(intrin_t *intrin, const char *name, const char *from) {
|
static ast_expression *intrin_func_self(intrin_t *intrin, const char *name, const char *from) {
|
||||||
size_t i;
|
ast_expression *find;
|
||||||
ast_expression *find;
|
|
||||||
|
|
||||||
/* try current first */
|
/* try current first */
|
||||||
if ((find = parser_find_global(intrin->parser, name)) && ((ast_value*)find)->expression.vtype == TYPE_FUNCTION)
|
if ((find = parser_find_global(intrin->parser, name)) && ((ast_value*)find)->expression.vtype == TYPE_FUNCTION)
|
||||||
for (i = 0; i < vec_size(intrin->parser->functions); ++i)
|
for (auto &it : intrin->parser->functions)
|
||||||
if (((ast_value*)find)->name && !strcmp(intrin->parser->functions[i]->name, ((ast_value*)find)->name) && intrin->parser->functions[i]->builtin < 0)
|
if (((ast_value*)find)->name && !strcmp(it->name, ((ast_value*)find)->name) && it->builtin < 0)
|
||||||
return find;
|
return find;
|
||||||
/* try name second */
|
/* try name second */
|
||||||
if ((find = intrin_func_try(intrin, offsetof(intrin_func_t, name), name)))
|
if ((find = intrin_func_try(intrin, offsetof(intrin_func_t, name), name)))
|
||||||
|
|
103
parser.cpp
103
parser.cpp
|
@ -2026,7 +2026,7 @@ static void parser_addlocal(parser_t *parser, const char *name, ast_expression *
|
||||||
|
|
||||||
static void parser_addglobal(parser_t *parser, const char *name, ast_expression *e)
|
static void parser_addglobal(parser_t *parser, const char *name, ast_expression *e)
|
||||||
{
|
{
|
||||||
vec_push(parser->globals, e);
|
parser->globals.push_back(e);
|
||||||
util_htset(parser->htglobals, name, e);
|
util_htset(parser->htglobals, name, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4035,7 +4035,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
|
||||||
ast_block_delete(block);
|
ast_block_delete(block);
|
||||||
goto enderr;
|
goto enderr;
|
||||||
}
|
}
|
||||||
vec_push(parser->functions, func);
|
parser->functions.push_back(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
parser_enterblock(parser);
|
parser_enterblock(parser);
|
||||||
|
@ -4114,7 +4114,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
|
||||||
|
|
||||||
enderrfn:
|
enderrfn:
|
||||||
(void)!parser_leaveblock(parser);
|
(void)!parser_leaveblock(parser);
|
||||||
vec_pop(parser->functions);
|
parser->functions.pop_back();
|
||||||
ast_function_delete(func);
|
ast_function_delete(func);
|
||||||
var->constval.vfunc = NULL;
|
var->constval.vfunc = NULL;
|
||||||
|
|
||||||
|
@ -4359,7 +4359,7 @@ static bool parser_create_array_accessor(parser_t *parser, ast_value *array, con
|
||||||
vec_push(func->blocks, body);
|
vec_push(func->blocks, body);
|
||||||
*out = fval;
|
*out = fval;
|
||||||
|
|
||||||
vec_push(parser->accessors, fval);
|
parser->accessors.push_back(fval);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -5171,12 +5171,12 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
|
||||||
was_end = false;
|
was_end = false;
|
||||||
if (!strcmp(var->name, "end_sys_globals")) {
|
if (!strcmp(var->name, "end_sys_globals")) {
|
||||||
var->uses++;
|
var->uses++;
|
||||||
parser->crc_globals = vec_size(parser->globals);
|
parser->crc_globals = parser->globals.size();
|
||||||
was_end = true;
|
was_end = true;
|
||||||
}
|
}
|
||||||
else if (!strcmp(var->name, "end_sys_fields")) {
|
else if (!strcmp(var->name, "end_sys_fields")) {
|
||||||
var->uses++;
|
var->uses++;
|
||||||
parser->crc_fields = vec_size(parser->fields);
|
parser->crc_fields = parser->fields.size();
|
||||||
was_end = true;
|
was_end = true;
|
||||||
}
|
}
|
||||||
if (was_end && var->expression.vtype == TYPE_FIELD) {
|
if (was_end && var->expression.vtype == TYPE_FIELD) {
|
||||||
|
@ -5362,11 +5362,11 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
|
||||||
/* deal with global variables, fields, functions */
|
/* deal with global variables, fields, functions */
|
||||||
if (!nofields && var->expression.vtype == TYPE_FIELD && parser->tok != '=') {
|
if (!nofields && var->expression.vtype == TYPE_FIELD && parser->tok != '=') {
|
||||||
var->isfield = true;
|
var->isfield = true;
|
||||||
vec_push(parser->fields, (ast_expression*)var);
|
parser->fields.push_back((ast_expression*)var);
|
||||||
util_htset(parser->htfields, var->name, var);
|
util_htset(parser->htfields, var->name, var);
|
||||||
if (isvector) {
|
if (isvector) {
|
||||||
for (i = 0; i < 3; ++i) {
|
for (i = 0; i < 3; ++i) {
|
||||||
vec_push(parser->fields, (ast_expression*)me[i]);
|
parser->fields.push_back((ast_expression*)me[i]);
|
||||||
util_htset(parser->htfields, me[i]->name, me[i]);
|
util_htset(parser->htfields, me[i]->name, me[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5463,7 +5463,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
|
||||||
ast_value_set_name(var, defname);
|
ast_value_set_name(var, defname);
|
||||||
|
|
||||||
/* push it to the to-be-generated globals */
|
/* push it to the to-be-generated globals */
|
||||||
vec_push(parser->globals, (ast_expression*)var);
|
parser->globals.push_back((ast_expression*)var);
|
||||||
|
|
||||||
/* same game for the vector members */
|
/* same game for the vector members */
|
||||||
if (isvector) {
|
if (isvector) {
|
||||||
|
@ -5475,7 +5475,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
|
||||||
vec_append(defname, ln, me[i]->name);
|
vec_append(defname, ln, me[i]->name);
|
||||||
ast_member_set_name(me[i], defname);
|
ast_member_set_name(me[i], defname);
|
||||||
|
|
||||||
vec_push(parser->globals, (ast_expression*)me[i]);
|
parser->globals.push_back((ast_expression*)me[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vec_free(defname);
|
vec_free(defname);
|
||||||
|
@ -5648,7 +5648,7 @@ skipvar:
|
||||||
parseerror(parser, "failed to allocate function for `%s`", var->name);
|
parseerror(parser, "failed to allocate function for `%s`", var->name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
vec_push(parser->functions, func);
|
parser->functions.push_back(func);
|
||||||
|
|
||||||
func->builtin = -builtin_num-1;
|
func->builtin = -builtin_num-1;
|
||||||
}
|
}
|
||||||
|
@ -5725,10 +5725,10 @@ skipvar:
|
||||||
else
|
else
|
||||||
localblock->locals.pop_back();
|
localblock->locals.pop_back();
|
||||||
/* push it to the to-be-generated globals */
|
/* push it to the to-be-generated globals */
|
||||||
vec_push(parser->globals, (ast_expression*)var);
|
parser->globals.push_back((ast_expression*)var);
|
||||||
if (isvector)
|
if (isvector)
|
||||||
for (i = 0; i < 3; ++i)
|
for (i = 0; i < 3; ++i)
|
||||||
vec_push(parser->globals, (ast_expression*)last_me[i]);
|
parser->globals.push_back((ast_expression*)last_me[i]);
|
||||||
folded_const = true;
|
folded_const = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6094,24 +6094,14 @@ static void parser_remove_ast(parser_t *parser)
|
||||||
if (parser->ast_cleaned)
|
if (parser->ast_cleaned)
|
||||||
return;
|
return;
|
||||||
parser->ast_cleaned = true;
|
parser->ast_cleaned = true;
|
||||||
for (i = 0; i < vec_size(parser->accessors); ++i) {
|
for (auto &it : parser->accessors) {
|
||||||
ast_delete(parser->accessors[i]->constval.vfunc);
|
ast_delete(it->constval.vfunc);
|
||||||
parser->accessors[i]->constval.vfunc = NULL;
|
it->constval.vfunc = nullptr;
|
||||||
ast_delete(parser->accessors[i]);
|
ast_delete(it);
|
||||||
}
|
}
|
||||||
for (i = 0; i < vec_size(parser->functions); ++i) {
|
for (auto &it : parser->functions) ast_delete(it);
|
||||||
ast_delete(parser->functions[i]);
|
for (auto &it : parser->globals) ast_delete(it);
|
||||||
}
|
for (auto &it : parser->fields) ast_delete(it);
|
||||||
for (i = 0; i < vec_size(parser->fields); ++i) {
|
|
||||||
ast_delete(parser->fields[i]);
|
|
||||||
}
|
|
||||||
for (i = 0; i < vec_size(parser->globals); ++i) {
|
|
||||||
ast_delete(parser->globals[i]);
|
|
||||||
}
|
|
||||||
vec_free(parser->accessors);
|
|
||||||
vec_free(parser->functions);
|
|
||||||
vec_free(parser->globals);
|
|
||||||
vec_free(parser->fields);
|
|
||||||
|
|
||||||
for (i = 0; i < vec_size(parser->variables); ++i)
|
for (i = 0; i < vec_size(parser->variables); ++i)
|
||||||
util_htdel(parser->variables[i]);
|
util_htdel(parser->variables[i]);
|
||||||
|
@ -6150,7 +6140,6 @@ void parser_cleanup(parser_t *parser)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parser_set_coverage_func(parser_t *parser, ir_builder *ir) {
|
static bool parser_set_coverage_func(parser_t *parser, ir_builder *ir) {
|
||||||
size_t i;
|
|
||||||
ast_expression *expr;
|
ast_expression *expr;
|
||||||
ast_value *cov;
|
ast_value *cov;
|
||||||
ast_function *func;
|
ast_function *func;
|
||||||
|
@ -6158,10 +6147,10 @@ static bool parser_set_coverage_func(parser_t *parser, ir_builder *ir) {
|
||||||
if (!OPTS_OPTION_BOOL(OPTION_COVERAGE))
|
if (!OPTS_OPTION_BOOL(OPTION_COVERAGE))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
func = NULL;
|
func = nullptr;
|
||||||
for (i = 0; i != vec_size(parser->functions); ++i) {
|
for (auto &it : parser->functions) {
|
||||||
if (!strcmp(parser->functions[i]->name, "coverage")) {
|
if (!strcmp(it->name, "coverage")) {
|
||||||
func = parser->functions[i];
|
func = it;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6191,9 +6180,8 @@ static bool parser_set_coverage_func(parser_t *parser, ir_builder *ir) {
|
||||||
|
|
||||||
bool parser_finish(parser_t *parser, const char *output)
|
bool parser_finish(parser_t *parser, const char *output)
|
||||||
{
|
{
|
||||||
size_t i;
|
ir_builder *ir;
|
||||||
ir_builder *ir;
|
bool retval = true;
|
||||||
bool retval = true;
|
|
||||||
|
|
||||||
if (compile_errors) {
|
if (compile_errors) {
|
||||||
con_out("*** there were compile errors\n");
|
con_out("*** there were compile errors\n");
|
||||||
|
@ -6206,12 +6194,11 @@ bool parser_finish(parser_t *parser, const char *output)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < vec_size(parser->fields); ++i) {
|
for (auto &it : parser->fields) {
|
||||||
ast_value *field;
|
|
||||||
bool hasvalue;
|
bool hasvalue;
|
||||||
if (!ast_istype(parser->fields[i], ast_value))
|
if (!ast_istype(it, ast_value))
|
||||||
continue;
|
continue;
|
||||||
field = (ast_value*)parser->fields[i];
|
ast_value *field = (ast_value*)it;
|
||||||
hasvalue = field->hasvalue;
|
hasvalue = field->hasvalue;
|
||||||
field->hasvalue = false;
|
field->hasvalue = false;
|
||||||
if (!ast_global_codegen((ast_value*)field, ir, true)) {
|
if (!ast_global_codegen((ast_value*)field, ir, true)) {
|
||||||
|
@ -6232,11 +6219,11 @@ bool parser_finish(parser_t *parser, const char *output)
|
||||||
(void)!ir_value_set_field(field->ir_v, ifld);
|
(void)!ir_value_set_field(field->ir_v, ifld);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < vec_size(parser->globals); ++i) {
|
for (auto &it : parser->globals) {
|
||||||
ast_value *asvalue;
|
ast_value *asvalue;
|
||||||
if (!ast_istype(parser->globals[i], ast_value))
|
if (!ast_istype(it, ast_value))
|
||||||
continue;
|
continue;
|
||||||
asvalue = (ast_value*)(parser->globals[i]);
|
asvalue = (ast_value*)it;
|
||||||
if (!asvalue->uses && !asvalue->hasvalue && asvalue->expression.vtype != TYPE_FUNCTION) {
|
if (!asvalue->uses && !asvalue->hasvalue && asvalue->expression.vtype != TYPE_FUNCTION) {
|
||||||
retval = retval && !compile_warning(ast_ctx(asvalue), WARN_UNUSED_VARIABLE,
|
retval = retval && !compile_warning(ast_ctx(asvalue), WARN_UNUSED_VARIABLE,
|
||||||
"unused global: `%s`", asvalue->name);
|
"unused global: `%s`", asvalue->name);
|
||||||
|
@ -6250,8 +6237,7 @@ bool parser_finish(parser_t *parser, const char *output)
|
||||||
/* Build function vararg accessor ast tree now before generating
|
/* Build function vararg accessor ast tree now before generating
|
||||||
* immediates, because the accessors may add new immediates
|
* immediates, because the accessors may add new immediates
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < vec_size(parser->functions); ++i) {
|
for (auto &f : parser->functions) {
|
||||||
ast_function *f = parser->functions[i];
|
|
||||||
if (f->varargs) {
|
if (f->varargs) {
|
||||||
if (parser->max_param_count > f->vtype->expression.params.size()) {
|
if (parser->max_param_count > f->vtype->expression.params.size()) {
|
||||||
f->varargs->expression.count = parser->max_param_count - f->vtype->expression.params.size();
|
f->varargs->expression.count = parser->max_param_count - f->vtype->expression.params.size();
|
||||||
|
@ -6278,12 +6264,10 @@ bool parser_finish(parser_t *parser, const char *output)
|
||||||
/* before generating any functions we need to set the coverage_func */
|
/* before generating any functions we need to set the coverage_func */
|
||||||
if (!parser_set_coverage_func(parser, ir))
|
if (!parser_set_coverage_func(parser, ir))
|
||||||
return false;
|
return false;
|
||||||
|
for (auto &it : parser->globals) {
|
||||||
for (i = 0; i < vec_size(parser->globals); ++i) {
|
if (!ast_istype(it, ast_value))
|
||||||
ast_value *asvalue;
|
|
||||||
if (!ast_istype(parser->globals[i], ast_value))
|
|
||||||
continue;
|
continue;
|
||||||
asvalue = (ast_value*)(parser->globals[i]);
|
ast_value *asvalue = (ast_value*)it;
|
||||||
if (!(asvalue->expression.flags & AST_FLAG_INITIALIZED))
|
if (!(asvalue->expression.flags & AST_FLAG_INITIALIZED))
|
||||||
{
|
{
|
||||||
if (asvalue->cvq == CV_CONST && !asvalue->hasvalue)
|
if (asvalue->cvq == CV_CONST && !asvalue->hasvalue)
|
||||||
|
@ -6300,10 +6284,8 @@ bool parser_finish(parser_t *parser, const char *output)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < vec_size(parser->fields); ++i) {
|
for (auto &it : parser->fields) {
|
||||||
ast_value *asvalue;
|
ast_value *asvalue = (ast_value*)it->next;
|
||||||
asvalue = (ast_value*)(parser->fields[i]->next);
|
|
||||||
|
|
||||||
if (!ast_istype((ast_expression*)asvalue, ast_value))
|
if (!ast_istype((ast_expression*)asvalue, ast_value))
|
||||||
continue;
|
continue;
|
||||||
if (asvalue->expression.vtype != TYPE_ARRAY)
|
if (asvalue->expression.vtype != TYPE_ARRAY)
|
||||||
|
@ -6320,8 +6302,7 @@ bool parser_finish(parser_t *parser, const char *output)
|
||||||
ir_builder_delete(ir);
|
ir_builder_delete(ir);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (i = 0; i < vec_size(parser->functions); ++i) {
|
for (auto &f : parser->functions) {
|
||||||
ast_function *f = parser->functions[i];
|
|
||||||
if (!ast_function_codegen(f, ir)) {
|
if (!ast_function_codegen(f, ir)) {
|
||||||
con_out("failed to generate function %s\n", f->name);
|
con_out("failed to generate function %s\n", f->name);
|
||||||
ir_builder_delete(ir);
|
ir_builder_delete(ir);
|
||||||
|
@ -6333,9 +6314,9 @@ bool parser_finish(parser_t *parser, const char *output)
|
||||||
|
|
||||||
if (OPTS_OPTION_BOOL(OPTION_DUMP))
|
if (OPTS_OPTION_BOOL(OPTION_DUMP))
|
||||||
ir_builder_dump(ir, con_out);
|
ir_builder_dump(ir, con_out);
|
||||||
for (i = 0; i < vec_size(parser->functions); ++i) {
|
for (auto &it : parser->functions) {
|
||||||
if (!ir_function_finalize(parser->functions[i]->ir_func)) {
|
if (!ir_function_finalize(it->ir_func)) {
|
||||||
con_out("failed to finalize function %s\n", parser->functions[i]->name);
|
con_out("failed to finalize function %s\n", it->name);
|
||||||
ir_builder_delete(ir);
|
ir_builder_delete(ir);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
28
parser.h
28
parser.h
|
@ -34,17 +34,17 @@ struct intrin_t {
|
||||||
|
|
||||||
struct parser_t {
|
struct parser_t {
|
||||||
lex_file *lex;
|
lex_file *lex;
|
||||||
int tok;
|
int tok;
|
||||||
|
|
||||||
bool ast_cleaned;
|
bool ast_cleaned;
|
||||||
|
|
||||||
ast_expression **globals;
|
std::vector<ast_expression *> globals;
|
||||||
ast_expression **fields;
|
std::vector<ast_expression *> fields;
|
||||||
ast_function **functions;
|
std::vector<ast_function *> functions;
|
||||||
size_t translated;
|
size_t translated;
|
||||||
|
|
||||||
/* must be deleted first, they reference immediates and values */
|
/* must be deleted first, they reference immediates and values */
|
||||||
ast_value **accessors;
|
std::vector<ast_value *> accessors;
|
||||||
|
|
||||||
ast_value *nil;
|
ast_value *nil;
|
||||||
ast_value *reserved_version;
|
ast_value *reserved_version;
|
||||||
|
@ -53,7 +53,7 @@ struct parser_t {
|
||||||
size_t crc_fields;
|
size_t crc_fields;
|
||||||
|
|
||||||
ast_function *function;
|
ast_function *function;
|
||||||
ht aliases;
|
ht aliases;
|
||||||
|
|
||||||
/* All the labels the function defined...
|
/* All the labels the function defined...
|
||||||
* Should they be in ast_function instead?
|
* Should they be in ast_function instead?
|
||||||
|
@ -71,10 +71,10 @@ struct parser_t {
|
||||||
|
|
||||||
/* not to be used directly, we use the hash table */
|
/* not to be used directly, we use the hash table */
|
||||||
ast_expression **_locals;
|
ast_expression **_locals;
|
||||||
size_t *_blocklocals;
|
size_t *_blocklocals;
|
||||||
ast_value **_typedefs;
|
ast_value **_typedefs;
|
||||||
size_t *_blocktypedefs;
|
size_t *_blocktypedefs;
|
||||||
lex_ctx_t *_block_ctx;
|
lex_ctx_t *_block_ctx;
|
||||||
|
|
||||||
/* we store the '=' operator info */
|
/* we store the '=' operator info */
|
||||||
const oper_info *assign_op;
|
const oper_info *assign_op;
|
||||||
|
@ -86,9 +86,9 @@ struct parser_t {
|
||||||
bool noref;
|
bool noref;
|
||||||
|
|
||||||
/* collected information */
|
/* collected information */
|
||||||
size_t max_param_count;
|
size_t max_param_count;
|
||||||
|
|
||||||
fold_t *fold;
|
fold_t *fold;
|
||||||
intrin_t *intrin;
|
intrin_t *intrin;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue