#include <string.h>
#include <math.h>
+#include "intrin.h"
+#include "fold.h"
+#include "ast.h"
#include "parser.h"
#define PARSER_HT_LOCALS 2
{
ast_value *fun;
if (!parser->function)
- return NULL;
- fun = parser->function->vtype;
+ return nullptr;
+ fun = parser->function->function_type;
for (auto &it : fun->expression.params) {
if (!strcmp(it->name, name))
return (ast_expression*)it;
}
- return NULL;
+ return nullptr;
}
static ast_expression* parser_find_local(parser_t *parser, const char *name, size_t upto, bool *isparam)
if ( (e = (ast_value*)util_htgeth(parser->typedefs[i], name, hash)) )
return e;
}
- return NULL;
+ return nullptr;
}
struct sy_elem {
e.etype = 0;
e.off = 0;
e.out = v;
- e.block = NULL;
+ e.block = nullptr;
e.ctx = ctx;
e.isparen = false;
return e;
sy_elem e;
e.etype = 1 + (op - operators);
e.off = 0;
- e.out = NULL;
- e.block = NULL;
+ e.out = nullptr;
+ e.block = nullptr;
e.ctx = ctx;
e.isparen = false;
return e;
sy_elem e;
e.etype = 0;
e.off = off;
- e.out = NULL;
- e.block = NULL;
+ e.out = nullptr;
+ e.block = nullptr;
e.ctx = ctx;
e.isparen = true;
return e;
entfield = ast_entfield_new(ctx, entity, (ast_expression*)index);
*out = (ast_expression*)entfield;
- oldindex->array = NULL;
- oldindex->index = NULL;
+ oldindex->array = nullptr;
+ oldindex->index = nullptr;
ast_delete(oldindex);
return true;
{
const oper_info *op;
lex_ctx_t ctx;
- ast_expression *out = NULL;
+ ast_expression *out = nullptr;
ast_expression *exprs[3];
ast_block *blocks[3];
ast_binstore *asbinstore;
exprs[1]->vtype == TYPE_NOEXPR)
{
if (exprs[1] == (ast_expression*)parser->const_vec[0])
- out = (ast_expression*)ast_member_new(ctx, exprs[0], 0, NULL);
+ out = (ast_expression*)ast_member_new(ctx, exprs[0], 0, nullptr);
else if (exprs[1] == (ast_expression*)parser->const_vec[1])
- out = (ast_expression*)ast_member_new(ctx, exprs[0], 1, NULL);
+ out = (ast_expression*)ast_member_new(ctx, exprs[0], 1, nullptr);
else if (exprs[1] == (ast_expression*)parser->const_vec[2])
- out = (ast_expression*)ast_member_new(ctx, exprs[0], 2, NULL);
+ out = (ast_expression*)ast_member_new(ctx, exprs[0], 2, nullptr);
else {
compile_error(ctx, "access to invalid vector component");
return false;
out = exprs[0];
break;
case opid2('-','P'):
- if ((out = fold_op(parser->fold, op, exprs)))
+ if ((out = parser->m_fold.op(op, exprs)))
break;
if (exprs[0]->vtype != TYPE_FLOAT &&
break;
case opid2('!','P'):
- if (!(out = fold_op(parser->fold, op, exprs))) {
+ if (!(out = parser->m_fold.op(op, exprs))) {
switch (exprs[0]->vtype) {
case TYPE_FLOAT:
out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_F, exprs[0]);
type_name[exprs[1]->vtype]);
return false;
}
- if (!(out = fold_op(parser->fold, op, exprs))) {
+ if (!(out = parser->m_fold.op(op, exprs))) {
switch (exprs[0]->vtype) {
case TYPE_FLOAT:
- out = fold_binary(ctx, INSTR_ADD_F, exprs[0], exprs[1]);
+ out = fold::binary(ctx, INSTR_ADD_F, exprs[0], exprs[1]);
break;
case TYPE_VECTOR:
- out = fold_binary(ctx, INSTR_ADD_V, exprs[0], exprs[1]);
+ out = fold::binary(ctx, INSTR_ADD_V, exprs[0], exprs[1]);
break;
default:
compile_error(ctx, "invalid types used in expression: cannot add type %s and %s",
type_name[exprs[0]->vtype]);
return false;
}
- if (!(out = fold_op(parser->fold, op, exprs))) {
+ if (!(out = parser->m_fold.op(op, exprs))) {
switch (exprs[0]->vtype) {
case TYPE_FLOAT:
- out = fold_binary(ctx, INSTR_SUB_F, exprs[0], exprs[1]);
+ out = fold::binary(ctx, INSTR_SUB_F, exprs[0], exprs[1]);
break;
case TYPE_VECTOR:
- out = fold_binary(ctx, INSTR_SUB_V, exprs[0], exprs[1]);
+ out = fold::binary(ctx, INSTR_SUB_V, exprs[0], exprs[1]);
break;
default:
compile_error(ctx, "invalid types used in expression: cannot subtract type %s from %s",
type_name[exprs[0]->vtype]);
return false;
}
- if (!(out = fold_op(parser->fold, op, exprs))) {
+ if (!(out = parser->m_fold.op(op, exprs))) {
switch (exprs[0]->vtype) {
case TYPE_FLOAT:
if (exprs[1]->vtype == TYPE_VECTOR)
- out = fold_binary(ctx, INSTR_MUL_FV, exprs[0], exprs[1]);
+ out = fold::binary(ctx, INSTR_MUL_FV, exprs[0], exprs[1]);
else
- out = fold_binary(ctx, INSTR_MUL_F, exprs[0], exprs[1]);
+ out = fold::binary(ctx, INSTR_MUL_F, exprs[0], exprs[1]);
break;
case TYPE_VECTOR:
if (exprs[1]->vtype == TYPE_FLOAT)
- out = fold_binary(ctx, INSTR_MUL_VF, exprs[0], exprs[1]);
+ out = fold::binary(ctx, INSTR_MUL_VF, exprs[0], exprs[1]);
else
- out = fold_binary(ctx, INSTR_MUL_V, exprs[0], exprs[1]);
+ out = fold::binary(ctx, INSTR_MUL_V, exprs[0], exprs[1]);
break;
default:
compile_error(ctx, "invalid types used in expression: cannot multiply types %s and %s",
compile_error(ctx, "invalid types used in expression: cannot divide types %s and %s", ty1, ty2);
return false;
}
- if (!(out = fold_op(parser->fold, op, exprs))) {
+ if (!(out = parser->m_fold.op(op, exprs))) {
if (exprs[0]->vtype == TYPE_FLOAT)
- out = fold_binary(ctx, INSTR_DIV_F, exprs[0], exprs[1]);
+ out = fold::binary(ctx, INSTR_DIV_F, exprs[0], exprs[1]);
else {
ast_type_to_string(exprs[0], ty1, sizeof(ty1));
ast_type_to_string(exprs[1], ty2, sizeof(ty2));
type_name[exprs[0]->vtype],
type_name[exprs[1]->vtype]);
return false;
- } else if (!(out = fold_op(parser->fold, op, exprs))) {
+ } else if (!(out = parser->m_fold.op(op, exprs))) {
/* generate a call to __builtin_mod */
- ast_expression *mod = intrin_func(parser->intrin, "mod");
- ast_call *call = NULL;
+ ast_expression *mod = parser->m_intrin.func("mod");
+ ast_call *call = nullptr;
if (!mod) return false; /* can return null for missing floor */
call = ast_call_new(parser_ctx(parser), mod);
return false;
}
- if (!(out = fold_op(parser->fold, op, exprs))) {
+ if (!(out = parser->m_fold.op(op, exprs))) {
/*
* IF the first expression is float, the following will be too
* since scalar ^ vector is not allowed.
*/
if (exprs[0]->vtype == TYPE_FLOAT) {
- out = fold_binary(ctx,
+ out = fold::binary(ctx,
(op->id == opid1('^') ? VINSTR_BITXOR : op->id == opid1('|') ? INSTR_BITOR : INSTR_BITAND),
exprs[0], exprs[1]);
} else {
* Bitop all the values of the vector components against the
* vectors components in question.
*/
- out = fold_binary(ctx,
+ out = fold::binary(ctx,
(op->id == opid1('^') ? VINSTR_BITXOR_V : op->id == opid1('|') ? VINSTR_BITOR_V : VINSTR_BITAND_V),
exprs[0], exprs[1]);
} else {
- out = fold_binary(ctx,
+ out = fold::binary(ctx,
(op->id == opid1('^') ? VINSTR_BITXOR_VF : op->id == opid1('|') ? VINSTR_BITOR_VF : VINSTR_BITAND_VF),
exprs[0], exprs[1]);
}
return false;
}
- if (!(out = fold_op(parser->fold, op, exprs))) {
- ast_expression *shift = intrin_func(parser->intrin, (op->id == opid2('<','<')) ? "__builtin_lshift" : "__builtin_rshift");
- ast_call *call = ast_call_new(parser_ctx(parser), shift);
+ if (!(out = parser->m_fold.op(op, exprs))) {
+ ast_expression *shift = parser->m_intrin.func((op->id == opid2('<','<')) ? "__builtin_lshift" : "__builtin_rshift");
+ ast_call *call = ast_call_new(parser_ctx(parser), shift);
call->params.push_back(exprs[0]);
call->params.push_back(exprs[1]);
out = (ast_expression*)call;
return false;
}
- if(!(out = fold_op(parser->fold, op, exprs))) {
- ast_expression *shift = intrin_func(parser->intrin, (op->id == opid3('<','<','=')) ? "__builtin_lshift" : "__builtin_rshift");
- ast_call *call = ast_call_new(parser_ctx(parser), shift);
+ if(!(out = parser->m_fold.op(op, exprs))) {
+ ast_expression *shift = parser->m_intrin.func((op->id == opid3('<','<','=')) ? "__builtin_lshift" : "__builtin_rshift");
+ ast_call *call = ast_call_new(parser_ctx(parser), shift);
call->params.push_back(exprs[0]);
call->params.push_back(exprs[1]);
out = (ast_expression*)ast_store_new(
generated_op += 1; /* INSTR_OR */
case opid2('&','&'):
generated_op += INSTR_AND;
- if (!(out = fold_op(parser->fold, op, exprs))) {
+ if (!(out = parser->m_fold.op(op, exprs))) {
if (OPTS_FLAG(PERL_LOGIC) && !ast_compare_type(exprs[0], exprs[1])) {
ast_type_to_string(exprs[0], ty1, sizeof(ty1));
ast_type_to_string(exprs[1], ty2, sizeof(ty2));
if (!out) break;
out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_F, out);
if (!out) break;
- exprs[i] = out; out = NULL;
+ exprs[i] = out; out = nullptr;
if (OPTS_FLAG(PERL_LOGIC)) {
/* here we want to keep the right expressions' type */
break;
if (!out) break;
out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_F, out);
if (!out) break;
- exprs[i] = out; out = NULL;
+ exprs[i] = out; out = nullptr;
if (OPTS_FLAG(PERL_LOGIC)) {
/* here we want to keep the right expressions' type */
break;
}
}
}
- out = fold_binary(ctx, generated_op, exprs[0], exprs[1]);
+ out = fold::binary(ctx, generated_op, exprs[0], exprs[1]);
}
break;
compile_error(ctx, "operands of ternary expression must have the same type, got %s and %s", ty1, ty2);
return false;
}
- if (!(out = fold_op(parser->fold, op, exprs)))
+ if (!(out = parser->m_fold.op(op, exprs)))
out = (ast_expression*)ast_ternary_new(ctx, exprs[0], exprs[1], exprs[2]);
break;
return false;
}
- if (!(out = fold_op(parser->fold, op, exprs))) {
- ast_call *gencall = ast_call_new(parser_ctx(parser), intrin_func(parser->intrin, "pow"));
+ if (!(out = parser->m_fold.op(op, exprs))) {
+ ast_call *gencall = ast_call_new(parser_ctx(parser), parser->m_intrin.func("pow"));
gencall->params.push_back(exprs[0]);
gencall->params.push_back(exprs[1]);
out = (ast_expression*)gencall;
return false;
}
- if (!(out = fold_op(parser->fold, op, exprs))) {
- out = fold_binary(
- parser_ctx(parser),
- VINSTR_CROSS,
- exprs[0],
- exprs[1]
+ if (!(out = parser->m_fold.op(op, exprs))) {
+ out = fold::binary(
+ parser_ctx(parser),
+ VINSTR_CROSS,
+ exprs[0],
+ exprs[1]
);
}
return false;
}
- if (!(out = fold_op(parser->fold, op, exprs))) {
+ if (!(out = parser->m_fold.op(op, exprs))) {
/* This whole block is NOT fold_binary safe */
ast_binary *eq = ast_binary_new(ctx, INSTR_EQ_F, exprs[0], exprs[1]);
out = (ast_expression*)ast_ternary_new(ctx,
(ast_expression*)ast_binary_new(ctx, INSTR_LT, exprs[0], exprs[1]),
/* out = -1 */
- (ast_expression*)parser->fold->imm_float[2],
+ (ast_expression*)parser->m_fold.imm_float(2),
/* } else { */
/* if (eq) { */
(ast_expression*)ast_ternary_new(ctx, (ast_expression*)eq,
/* out = 0 */
- (ast_expression*)parser->fold->imm_float[0],
+ (ast_expression*)parser->m_fold.imm_float(0),
/* } else { */
/* out = 1 */
- (ast_expression*)parser->fold->imm_float[1]
+ (ast_expression*)parser->m_fold.imm_float(1)
/* } */
)
/* } */
type_name[exprs[1]->vtype]);
return false;
}
- if (!(out = fold_op(parser->fold, op, exprs)))
- out = fold_binary(ctx, generated_op, exprs[0], exprs[1]);
+ if (!(out = parser->m_fold.op(op, exprs)))
+ out = fold::binary(ctx, generated_op, exprs[0], exprs[1]);
break;
case opid2('!', '='):
if (exprs[0]->vtype != exprs[1]->vtype) {
type_name[exprs[1]->vtype]);
return false;
}
- if (!(out = fold_op(parser->fold, op, exprs)))
- out = fold_binary(ctx, type_ne_instr[exprs[0]->vtype], exprs[0], exprs[1]);
+ if (!(out = parser->m_fold.op(op, exprs)))
+ out = fold::binary(ctx, type_ne_instr[exprs[0]->vtype], exprs[0], exprs[1]);
break;
case opid2('=', '='):
if (exprs[0]->vtype != exprs[1]->vtype) {
type_name[exprs[1]->vtype]);
return false;
}
- if (!(out = fold_op(parser->fold, op, exprs)))
- out = fold_binary(ctx, type_eq_instr[exprs[0]->vtype], exprs[0], exprs[1]);
+ if (!(out = parser->m_fold.op(op, exprs)))
+ out = fold::binary(ctx, type_eq_instr[exprs[0]->vtype], exprs[0], exprs[1]);
break;
case opid1('='):
if (ast_istype(exprs[0], ast_entfield)) {
out = (ast_expression*)ast_binstore_new(ctx, INSTR_STOREP_F, addop,
exprs[0],
- (ast_expression*)parser->fold->imm_float[1]);
+ (ast_expression*)parser->m_fold.imm_float(1));
} else {
out = (ast_expression*)ast_binstore_new(ctx, INSTR_STORE_F, addop,
exprs[0],
- (ast_expression*)parser->fold->imm_float[1]);
+ (ast_expression*)parser->m_fold.imm_float(1));
}
break;
case opid3('S','+','+'):
if (ast_istype(exprs[0], ast_entfield)) {
out = (ast_expression*)ast_binstore_new(ctx, INSTR_STOREP_F, addop,
exprs[0],
- (ast_expression*)parser->fold->imm_float[1]);
+ (ast_expression*)parser->m_fold.imm_float(1));
} else {
out = (ast_expression*)ast_binstore_new(ctx, INSTR_STORE_F, addop,
exprs[0],
- (ast_expression*)parser->fold->imm_float[1]);
+ (ast_expression*)parser->m_fold.imm_float(1));
}
if (!out)
return false;
- out = fold_binary(ctx, subop,
+ out = fold::binary(ctx, subop,
out,
- (ast_expression*)parser->fold->imm_float[1]);
+ (ast_expression*)parser->m_fold.imm_float(1));
break;
case opid2('+','='):
out = (ast_expression*)ast_binstore_new(ctx, assignop, INSTR_MUL_VF,
exprs[0], exprs[1]);
} else {
- out = fold_binary(ctx, INSTR_DIV_F,
- (ast_expression*)parser->fold->imm_float[1],
+ out = fold::binary(ctx, INSTR_DIV_F,
+ (ast_expression*)parser->m_fold.imm_float(1),
exprs[1]);
if (!out) {
compile_error(ctx, "internal error: failed to generate division");
else
assignop = type_store_instr[exprs[0]->vtype];
if (exprs[0]->vtype == TYPE_FLOAT)
- out = fold_binary(ctx, INSTR_BITAND, exprs[0], exprs[1]);
+ out = fold::binary(ctx, INSTR_BITAND, exprs[0], exprs[1]);
else
- out = fold_binary(ctx, VINSTR_BITAND_V, exprs[0], exprs[1]);
+ out = fold::binary(ctx, VINSTR_BITAND_V, exprs[0], exprs[1]);
if (!out)
return false;
(void)check_write_to(ctx, exprs[0]);
compile_error(ast_ctx(exprs[0]), "operand of length operator not a valid constant expression");
return false;
}
- out = fold_op(parser->fold, op, exprs);
+ out = parser->m_fold.op(op, exprs);
break;
case opid2('~', 'P'):
compile_error(ast_ctx(exprs[0]), "invalid type for bit not: %s", ty1);
return false;
}
- if (!(out = fold_op(parser->fold, op, exprs))) {
+ if (!(out = parser->m_fold.op(op, exprs))) {
if (exprs[0]->vtype == TYPE_FLOAT) {
- out = fold_binary(ctx, INSTR_SUB_F, (ast_expression*)parser->fold->imm_float[2], exprs[0]);
+ out = fold::binary(ctx, INSTR_SUB_F, (ast_expression*)parser->m_fold.imm_float(2), exprs[0]);
} else {
- out = fold_binary(ctx, INSTR_SUB_V, (ast_expression*)parser->fold->imm_vector[1], exprs[0]);
+ out = fold::binary(ctx, INSTR_SUB_V, (ast_expression*)parser->m_fold.imm_vector(1), exprs[0]);
}
}
break;
{
/* was a function call */
ast_expression *fun;
- ast_value *funval = NULL;
+ ast_value *funval = nullptr;
ast_call *call;
size_t fid;
sy->argc.pop_back();
if (sy->out.size() < fid) {
- parseerror(parser, "internal error: broken function call%lu < %lu+%lu\n",
- (unsigned long)sy->out.size(),
- (unsigned long)fid,
- (unsigned long)paramcount);
+ parseerror(parser, "internal error: broken function call %zu < %zu+%zu\n",
+ sy->out.size(),
+ fid,
+ paramcount);
return false;
}
* TODO handle this at the intrinsic level with an ast_intrinsic
* node and codegen.
*/
- if ((fun = sy->out[fid].out) == intrin_debug_typestring(parser->intrin)) {
+ if ((fun = sy->out[fid].out) == parser->m_intrin.debug_typestring()) {
char ty[1024];
if (fid+2 != sy->out.size() || sy->out.back().block) {
parseerror(parser, "intrinsic __builtin_debug_typestring requires exactly 1 parameter");
ast_type_to_string(sy->out.back().out, ty, sizeof(ty));
ast_unref(sy->out.back().out);
sy->out[fid] = syexp(ast_ctx(sy->out.back().out),
- (ast_expression*)fold_constgen_string(parser->fold, ty, false));
+ (ast_expression*)parser->m_fold.constgen_string(ty, false));
sy->out.pop_back();
return true;
}
* intrinsic call and just evaluate it i.e constant fold it.
*/
if (fold && ast_istype(fun, ast_value) && ((ast_value*)fun)->intrinsic) {
- ast_expression **exprs = NULL;
- ast_expression *foldval = NULL;
+ ast_expression **exprs = nullptr;
+ ast_expression *foldval = nullptr;
for (i = 0; i < paramcount; i++)
vec_push(exprs, sy->out[fid+1 + i].out);
- if (!(foldval = intrin_fold(parser->intrin, (ast_value*)fun, exprs))) {
+ if (!(foldval = parser->m_intrin.do_fold((ast_value*)fun, exprs))) {
vec_free(exprs);
goto fold_leave;
}
* Blub: what sorts of unreffing and resizing of
* sy->out should I be doing here?
*/
- sy->out[fid] = syexp(foldval->node.context, foldval);
+ sy->out[fid] = syexp(foldval->context, foldval);
sy->out.erase(sy->out.end() - paramcount, sy->out.end());
vec_free(exprs);
return false;
if (fid+1 + paramcount != sy->out.size()) {
- parseerror(parser, "internal error: parameter count mismatch: (%lu+1+%lu), %lu",
- (unsigned long)fid, (unsigned long)paramcount, (unsigned long)sy->out.size());
+ parseerror(parser, "internal error: parameter count mismatch: (%zu+1+%zu), %zu",
+ fid,
+ paramcount,
+ sy->out.size());
return false;
}
for (i = 0; i < paramcount; ++i)
call->params.push_back(sy->out[fid+1 + i].out);
sy->out.erase(sy->out.end() - paramcount, sy->out.end());
- (void)!ast_call_check_types(call, parser->function->vtype->expression.varparam);
+ (void)!ast_call_check_types(call, parser->function->function_type->expression.varparam);
if (parser->max_param_count < paramcount)
parser->max_param_count = paramcount;
if ((fun->flags & AST_FLAG_VARIADIC) &&
!(/*funval->cvq == CV_CONST && */ funval->hasvalue && funval->constval.vfunc->builtin))
{
- call->va_count = (ast_expression*)fold_constgen_float(parser->fold, (qcfloat_t)paramcount, false);
+ call->va_count = (ast_expression*)parser->m_fold.constgen_float((qcfloat_t)paramcount, false);
}
}
/* overwrite fid, the function, with a call */
- sy->out[fid] = syexp(call->expression.node.context, (ast_expression*)call);
+ sy->out[fid] = syexp(call->expression.context, (ast_expression*)call);
if (fun->vtype != TYPE_FUNCTION) {
parseerror(parser, "not a function (%s)", type_name[fun->vtype]);
parseerror(parser, "could not determine function return type");
return false;
} else {
- ast_value *fval = (ast_istype(fun, ast_value) ? ((ast_value*)fun) : NULL);
+ ast_value *fval = (ast_istype(fun, ast_value) ? ((ast_value*)fun) : nullptr);
if (fun->flags & AST_FLAG_DEPRECATED) {
if (!fval) {
{
ast_expression *idx, *out;
ast_value *typevar;
- ast_value *funtype = parser->function->vtype;
+ ast_value *funtype = parser->function->function_type;
lex_ctx_t ctx = parser_ctx(parser);
if (!parser->function->varargs) {
parseerror(parser, "function has no variable argument list");
- return NULL;
+ return nullptr;
}
if (!parser_next(parser) || parser->tok != '(') {
parseerror(parser, "expected parameter index and type in parenthesis");
- return NULL;
+ return nullptr;
}
if (!parser_next(parser)) {
parseerror(parser, "error parsing parameter index");
- return NULL;
+ return nullptr;
}
idx = parse_expression_leave(parser, true, false, false);
if (!idx)
- return NULL;
+ return nullptr;
if (parser->tok != ',') {
if (parser->tok != ')') {
ast_unref(idx);
parseerror(parser, "expected comma after parameter index");
- return NULL;
+ return nullptr;
}
/* vararg piping: ...(start) */
out = (ast_expression*)ast_argpipe_new(ctx, idx);
if (!parser_next(parser) || (parser->tok != TOKEN_IDENT && parser->tok != TOKEN_TYPENAME)) {
ast_unref(idx);
parseerror(parser, "expected typename for vararg");
- return NULL;
+ return nullptr;
}
- typevar = parse_typename(parser, NULL, NULL, NULL);
+ typevar = parse_typename(parser, nullptr, nullptr, nullptr);
if (!typevar) {
ast_unref(idx);
- return NULL;
+ return nullptr;
}
if (parser->tok != ')') {
ast_unref(idx);
ast_delete(typevar);
parseerror(parser, "expected closing paren");
- return NULL;
+ return nullptr;
}
if (funtype->expression.varparam &&
parseerror(parser, "expected a constant string in translatable-string extension");
return false;
}
- val = (ast_value*)fold_constgen_string(parser->fold, parser_tokval(parser), true);
+ val = (ast_value*)parser->m_fold.constgen_string(parser_tokval(parser), true);
if (!val)
return false;
sy->out.push_back(syexp(parser_ctx(parser), (ast_expression*)val));
return true;
}
else if (parser->tok == TOKEN_FLOATCONST) {
- ast_expression *val = fold_constgen_float(parser->fold, (parser_token(parser)->constval.f), false);
+ ast_expression *val = parser->m_fold.constgen_float((parser_token(parser)->constval.f), false);
if (!val)
return false;
sy->out.push_back(syexp(parser_ctx(parser), val));
return true;
}
else if (parser->tok == TOKEN_INTCONST || parser->tok == TOKEN_CHARCONST) {
- ast_expression *val = fold_constgen_float(parser->fold, (qcfloat_t)(parser_token(parser)->constval.i), false);
+ ast_expression *val = parser->m_fold.constgen_float((qcfloat_t)(parser_token(parser)->constval.i), false);
if (!val)
return false;
sy->out.push_back(syexp(parser_ctx(parser), val));
return true;
}
else if (parser->tok == TOKEN_STRINGCONST) {
- ast_expression *val = fold_constgen_string(parser->fold, parser_tokval(parser), false);
+ ast_expression *val = parser->m_fold.constgen_string(parser_tokval(parser), false);
if (!val)
return false;
sy->out.push_back(syexp(parser_ctx(parser), val));
return true;
}
else if (parser->tok == TOKEN_VECTORCONST) {
- ast_expression *val = fold_constgen_vector(parser->fold, parser_token(parser)->constval.v);
+ ast_expression *val = parser->m_fold.constgen_vector(parser_token(parser)->constval.v);
if (!val)
return false;
sy->out.push_back(syexp(parser_ctx(parser), val));
else if (parser->tok == TOKEN_IDENT)
{
const char *ctoken = parser_tokval(parser);
- ast_expression *prev = sy->out.size() ? sy->out.back().out : NULL;
+ ast_expression *prev = sy->out.size() ? sy->out.back().out : nullptr;
ast_expression *var;
/* a_vector.{x,y,z} */
if (sy->ops.empty() ||
operators[sy->ops.back().etype-1].id != opid1('.'))
{
/* When adding more intrinsics, fix the above condition */
- prev = NULL;
+ prev = nullptr;
}
if (prev && prev->vtype == TYPE_VECTOR && ctoken[0] >= 'x' && ctoken[0] <= 'z' && !ctoken[1])
{
}
}
if (!var && !strcmp(parser_tokval(parser), "__FUNC__"))
- var = (ast_expression*)fold_constgen_string(parser->fold, parser->function->name, false);
+ var = (ast_expression*)parser->m_fold.constgen_string(parser->function->name, false);
if (!var) {
/*
* now we try for the real intrinsic hashtable. If the string
* use the identifier as is.
*/
if (!strncmp(parser_tokval(parser), "__builtin_", 10)) {
- var = intrin_func(parser->intrin, parser_tokval(parser));
+ var = parser->m_intrin.func(parser_tokval(parser));
}
/*
* the first one masks for __builtin though, we emit warning here.
*/
if (!var) {
- if ((var = intrin_func(parser->intrin, parser_tokval(parser)))) {
+ if ((var = parser->m_intrin.func(parser_tokval(parser)))) {
(void)!compile_warning(
parser_ctx(parser),
WARN_BUILTINS,
static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma, bool truthvalue, bool with_labels)
{
- ast_expression *expr = NULL;
+ ast_expression *expr = nullptr;
shunt sy;
bool wantop = false;
/* only warn once about an assignment in a truth value because the current code
{
/* classify the operator */
const oper_info *op;
- const oper_info *olast = NULL;
+ const oper_info *olast = nullptr;
size_t o;
for (o = 0; o < operator_count; ++o) {
if (((!(operators[o].flags & OP_PREFIX) == !!wantop)) &&
if (sy.ops.size() && !sy.ops.back().isparen)
olast = &operators[sy.ops.back().etype-1];
else
- olast = NULL;
+ olast = nullptr;
}
#define IsAssignOp(x) (\
if (sy.ops.size() && !sy.ops.back().isparen)
olast = &operators[sy.ops.back().etype-1];
else
- olast = NULL;
+ olast = nullptr;
}
if (op->id == opid1('(')) {
if (last->isimm == true && last->cvq == CV_CONST &&
last->hasvalue && last->expression.vtype == TYPE_STRING)
{
- char *newstr = NULL;
+ char *newstr = nullptr;
util_asprintf(&newstr, "%s%s", last->constval.vstring, parser_tokval(parser));
- sy.out.back().out = (ast_expression*)fold_constgen_string(parser->fold, newstr, false);
+ sy.out.back().out = (ast_expression*)parser->m_fold.constgen_string(newstr, false);
mem_d(newstr);
concatenated = true;
}
parser->lex->flags.noops = true;
if (sy.out.size() != 1) {
parseerror(parser, "expression expected");
- expr = NULL;
+ expr = nullptr;
} else
expr = sy.out[0].out;
if (sy.paren.size()) {
- parseerror(parser, "internal error: vec_size(sy.paren) = %lu", (unsigned long)sy.paren.size());
- return NULL;
+ parseerror(parser, "internal error: sy.paren.size() = %zu", sy.paren.size());
+ return nullptr;
}
return expr;
parser->lex->flags.noops = true;
for (auto &it : sy.out)
if (it.out) ast_unref(it.out);
- return NULL;
+ return nullptr;
}
static ast_expression* parse_expression(parser_t *parser, bool stopatcomma, bool with_labels)
{
ast_expression *e = parse_expression_leave(parser, stopatcomma, false, with_labels);
if (!e)
- return NULL;
+ return nullptr;
if (parser->tok != ';') {
parseerror(parser, "semicolon expected after expression");
ast_unref(e);
- return NULL;
+ return nullptr;
}
if (!parser_next(parser)) {
ast_unref(e);
- return NULL;
+ return nullptr;
}
return e;
}
if (!cond) {
ast_unref(prev);
parseerror(parser, "internal error: failed to process condition");
- return NULL;
+ return nullptr;
}
ifnot = !ifnot;
}
if (!cond) {
ast_unref(prev);
parseerror(parser, "internal error: failed to process condition");
- return NULL;
+ return nullptr;
}
ifnot = !ifnot;
}
while (cond && ast_istype(cond, ast_unary) && unary->op == INSTR_NOT_F)
{
cond = unary->operand;
- unary->operand = NULL;
+ unary->operand = nullptr;
ast_delete(unary);
ifnot = !ifnot;
unary = (ast_unary*)cond;
static bool parse_if(parser_t *parser, ast_block *block, ast_expression **out)
{
ast_ifthen *ifthen;
- ast_expression *cond, *ontrue = NULL, *onfalse = NULL;
+ ast_expression *cond, *ontrue = nullptr, *onfalse = nullptr;
bool ifnot = false;
lex_ctx_t ctx = parser_ctx(parser);
static bool parse_while(parser_t *parser, ast_block *block, ast_expression **out)
{
bool rv;
- char *label = NULL;
+ char *label = nullptr;
/* skip the 'while' and get the body */
if (!parser_next(parser)) {
parseerror(parser, "internal error: label stack corrupted");
rv = false;
ast_delete(*out);
- *out = NULL;
+ *out = nullptr;
}
else {
parser->breaks.pop_back();
ast_unref(ontrue);
return false;
}
- aloop = ast_loop_new(ctx, NULL, cond, ifnot, NULL, false, NULL, ontrue);
+ aloop = ast_loop_new(ctx, nullptr, cond, ifnot, nullptr, false, nullptr, ontrue);
*out = (ast_expression*)aloop;
return true;
}
static bool parse_dowhile(parser_t *parser, ast_block *block, ast_expression **out)
{
bool rv;
- char *label = NULL;
+ char *label = nullptr;
/* skip the 'do' and get the body */
if (!parser_next(parser)) {
parseerror(parser, "internal error: label stack corrupted");
rv = false;
/*
- * Test for NULL otherwise ast_delete dereferences null pointer
+ * Test for nullptr otherwise ast_delete dereferences null pointer
* and boom.
*/
if (*out)
ast_delete(*out);
- *out = NULL;
+ *out = nullptr;
}
else {
parser->breaks.pop_back();
ast_delete(ontrue);
return false;
}
- aloop = ast_loop_new(ctx, NULL, NULL, false, cond, ifnot, NULL, ontrue);
+ aloop = ast_loop_new(ctx, nullptr, nullptr, false, cond, ifnot, nullptr, ontrue);
*out = (ast_expression*)aloop;
return true;
}
static bool parse_for(parser_t *parser, ast_block *block, ast_expression **out)
{
bool rv;
- char *label = NULL;
+ char *label = nullptr;
/* skip the 'for' and check for opening paren */
if (!parser_next(parser)) {
parseerror(parser, "internal error: label stack corrupted");
rv = false;
ast_delete(*out);
- *out = NULL;
+ *out = nullptr;
}
else {
parser->breaks.pop_back();
parser_enterblock(parser);
- initexpr = NULL;
- cond = NULL;
- increment = NULL;
- ontrue = NULL;
+ initexpr = nullptr;
+ cond = nullptr;
+ increment = nullptr;
+ ontrue = nullptr;
/* parse into the expression */
if (!parser_next(parser)) {
goto onerr;
}
- typevar = NULL;
+ typevar = nullptr;
if (parser->tok == TOKEN_IDENT)
typevar = parser_find_typedef(parser, parser_tokval(parser), 0);
if (typevar || parser->tok == TOKEN_TYPENAME) {
- if (!parse_variable(parser, block, true, CV_VAR, typevar, false, false, 0, NULL))
+ if (!parse_variable(parser, block, true, CV_VAR, typevar, false, false, 0, nullptr))
goto onerr;
}
else if (parser->tok != ';')
if (!cond)
goto onerr;
}
- aloop = ast_loop_new(ctx, initexpr, cond, ifnot, NULL, false, increment, ontrue);
+ aloop = ast_loop_new(ctx, initexpr, cond, ifnot, nullptr, false, increment, ontrue);
*out = (ast_expression*)aloop;
if (!parser_leaveblock(parser)) {
static bool parse_return(parser_t *parser, ast_block *block, ast_expression **out)
{
- ast_expression *exp = NULL;
- ast_expression *var = NULL;
- ast_return *ret = NULL;
+ ast_expression *exp = nullptr;
+ ast_expression *var = nullptr;
+ ast_return *ret = nullptr;
ast_value *retval = parser->function->return_value;
- ast_value *expected = parser->function->vtype;
+ ast_value *expected = parser->function->function_type;
lex_ctx_t ctx = parser_ctx(parser);
}
else if (!strcmp(parser_tokval(parser), "alias") && !(flags & AST_FLAG_ALIAS)) {
flags |= AST_FLAG_ALIAS;
- *message = NULL;
+ *message = nullptr;
if (!parser_next(parser)) {
parseerror(parser, "parse error in attribute");
}
else if (!strcmp(parser_tokval(parser), "deprecated") && !(flags & AST_FLAG_DEPRECATED)) {
flags |= AST_FLAG_DEPRECATED;
- *message = NULL;
+ *message = nullptr;
if (!parser_next(parser)) {
parseerror(parser, "parse error in attribute");
argerr: /* ugly */
if (*message) mem_d(*message);
- *message = NULL;
+ *message = nullptr;
*cvq = CV_WRONG;
return false;
}
static bool parse_switch(parser_t *parser, ast_block *block, ast_expression **out)
{
bool rv;
- char *label = NULL;
+ char *label = nullptr;
/* skip the 'while' and get the body */
if (!parser_next(parser)) {
parseerror(parser, "internal error: label stack corrupted");
rv = false;
ast_delete(*out);
- *out = NULL;
+ *out = nullptr;
}
else {
parser->breaks.pop_back();
/* new block; allow some variables to be declared here */
parser_enterblock(parser);
while (true) {
- typevar = NULL;
+ typevar = nullptr;
if (parser->tok == TOKEN_IDENT)
typevar = parser_find_typedef(parser, parser_tokval(parser), 0);
if (typevar || parser->tok == TOKEN_TYPENAME) {
- if (!parse_variable(parser, block, true, CV_NONE, typevar, false, false, 0, NULL)) {
+ if (!parse_variable(parser, block, true, CV_NONE, typevar, false, false, 0, nullptr)) {
ast_delete(switchnode);
return false;
}
continue;
}
- if (parse_qualifiers(parser, true, &cvq, &noref, &is_static, &qflags, NULL))
+ if (parse_qualifiers(parser, true, &cvq, &noref, &is_static, &qflags, nullptr))
{
if (cvq == CV_WRONG) {
ast_delete(switchnode);
return false;
}
- if (!parse_variable(parser, block, true, cvq, NULL, noref, is_static, qflags, NULL)) {
+ if (!parse_variable(parser, block, true, cvq, nullptr, noref, is_static, qflags, nullptr)) {
ast_delete(switchnode);
return false;
}
}
}
else if (!strcmp(parser_tokval(parser), "default")) {
- swcase.value = NULL;
+ swcase.value = nullptr;
if (!parser_next(parser)) {
ast_delete(switchnode);
parseerror(parser, "expected colon");
ast_expression *cond;
if (!*side)
- return NULL;
+ return nullptr;
if (ast_istype(*side, ast_ternary)) {
ast_ternary *tern = (ast_ternary*)*side;
parseerror(parser, "expected label or expression in ternary");
if (on_true) ast_unref(on_true);
if (on_false) ast_unref(on_false);
- return NULL;
+ return nullptr;
}
cond = tern->cond;
- tern->cond = NULL;
+ tern->cond = nullptr;
ast_delete(tern);
- *side = NULL;
+ *side = nullptr;
return (ast_expression*)ast_ifthen_new(parser_ctx(parser), cond, on_true, on_false);
} else if (ast_istype(*side, ast_label)) {
ast_goto *gt = ast_goto_new(parser_ctx(parser), ((ast_label*)*side)->name);
ast_goto_set_label(gt, ((ast_label*)*side));
- *side = NULL;
+ *side = nullptr;
return (ast_expression*)gt;
}
- return NULL;
+ return nullptr;
}
static bool parse_goto(parser_t *parser, ast_expression **out)
{
- ast_goto *gt = NULL;
+ ast_goto *gt = nullptr;
ast_expression *lbl;
if (!parser_next(parser))
bool noref, is_static;
int cvq = CV_NONE;
uint32_t qflags = 0;
- ast_value *typevar = NULL;
- char *vstring = NULL;
+ ast_value *typevar = nullptr;
+ char *vstring = nullptr;
- *out = NULL;
+ *out = nullptr;
if (parser->tok == TOKEN_IDENT)
typevar = parser_find_typedef(parser, parser_tokval(parser), 0);
if (parsewarning(parser, WARN_EXTENSIONS, "missing 'local' keyword when declaring a local variable"))
return false;
}
- if (!parse_variable(parser, block, false, CV_NONE, typevar, false, false, 0, NULL))
+ if (!parse_variable(parser, block, false, CV_NONE, typevar, false, false, 0, nullptr))
return false;
return true;
}
{
if (cvq == CV_WRONG)
return false;
- return parse_variable(parser, block, false, cvq, NULL, noref, is_static, qflags, vstring);
+ return parse_variable(parser, block, false, cvq, nullptr, noref, is_static, qflags, vstring);
}
else if (parser->tok == TOKEN_KEYWORD)
{
bool flag = false;
bool reverse = false;
qcfloat_t num = 0;
- ast_value **values = NULL;
- ast_value *var = NULL;
+ ast_value **values = nullptr;
+ ast_value *var = nullptr;
ast_value *asvalue;
ast_expression *old;
while (parser->tok != TOKEN_EOF && parser->tok < TOKEN_ERROR)
{
- ast_expression *expr = NULL;
+ ast_expression *expr = nullptr;
if (parser->tok == '}')
break;
if (!parse_statement(parser, block, &expr, false)) {
/* parseerror(parser, "parse error"); */
- block = NULL;
+ block = nullptr;
goto cleanup;
}
if (!expr)
continue;
if (!ast_block_add_expr(block, expr)) {
ast_delete(block);
- block = NULL;
+ block = nullptr;
goto cleanup;
}
}
if (parser->tok != '}') {
- block = NULL;
+ block = nullptr;
} else {
(void)parser_next(parser);
}
ast_block *block;
block = ast_block_new(parser_ctx(parser));
if (!block)
- return NULL;
+ return nullptr;
if (!parse_block_into(parser, block)) {
ast_block_delete(block);
- return NULL;
+ return nullptr;
}
return block;
}
*out = (ast_expression*)parse_block(parser);
return !!*out;
}
- return parse_statement(parser, NULL, out, false);
+ return parse_statement(parser, nullptr, out, false);
}
static bool create_vector_members(ast_value *var, ast_member **me)
static bool parse_function_body(parser_t *parser, ast_value *var)
{
- ast_block *block = NULL;
+ ast_block *block = nullptr;
ast_function *func;
ast_function *old;
- ast_expression *framenum = NULL;
- ast_expression *nextthink = NULL;
+ ast_expression *framenum = nullptr;
+ ast_expression *nextthink = nullptr;
/* None of the following have to be deleted */
- ast_expression *fld_think = NULL, *fld_nextthink = NULL, *fld_frame = NULL;
- ast_expression *gbl_time = NULL, *gbl_self = NULL;
+ ast_expression *fld_think = nullptr, *fld_nextthink = nullptr, *fld_frame = nullptr;
+ ast_expression *gbl_time = nullptr, *gbl_self = nullptr;
bool has_frame_think;
bool retval = true;
* self.nextthink = time + 0.1;
* self.think = nextthink;
*/
- nextthink = NULL;
+ nextthink = nullptr;
fld_think = parser_find_field(parser, "think");
fld_nextthink = parser_find_field(parser, "nextthink");
self_think = (ast_expression*)ast_entfield_new(ctx, gbl_self, fld_think);
time_plus_1 = (ast_expression*)ast_binary_new(ctx, INSTR_ADD_F,
- gbl_time, (ast_expression*)fold_constgen_float(parser->fold, frame_delta, false));
+ gbl_time, (ast_expression*)parser->m_fold.constgen_float(frame_delta, false));
if (!self_frame || !self_nextthink || !self_think || !time_plus_1) {
if (self_frame) ast_delete(self_frame);
func = var->constval.vfunc;
if (!func) {
- parseerror(parser, "internal error: NULL function: `%s`", var->name);
+ parseerror(parser, "internal error: nullptr function: `%s`", var->name);
ast_block_delete(block);
goto enderr;
}
char name[1024];
ast_value *varargs = ast_value_new(ast_ctx(var), "reserved:va_args", TYPE_ARRAY);
varargs->expression.flags |= AST_FLAG_IS_VARARG;
- varargs->expression.next = (ast_expression*)ast_value_new(ast_ctx(var), NULL, TYPE_VECTOR);
+ varargs->expression.next = (ast_expression*)ast_value_new(ast_ctx(var), nullptr, TYPE_VECTOR);
varargs->expression.count = 0;
util_snprintf(name, sizeof(name), "%s##va##SET", var->name);
if (!parser_create_array_setter_proto(parser, varargs, name)) {
goto enderrfn;
}
func->varargs = varargs;
- func->fixedparams = (ast_value*)fold_constgen_float(parser->fold, var->expression.params.size(), false);
+ func->fixedparams = (ast_value*)parser->m_fold.constgen_float(var->expression.params.size(), false);
}
parser->function = func;
(void)!parser_leaveblock(parser);
parser->functions.pop_back();
ast_function_delete(func);
- var->constval.vfunc = NULL;
+ var->constval.vfunc = nullptr;
enderr:
parser->function = old;
if (!left || !right) {
if (left) ast_delete(left);
if (right) ast_delete(right);
- return NULL;
+ return nullptr;
}
cmp = ast_binary_new(ctx, INSTR_LT,
(ast_expression*)index,
- (ast_expression*)fold_constgen_float(parser->fold, middle, false));
+ (ast_expression*)parser->m_fold.constgen_float(middle, false));
if (!cmp) {
ast_delete(left);
ast_delete(right);
parseerror(parser, "internal error: failed to create comparison for array setter");
- return NULL;
+ return nullptr;
}
ifthen = ast_ifthen_new(ctx, (ast_expression*)cmp, left, right);
if (!ifthen) {
ast_delete(cmp); /* will delete left and right */
parseerror(parser, "internal error: failed to create conditional jump for array setter");
- return NULL;
+ return nullptr;
}
return (ast_expression*)ifthen;
if (value->expression.vtype == TYPE_FIELD && value->expression.next->vtype == TYPE_VECTOR)
assignop = INSTR_STORE_V;
- subscript = ast_array_index_new(ctx, (ast_expression*)array, (ast_expression*)fold_constgen_float(parser->fold, from, false));
+ subscript = ast_array_index_new(ctx, (ast_expression*)array, (ast_expression*)parser->m_fold.constgen_float(from, false));
if (!subscript)
- return NULL;
+ return nullptr;
st = ast_store_new(ctx, assignop, (ast_expression*)subscript, (ast_expression*)value);
if (!st) {
ast_delete(subscript);
- return NULL;
+ return nullptr;
}
block = ast_block_new(ctx);
if (!block) {
ast_delete(st);
- return NULL;
+ return nullptr;
}
if (!ast_block_add_expr(block, (ast_expression*)st)) {
ast_delete(block);
- return NULL;
+ return nullptr;
}
- ret = ast_return_new(ctx, NULL);
+ ret = ast_return_new(ctx, nullptr);
if (!ret) {
ast_delete(block);
- return NULL;
+ return nullptr;
}
if (!ast_block_add_expr(block, (ast_expression*)ret)) {
ast_delete(block);
- return NULL;
+ return nullptr;
}
return (ast_expression*)block;
if (value->expression.vtype == TYPE_FIELD && value->expression.next->vtype == TYPE_VECTOR)
assignop = INSTR_STOREP_V;
- subscript = ast_array_index_new(ctx, (ast_expression*)array, (ast_expression*)fold_constgen_float(parser->fold, from, false));
+ subscript = ast_array_index_new(ctx, (ast_expression*)array, (ast_expression*)parser->m_fold.constgen_float(from, false));
if (!subscript)
- return NULL;
+ return nullptr;
subscript->expression.next = ast_type_copy(ast_ctx(subscript), (ast_expression*)subscript);
subscript->expression.vtype = TYPE_FIELD;
(ast_expression*)subscript);
if (!entfield) {
ast_delete(subscript);
- return NULL;
+ return nullptr;
}
st = ast_store_new(ctx, assignop, (ast_expression*)entfield, (ast_expression*)value);
if (!st) {
ast_delete(entfield);
- return NULL;
+ return nullptr;
}
block = ast_block_new(ctx);
if (!block) {
ast_delete(st);
- return NULL;
+ return nullptr;
}
if (!ast_block_add_expr(block, (ast_expression*)st)) {
ast_delete(block);
- return NULL;
+ return nullptr;
}
- ret = ast_return_new(ctx, NULL);
+ ret = ast_return_new(ctx, nullptr);
if (!ret) {
ast_delete(block);
- return NULL;
+ return nullptr;
}
if (!ast_block_add_expr(block, (ast_expression*)ret)) {
ast_delete(block);
- return NULL;
+ return nullptr;
}
return (ast_expression*)block;
ast_return *ret;
ast_array_index *subscript;
- subscript = ast_array_index_new(ctx, (ast_expression*)array, (ast_expression*)fold_constgen_float(parser->fold, from, false));
+ subscript = ast_array_index_new(ctx, (ast_expression*)array, (ast_expression*)parser->m_fold.constgen_float(from, false));
if (!subscript)
- return NULL;
+ return nullptr;
ret = ast_return_new(ctx, (ast_expression*)subscript);
if (!ret) {
ast_delete(subscript);
- return NULL;
+ return nullptr;
}
return (ast_expression*)ret;
static bool parser_create_array_accessor(parser_t *parser, ast_value *array, const char *funcname, ast_value **out)
{
- ast_function *func = NULL;
- ast_value *fval = NULL;
- ast_block *body = NULL;
+ ast_function *func = nullptr;
+ ast_value *fval = nullptr;
+ ast_block *body = nullptr;
fval = ast_value_new(ast_ctx(array), funcname, TYPE_FUNCTION);
if (!fval) {
static ast_value* parser_create_array_setter_proto(parser_t *parser, ast_value *array, const char *funcname)
{
- ast_value *index = NULL;
- ast_value *value = NULL;
+ ast_value *index = nullptr;
+ ast_value *value = nullptr;
ast_function *func;
ast_value *fval;
if (!ast_istype(array->expression.next, ast_value)) {
parseerror(parser, "internal error: array accessor needs to build an ast_value with a copy of the element type");
- return NULL;
+ return nullptr;
}
if (!parser_create_array_accessor(parser, array, funcname, &fval))
- return NULL;
+ return nullptr;
func = fval->constval.vfunc;
fval->expression.next = (ast_expression*)ast_value_new(ast_ctx(array), "<void>", TYPE_VOID);
if (value) ast_delete(value);
ast_delete(func);
ast_delete(fval);
- return NULL;
+ return nullptr;
}
static bool parser_create_array_setter_impl(parser_t *parser, ast_value *array)
{
- ast_expression *root = NULL;
+ ast_expression *root = nullptr;
root = array_setter_node(parser, array,
array->setter->expression.params[0],
array->setter->expression.params[1],
static bool parser_create_array_field_setter(parser_t *parser, ast_value *array, const char *funcname)
{
- ast_expression *root = NULL;
- ast_value *entity = NULL;
- ast_value *index = NULL;
- ast_value *value = NULL;
+ ast_expression *root = nullptr;
+ ast_value *entity = nullptr;
+ ast_value *index = nullptr;
+ ast_value *value = nullptr;
ast_function *func;
ast_value *fval;
static ast_value* parser_create_array_getter_proto(parser_t *parser, ast_value *array, const ast_expression *elemtype, const char *funcname)
{
- ast_value *index = NULL;
+ ast_value *index = nullptr;
ast_value *fval;
ast_function *func;
*/
if (!ast_istype(array->expression.next, ast_value)) {
parseerror(parser, "internal error: array accessor needs to build an ast_value with a copy of the element type");
- return NULL;
+ return nullptr;
}
if (!parser_create_array_accessor(parser, array, funcname, &fval))
- return NULL;
+ return nullptr;
func = fval->constval.vfunc;
fval->expression.next = ast_type_copy(ast_ctx(array), elemtype);
if (index) ast_delete(index);
ast_delete(func);
ast_delete(fval);
- return NULL;
+ return nullptr;
}
static bool parser_create_array_getter_impl(parser_t *parser, ast_value *array)
{
- ast_expression *root = NULL;
+ ast_expression *root = nullptr;
root = array_getter_node(parser, array, array->getter->expression.params[0], 0, array->expression.count);
if (!root) {
ast_value *fval;
bool first = true;
bool variadic = false;
- ast_value *varparam = NULL;
- char *argcounter = NULL;
+ ast_value *varparam = nullptr;
+ char *argcounter = nullptr;
/* 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;
+ return nullptr;
}
/* parse variables until we hit a closing paren */
}
first = false;
- ast_value *param = parse_typename(parser, NULL, NULL, &is_varargs);
+ ast_value *param = parse_typename(parser, nullptr, nullptr, &is_varargs);
if (!param && !is_varargs)
goto on_error;
if (is_varargs) {
ast_delete(var);
for (auto &it : params)
ast_delete(it);
- return NULL;
+ return nullptr;
}
static ast_value *parse_arraysize(parser_t *parser, ast_value *var)
if (!parser_next(parser)) {
ast_delete(var);
parseerror(parser, "expected array-size");
- return NULL;
+ return nullptr;
}
if (parser->tok != ']') {
ast_unref(cexp);
ast_delete(var);
parseerror(parser, "expected array-size as constant positive integer");
- return NULL;
+ return nullptr;
}
cval = (ast_value*)cexp;
}
else {
- cexp = NULL;
- cval = NULL;
+ cexp = nullptr;
+ cval = nullptr;
}
tmp = ast_value_new(ctx, "<type[]>", TYPE_ARRAY);
ast_unref(cexp);
ast_delete(var);
parseerror(parser, "array-size must be a positive integer constant");
- return NULL;
+ return nullptr;
}
ast_unref(cexp);
if (parser->tok != ']') {
ast_delete(var);
parseerror(parser, "expected ']' after array-size");
- return NULL;
+ return nullptr;
}
if (!parser_next(parser)) {
ast_delete(var);
parseerror(parser, "error after parsing array size");
- return NULL;
+ return nullptr;
}
return var;
}
/* Parse a complete typename.
- * for single-variables (ie. function parameters or typedefs) storebase should be NULL
+ * for single-variables (ie. function parameters or typedefs) storebase should be nullptr
* but when parsing variables separated by comma
* 'storebase' should point to where the base-type should be kept.
* The base type makes up every bit of type information which comes *before* the
* variable name.
*
- * NOTE: The value must either be named, have a NULL name, or a name starting
+ * NOTE: The value must either be named, have a nullptr name, or a name starting
* with '<'. In the first case, this will be the actual variable or type
* name, in the other cases it is assumed that the name will appear
* later, and an error is generated otherwise.
ast_value *var, *tmp;
lex_ctx_t ctx;
- const char *name = NULL;
+ const char *name = nullptr;
bool isfield = false;
bool wasarray = false;
size_t morefields = 0;
/* if we parsed a dot we need a typename now */
if (!parser_next(parser)) {
parseerror(parser, "expected typename for field definition");
- return NULL;
+ return nullptr;
}
/* Further dots are handled seperately because they won't be part of the
vararg = false;
if (!parser_next(parser)) {
parseerror(parser, "expected typename for field definition");
- return NULL;
+ return nullptr;
}
}
}
if (!cached_typedef && parser->tok != TOKEN_TYPENAME) {
if (vararg && is_vararg) {
*is_vararg = true;
- return NULL;
+ return nullptr;
}
parseerror(parser, "expected typename");
- return NULL;
+ return nullptr;
}
/* generate the basic type value */
if (!parser_next(parser)) {
ast_delete(var);
parseerror(parser, "parse error after typename");
- return NULL;
+ return nullptr;
}
/* an opening paren now starts the parameter-list of a function
if (parser->tok == '(') {
var = parse_parameter_list(parser, var);
if (!var)
- return NULL;
+ return nullptr;
}
/* store the base if requested */
ast_delete(var);
mem_d(name);
parseerror(parser, "error after variable or field declaration");
- return NULL;
+ return nullptr;
}
}
var = parse_arraysize(parser, var);
if (!var) {
if (name) mem_d(name);
- return NULL;
+ return nullptr;
}
}
var = parse_parameter_list(parser, var);
if (!var) {
if (name) mem_d(name);
- return NULL;
+ return nullptr;
}
}
ast_delete(var);
mem_d(name);
parseerror(parser, "internal error: failed to set name");
- return NULL;
+ return nullptr;
}
/* free the name, ast_value_set_name duplicates */
mem_d(name);
ast_value *typevar, *oldtype;
ast_expression *old;
- typevar = parse_typename(parser, NULL, NULL, NULL);
+ typevar = parse_typename(parser, nullptr, nullptr, nullptr);
if (!typevar)
return false;
bool was_end;
size_t i;
- ast_value *basetype = NULL;
+ ast_value *basetype = nullptr;
bool retval = true;
bool isparam = false;
bool isvector = false;
bool cleanvar = true;
bool wasarray = false;
- ast_member *me[3] = { NULL, NULL, NULL };
- ast_member *last_me[3] = { NULL, NULL, NULL };
+ ast_member *me[3] = { nullptr, nullptr, nullptr };
+ ast_member *last_me[3] = { nullptr, nullptr, nullptr };
if (!localblock && is_static)
parseerror(parser, "`static` qualifier is not supported in global scope");
/* get the first complete variable */
- var = parse_typename(parser, &basetype, cached_typedef, NULL);
+ var = parse_typename(parser, &basetype, cached_typedef, nullptr);
if (!var) {
if (basetype)
ast_delete(basetype);
}
while (true) {
- proto = NULL;
+ proto = nullptr;
wasarray = false;
/* Part 0: finish the type */
goto cleanup;
}
ast_delete(var);
- var = NULL;
+ var = nullptr;
goto skipvar;
/*
parseerror(parser, "field `%s` already declared here: %s:%i",
retval = false;
if (proto->desc)
mem_d(proto->desc);
- proto = NULL;
+ proto = nullptr;
goto cleanup;
}
proto->expression.flags |= var->expression.flags;
if (!ast_istype(old, ast_value)) {
parseerror(parser, "internal error: not an ast_value");
retval = false;
- proto = NULL;
+ proto = nullptr;
goto cleanup;
}
if (!parser_check_qualifiers(parser, var, proto)) {
retval = false;
- proto = NULL;
+ proto = nullptr;
goto cleanup;
}
proto->expression.flags |= var->expression.flags;
if (ast_istype(old, ast_value))
var = proto = (ast_value*)old;
else {
- var = NULL;
+ var = nullptr;
goto skipvar;
}
}
/* a static adds itself to be generated like any other global
* but is added to the local namespace instead
*/
- char *defname = NULL;
+ char *defname = nullptr;
size_t prefix_len, ln;
size_t sn, sn_size;
* counter value.
* The counter is incremented either way.
*/
- sn_size = vec_size(parser->function->static_names);
+ sn_size = parser->function->static_names.size();
for (sn = 0; sn != sn_size; ++sn) {
if (strcmp(parser->function->static_names[sn], var->name) == 0)
break;
}
if (sn != sn_size) {
- char *num = NULL;
+ char *num = nullptr;
int len = util_asprintf(&num, "#%u", parser->function->static_count);
vec_append(defname, len, num);
mem_d(num);
}
else
- vec_push(parser->function->static_names, util_strdup(var->name));
+ parser->function->static_names.push_back(util_strdup(var->name));
parser->function->static_count++;
ast_value_set_name(var, defname);
}
}
memcpy(last_me, me, sizeof(me));
- me[0] = me[1] = me[2] = NULL;
+ me[0] = me[1] = me[2] = nullptr;
cleanvar = false;
/* Part 2.2
* deal with arrays
}
if (parser->tok == '#') {
- ast_function *func = NULL;
- ast_value *number = NULL;
+ ast_function *func = nullptr;
+ ast_value *number = nullptr;
float fractional;
float integral;
int builtin_num;
parseerror(parser, "expected comma or semicolon");
if (func)
ast_function_delete(func);
- var->constval.vfunc = NULL;
+ var->constval.vfunc = nullptr;
break;
}
}
cexp = parse_expression_leave(parser, true, false, false);
if (!cexp)
break;
- cval = ast_istype(cexp, ast_value) ? (ast_value*)cexp : NULL;
+ cval = ast_istype(cexp, ast_value) ? (ast_value*)cexp : nullptr;
/* deal with foldable constants: */
if (localblock &&
bool noref = false;
bool is_static = false;
uint32_t qflags = 0;
- ast_value *istype = NULL;
- char *vstring = NULL;
+ ast_value *istype = nullptr;
+ char *vstring = nullptr;
if (parser->tok == TOKEN_IDENT)
istype = parser_find_typedef(parser, parser_tokval(parser), 0);
if (istype || parser->tok == TOKEN_TYPENAME || parser->tok == '.' || parser->tok == TOKEN_DOTS)
{
- return parse_variable(parser, NULL, false, CV_NONE, istype, false, false, 0, NULL);
+ return parse_variable(parser, nullptr, false, CV_NONE, istype, false, false, 0, nullptr);
}
else if (parse_qualifiers(parser, false, &cvq, &noref, &is_static, &qflags, &vstring))
{
if (cvq == CV_WRONG)
return false;
- return parse_variable(parser, NULL, false, cvq, NULL, noref, is_static, qflags, vstring);
+ return parse_variable(parser, nullptr, false, cvq, nullptr, noref, is_static, qflags, vstring);
}
else if (parser->tok == TOKEN_IDENT && !strcmp(parser_tokval(parser), "enum"))
{
parser = (parser_t*)mem_a(sizeof(parser_t));
if (!parser)
- return NULL;
+ return nullptr;
memset(parser, 0, sizeof(*parser));
if (!parser->assign_op) {
con_err("internal error: initializing parser: failed to find assign operator\n");
mem_d(parser);
- return NULL;
+ return nullptr;
}
vec_push(parser->variables, parser->htfields = util_htnew(PARSER_HT_SIZE));
parser->reserved_version->expression.flags |= AST_FLAG_INCLUDE_DEF;
parser->reserved_version->constval.vstring = util_strdup(GMQCC_FULL_VERSION_STRING);
} else {
- parser->reserved_version = NULL;
+ parser->reserved_version = nullptr;
}
- parser->fold = fold_init (parser);
- parser->intrin = intrin_init(parser);
+ parser->m_fold = fold(parser);
+ parser->m_intrin = intrin(parser);
return parser;
}
else if (compile_errors)
parseerror(parser, "there have been errors, bailing out");
lex_close(parser->lex);
- parser->lex = NULL;
+ parser->lex = nullptr;
return false;
}
}
} else {
parseerror(parser, "parse error");
lex_close(parser->lex);
- parser->lex = NULL;
+ parser->lex = nullptr;
return false;
}
lex_close(parser->lex);
- parser->lex = NULL;
+ parser->lex = nullptr;
return !compile_errors;
}
ast_value_delete(parser->reserved_version);
util_htdel(parser->aliases);
- fold_cleanup(parser->fold);
- intrin_cleanup(parser->intrin);
}
void parser_cleanup(parser_t *parser)
return true;
}
- cov = func->vtype;
+ cov = func->function_type;
expr = (ast_expression*)cov;
if (expr->vtype != TYPE_FUNCTION || expr->params.size()) {
*/
for (auto &f : parser->functions) {
if (f->varargs) {
- if (parser->max_param_count > f->vtype->expression.params.size()) {
- f->varargs->expression.count = parser->max_param_count - f->vtype->expression.params.size();
+ 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_create_array_setter_impl(parser, f->varargs)) {
con_out("failed to generate vararg setter for %s\n", f->name);
ir_builder_delete(ir);
}
} else {
ast_delete(f->varargs);
- f->varargs = NULL;
+ f->varargs = nullptr;
}
}
}
/* Now we can generate immediates */
- if (!fold_generate(parser->fold, ir))
+ if (!parser->m_fold.generate(ir))
return false;
/* before generating any functions we need to set the coverage_func */