mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-04-05 01:11:00 +00:00
ast_expression: params -> type_params
This commit is contained in:
parent
9535805c02
commit
dedb3a49bd
4 changed files with 69 additions and 69 deletions
48
ast.cpp
48
ast.cpp
|
@ -104,7 +104,7 @@ static void ast_expression_delete(ast_expression *self)
|
|||
{
|
||||
if (self->next)
|
||||
ast_delete(self->next);
|
||||
for (auto &it : self->params)
|
||||
for (auto &it : self->type_params)
|
||||
ast_delete(it);
|
||||
if (self->varparam)
|
||||
ast_delete(self->varparam);
|
||||
|
@ -128,9 +128,9 @@ ast_value* ast_value_copy(const ast_value *self)
|
|||
selfex = &cp->expression;
|
||||
selfex->count = fromex->count;
|
||||
selfex->flags = fromex->flags;
|
||||
for (auto &it : fromex->params) {
|
||||
for (auto &it : fromex->type_params) {
|
||||
ast_value *v = ast_value_copy(it);
|
||||
selfex->params.push_back(v);
|
||||
selfex->type_params.push_back(v);
|
||||
}
|
||||
return cp;
|
||||
}
|
||||
|
@ -147,9 +147,9 @@ void ast_type_adopt_impl(ast_expression *self, const ast_expression *other)
|
|||
selfex = self;
|
||||
selfex->count = fromex->count;
|
||||
selfex->flags = fromex->flags;
|
||||
for (auto &it : fromex->params) {
|
||||
for (auto &it : fromex->type_params) {
|
||||
ast_value *v = ast_value_copy(it);
|
||||
selfex->params.push_back(v);
|
||||
selfex->type_params.push_back(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,9 +189,9 @@ ast_expression* ast_type_copy(lex_ctx_t ctx, const ast_expression *ex)
|
|||
|
||||
selfex->count = fromex->count;
|
||||
selfex->flags = fromex->flags;
|
||||
for (auto &it : fromex->params) {
|
||||
for (auto &it : fromex->type_params) {
|
||||
ast_value *v = ast_value_copy(it);
|
||||
selfex->params.push_back(v);
|
||||
selfex->type_params.push_back(v);
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -207,18 +207,18 @@ bool ast_compare_type(ast_expression *a, ast_expression *b)
|
|||
return false;
|
||||
if (!a->next != !b->next)
|
||||
return false;
|
||||
if (a->params.size() != b->params.size())
|
||||
if (a->type_params.size() != b->type_params.size())
|
||||
return false;
|
||||
if ((a->flags & AST_FLAG_TYPE_MASK) !=
|
||||
(b->flags & AST_FLAG_TYPE_MASK) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (a->params.size()) {
|
||||
if (a->type_params.size()) {
|
||||
size_t i;
|
||||
for (i = 0; i < a->params.size(); ++i) {
|
||||
if (!ast_compare_type((ast_expression*)a->params[i],
|
||||
(ast_expression*)b->params[i]))
|
||||
for (i = 0; i < a->type_params.size(); ++i) {
|
||||
if (!ast_compare_type((ast_expression*)a->type_params[i],
|
||||
(ast_expression*)b->type_params[i]))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -267,19 +267,19 @@ static size_t ast_type_to_string_impl(ast_expression *e, char *buf, size_t bufsi
|
|||
pos = ast_type_to_string_impl(e->next, buf, bufsize, pos);
|
||||
if (pos + 2 >= bufsize)
|
||||
goto full;
|
||||
if (e->params.empty()) {
|
||||
if (e->type_params.empty()) {
|
||||
buf[pos++] = '(';
|
||||
buf[pos++] = ')';
|
||||
return pos;
|
||||
}
|
||||
buf[pos++] = '(';
|
||||
pos = ast_type_to_string_impl((ast_expression*)(e->params[0]), buf, bufsize, pos);
|
||||
for (i = 1; i < e->params.size(); ++i) {
|
||||
pos = ast_type_to_string_impl((ast_expression*)(e->type_params[0]), buf, bufsize, pos);
|
||||
for (i = 1; i < e->type_params.size(); ++i) {
|
||||
if (pos + 2 >= bufsize)
|
||||
goto full;
|
||||
buf[pos++] = ',';
|
||||
buf[pos++] = ' ';
|
||||
pos = ast_type_to_string_impl((ast_expression*)(e->params[i]), buf, bufsize, pos);
|
||||
pos = ast_type_to_string_impl((ast_expression*)(e->type_params[i]), buf, bufsize, pos);
|
||||
}
|
||||
if (pos + 1 >= bufsize)
|
||||
goto full;
|
||||
|
@ -394,7 +394,7 @@ void ast_value_delete(ast_value* self)
|
|||
|
||||
void ast_value_params_add(ast_value *self, ast_value *p)
|
||||
{
|
||||
self->expression.params.push_back(p);
|
||||
self->expression.type_params.push_back(p);
|
||||
}
|
||||
|
||||
bool ast_value_set_name(ast_value *self, const char *name)
|
||||
|
@ -1042,8 +1042,8 @@ bool ast_call_check_types(ast_call *self, ast_expression *va_type)
|
|||
bool retval = true;
|
||||
const ast_expression *func = self->func;
|
||||
size_t count = self->params.size();
|
||||
if (count > func->params.size())
|
||||
count = func->params.size();
|
||||
if (count > func->type_params.size())
|
||||
count = func->type_params.size();
|
||||
|
||||
for (i = 0; i < count; ++i) {
|
||||
if (ast_istype(self->params[i], ast_argpipe)) {
|
||||
|
@ -1052,13 +1052,13 @@ bool ast_call_check_types(ast_call *self, ast_expression *va_type)
|
|||
compile_error(ast_ctx(self), "argpipe must be the last parameter to a function call");
|
||||
return false;
|
||||
}
|
||||
if (!ast_call_check_vararg(self, va_type, (ast_expression*)func->params[i]))
|
||||
if (!ast_call_check_vararg(self, va_type, (ast_expression*)func->type_params[i]))
|
||||
retval = false;
|
||||
}
|
||||
else if (!ast_compare_type(self->params[i], (ast_expression*)(func->params[i])))
|
||||
else if (!ast_compare_type(self->params[i], (ast_expression*)(func->type_params[i])))
|
||||
{
|
||||
ast_type_to_string(self->params[i], tgot, sizeof(tgot));
|
||||
ast_type_to_string((ast_expression*)func->params[i], texp, sizeof(texp));
|
||||
ast_type_to_string((ast_expression*)func->type_params[i], texp, sizeof(texp));
|
||||
compile_error(ast_ctx(self), "invalid type for parameter %u in function call: expected %s, got %s",
|
||||
(unsigned int)(i+1), texp, tgot);
|
||||
/* we don't immediately return */
|
||||
|
@ -1066,7 +1066,7 @@ bool ast_call_check_types(ast_call *self, ast_expression *va_type)
|
|||
}
|
||||
}
|
||||
count = self->params.size();
|
||||
if (count > func->params.size() && func->varparam) {
|
||||
if (count > func->type_params.size() && func->varparam) {
|
||||
for (; i < count; ++i) {
|
||||
if (ast_istype(self->params[i], ast_argpipe)) {
|
||||
/* warn about type safety instead */
|
||||
|
@ -1782,7 +1782,7 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
|
|||
|
||||
/* fill the parameter list */
|
||||
ec = &self->function_type->expression;
|
||||
for (auto &it : ec->params) {
|
||||
for (auto &it : ec->type_params) {
|
||||
if (it->expression.vtype == TYPE_FIELD)
|
||||
vec_push(irf->params, it->expression.next->vtype);
|
||||
else
|
||||
|
|
2
ast.h
2
ast.h
|
@ -149,7 +149,7 @@ struct ast_expression : ast_node {
|
|||
ast_expression *next;
|
||||
/* arrays get a member-count */
|
||||
size_t count;
|
||||
std::vector<ast_value*> params;
|
||||
std::vector<ast_value*> type_params;
|
||||
|
||||
ast_flag_t flags;
|
||||
/* void foo(string...) gets varparam set as a restriction
|
||||
|
|
42
intrin.cpp
42
intrin.cpp
|
@ -55,7 +55,7 @@ ast_expression *intrin::isfinite_() {
|
|||
ast_block *block = ast_block_new(ctx());
|
||||
|
||||
/* float x; */
|
||||
val->expression.params.push_back(x);
|
||||
val->expression.type_params.push_back(x);
|
||||
|
||||
/* <callisnan> = isnan(x); */
|
||||
callisnan->params.push_back((ast_expression*)x);
|
||||
|
@ -124,7 +124,7 @@ ast_expression *intrin::isinf_() {
|
|||
)
|
||||
);
|
||||
|
||||
val->expression.params.push_back(x);
|
||||
val->expression.type_params.push_back(x);
|
||||
func->blocks.push_back(body);
|
||||
|
||||
reg(val, func);
|
||||
|
@ -169,7 +169,7 @@ ast_expression *intrin::isnan_() {
|
|||
)
|
||||
);
|
||||
|
||||
val->expression.params.push_back(arg1);
|
||||
val->expression.type_params.push_back(arg1);
|
||||
func->blocks.push_back(body);
|
||||
|
||||
reg(val, func);
|
||||
|
@ -189,7 +189,7 @@ ast_expression *intrin::isnormal_() {
|
|||
ast_block *body = ast_block_new(ctx());
|
||||
ast_function *func = value(&val, "isnormal", TYPE_FLOAT);
|
||||
|
||||
val->expression.params.push_back(x);
|
||||
val->expression.type_params.push_back(x);
|
||||
callisfinite->params.push_back((ast_expression*)x);
|
||||
|
||||
/* return <callisfinite> */
|
||||
|
@ -216,7 +216,7 @@ ast_expression *intrin::signbit_() {
|
|||
ast_block *body = ast_block_new(ctx());
|
||||
ast_function *func = value(&val, "signbit", TYPE_FLOAT);
|
||||
|
||||
val->expression.params.push_back(x);
|
||||
val->expression.type_params.push_back(x);
|
||||
|
||||
/* return (x < 0); */
|
||||
body->exprs.push_back(
|
||||
|
@ -254,7 +254,7 @@ ast_expression *intrin::acosh_() {
|
|||
ast_block *body = ast_block_new(ctx());
|
||||
ast_function *func = value(&val, "acosh", TYPE_FLOAT);
|
||||
|
||||
val->expression.params.push_back(x);
|
||||
val->expression.type_params.push_back(x);
|
||||
|
||||
/* <callsqrt> = sqrt((x * x) - 1); */
|
||||
callsqrt->params.push_back(
|
||||
|
@ -307,7 +307,7 @@ ast_expression *intrin::asinh_() {
|
|||
ast_block *body = ast_block_new(ctx());
|
||||
ast_function *func = value(&val, "asinh", TYPE_FLOAT);
|
||||
|
||||
val->expression.params.push_back(x);
|
||||
val->expression.type_params.push_back(x);
|
||||
|
||||
/* <callsqrt> = sqrt((x * x) + 1); */
|
||||
callsqrt->params.push_back(
|
||||
|
@ -359,7 +359,7 @@ ast_expression *intrin::atanh_() {
|
|||
ast_block *body = ast_block_new(ctx());
|
||||
ast_function *func = value(&val, "atanh", TYPE_FLOAT);
|
||||
|
||||
val->expression.params.push_back(x);
|
||||
val->expression.type_params.push_back(x);
|
||||
|
||||
/* <callog> = log((1 + x) / (1 - x)); */
|
||||
calllog->params.push_back(
|
||||
|
@ -416,7 +416,7 @@ ast_expression *intrin::exp_() {
|
|||
ast_block *body = ast_block_new(ctx());
|
||||
ast_function *func = value(&val, "exp", TYPE_FLOAT);
|
||||
|
||||
val->expression.params.push_back(x);
|
||||
val->expression.type_params.push_back(x);
|
||||
|
||||
body->locals.push_back(sum);
|
||||
body->locals.push_back(acc);
|
||||
|
@ -521,7 +521,7 @@ ast_expression *intrin::exp2_() {
|
|||
ast_block *body = ast_block_new(ctx());
|
||||
ast_function *func = value(&val, "exp2", TYPE_FLOAT);
|
||||
|
||||
val->expression.params.push_back(arg1);
|
||||
val->expression.type_params.push_back(arg1);
|
||||
|
||||
callpow->params.push_back((ast_expression*)m_fold->m_imm_float[3]);
|
||||
callpow->params.push_back((ast_expression*)arg1);
|
||||
|
@ -551,7 +551,7 @@ ast_expression *intrin::expm1_() {
|
|||
ast_block *body = ast_block_new(ctx());
|
||||
ast_function *func = value(&val, "expm1", TYPE_FLOAT);
|
||||
|
||||
val->expression.params.push_back(x);
|
||||
val->expression.type_params.push_back(x);
|
||||
|
||||
/* <callexp> = exp(x); */
|
||||
callexp->params.push_back((ast_expression*)x);
|
||||
|
@ -659,8 +659,8 @@ ast_expression *intrin::pow_() {
|
|||
body->locals.push_back(accumulate);
|
||||
body->locals.push_back(mid);
|
||||
|
||||
val->expression.params.push_back(base);
|
||||
val->expression.params.push_back(exp);
|
||||
val->expression.type_params.push_back(base);
|
||||
val->expression.type_params.push_back(exp);
|
||||
|
||||
/*
|
||||
* if (exp == 0.0)
|
||||
|
@ -1036,8 +1036,8 @@ ast_expression *intrin::mod_() {
|
|||
ast_block *body = ast_block_new(ctx());
|
||||
ast_function *func = value(&val, "mod", TYPE_FLOAT);
|
||||
|
||||
val->expression.params.push_back(a);
|
||||
val->expression.params.push_back(b);
|
||||
val->expression.type_params.push_back(a);
|
||||
val->expression.type_params.push_back(b);
|
||||
|
||||
body->locals.push_back(div);
|
||||
body->locals.push_back(sign);
|
||||
|
@ -1147,7 +1147,7 @@ ast_expression *intrin::fabs_() {
|
|||
)
|
||||
);
|
||||
|
||||
val->expression.params.push_back(arg1);
|
||||
val->expression.type_params.push_back(arg1);
|
||||
|
||||
func->blocks.push_back(body);
|
||||
reg(val, func);
|
||||
|
@ -1406,8 +1406,8 @@ ast_expression *intrin::ln_() {
|
|||
ast_function *func = value(&val, "ln", TYPE_FLOAT);
|
||||
size_t i;
|
||||
|
||||
val->expression.params.push_back(power);
|
||||
val->expression.params.push_back(base);
|
||||
val->expression.type_params.push_back(power);
|
||||
val->expression.type_params.push_back(base);
|
||||
|
||||
block->locals.push_back(whole);
|
||||
block->locals.push_back(nth);
|
||||
|
@ -1864,7 +1864,7 @@ ast_expression *intrin::log_variant(const char *name, float base) {
|
|||
ast_block *body = ast_block_new(ctx());
|
||||
ast_function *func = value(&val, name, TYPE_FLOAT);
|
||||
|
||||
val->expression.params.push_back(arg1);
|
||||
val->expression.type_params.push_back(arg1);
|
||||
|
||||
callln->params.push_back((ast_expression*)arg1);
|
||||
callln->params.push_back((ast_expression*)m_fold->constgen_float(base, false));
|
||||
|
@ -1908,8 +1908,8 @@ ast_expression *intrin::shift_variant(const char *name, size_t instr) {
|
|||
ast_block *body = ast_block_new(ctx());
|
||||
ast_function *func = value(&val, name, TYPE_FLOAT);
|
||||
|
||||
val->expression.params.push_back(a);
|
||||
val->expression.params.push_back(b);
|
||||
val->expression.type_params.push_back(a);
|
||||
val->expression.type_params.push_back(b);
|
||||
|
||||
/* <callpow> = pow(2, b) */
|
||||
callpow->params.push_back((ast_expression*)m_fold->m_imm_float[3]);
|
||||
|
|
46
parser.cpp
46
parser.cpp
|
@ -103,7 +103,7 @@ static ast_expression* parser_find_param(parser_t *parser, const char *name)
|
|||
if (!parser->function)
|
||||
return nullptr;
|
||||
fun = parser->function->function_type;
|
||||
for (auto &it : fun->expression.params) {
|
||||
for (auto &it : fun->expression.type_params) {
|
||||
if (!strcmp(it->name, name))
|
||||
return (ast_expression*)it;
|
||||
}
|
||||
|
@ -1316,22 +1316,22 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
|
|||
ast_ctx(fun).line);
|
||||
}
|
||||
|
||||
if (fun->params.size() != paramcount &&
|
||||
if (fun->type_params.size() != paramcount &&
|
||||
!((fun->flags & AST_FLAG_VARIADIC) &&
|
||||
fun->params.size() < paramcount))
|
||||
fun->type_params.size() < paramcount))
|
||||
{
|
||||
const char *fewmany = (fun->params.size() > paramcount) ? "few" : "many";
|
||||
const char *fewmany = (fun->type_params.size() > paramcount) ? "few" : "many";
|
||||
if (fval)
|
||||
return !parsewarning(parser, WARN_INVALID_PARAMETER_COUNT,
|
||||
"too %s parameters for call to %s: expected %i, got %i\n"
|
||||
" -> `%s` has been declared here: %s:%i",
|
||||
fewmany, fval->name, (int)fun->params.size(), (int)paramcount,
|
||||
fewmany, fval->name, (int)fun->type_params.size(), (int)paramcount,
|
||||
fval->name, ast_ctx(fun).file, (int)ast_ctx(fun).line);
|
||||
else
|
||||
return !parsewarning(parser, WARN_INVALID_PARAMETER_COUNT,
|
||||
"too %s parameters for function call: expected %i, got %i\n"
|
||||
" -> it has been declared here: %s:%i",
|
||||
fewmany, (int)fun->params.size(), (int)paramcount,
|
||||
fewmany, (int)fun->type_params.size(), (int)paramcount,
|
||||
ast_ctx(fun).file, (int)ast_ctx(fun).line);
|
||||
}
|
||||
}
|
||||
|
@ -4032,7 +4032,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
|
|||
|
||||
parser_enterblock(parser);
|
||||
|
||||
for (auto &it : var->expression.params) {
|
||||
for (auto &it : var->expression.type_params) {
|
||||
size_t e;
|
||||
ast_member *me[3];
|
||||
|
||||
|
@ -4079,7 +4079,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var)
|
|||
goto enderrfn;
|
||||
}
|
||||
func->varargs = varargs;
|
||||
func->fixedparams = (ast_value*)parser->m_fold.constgen_float(var->expression.params.size(), false);
|
||||
func->fixedparams = (ast_value*)parser->m_fold.constgen_float(var->expression.type_params.size(), false);
|
||||
}
|
||||
|
||||
parser->function = func;
|
||||
|
@ -4381,8 +4381,8 @@ static ast_value* parser_create_array_setter_proto(parser_t *parser, ast_value *
|
|||
goto cleanup;
|
||||
}
|
||||
(void)!ast_value_set_name(value, "value"); /* not important */
|
||||
fval->expression.params.push_back(index);
|
||||
fval->expression.params.push_back(value);
|
||||
fval->expression.type_params.push_back(index);
|
||||
fval->expression.type_params.push_back(value);
|
||||
|
||||
array->setter = fval;
|
||||
return fval;
|
||||
|
@ -4398,8 +4398,8 @@ static bool parser_create_array_setter_impl(parser_t *parser, ast_value *array)
|
|||
{
|
||||
ast_expression *root = nullptr;
|
||||
root = array_setter_node(parser, array,
|
||||
array->setter->expression.params[0],
|
||||
array->setter->expression.params[1],
|
||||
array->setter->expression.type_params[0],
|
||||
array->setter->expression.type_params[1],
|
||||
0, array->expression.count);
|
||||
if (!root) {
|
||||
parseerror(parser, "failed to build accessor search tree");
|
||||
|
@ -4446,9 +4446,9 @@ static bool parser_create_array_field_setter(parser_t *parser, ast_value *array,
|
|||
goto cleanup;
|
||||
}
|
||||
(void)!ast_value_set_name(value, "value"); /* not important */
|
||||
fval->expression.params.push_back(entity);
|
||||
fval->expression.params.push_back(index);
|
||||
fval->expression.params.push_back(value);
|
||||
fval->expression.type_params.push_back(entity);
|
||||
fval->expression.type_params.push_back(index);
|
||||
fval->expression.type_params.push_back(value);
|
||||
|
||||
root = array_field_setter_node(parser, array, entity, index, value, 0, array->expression.count);
|
||||
if (!root) {
|
||||
|
@ -4493,7 +4493,7 @@ static ast_value* parser_create_array_getter_proto(parser_t *parser, ast_value *
|
|||
parseerror(parser, "failed to create locals for array accessor");
|
||||
goto cleanup;
|
||||
}
|
||||
fval->expression.params.push_back(index);
|
||||
fval->expression.type_params.push_back(index);
|
||||
|
||||
array->getter = fval;
|
||||
return fval;
|
||||
|
@ -4508,7 +4508,7 @@ static bool parser_create_array_getter_impl(parser_t *parser, ast_value *array)
|
|||
{
|
||||
ast_expression *root = nullptr;
|
||||
|
||||
root = array_getter_node(parser, array, array->getter->expression.params[0], 0, array->expression.count);
|
||||
root = array_getter_node(parser, array, array->getter->expression.type_params[0], 0, array->expression.count);
|
||||
if (!root) {
|
||||
parseerror(parser, "failed to build accessor search tree");
|
||||
return false;
|
||||
|
@ -4631,7 +4631,7 @@ static ast_value *parse_parameter_list(parser_t *parser, ast_value *var)
|
|||
fval->expression.flags |= AST_FLAG_VARIADIC;
|
||||
var = fval;
|
||||
|
||||
var->expression.params = params;
|
||||
var->expression.type_params = params;
|
||||
var->expression.varparam = (ast_expression*)varparam;
|
||||
var->argcounter = argcounter;
|
||||
|
||||
|
@ -5234,8 +5234,8 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield
|
|||
goto cleanup;
|
||||
}
|
||||
/* we need the new parameter-names */
|
||||
for (i = 0; i < proto->expression.params.size(); ++i)
|
||||
ast_value_set_name(proto->expression.params[i], var->expression.params[i]->name);
|
||||
for (i = 0; i < proto->expression.type_params.size(); ++i)
|
||||
ast_value_set_name(proto->expression.type_params[i], var->expression.type_params[i]->name);
|
||||
if (!parser_check_qualifiers(parser, var, proto)) {
|
||||
retval = false;
|
||||
if (proto->desc)
|
||||
|
@ -6153,7 +6153,7 @@ static bool parser_set_coverage_func(parser_t *parser, ir_builder *ir) {
|
|||
cov = func->function_type;
|
||||
expr = (ast_expression*)cov;
|
||||
|
||||
if (expr->vtype != TYPE_FUNCTION || expr->params.size()) {
|
||||
if (expr->vtype != TYPE_FUNCTION || expr->type_params.size()) {
|
||||
char ty[1024];
|
||||
ast_type_to_string(expr, ty, sizeof(ty));
|
||||
con_out("invalid type for coverage(): %s\n", ty);
|
||||
|
@ -6226,8 +6226,8 @@ bool parser_finish(parser_t *parser, const char *output)
|
|||
*/
|
||||
for (auto &f : parser->functions) {
|
||||
if (f->varargs) {
|
||||
if (parser->max_param_count > f->function_type->expression.params.size()) {
|
||||
f->varargs->expression.count = parser->max_param_count - f->function_type->expression.params.size();
|
||||
if (parser->max_param_count > f->function_type->expression.type_params.size()) {
|
||||
f->varargs->expression.count = parser->max_param_count - f->function_type->expression.type_params.size();
|
||||
if (!parser_create_array_setter_impl(parser, f->varargs)) {
|
||||
con_out("failed to generate vararg setter for %s\n", f->name);
|
||||
ir_builder_delete(ir);
|
||||
|
|
Loading…
Reference in a new issue