s/NULL/nullptr/

This commit is contained in:
Dale Weiler 2015-01-15 15:18:33 -05:00
parent 6e68526680
commit 76278e8b97
17 changed files with 657 additions and 657 deletions

206
ast.cpp
View file

@ -10,7 +10,7 @@
#define ast_instantiate(T, ctx, destroyfn) \
T* self = (T*)mem_a(sizeof(T)); \
if (!self) { \
return NULL; \
return nullptr; \
} \
new (self) T(); \
ast_node_init((ast_node*)self, ctx, TYPE_##T); \
@ -89,11 +89,11 @@ static void ast_expression_init(ast_expression *self,
{
self->codegen = codegen;
self->vtype = TYPE_VOID;
self->next = NULL;
self->outl = NULL;
self->outr = NULL;
self->next = nullptr;
self->outl = nullptr;
self->outr = nullptr;
self->count = 0;
self->varparam = NULL;
self->varparam = nullptr;
self->flags = 0;
if (OPTS_OPTION_BOOL(OPTION_COVERAGE))
self->flags |= AST_FLAG_BLOCK_COVERAGE;
@ -155,9 +155,9 @@ void ast_type_adopt_impl(ast_expression *self, const ast_expression *other)
static ast_expression* ast_shallow_type(lex_ctx_t ctx, int vtype)
{
ast_instantiate(ast_expression, ctx, ast_expression_delete_full);
ast_expression_init(self, NULL);
self->codegen = NULL;
self->next = NULL;
ast_expression_init(self, nullptr);
self->codegen = nullptr;
self->next = nullptr;
self->vtype = vtype;
return self;
}
@ -168,23 +168,23 @@ ast_expression* ast_type_copy(lex_ctx_t ctx, const ast_expression *ex)
ast_expression *selfex;
if (!ex)
return NULL;
return nullptr;
else
{
ast_instantiate(ast_expression, ctx, ast_expression_delete_full);
ast_expression_init(self, NULL);
ast_expression_init(self, nullptr);
fromex = ex;
selfex = self;
/* This may never be codegen()d */
selfex->codegen = NULL;
selfex->codegen = nullptr;
selfex->vtype = fromex->vtype;
if (fromex->next)
selfex->next = ast_type_copy(ctx, fromex->next);
else
selfex->next = NULL;
selfex->next = nullptr;
selfex->count = fromex->count;
selfex->flags = fromex->flags;
@ -326,9 +326,9 @@ ast_value* ast_value_new(lex_ctx_t ctx, const char *name, int t)
(ast_expression_codegen*)&ast_value_codegen);
self->expression.node.keep = true; /* keep */
self->name = name ? util_strdup(name) : NULL;
self->name = name ? util_strdup(name) : nullptr;
self->expression.vtype = t;
self->expression.next = NULL;
self->expression.next = nullptr;
self->isfield = false;
self->cvq = CV_NONE;
self->hasvalue = false;
@ -337,15 +337,15 @@ ast_value* ast_value_new(lex_ctx_t ctx, const char *name, int t)
self->uses = 0;
memset(&self->constval, 0, sizeof(self->constval));
self->ir_v = NULL;
self->ir_values = NULL;
self->ir_v = nullptr;
self->ir_values = nullptr;
self->ir_value_count = 0;
self->setter = NULL;
self->getter = NULL;
self->desc = NULL;
self->setter = nullptr;
self->getter = nullptr;
self->desc = nullptr;
self->argcounter = NULL;
self->argcounter = nullptr;
self->intrinsic = false;
return self;
@ -365,7 +365,7 @@ void ast_value_delete(ast_value* self)
break;
case TYPE_FUNCTION:
/* unlink us from the function node */
self->constval.vfunc->vtype = NULL;
self->constval.vfunc->vtype = nullptr;
break;
/* NOTE: delete function? currently collected in
* the parser structure
@ -566,7 +566,7 @@ ast_entfield* ast_entfield_new(lex_ctx_t ctx, ast_expression *entity, ast_expres
{
if (field->vtype != TYPE_FIELD) {
compile_error(ctx, "ast_entfield_new with expression not of type field");
return NULL;
return nullptr;
}
return ast_entfield_new_force(ctx, entity, field, field->next);
}
@ -578,7 +578,7 @@ ast_entfield* ast_entfield_new_force(lex_ctx_t ctx, ast_expression *entity, ast_
if (!outtype) {
mem_d(self);
/* Error: field has no type... */
return NULL;
return nullptr;
}
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_entfield_codegen);
@ -605,14 +605,14 @@ ast_member* ast_member_new(lex_ctx_t ctx, ast_expression *owner, unsigned int fi
ast_instantiate(ast_member, ctx, ast_member_delete);
if (field >= 3) {
mem_d(self);
return NULL;
return nullptr;
}
if (owner->vtype != TYPE_VECTOR &&
owner->vtype != TYPE_FIELD) {
compile_error(ctx, "member-access on an invalid owner of type %s", type_name[owner->vtype]);
mem_d(self);
return NULL;
return nullptr;
}
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_member_codegen);
@ -620,7 +620,7 @@ ast_member* ast_member_new(lex_ctx_t ctx, ast_expression *owner, unsigned int fi
if (owner->vtype == TYPE_VECTOR) {
self->expression.vtype = TYPE_FLOAT;
self->expression.next = NULL;
self->expression.next = nullptr;
} else {
self->expression.vtype = TYPE_FIELD;
self->expression.next = ast_shallow_type(ctx, TYPE_FLOAT);
@ -634,7 +634,7 @@ ast_member* ast_member_new(lex_ctx_t ctx, ast_expression *owner, unsigned int fi
if (name)
self->name = util_strdup(name);
else
self->name = NULL;
self->name = nullptr;
return self;
}
@ -671,7 +671,7 @@ ast_array_index* ast_array_index_new(lex_ctx_t ctx, ast_expression *array, ast_e
if (!outtype) {
mem_d(self);
/* Error: field has no type... */
return NULL;
return nullptr;
}
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_array_index_codegen);
@ -686,7 +686,7 @@ ast_array_index* ast_array_index_new(lex_ctx_t ctx, ast_expression *array, ast_e
if (self->expression.vtype != TYPE_ARRAY) {
compile_error(ast_ctx(self), "array_index node on type");
ast_array_index_delete(self);
return NULL;
return nullptr;
}
self->array = outtype;
self->expression.vtype = TYPE_FIELD;
@ -728,7 +728,7 @@ ast_ifthen* ast_ifthen_new(lex_ctx_t ctx, ast_expression *cond, ast_expression *
if (!ontrue && !onfalse) {
/* because it is invalid */
mem_d(self);
return NULL;
return nullptr;
}
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_ifthen_codegen);
@ -759,10 +759,10 @@ ast_ternary* ast_ternary_new(lex_ctx_t ctx, ast_expression *cond, ast_expression
{
ast_expression *exprtype = ontrue;
ast_instantiate(ast_ternary, ctx, ast_ternary_delete);
/* This time NEITHER must be NULL */
/* This time NEITHER must be nullptr */
if (!ontrue || !onfalse) {
mem_d(self);
return NULL;
return nullptr;
}
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_ternary_codegen);
@ -783,7 +783,7 @@ ast_ternary* ast_ternary_new(lex_ctx_t ctx, ast_expression *cond, ast_expression
void ast_ternary_delete(ast_ternary *self)
{
/* the if()s are only there because computed-gotos can set them
* to NULL
* to nullptr
*/
if (self->cond) ast_unref(self->cond);
if (self->on_true) ast_unref(self->on_true);
@ -892,7 +892,7 @@ ast_label* ast_label_new(lex_ctx_t ctx, const char *name, bool undefined)
self->expression.vtype = TYPE_NOEXPR;
self->name = util_strdup(name);
self->irblock = NULL;
self->irblock = nullptr;
self->undefined = undefined;
return self;
@ -916,8 +916,8 @@ ast_goto* ast_goto_new(lex_ctx_t ctx, const char *name)
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_goto_codegen);
self->name = util_strdup(name);
self->target = NULL;
self->irblock_from = NULL;
self->target = nullptr;
self->irblock_from = nullptr;
return self;
}
@ -961,14 +961,14 @@ ast_call* ast_call_new(lex_ctx_t ctx,
if (!funcexpr->next) {
compile_error(ctx, "not a function");
mem_d(self);
return NULL;
return nullptr;
}
ast_expression_init((ast_expression*)self, (ast_expression_codegen*)&ast_call_codegen);
ast_side_effects(self) = true;
self->func = funcexpr;
self->va_count = NULL;
self->va_count = nullptr;
ast_type_adopt(self, funcexpr->next);
@ -1129,7 +1129,7 @@ bool ast_block_add_expr(ast_block *self, ast_expression *e)
self->exprs.push_back(e);
if (self->expression.next) {
ast_delete(self->expression.next);
self->expression.next = NULL;
self->expression.next = nullptr;
}
ast_type_adopt(self, e);
return true;
@ -1173,28 +1173,28 @@ ast_function* ast_function_new(lex_ctx_t ctx, const char *name, ast_value *vtype
}
self->vtype = vtype;
self->name = name ? util_strdup(name) : NULL;
self->name = name ? util_strdup(name) : nullptr;
self->labelcount = 0;
self->builtin = 0;
self->ir_func = NULL;
self->curblock = NULL;
self->ir_func = nullptr;
self->curblock = nullptr;
vtype->hasvalue = true;
vtype->constval.vfunc = self;
self->varargs = NULL;
self->argc = NULL;
self->fixedparams = NULL;
self->return_value = NULL;
self->varargs = nullptr;
self->argc = nullptr;
self->fixedparams = nullptr;
self->return_value = nullptr;
self->static_count = 0;
return self;
cleanup:
mem_d(self);
return NULL;
return nullptr;
}
void ast_function_delete(ast_function *self)
@ -1204,7 +1204,7 @@ void ast_function_delete(ast_function *self)
if (self->vtype) {
/* ast_value_delete(self->vtype); */
self->vtype->hasvalue = false;
self->vtype->constval.vfunc = NULL;
self->vtype->constval.vfunc = nullptr;
/* We use unref - if it was stored in a global table it is supposed
* to be deleted from *there*
*/
@ -1235,7 +1235,7 @@ const char* ast_function_label(ast_function *self, const char *prefix)
!OPTS_OPTION_BOOL(OPTION_DUMPFIN) &&
!OPTS_OPTION_BOOL(OPTION_DEBUG))
{
return NULL;
return nullptr;
}
id = (self->labelcount++);
@ -1254,7 +1254,7 @@ const char* ast_function_label(ast_function *self, const char *prefix)
/*********************************************************************/
/* AST codegen part
* by convention you must never pass NULL to the 'ir_value **out'
* by convention you must never pass nullptr to the 'ir_value **out'
* parameter. If you really don't care about the output, pass a dummy.
* But I can't imagine a pituation where the output is truly unnecessary.
*/
@ -1367,7 +1367,7 @@ static bool check_array(ast_value *self, ast_value *array)
bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
{
ir_value *v = NULL;
ir_value *v = nullptr;
if (self->expression.vtype == TYPE_NIL) {
compile_error(ast_ctx(self), "internal error: trying to generate a variable of TYPE_NIL");
@ -1602,7 +1602,7 @@ error: /* clean up */
static bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
{
ir_value *v = NULL;
ir_value *v = nullptr;
if (self->expression.vtype == TYPE_NIL) {
compile_error(ast_ctx(self), "internal error: trying to generate a variable of TYPE_NIL");
@ -1856,7 +1856,7 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
if (!self->vtype->expression.next ||
self->vtype->expression.next->vtype == TYPE_VOID)
{
return ir_block_create_return(self->curblock, ast_ctx(self), NULL);
return ir_block_create_return(self->curblock, ast_ctx(self), nullptr);
}
else if (vec_size(self->curblock->entries) || self->curblock == irf->first)
{
@ -1872,7 +1872,7 @@ bool ast_function_codegen(ast_function *self, ir_builder *ir)
{
return false;
}
return ir_block_create_return(self->curblock, ast_ctx(self), NULL);
return ir_block_create_return(self->curblock, ast_ctx(self), nullptr);
}
}
return true;
@ -1911,13 +1911,13 @@ bool ast_block_codegen(ast_block *self, ast_function *func, bool lvalue, ir_valu
return true;
}
/* output is NULL at first, we'll have each expression
/* output is nullptr at first, we'll have each expression
* assign to out output, thus, a comma-operator represention
* using an ast_block will return the last generated value,
* so: (b, c) + a executed both b and c, and returns c,
* which is then added to a.
*/
*out = NULL;
*out = nullptr;
/* generate locals */
for (auto &it : self->locals) {
@ -1948,12 +1948,12 @@ bool ast_block_codegen(ast_block *self, ast_function *func, bool lvalue, ir_valu
bool ast_store_codegen(ast_store *self, ast_function *func, bool lvalue, ir_value **out)
{
ast_expression_codegen *cgen;
ir_value *left = NULL;
ir_value *right = NULL;
ir_value *left = nullptr;
ir_value *right = nullptr;
ast_value *arr;
ast_value *idx = 0;
ast_array_index *ai = NULL;
ast_array_index *ai = nullptr;
if (lvalue && self->expression.outl) {
*out = self->expression.outl;
@ -1972,7 +1972,7 @@ bool ast_store_codegen(ast_store *self, ast_function *func, bool lvalue, ir_valu
idx = (ast_value*)ai->index;
if (ast_istype(ai->index, ast_value) && idx->hasvalue && idx->cvq == CV_CONST)
ai = NULL;
ai = nullptr;
}
if (ai) {
@ -2189,12 +2189,12 @@ bool ast_binary_codegen(ast_binary *self, ast_function *func, bool lvalue, ir_va
bool ast_binstore_codegen(ast_binstore *self, ast_function *func, bool lvalue, ir_value **out)
{
ast_expression_codegen *cgen;
ir_value *leftl = NULL, *leftr, *right, *bin;
ir_value *leftl = nullptr, *leftr, *right, *bin;
ast_value *arr;
ast_value *idx = 0;
ast_array_index *ai = NULL;
ir_value *iridx = NULL;
ast_array_index *ai = nullptr;
ir_value *iridx = nullptr;
if (lvalue && self->expression.outl) {
*out = self->expression.outl;
@ -2213,7 +2213,7 @@ bool ast_binstore_codegen(ast_binstore *self, ast_function *func, bool lvalue, i
idx = (ast_value*)ai->index;
if (ast_istype(ai->index, ast_value) && idx->hasvalue && idx->cvq == CV_CONST)
ai = NULL;
ai = nullptr;
}
/* for a binstore we need both an lvalue and an rvalue for the left side */
@ -2324,7 +2324,7 @@ bool ast_return_codegen(ast_return *self, ast_function *func, bool lvalue, ir_va
ast_expression_codegen *cgen;
ir_value *operand;
*out = NULL;
*out = nullptr;
/* In the context of a return operation, we don't actually return
* anything...
@ -2349,7 +2349,7 @@ bool ast_return_codegen(ast_return *self, ast_function *func, bool lvalue, ir_va
if (!ir_block_create_return(func->curblock, ast_ctx(self), operand))
return false;
} else {
if (!ir_block_create_return(func->curblock, ast_ctx(self), NULL))
if (!ir_block_create_return(func->curblock, ast_ctx(self), nullptr))
return false;
}
@ -2441,7 +2441,7 @@ bool ast_member_codegen(ast_member *self, ast_function *func, bool lvalue, ir_va
*out = ir_value_vector_member(vec, self->field);
self->expression.outl = *out;
return (*out != NULL);
return (*out != nullptr);
}
bool ast_array_index_codegen(ast_array_index *self, ast_function *func, bool lvalue, ir_value **out)
@ -2536,7 +2536,7 @@ bool ast_array_index_codegen(ast_array_index *self, ast_function *func, bool lva
bool ast_argpipe_codegen(ast_argpipe *self, ast_function *func, bool lvalue, ir_value **out)
{
*out = NULL;
*out = nullptr;
if (lvalue) {
compile_error(ast_ctx(self), "argpipe node: not an lvalue");
return false;
@ -2557,9 +2557,9 @@ bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_va
ir_block *cond;
ir_block *ontrue;
ir_block *onfalse;
ir_block *ontrue_endblock = NULL;
ir_block *onfalse_endblock = NULL;
ir_block *merge = NULL;
ir_block *ontrue_endblock = nullptr;
ir_block *onfalse_endblock = nullptr;
ir_block *merge = nullptr;
int fold = 0;
/* We don't output any value, thus also don't care about r/lvalue */
@ -2600,7 +2600,7 @@ bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_va
/* we now need to work from the current endpoint */
ontrue_endblock = func->curblock;
} else
ontrue = NULL;
ontrue = nullptr;
/* on-false path */
if (self->on_false) {
@ -2620,7 +2620,7 @@ bool ast_ifthen_codegen(ast_ifthen *self, ast_function *func, bool lvalue, ir_va
/* we now need to work from the current endpoint */
onfalse_endblock = func->curblock;
} else
onfalse = NULL;
onfalse = nullptr;
/* Merge block were they all merge in to */
if (!ontrue || !onfalse || !ontrue_endblock->final || !onfalse_endblock->final)
@ -2659,9 +2659,9 @@ bool ast_ternary_codegen(ast_ternary *self, ast_function *func, bool lvalue, ir_
ir_instr *phi;
ir_block *cond = func->curblock;
ir_block *cond_out = NULL;
ir_block *ontrue, *ontrue_out = NULL;
ir_block *onfalse, *onfalse_out = NULL;
ir_block *cond_out = nullptr;
ir_block *ontrue, *ontrue_out = nullptr;
ir_block *onfalse, *onfalse_out = nullptr;
ir_block *merge;
int fold = 0;
@ -2773,28 +2773,28 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
{
ast_expression_codegen *cgen;
ir_value *dummy = NULL;
ir_value *precond = NULL;
ir_value *postcond = NULL;
ir_value *dummy = nullptr;
ir_value *precond = nullptr;
ir_value *postcond = nullptr;
/* Since we insert some jumps "late" so we have blocks
* ordered "nicely", we need to keep track of the actual end-blocks
* of expressions to add the jumps to.
*/
ir_block *bbody = NULL, *end_bbody = NULL;
ir_block *bprecond = NULL, *end_bprecond = NULL;
ir_block *bpostcond = NULL, *end_bpostcond = NULL;
ir_block *bincrement = NULL, *end_bincrement = NULL;
ir_block *bout = NULL, *bin = NULL;
ir_block *bbody = nullptr, *end_bbody = nullptr;
ir_block *bprecond = nullptr, *end_bprecond = nullptr;
ir_block *bpostcond = nullptr, *end_bpostcond = nullptr;
ir_block *bincrement = nullptr, *end_bincrement = nullptr;
ir_block *bout = nullptr, *bin = nullptr;
/* let's at least move the outgoing block to the end */
size_t bout_id;
/* 'break' and 'continue' need to be able to find the right blocks */
ir_block *bcontinue = NULL;
ir_block *bbreak = NULL;
ir_block *bcontinue = nullptr;
ir_block *bbreak = nullptr;
ir_block *tmpblock = NULL;
ir_block *tmpblock = nullptr;
(void)lvalue;
(void)out;
@ -2846,7 +2846,7 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
end_bprecond = func->curblock;
} else {
bprecond = end_bprecond = NULL;
bprecond = end_bprecond = nullptr;
}
/* Now the next blocks won't be ordered nicely, but we need to
@ -2858,7 +2858,7 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
return false;
bcontinue = bincrement; /* increment comes before the pre-loop-condition */
} else {
bincrement = end_bincrement = NULL;
bincrement = end_bincrement = nullptr;
}
if (self->postcond) {
@ -2867,7 +2867,7 @@ bool ast_loop_codegen(ast_loop *self, ast_function *func, bool lvalue, ir_value
return false;
bcontinue = bpostcond; /* postcond comes before the increment */
} else {
bpostcond = end_bpostcond = NULL;
bpostcond = end_bpostcond = nullptr;
}
bout_id = vec_size(func->ir_func->blocks);
@ -3024,7 +3024,7 @@ bool ast_breakcont_codegen(ast_breakcont *self, ast_function *func, bool lvalue,
{
ir_block *target;
*out = NULL;
*out = nullptr;
if (lvalue) {
compile_error(ast_ctx(self), "break/continue expression is not an l-value");
@ -3056,15 +3056,15 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va
{
ast_expression_codegen *cgen;
ast_switch_case *def_case = NULL;
ir_block *def_bfall = NULL;
ir_block *def_bfall_to = NULL;
ast_switch_case *def_case = nullptr;
ir_block *def_bfall = nullptr;
ir_block *def_bfall_to = nullptr;
bool set_def_bfall_to = false;
ir_value *dummy = NULL;
ir_value *irop = NULL;
ir_block *bout = NULL;
ir_block *bfall = NULL;
ir_value *dummy = nullptr;
ir_value *irop = nullptr;
ir_block *bout = nullptr;
ir_block *bfall = nullptr;
size_t bout_id;
char typestr[1024];
@ -3160,7 +3160,7 @@ bool ast_switch_codegen(ast_switch *self, ast_function *func, bool lvalue, ir_va
/* The default case */
/* Remember where to fall through from: */
def_bfall = bfall;
bfall = NULL;
bfall = nullptr;
/* remember which case it was */
def_case = swcase;
/* And the next case will be remembered */
@ -3227,7 +3227,7 @@ bool ast_label_codegen(ast_label *self, ast_function *func, bool lvalue, ir_valu
return false;
}
*out = NULL;
*out = nullptr;
if (lvalue) {
compile_error(ast_ctx(self), "internal error: ast_label cannot be an lvalue");
return false;
@ -3258,7 +3258,7 @@ bool ast_label_codegen(ast_label *self, ast_function *func, bool lvalue, ir_valu
bool ast_goto_codegen(ast_goto *self, ast_function *func, bool lvalue, ir_value **out)
{
*out = NULL;
*out = nullptr;
if (lvalue) {
compile_error(ast_ctx(self), "internal error: ast_goto cannot be an lvalue");
return false;
@ -3309,7 +3309,7 @@ bool ast_state_codegen(ast_state *self, ast_function *func, bool lvalue, ir_valu
compile_error(ast_ctx(self), "internal error: ast_state cannot be reused!");
return false;
}
*out = NULL;
*out = nullptr;
cgen = self->framenum->codegen;
if (!(*cgen)((ast_expression*)(self->framenum), func, false, &frameval))
@ -3338,7 +3338,7 @@ bool ast_call_codegen(ast_call *self, ast_function *func, bool lvalue, ir_value
std::vector<ir_value*> params;
ir_instr *callinstr;
ir_value *funval = NULL;
ir_value *funval = nullptr;
/* return values are never lvalues */
if (lvalue) {

8
ast.h
View file

@ -404,12 +404,12 @@ ast_store* ast_store_new(lex_ctx_t ctx, int op,
/* If
*
* A general 'if then else' statement, either side can be NULL and will
* thus be omitted. It is an error for *both* cases to be NULL at once.
* A general 'if then else' statement, either side can be nullptr and will
* thus be omitted. It is an error for *both* cases to be nullptr at once.
*
* During its 'codegen' it'll be changing the ast_function's block.
*
* An if is also an "expression". Its codegen will put NULL into the
* An if is also an "expression". Its codegen will put nullptr into the
* output field though. For ternary expressions an ast_ternary will be
* added.
*/
@ -431,7 +431,7 @@ ast_ifthen* ast_ifthen_new(lex_ctx_t ctx, ast_expression *cond, ast_expression *
* a PHI node.
*
* The other difference is that in an ast_ternary, NEITHER side
* must be NULL, there's ALWAYS an else branch.
* must be nullptr, there's ALWAYS an else branch.
*
* This is the only ast_node beside ast_value which contains
* an ir_value. Theoretically we don't need to remember it though.

View file

@ -291,7 +291,7 @@ static void code_stats(const char *filename, const char *lnofile, code_t *code,
bool code_write(code_t *code, const char *filename, const char *lnofile) {
prog_header_t code_header;
FILE *fp = NULL;
FILE *fp = nullptr;
code_create_header(code, &code_header, filename, lnofile);
@ -319,7 +319,7 @@ bool code_write(code_t *code, const char *filename, const char *lnofile) {
}
fclose(fp);
fp = NULL;
fp = nullptr;
}
fp = fopen(filename, "wb");

View file

@ -16,7 +16,7 @@ static con_t console;
/*
* Enables color on output if supported.
* NOTE: The support for checking colors is NULL. On windows this will
* NOTE: The support for checking colors is nullptr. On windows this will
* always work, on *nix it depends if the term has colors.
*
* NOTE: This prevents colored output to piped stdout/err via isatty
@ -138,7 +138,7 @@ static void con_vprintmsg_c(int level, const char *name, size_t line, size_t col
}
void con_vprintmsg(int level, const char *name, size_t line, size_t column, const char *msgtype, const char *msg, va_list ap) {
con_vprintmsg_c(level, name, line, column, msgtype, msg, ap, NULL);
con_vprintmsg_c(level, name, line, column, msgtype, msg, ap, nullptr);
}
void con_printmsg(int level, const char *name, size_t line, size_t column, const char *msgtype, const char *msg, ...) {

View file

@ -42,12 +42,12 @@ qc_program_t* prog_load(const char *filename, bool skipversion)
has_frame = false;
if (!file)
return NULL;
return nullptr;
if (fread(&header, sizeof(header), 1, file) != 1) {
loaderror("failed to read header from '%s'", filename);
fclose(file);
return NULL;
return nullptr;
}
util_swap_header(header);
@ -55,14 +55,14 @@ qc_program_t* prog_load(const char *filename, bool skipversion)
if (!skipversion && header.version != 6) {
loaderror("header says this is a version %i progs, we need version 6\n", header.version);
fclose(file);
return NULL;
return nullptr;
}
prog = (qc_program_t*)mem_a(sizeof(qc_program_t));
if (!prog) {
fclose(file);
fprintf(stderr, "failed to allocate program data\n");
return NULL;
return nullptr;
}
memset(prog, 0, sizeof(*prog));
@ -163,7 +163,7 @@ error:
mem_d(prog);
fclose(file);
return NULL;
return nullptr;
}
void prog_delete(qc_program_t *prog)
@ -511,7 +511,7 @@ static qcint_t prog_enterfunction(qc_program_t *prog, prog_section_function_t *f
}
static qcint_t prog_leavefunction(qc_program_t *prog) {
prog_section_function_t *prev = NULL;
prog_section_function_t *prev = nullptr;
size_t oldsp;
qc_exec_stack_t st = vec_last(prog->stack);
@ -623,7 +623,7 @@ struct qcvm_parameter {
const char *value;
};
static qcvm_parameter *main_params = NULL;
static qcvm_parameter *main_params = nullptr;
#define CheckArgs(num) do { \
if (prog->argc != (num)) { \
@ -640,7 +640,7 @@ static qcvm_parameter *main_params = NULL;
static int qc_print(qc_program_t *prog) {
size_t i;
const char *laststr = NULL;
const char *laststr = nullptr;
for (i = 0; i < (size_t)prog->argc; ++i) {
qcany_t *str = (qcany_t*)(&prog->globals[0] + OFS_PARM0 + 3*i);
laststr = prog_getstring(prog, str->string);
@ -678,7 +678,7 @@ static int qc_stof(qc_program_t *prog) {
qcany_t num;
CheckArgs(1);
str = GetArg(0);
num._float = (float)strtod(prog_getstring(prog, str->string), NULL);
num._float = (float)strtod(prog_getstring(prog, str->string), nullptr);
Return(num);
return 0;
}
@ -833,7 +833,7 @@ static int qc_pow(qc_program_t *prog) {
}
static prog_builtin_t qc_builtins[] = {
NULL,
nullptr,
&qc_print, /* 1 */
&qc_ftos, /* 2 */
&qc_spawn, /* 3 */
@ -851,7 +851,7 @@ static prog_builtin_t qc_builtins[] = {
&qc_pow /* 15 */
};
static const char *arg0 = NULL;
static const char *arg0 = nullptr;
static void version(void) {
printf("GMQCC-QCVM %d.%d.%d Built %s %s\n",
@ -925,8 +925,8 @@ int main(int argc, char **argv) {
bool opts_disasm = false;
bool opts_info = false;
bool noexec = false;
const char *progsfile = NULL;
const char **dis_list = NULL;
const char *progsfile = nullptr;
const char **dis_list = nullptr;
int opts_v = 0;
arg0 = argv[0];
@ -1128,7 +1128,7 @@ int main(int argc, char **argv) {
return 0;
}
if (opts_printdefs) {
const char *getstring = NULL;
const char *getstring = nullptr;
for (auto &it : prog->defs) {
printf("Global: %8s %-16s at %u%s",
type_name[it.type & DEF_TYPEMASK],
@ -1544,7 +1544,7 @@ while (prog->vmerror == 0) {
case INSTR_CALL8:
prog->argc = st->opcode - INSTR_CALL0;
if (!OPA->function)
qcvmerror(prog, "NULL function in `%s`", prog->filename);
qcvmerror(prog, "nullptr function in `%s`", prog->filename);
if(!OPA->function || OPA->function >= (qcint_t)prog->functions.size())
{

108
fold.cpp
View file

@ -651,9 +651,9 @@ static GMQCC_INLINE vec3_t vec3_neg(lex_ctx_t ctx, vec3_t a) {
sfloat_neg(&s[1], v[1].s);
sfloat_neg(&s[2], v[2].s);
sfloat_check(ctx, &s[0], NULL);
sfloat_check(ctx, &s[1], NULL);
sfloat_check(ctx, &s[2], NULL);
sfloat_check(ctx, &s[0], nullptr);
sfloat_check(ctx, &s[1], nullptr);
sfloat_check(ctx, &s[2], nullptr);
end:
out.x = -a.x;
@ -742,11 +742,11 @@ static GMQCC_INLINE qcfloat_t vec3_mulvv(lex_ctx_t ctx, vec3_t a, vec3_t b) {
r[3] = sfloat_add(&s[3], r[0], r[1]);
r[4] = sfloat_add(&s[4], r[3], r[2]);
sfloat_check(ctx, &s[0], NULL);
sfloat_check(ctx, &s[1], NULL);
sfloat_check(ctx, &s[2], NULL);
sfloat_check(ctx, &s[3], NULL);
sfloat_check(ctx, &s[4], NULL);
sfloat_check(ctx, &s[0], nullptr);
sfloat_check(ctx, &s[1], nullptr);
sfloat_check(ctx, &s[2], nullptr);
sfloat_check(ctx, &s[3], nullptr);
sfloat_check(ctx, &s[4], nullptr);
end:
return (a.x * b.x + a.y * b.y + a.z * b.z);
@ -837,12 +837,12 @@ static GMQCC_INLINE vec3_t vec3_cross(lex_ctx_t ctx, vec3_t a, vec3_t b) {
r[7] = sfloat_sub(&s[7], r[2], r[3]);
r[8] = sfloat_sub(&s[8], r[4], r[5]);
sfloat_check(ctx, &s[0], NULL);
sfloat_check(ctx, &s[1], NULL);
sfloat_check(ctx, &s[2], NULL);
sfloat_check(ctx, &s[3], NULL);
sfloat_check(ctx, &s[4], NULL);
sfloat_check(ctx, &s[5], NULL);
sfloat_check(ctx, &s[0], nullptr);
sfloat_check(ctx, &s[1], nullptr);
sfloat_check(ctx, &s[2], nullptr);
sfloat_check(ctx, &s[3], nullptr);
sfloat_check(ctx, &s[4], nullptr);
sfloat_check(ctx, &s[5], nullptr);
sfloat_check(ctx, &s[6], "x");
sfloat_check(ctx, &s[7], "y");
sfloat_check(ctx, &s[8], "z");
@ -977,7 +977,7 @@ ast_expression *fold_constgen_vector(fold_t *fold, vec3_t value) {
ast_expression *fold_constgen_string(fold_t *fold, const char *str, bool translate) {
hash_table_t *table = (translate) ? fold->imm_string_untranslate : fold->imm_string_dotranslate;
ast_value *out = NULL;
ast_value *out = nullptr;
size_t hash = util_hthash(table, str);
if ((out = (ast_value*)util_htgeth(table, str, hash)))
@ -1038,7 +1038,7 @@ static bool fold_check_except_float_impl(void (*callback)(void),
if (!OPTS_FLAG(ARITHMETIC_EXCEPTIONS))
goto inexact_possible;
sfloat_check(fold_ctx(fold), &s, NULL);
sfloat_check(fold_ctx(fold), &s, nullptr);
inexact_possible:
return s.exceptionflags & SFLOAT_INEXACT;
@ -1063,13 +1063,13 @@ static GMQCC_INLINE ast_expression *fold_op_mul_vec(fold_t *fold, vec3_t vec, as
if (!y && !z) {
ast_expression *out;
++opts_optimizationcount[OPTIM_VECTOR_COMPONENTS];
out = (ast_expression*)ast_member_new(fold_ctx(fold), (ast_expression*)sel, set[0]-'x', NULL);
out = (ast_expression*)ast_member_new(fold_ctx(fold), (ast_expression*)sel, set[0]-'x', nullptr);
out->node.keep = false;
((ast_member*)out)->rvalue = true;
if (x != -1.0f)
return (ast_expression*)ast_binary_new(fold_ctx(fold), INSTR_MUL_F, fold_constgen_float(fold, x, false), out);
}
return NULL;
return nullptr;
}
@ -1077,14 +1077,14 @@ static GMQCC_INLINE ast_expression *fold_op_neg(fold_t *fold, ast_value *a) {
if (isfloat(a)) {
if (fold_can_1(a)) {
/* Negation can produce inexact as well */
bool inexact = fold_check_except_float(&sfloat_neg, fold, a, NULL);
bool inexact = fold_check_except_float(&sfloat_neg, fold, a, nullptr);
return fold_constgen_float(fold, -fold_immvalue_float(a), inexact);
}
} else if (isvector(a)) {
if (fold_can_1(a))
return fold_constgen_vector(fold, vec3_neg(fold_ctx(fold), fold_immvalue_vector(a)));
}
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_not(fold_t *fold, ast_value *a) {
@ -1102,7 +1102,7 @@ static GMQCC_INLINE ast_expression *fold_op_not(fold_t *fold, ast_value *a) {
return fold_constgen_float(fold, !fold_immvalue_string(a) || !*fold_immvalue_string(a), false);
}
}
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_add(fold_t *fold, ast_value *a, ast_value *b) {
@ -1117,7 +1117,7 @@ static GMQCC_INLINE ast_expression *fold_op_add(fold_t *fold, ast_value *a, ast_
fold_immvalue_vector(a),
fold_immvalue_vector(b)));
}
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_sub(fold_t *fold, ast_value *a, ast_value *b) {
@ -1132,7 +1132,7 @@ static GMQCC_INLINE ast_expression *fold_op_sub(fold_t *fold, ast_value *a, ast_
fold_immvalue_vector(a),
fold_immvalue_vector(b)));
}
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_mul(fold_t *fold, ast_value *a, ast_value *b) {
@ -1166,7 +1166,7 @@ static GMQCC_INLINE ast_expression *fold_op_mul(fold_t *fold, ast_value *a, ast_
}
}
}
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_div(fold_t *fold, ast_value *a, ast_value *b) {
@ -1201,13 +1201,13 @@ static GMQCC_INLINE ast_expression *fold_op_div(fold_t *fold, ast_value *a, ast_
);
}
}
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_mod(fold_t *fold, ast_value *a, ast_value *b) {
return (fold_can_2(a, b))
? fold_constgen_float(fold, fmod(fold_immvalue_float(a), fold_immvalue_float(b)), false)
: NULL;
: nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_bor(fold_t *fold, ast_value *a, ast_value *b) {
@ -1223,7 +1223,7 @@ static GMQCC_INLINE ast_expression *fold_op_bor(fold_t *fold, ast_value *a, ast_
return fold_constgen_vector(fold, vec3_orvf(fold_immvalue_vector(a), fold_immvalue_float(b)));
}
}
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_band(fold_t *fold, ast_value *a, ast_value *b) {
@ -1239,7 +1239,7 @@ static GMQCC_INLINE ast_expression *fold_op_band(fold_t *fold, ast_value *a, ast
return fold_constgen_vector(fold, vec3_andvf(fold_immvalue_vector(a), fold_immvalue_float(b)));
}
}
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_xor(fold_t *fold, ast_value *a, ast_value *b) {
@ -1254,19 +1254,19 @@ static GMQCC_INLINE ast_expression *fold_op_xor(fold_t *fold, ast_value *a, ast_
return fold_constgen_vector(fold, vec3_xorvf(fold_immvalue_vector(a), fold_immvalue_float(b)));
}
}
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_lshift(fold_t *fold, ast_value *a, ast_value *b) {
if (fold_can_2(a, b) && isfloats(a, b))
return fold_constgen_float(fold, (qcfloat_t)floorf(fold_immvalue_float(a) * powf(2.0f, fold_immvalue_float(b))), false);
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_rshift(fold_t *fold, ast_value *a, ast_value *b) {
if (fold_can_2(a, b) && isfloats(a, b))
return fold_constgen_float(fold, (qcfloat_t)floorf(fold_immvalue_float(a) / powf(2.0f, fold_immvalue_float(b))), false);
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_andor(fold_t *fold, ast_value *a, ast_value *b, float expr) {
@ -1287,7 +1287,7 @@ static GMQCC_INLINE ast_expression *fold_op_andor(fold_t *fold, ast_value *a, as
);
}
}
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_tern(fold_t *fold, ast_value *a, ast_value *b, ast_value *c) {
@ -1296,13 +1296,13 @@ static GMQCC_INLINE ast_expression *fold_op_tern(fold_t *fold, ast_value *a, ast
? (ast_expression*)b
: (ast_expression*)c;
}
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_exp(fold_t *fold, ast_value *a, ast_value *b) {
if (fold_can_2(a, b))
return fold_constgen_float(fold, (qcfloat_t)powf(fold_immvalue_float(a), fold_immvalue_float(b)), false);
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_lteqgt(fold_t *fold, ast_value *a, ast_value *b) {
@ -1312,7 +1312,7 @@ static GMQCC_INLINE ast_expression *fold_op_lteqgt(fold_t *fold, ast_value *a, a
if (fold_immvalue_float(a) == fold_immvalue_float(b)) return (ast_expression*)fold->imm_float[0];
if (fold_immvalue_float(a) > fold_immvalue_float(b)) return (ast_expression*)fold->imm_float[1];
}
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_ltgt(fold_t *fold, ast_value *a, ast_value *b, bool lt) {
@ -1321,7 +1321,7 @@ static GMQCC_INLINE ast_expression *fold_op_ltgt(fold_t *fold, ast_value *a, ast
return (lt) ? (ast_expression*)fold->imm_float[!!(fold_immvalue_float(a) < fold_immvalue_float(b))]
: (ast_expression*)fold->imm_float[!!(fold_immvalue_float(a) > fold_immvalue_float(b))];
}
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_cmp(fold_t *fold, ast_value *a, ast_value *b, bool ne) {
@ -1337,7 +1337,7 @@ static GMQCC_INLINE ast_expression *fold_op_cmp(fold_t *fold, ast_value *a, ast_
return (ast_expression*)fold->imm_float[!(ne ? vec3_cmp(la, lb) : !vec3_cmp(la, lb))];
}
}
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_bnot(fold_t *fold, ast_value *a) {
@ -1350,7 +1350,7 @@ static GMQCC_INLINE ast_expression *fold_op_bnot(fold_t *fold, ast_value *a) {
return fold_constgen_vector(fold, vec3_not(fold_immvalue_vector(a)));
}
}
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_cross(fold_t *fold, ast_value *a, ast_value *b) {
@ -1358,7 +1358,7 @@ static GMQCC_INLINE ast_expression *fold_op_cross(fold_t *fold, ast_value *a, as
return fold_constgen_vector(fold, vec3_cross(fold_ctx(fold),
fold_immvalue_vector(a),
fold_immvalue_vector(b)));
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_length(fold_t *fold, ast_value *a) {
@ -1366,26 +1366,26 @@ static GMQCC_INLINE ast_expression *fold_op_length(fold_t *fold, ast_value *a) {
return fold_constgen_float(fold, strlen(fold_immvalue_string(a)), false);
if (isarray(a))
return fold_constgen_float(fold, a->initlist.size(), false);
return NULL;
return nullptr;
}
ast_expression *fold_op(fold_t *fold, const oper_info *info, ast_expression **opexprs) {
ast_value *a = (ast_value*)opexprs[0];
ast_value *b = (ast_value*)opexprs[1];
ast_value *c = (ast_value*)opexprs[2];
ast_expression *e = NULL;
ast_expression *e = nullptr;
/* can a fold operation be applied to this operator usage? */
if (!info->folds)
return NULL;
return nullptr;
switch(info->operands) {
case 3: if(!c) return NULL;
case 2: if(!b) return NULL;
case 3: if(!c) return nullptr;
case 2: if(!b) return nullptr;
case 1:
if(!a) {
compile_error(fold_ctx(fold), "internal error: fold_op no operands to fold\n");
return NULL;
return nullptr;
}
}
@ -1433,7 +1433,7 @@ ast_expression *fold_op(fold_t *fold, const oper_info *info, ast_expression **op
}
#undef fold_op_case
compile_error(fold_ctx(fold), "internal error: attempted to constant-fold for unsupported operator");
return NULL;
return nullptr;
}
/*
@ -1486,7 +1486,7 @@ static GMQCC_INLINE ast_expression *fold_intrin_fabs(fold_t *fold, ast_value *a)
ast_expression *fold_intrin(fold_t *fold, const char *intrin, ast_expression **arg) {
ast_expression *ret = NULL;
ast_expression *ret = nullptr;
ast_value *a = (ast_value*)arg[0];
ast_value *b = (ast_value*)arg[1];
@ -1537,7 +1537,7 @@ ast_expression *fold_intrin(fold_t *fold, const char *intrin, ast_expression **a
/*#define fold_can_2(X,Y) (fold_can_1(X) && fold_can_1(Y))*/
static ast_expression *fold_superfluous(ast_expression *left, ast_expression *right, int op) {
ast_expression *swapped = NULL; /* using this as bool */
ast_expression *swapped = nullptr; /* using this as bool */
ast_value *load;
if (!ast_istype(right, ast_value) || !fold_can_1((load = (ast_value*)right))) {
@ -1547,12 +1547,12 @@ static ast_expression *fold_superfluous(ast_expression *left, ast_expression *ri
}
if (!ast_istype(right, ast_value) || !fold_can_1((load = (ast_value*)right)))
return NULL;
return nullptr;
switch (op) {
case INSTR_DIV_F:
if (swapped)
return NULL;
return nullptr;
case INSTR_MUL_F:
if (fold_immvalue_float(load) == 1.0f) {
++opts_optimizationcount[OPTIM_PEEPHOLE];
@ -1564,7 +1564,7 @@ static ast_expression *fold_superfluous(ast_expression *left, ast_expression *ri
case INSTR_SUB_F:
if (swapped)
return NULL;
return nullptr;
case INSTR_ADD_F:
if (fold_immvalue_float(load) == 0.0f) {
++opts_optimizationcount[OPTIM_PEEPHOLE];
@ -1583,7 +1583,7 @@ static ast_expression *fold_superfluous(ast_expression *left, ast_expression *ri
case INSTR_SUB_V:
if (swapped)
return NULL;
return nullptr;
case INSTR_ADD_V:
if (vec3_cmp(fold_immvalue_vector(load), vec3_create(0, 0, 0))) {
++opts_optimizationcount[OPTIM_PEEPHOLE];
@ -1593,7 +1593,7 @@ static ast_expression *fold_superfluous(ast_expression *left, ast_expression *ri
break;
}
return NULL;
return nullptr;
}
ast_expression *fold_binary(lex_ctx_t ctx, int op, ast_expression *left, ast_expression *right) {
@ -1611,7 +1611,7 @@ static GMQCC_INLINE int fold_cond(ir_value *condval, ast_function *func, ast_ift
bool istrue = (fold_immvalue_float(condval) != 0.0f && branch->on_true);
bool isfalse = (fold_immvalue_float(condval) == 0.0f && branch->on_false);
ast_expression *path = (istrue) ? branch->on_true :
(isfalse) ? branch->on_false : NULL;
(isfalse) ? branch->on_false : nullptr;
if (!path) {
/*
* no path to take implies that the evaluation is if(0) and there

View file

@ -52,7 +52,7 @@ struct ftepp_t {
/* __DATE__ */
static char *ftepp_predef_date(ftepp_t *context) {
const struct tm *itime = NULL;
const struct tm *itime = nullptr;
char *value = (char*)mem_a(82);
time_t rtime;
@ -67,7 +67,7 @@ static char *ftepp_predef_date(ftepp_t *context) {
/* __TIME__ */
static char *ftepp_predef_time(ftepp_t *context) {
const struct tm *itime = NULL;
const struct tm *itime = nullptr;
char *value = (char*)mem_a(82);
time_t rtime;
@ -179,7 +179,7 @@ bool ftepp_predef_exists(const char *name) {
/* singleton because we're allowed */
static GMQCC_INLINE char *(*ftepp_predef(const char *name))(ftepp_t *context) {
size_t i = ftepp_predef_index(name);
return (i != 0) ? ftepp_predefs[i-1].func : NULL;
return (i != 0) ? ftepp_predefs[i-1].func : nullptr;
}
#define ftepp_tokval(f) ((f)->lex->tok.value)
@ -416,7 +416,7 @@ static bool ftepp_define_body(ftepp_t *ftepp, ppmacro *macro)
return false;
}
index = (int)strtol(ftepp_tokval(ftepp), NULL, 10);
index = (int)strtol(ftepp_tokval(ftepp), nullptr, 10);
if (ftepp_next(ftepp) != ']') {
ftepp_error(ftepp, "expected `]` in __VA_ARGS__ subscript");
@ -482,7 +482,7 @@ static const char *ftepp_math_constants[][2] = {
static bool ftepp_define(ftepp_t *ftepp)
{
ppmacro *macro = NULL;
ppmacro *macro = nullptr;
size_t l = ftepp_ctx(ftepp).line;
size_t i;
bool mathconstant = false;
@ -510,7 +510,7 @@ static bool ftepp_define(ftepp_t *ftepp)
/* user defined ones take precedence */
if (macro && mathconstant) {
ftepp_macro_delete(ftepp, ftepp_tokval(ftepp));
macro = NULL;
macro = nullptr;
}
}
@ -580,7 +580,7 @@ static void macroparam_clean(macroparam *self)
/* need to leave the last token up */
static bool ftepp_macro_call_params(ftepp_t *ftepp, macroparam **out_params)
{
macroparam *params = NULL;
macroparam *params = nullptr;
pptoken *ptok;
macroparam mp;
size_t parens = 0;
@ -589,7 +589,7 @@ static bool ftepp_macro_call_params(ftepp_t *ftepp, macroparam **out_params)
if (!ftepp_skipallwhite(ftepp))
return false;
while (ftepp->token != ')') {
mp.tokens = NULL;
mp.tokens = nullptr;
if (!ftepp_skipallwhite(ftepp))
return false;
while (parens || ftepp->token != ',') {
@ -608,7 +608,7 @@ static bool ftepp_macro_call_params(ftepp_t *ftepp, macroparam **out_params)
}
}
vec_push(params, mp);
mp.tokens = NULL;
mp.tokens = nullptr;
if (ftepp->token == ')')
break;
if (ftepp->token != ',') {
@ -711,7 +711,7 @@ static void ftepp_param_out(ftepp_t *ftepp, macroparam *param)
else {
ppmacro *find = ftepp_macro_find(ftepp, out->value);
if (OPTS_FLAG(FTEPP_INDIRECT_EXPANSION) && find && !find->has_params)
ftepp_macro_expand(ftepp, find, NULL, false);
ftepp_macro_expand(ftepp, find, nullptr, false);
else
ftepp_out(ftepp, out->value, false);
}
@ -721,7 +721,7 @@ static void ftepp_param_out(ftepp_t *ftepp, macroparam *param)
static bool ftepp_preprocess(ftepp_t *ftepp);
static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *params, bool resetline)
{
char *buffer = NULL;
char *buffer = nullptr;
char *old_string = ftepp->output_string;
char *inner_string;
lex_file *old_lexer = ftepp->lex;
@ -747,7 +747,7 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param
if (!vec_size(macro->output))
return true;
ftepp->output_string = NULL;
ftepp->output_string = nullptr;
for (o = 0; o < vec_size(macro->output); ++o) {
pptoken *out = macro->output[o];
switch (out->token) {
@ -849,7 +849,7 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param
old_inmacro = ftepp->in_macro;
ftepp->in_macro = true;
ftepp->output_string = NULL;
ftepp->output_string = nullptr;
if (!ftepp_preprocess(ftepp)) {
ftepp->in_macro = old_inmacro;
vec_free(ftepp->lex->open_string);
@ -865,7 +865,7 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param
inner_string = ftepp->output_string;
ftepp->output_string = old_string;
has_newlines = (strchr(inner_string, '\n') != NULL);
has_newlines = (strchr(inner_string, '\n') != nullptr);
if (has_newlines && !old_inmacro)
ftepp_recursion_header(ftepp);
@ -892,12 +892,12 @@ cleanup:
static bool ftepp_macro_call(ftepp_t *ftepp, ppmacro *macro)
{
size_t o;
macroparam *params = NULL;
macroparam *params = nullptr;
bool retval = true;
size_t paramline;
if (!macro->has_params) {
if (!ftepp_macro_expand(ftepp, macro, NULL, false))
if (!ftepp_macro_expand(ftepp, macro, nullptr, false))
return false;
ftepp_next(ftepp);
return true;
@ -1289,12 +1289,12 @@ static void unescape(const char *str, char *out) {
static char *ftepp_include_find_path(const char *file, const char *pathfile)
{
FILE *fp;
char *filename = NULL;
char *filename = nullptr;
const char *last_slash;
size_t len;
if (!pathfile)
return NULL;
return nullptr;
last_slash = strrchr(pathfile, '/');
@ -1314,12 +1314,12 @@ static char *ftepp_include_find_path(const char *file, const char *pathfile)
return filename;
}
vec_free(filename);
return NULL;
return nullptr;
}
static char *ftepp_include_find(ftepp_t *ftepp, const char *file)
{
char *filename = NULL;
char *filename = nullptr;
filename = ftepp_include_find_path(file, ftepp->includename);
if (!filename)
@ -1328,7 +1328,7 @@ static char *ftepp_include_find(ftepp_t *ftepp, const char *file)
}
static bool ftepp_directive_warning(ftepp_t *ftepp) {
char *message = NULL;
char *message = nullptr;
if (!ftepp_skipspace(ftepp))
return false;
@ -1359,7 +1359,7 @@ static bool ftepp_directive_warning(ftepp_t *ftepp) {
}
static void ftepp_directive_error(ftepp_t *ftepp) {
char *message = NULL;
char *message = nullptr;
if (!ftepp_skipspace(ftepp))
return;
@ -1387,7 +1387,7 @@ static void ftepp_directive_error(ftepp_t *ftepp) {
}
static void ftepp_directive_message(ftepp_t *ftepp) {
char *message = NULL;
char *message = nullptr;
if (!ftepp_skipspace(ftepp))
return;
@ -1426,7 +1426,7 @@ static bool ftepp_include(ftepp_t *ftepp)
lex_ctx_t ctx;
char lineno[128];
char *filename;
char *parsename = NULL;
char *parsename = nullptr;
char *old_includename;
(void)ftepp_next(ftepp);
@ -1437,8 +1437,8 @@ static bool ftepp_include(ftepp_t *ftepp)
ppmacro *macro = ftepp_macro_find(ftepp, ftepp_tokval(ftepp));
if (macro) {
char *backup = ftepp->output_string;
ftepp->output_string = NULL;
if (ftepp_macro_expand(ftepp, macro, NULL, true)) {
ftepp->output_string = nullptr;
if (ftepp_macro_expand(ftepp, macro, nullptr, true)) {
parsename = util_strdup(ftepp->output_string);
vec_free(ftepp->output_string);
ftepp->output_string = backup;
@ -1708,7 +1708,7 @@ static bool ftepp_preprocess(ftepp_t *ftepp)
bool newline = true;
/* predef stuff */
char *expand = NULL;
char *expand = nullptr;
ftepp->lex->flags.preprocessing = true;
ftepp->lex->flags.mergelines = false;
@ -1739,7 +1739,7 @@ static bool ftepp_preprocess(ftepp_t *ftepp)
if (ftepp->output_on)
macro = ftepp_macro_find(ftepp, ftepp_tokval(ftepp));
else
macro = NULL;
macro = nullptr;
if (!macro) {
ftepp_out(ftepp, ftepp_tokval(ftepp), false);
@ -1801,10 +1801,10 @@ static bool ftepp_preprocess_done(ftepp_t *ftepp)
retval = false;
}
lex_close(ftepp->lex);
ftepp->lex = NULL;
ftepp->lex = nullptr;
if (ftepp->itemname) {
mem_d(ftepp->itemname);
ftepp->itemname = NULL;
ftepp->itemname = nullptr;
}
return retval;
}
@ -1837,7 +1837,7 @@ bool ftepp_preprocess_string(ftepp_t *ftepp, const char *name, const char *str)
void ftepp_add_macro(ftepp_t *ftepp, const char *name, const char *value) {
char *create = NULL;
char *create = nullptr;
/* use saner path for empty macros */
if (!value) {
@ -1864,15 +1864,15 @@ ftepp_t *ftepp_create()
ftepp = ftepp_new();
if (!ftepp)
return NULL;
return nullptr;
memset(minor, 0, sizeof(minor));
memset(major, 0, sizeof(major));
/* set the right macro based on the selected standard */
ftepp_add_define(ftepp, NULL, "GMQCC");
ftepp_add_define(ftepp, nullptr, "GMQCC");
if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_FTEQCC) {
ftepp_add_define(ftepp, NULL, "__STD_FTEQCC__");
ftepp_add_define(ftepp, nullptr, "__STD_FTEQCC__");
/* 1.00 */
major[0] = '"';
major[1] = '1';
@ -1882,15 +1882,15 @@ ftepp_t *ftepp_create()
minor[1] = '0';
minor[2] = '"';
} else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_GMQCC) {
ftepp_add_define(ftepp, NULL, "__STD_GMQCC__");
ftepp_add_define(ftepp, nullptr, "__STD_GMQCC__");
util_snprintf(major, 32, "\"%d\"", GMQCC_VERSION_MAJOR);
util_snprintf(minor, 32, "\"%d\"", GMQCC_VERSION_MINOR);
} else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_QCCX) {
ftepp_add_define(ftepp, NULL, "__STD_QCCX__");
ftepp_add_define(ftepp, nullptr, "__STD_QCCX__");
util_snprintf(major, 32, "\"%d\"", GMQCC_VERSION_MAJOR);
util_snprintf(minor, 32, "\"%d\"", GMQCC_VERSION_MINOR);
} else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_QCC) {
ftepp_add_define(ftepp, NULL, "__STD_QCC__");
ftepp_add_define(ftepp, nullptr, "__STD_QCC__");
/* 1.0 */
major[0] = '"';
major[1] = '1';

View file

@ -227,7 +227,7 @@ void _util_vec_delete(void *vec);
/* exposed interface */
#define vec_meta(A) ((vector_t*)(((char *)(A)) - sizeof(vector_t)))
#define vec_free(A) ((void)((A) ? (_util_vec_delete((void *)(A)), (A) = NULL) : 0))
#define vec_free(A) ((void)((A) ? (_util_vec_delete((void *)(A)), (A) = nullptr) : 0))
#define vec_push(A,V) (GMQCC_VEC_WILLGROW((A),1), (A)[vec_meta(A)->used++] = (V))
#define vec_size(A) ((A) ? vec_meta(A)->used : 0)
#define vec_add(A,N) (GMQCC_VEC_WILLGROW((A),(N)), vec_meta(A)->used += (N), &(A)[vec_meta(A)->used-(N)])

View file

@ -4,8 +4,8 @@
#define intrin_ctx(I) parser_ctx((I)->parser)
static GMQCC_INLINE ast_function *intrin_value(intrin_t *intrin, ast_value **out, const char *name, qcint_t vtype) {
ast_value *value = NULL;
ast_function *func = NULL;
ast_value *value = nullptr;
ast_function *func = nullptr;
char buffer[1024];
char stype [1024];
@ -32,7 +32,7 @@ static GMQCC_INLINE void intrin_reg(intrin_t *intrin, ast_value *const value, as
/*
* since some intrinsics depend on each other there is the possibility
* that an intrinsic will fail to get a 'depended' function that a
* builtin needs, causing some dependency in the chain to have a NULL
* builtin needs, causing some dependency in the chain to have a nullptr
* function. This will cause a segmentation fault at code generation,
* even though an error was raised. To contiue to allow it (instead
* of stopping compilation right away). We need to return from the
@ -40,8 +40,8 @@ static GMQCC_INLINE void intrin_reg(intrin_t *intrin, ast_value *const value, as
*/
static ast_expression *intrin_func_self(intrin_t *intrin, const char *name, const char *from);
static ast_expression *intrin_nullfunc(intrin_t *intrin) {
ast_value *value = NULL;
ast_function *func = intrin_value(intrin, &value, NULL, TYPE_VOID);
ast_value *value = nullptr;
ast_function *func = intrin_value(intrin, &value, nullptr, TYPE_VOID);
intrin_reg(intrin, value, func);
return (ast_expression*)value;
}
@ -52,7 +52,7 @@ static ast_expression *intrin_isfinite(intrin_t *intrin) {
* return !(isnan(x) || isinf(x));
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_function *func = intrin_value(intrin, &value, "isfinite", TYPE_FLOAT);
ast_call *callisnan = ast_call_new(intrin_ctx(intrin), intrin_func_self(intrin, "isnan", "isfinite"));
@ -97,7 +97,7 @@ static ast_expression *intrin_isinf(intrin_t *intrin) {
* return (x != 0.0) && (x + x == x);
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "isinf", TYPE_FLOAT);
@ -146,7 +146,7 @@ static ast_expression *intrin_isnan(intrin_t *intrin) {
* return (x != local);
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_value *arg1 = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_value *local = ast_value_new(intrin_ctx(intrin), "local", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
@ -188,7 +188,7 @@ static ast_expression *intrin_isnormal(intrin_t *intrin) {
* return isfinite(x);
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_call *callisfinite = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "isfinite", "isnormal"));
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
@ -216,7 +216,7 @@ static ast_expression *intrin_signbit(intrin_t *intrin) {
* return (x < 0);
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "signbit", TYPE_FLOAT);
@ -252,7 +252,7 @@ static ast_expression *intrin_acosh(intrin_t *intrin) {
* return log(x + sqrt((x * x) - 1));
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_call *calllog = ast_call_new(intrin_ctx(intrin), intrin_func_self(intrin, "log", "acosh"));
ast_call *callsqrt = ast_call_new(intrin_ctx(intrin), intrin_func_self(intrin, "sqrt", "acosh"));
@ -305,7 +305,7 @@ static ast_expression *intrin_asinh(intrin_t *intrin) {
* return log(x + sqrt((x * x) + 1));
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_call *calllog = ast_call_new(intrin_ctx(intrin), intrin_func_self(intrin, "log", "asinh"));
ast_call *callsqrt = ast_call_new(intrin_ctx(intrin), intrin_func_self(intrin, "sqrt", "asinh"));
@ -358,7 +358,7 @@ static ast_expression *intrin_atanh(intrin_t *intrin) {
* return 0.5 * log((1 + x) / (1 - x))
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_call *calllog = ast_call_new(intrin_ctx(intrin), intrin_func_self(intrin, "log", "atanh"));
ast_block *body = ast_block_new(intrin_ctx(intrin));
@ -413,7 +413,7 @@ static ast_expression *intrin_exp(intrin_t *intrin) {
* return sum;
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_value *sum = ast_value_new(intrin_ctx(intrin), "sum", TYPE_FLOAT);
ast_value *acc = ast_value_new(intrin_ctx(intrin), "acc", TYPE_FLOAT);
@ -469,7 +469,7 @@ static ast_expression *intrin_exp(intrin_t *intrin) {
(ast_expression*)fold_constgen_float(intrin->fold, 200.0f, false)
),
false,
NULL,
nullptr,
false,
/* ++i; */
(ast_expression*)ast_binstore_new(
@ -520,7 +520,7 @@ static ast_expression *intrin_exp2(intrin_t *intrin) {
* return pow(2, x);
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_call *callpow = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "pow", "exp2"));
ast_value *arg1 = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
@ -550,7 +550,7 @@ static ast_expression *intrin_expm1(intrin_t *intrin) {
* return exp(x) - 1;
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_call *callexp = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "exp", "expm1"));
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
@ -621,7 +621,7 @@ static ast_expression *intrin_pow(intrin_t *intrin) {
* return accumulate;
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_function *func = intrin_value(intrin, &value, "pow", TYPE_FLOAT);
/* prepare some calls for later */
@ -684,7 +684,7 @@ static ast_expression *intrin_pow(intrin_t *intrin) {
intrin_ctx(intrin),
(ast_expression*)intrin->fold->imm_float[1]
),
NULL
nullptr
)
);
@ -705,7 +705,7 @@ static ast_expression *intrin_pow(intrin_t *intrin) {
intrin_ctx(intrin),
(ast_expression*)base
),
NULL
nullptr
)
);
@ -741,7 +741,7 @@ static ast_expression *intrin_pow(intrin_t *intrin) {
(ast_expression*)callpow1
)
),
NULL
nullptr
)
);
@ -797,7 +797,7 @@ static ast_expression *intrin_pow(intrin_t *intrin) {
(ast_expression*)intrin->fold->imm_float[1]
),
(ast_expression*)expgt1,
NULL
nullptr
)
);
@ -989,7 +989,7 @@ static ast_expression *intrin_pow(intrin_t *intrin) {
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
/* init */
NULL,
nullptr,
/* pre condition */
(ast_expression*)ast_binary_new(
intrin_ctx(intrin),
@ -1000,11 +1000,11 @@ static ast_expression *intrin_pow(intrin_t *intrin) {
/* pre not */
false,
/* post condition */
NULL,
nullptr,
/* post not */
false,
/* increment expression */
NULL,
nullptr,
/* code block */
(ast_expression*)whileblock
)
@ -1032,7 +1032,7 @@ static ast_expression *intrin_mod(intrin_t *intrin) {
* return a - b * sign * floor(sign * div);
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_call *call = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "floor", "mod"));
ast_value *a = ast_value_new(intrin_ctx(intrin), "a", TYPE_FLOAT);
ast_value *b = ast_value_new(intrin_ctx(intrin), "b", TYPE_FLOAT);
@ -1126,7 +1126,7 @@ static ast_expression *intrin_fabs(intrin_t *intrin) {
* return x < 0 ? -x : x;
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_value *arg1 = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "fabs", TYPE_FLOAT);
@ -1167,7 +1167,7 @@ static ast_expression *intrin_epsilon(intrin_t *intrin) {
* return eps;
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_value *eps = ast_value_new(intrin_ctx(intrin), "eps", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
ast_function *func = intrin_value(intrin, &value, "epsilon", TYPE_FLOAT);
@ -1187,8 +1187,8 @@ static ast_expression *intrin_epsilon(intrin_t *intrin) {
body->exprs.push_back(
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
NULL,
NULL,
nullptr,
nullptr,
false,
(ast_expression*)ast_binary_new(
intrin_ctx(intrin),
@ -1207,7 +1207,7 @@ static ast_expression *intrin_epsilon(intrin_t *intrin) {
(ast_expression*)intrin->fold->imm_float[1]
),
false,
NULL,
nullptr,
(ast_expression*)ast_binstore_new(
intrin_ctx(intrin),
INSTR_STORE_F,
@ -1238,7 +1238,7 @@ static ast_expression *intrin_nan(intrin_t *intrin) {
* return x / x;
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_function *func = intrin_value(intrin, &value, "nan", TYPE_FLOAT);
ast_block *block = ast_block_new(intrin_ctx(intrin));
@ -1279,7 +1279,7 @@ static ast_expression *intrin_inf(intrin_t *intrin) {
* return x / y;
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_value *x = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_value *y = ast_value_new(intrin_ctx(intrin), "y", TYPE_FLOAT);
ast_function *func = intrin_value(intrin, &value, "inf", TYPE_FLOAT);
@ -1384,7 +1384,7 @@ static ast_expression *intrin_ln(intrin_t *intrin) {
* }
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_value *power = ast_value_new(intrin_ctx(intrin), "power", TYPE_FLOAT);
ast_value *base = ast_value_new(intrin_ctx(intrin), "base", TYPE_FLOAT);
ast_value *whole = ast_value_new(intrin_ctx(intrin), "whole", TYPE_FLOAT);
@ -1538,7 +1538,7 @@ static ast_expression *intrin_ln(intrin_t *intrin) {
intrin_func_self(intrin, "__builtin_nan", "ln")
)
),
NULL
nullptr
)
);
@ -1553,7 +1553,7 @@ static ast_expression *intrin_ln(intrin_t *intrin) {
(ast_expression*)intrin->fold->imm_float[1]
),
(ast_expression*)((i) ? blt1 : plt1),
NULL
nullptr
)
);
}
@ -1657,7 +1657,7 @@ static ast_expression *intrin_ln(intrin_t *intrin) {
whileloop->exprs.push_back(
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
NULL,
nullptr,
(ast_expression*)ast_binary_new(
intrin_ctx(intrin),
INSTR_GE,
@ -1665,9 +1665,9 @@ static ast_expression *intrin_ln(intrin_t *intrin) {
(ast_expression*)newbase2
),
false,
NULL,
nullptr,
false,
NULL,
nullptr,
(ast_expression*)nestwhile
)
);
@ -1698,7 +1698,7 @@ static ast_expression *intrin_ln(intrin_t *intrin) {
forloop->exprs.push_back(
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
NULL,
nullptr,
(ast_expression*)ast_binary_new(
intrin_ctx(intrin),
INSTR_GE,
@ -1706,9 +1706,9 @@ static ast_expression *intrin_ln(intrin_t *intrin) {
(ast_expression*)base
),
false,
NULL,
nullptr,
false,
NULL,
nullptr,
(ast_expression*)whileloop
)
);
@ -1805,7 +1805,7 @@ static ast_expression *intrin_ln(intrin_t *intrin) {
false,
0
),
NULL
nullptr
)
);
@ -1828,13 +1828,13 @@ static ast_expression *intrin_ln(intrin_t *intrin) {
block->exprs.push_back(
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
NULL,
/* for(; 1; ) ?? (can this be NULL too?) */
nullptr,
/* for(; 1; ) ?? (can this be nullptr too?) */
(ast_expression*)intrin->fold->imm_float[1],
false,
NULL,
nullptr,
false,
NULL,
nullptr,
(ast_expression*)forloop
)
);
@ -1863,7 +1863,7 @@ static ast_expression *intrin_ln(intrin_t *intrin) {
}
static ast_expression *intrin_log_variant(intrin_t *intrin, const char *name, float base) {
ast_value *value = NULL;
ast_value *value = nullptr;
ast_call *callln = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "__builtin_ln", name));
ast_value *arg1 = ast_value_new(intrin_ctx(intrin), "x", TYPE_FLOAT);
ast_block *body = ast_block_new(intrin_ctx(intrin));
@ -1905,7 +1905,7 @@ static ast_expression *intrin_shift_variant(intrin_t *intrin, const char *name,
* float [shift] (float a, float b) {
* return floor(a [instr] pow(2, b));
*/
ast_value *value = NULL;
ast_value *value = nullptr;
ast_call *callpow = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "pow", name));
ast_call *callfloor = ast_call_new (intrin_ctx(intrin), intrin_func_self(intrin, "floor", name));
ast_value *a = ast_value_new(intrin_ctx(intrin), "a", TYPE_FLOAT);
@ -2017,14 +2017,14 @@ void intrin_cleanup(intrin_t *intrin) {
ast_expression *intrin_fold(intrin_t *intrin, ast_value *value, ast_expression **exprs) {
if (!value || !value->name)
return NULL;
return nullptr;
for (auto &it : intrin->intrinsics) {
if (!strcmp(value->name, it.name))
return (vec_size(exprs) != it.args)
? NULL
? nullptr
: fold_intrin(intrin->fold, value->name + 10, exprs);
}
return NULL;
return nullptr;
}
static GMQCC_INLINE ast_expression *intrin_func_try(intrin_t *intrin, size_t offset, const char *compare) {
@ -2055,11 +2055,11 @@ static ast_expression *intrin_func_self(intrin_t *intrin, const char *name, cons
if (from) {
intrin_error(intrin, "need function `%s', compiler depends on it for `__builtin_%s'", name, from);
return intrin_func_self(intrin, "#nullfunc", NULL);
return intrin_func_self(intrin, "#nullfunc", nullptr);
}
return NULL;
return nullptr;
}
ast_expression *intrin_func(intrin_t *intrin, const char *name) {
return intrin_func_self(intrin, name, NULL);
return intrin_func_self(intrin, name, nullptr);
}

210
ir.cpp
View file

@ -291,19 +291,19 @@ ir_builder* ir_builder_new(const char *modulename)
self = (ir_builder*)mem_a(sizeof(*self));
if (!self)
return NULL;
return nullptr;
self->functions = NULL;
self->globals = NULL;
self->fields = NULL;
self->filenames = NULL;
self->filestrings = NULL;
self->functions = nullptr;
self->globals = nullptr;
self->fields = nullptr;
self->filenames = nullptr;
self->filestrings = nullptr;
self->htglobals = util_htnew(IR_HT_SIZE);
self->htfields = util_htnew(IR_HT_SIZE);
self->htfunctions = util_htnew(IR_HT_SIZE);
self->extparams = NULL;
self->extparam_protos = NULL;
self->extparams = nullptr;
self->extparam_protos = nullptr;
self->first_common_globaltemp = 0;
self->max_globaltemps = 0;
@ -311,10 +311,10 @@ ir_builder* ir_builder_new(const char *modulename)
self->max_locals = 0;
self->str_immediate = 0;
self->name = NULL;
self->name = nullptr;
if (!ir_builder_set_name(self, modulename)) {
mem_d(self);
return NULL;
return nullptr;
}
self->nil = ir_value_var("nil", store_value, TYPE_NIL);
@ -329,8 +329,8 @@ ir_builder* ir_builder_new(const char *modulename)
self->vinstr_temp[i]->cvq = CV_CONST;
}
self->reserved_va_count = NULL;
self->coverage_func = NULL;
self->reserved_va_count = nullptr;
self->coverage_func = nullptr;
self->code = code_init();
@ -389,14 +389,14 @@ ir_function* ir_builder_create_function(ir_builder *self, const char *name, int
{
ir_function *fn = ir_builder_get_function(self, name);
if (fn) {
return NULL;
return nullptr;
}
fn = ir_function_new(self, outtype);
if (!ir_function_set_name(fn, name))
{
ir_function_delete(fn);
return NULL;
return nullptr;
}
vec_push(self->functions, fn);
util_htset(self->htfunctions, name, fn);
@ -404,7 +404,7 @@ ir_function* ir_builder_create_function(ir_builder *self, const char *name, int
fn->value = ir_builder_create_global(self, fn->name, TYPE_FUNCTION);
if (!fn->value) {
ir_function_delete(fn);
return NULL;
return nullptr;
}
fn->value->hasvalue = true;
@ -428,7 +428,7 @@ ir_value* ir_builder_create_global(ir_builder *self, const char *name, int vtype
{
ve = ir_builder_get_global(self, name);
if (ve) {
return NULL;
return nullptr;
}
}
@ -455,7 +455,7 @@ ir_value* ir_builder_create_field(ir_builder *self, const char *name, int vtype)
{
ir_value *ve = ir_builder_get_field(self, name);
if (ve) {
return NULL;
return nullptr;
}
ve = ir_value_var(name, store_global, TYPE_FIELD);
@ -480,14 +480,14 @@ ir_function* ir_function_new(ir_builder* owner, int outtype)
self = (ir_function*)mem_a(sizeof(*self));
if (!self)
return NULL;
return nullptr;
memset(self, 0, sizeof(*self));
self->name = NULL;
self->name = nullptr;
if (!ir_function_set_name(self, "<@unnamed>")) {
mem_d(self);
return NULL;
return nullptr;
}
self->flags = 0;
@ -495,13 +495,13 @@ ir_function* ir_function_new(ir_builder* owner, int outtype)
self->context.file = "<@no context>";
self->context.line = 0;
self->outtype = outtype;
self->value = NULL;
self->value = nullptr;
self->builtin = 0;
self->params = NULL;
self->blocks = NULL;
self->values = NULL;
self->locals = NULL;
self->params = nullptr;
self->blocks = nullptr;
self->values = nullptr;
self->locals = nullptr;
self->max_varargs = 0;
@ -581,7 +581,7 @@ ir_block* ir_function_create_block(lex_ctx_t ctx, ir_function *self, const char
vec_push(self->blocks, bn);
if ((self->flags & IR_FLAG_BLOCK_COVERAGE) && self->owner->coverage_func)
(void)ir_block_create_call(bn, ctx, NULL, self->owner->coverage_func, false);
(void)ir_block_create_call(bn, ctx, nullptr, self->owner->coverage_func, false);
return bn;
}
@ -716,7 +716,7 @@ static bool ir_function_pass_tailrecursion(ir_function *self)
for (b = 0; b < vec_size(self->blocks); ++b) {
ir_value *funcval;
ir_instr *ret, *call, *store = NULL;
ir_instr *ret, *call, *store = nullptr;
ir_block *block = self->blocks[b];
if (!block->final || vec_size(block->instr) < 2)
@ -861,7 +861,7 @@ ir_value* ir_function_create_local(ir_function *self, const char *name, int vtyp
vec_size(self->locals) &&
self->locals[vec_size(self->locals)-1]->store != store_param) {
irerror(self->context, "cannot add parameters after adding locals");
return NULL;
return nullptr;
}
ve = ir_value_var(name, (param ? store_param : store_local), vtype);
@ -880,19 +880,19 @@ ir_block* ir_block_new(ir_function* owner, const char *name)
ir_block *self = new ir_block;
memset(self, 0, sizeof(*self));
self->label = NULL;
self->label = nullptr;
if (name && !ir_block_set_label(self, name)) {
mem_d(self);
return NULL;
return nullptr;
}
self->owner = owner;
self->context.file = "<@no context>";
self->context.line = 0;
self->final = false;
self->instr = NULL;
self->entries = NULL;
self->exits = NULL;
self->instr = nullptr;
self->entries = nullptr;
self->exits = nullptr;
self->eid = 0;
self->is_return = false;
@ -943,11 +943,11 @@ static ir_instr* ir_instr_new(lex_ctx_t ctx, ir_block* owner, int op)
self->owner = owner;
self->context = ctx;
self->opcode = op;
self->_ops[0] = NULL;
self->_ops[1] = NULL;
self->_ops[2] = NULL;
self->bops[0] = NULL;
self->bops[1] = NULL;
self->_ops[0] = nullptr;
self->_ops[1] = nullptr;
self->_ops[2] = nullptr;
self->bops[0] = nullptr;
self->bops[1] = nullptr;
self->eid = 0;
self->likely = true;
return self;
@ -980,9 +980,9 @@ static void ir_instr_delete(ir_instr *self)
if (vec_ir_instr_find(it->reads, self, &idx))
it->reads.erase(it->reads.begin() + idx);
}
(void)!ir_instr_op(self, 0, NULL, false);
(void)!ir_instr_op(self, 1, NULL, false);
(void)!ir_instr_op(self, 2, NULL, false);
(void)!ir_instr_op(self, 0, nullptr, false);
(void)!ir_instr_op(self, 1, nullptr, false);
(void)!ir_instr_op(self, 2, nullptr, false);
mem_d(self);
}
@ -1044,26 +1044,26 @@ ir_value* ir_value_var(const char *name, int storetype, int vtype)
self->hasvalue = false;
self->context.file = "<@no context>";
self->context.line = 0;
self->name = NULL;
self->name = nullptr;
if (name && !ir_value_set_name(self, name)) {
irerror(self->context, "out of memory");
mem_d(self);
return NULL;
return nullptr;
}
memset(&self->constval, 0, sizeof(self->constval));
memset(&self->code, 0, sizeof(self->code));
self->members[0] = NULL;
self->members[1] = NULL;
self->members[2] = NULL;
self->memberof = NULL;
self->members[0] = nullptr;
self->members[1] = nullptr;
self->members[2] = nullptr;
self->memberof = nullptr;
self->unique_life = false;
self->locked = false;
self->callparam = false;
self->life = NULL;
self->life = nullptr;
return self;
}
@ -1087,7 +1087,7 @@ ir_value* ir_value_vector_member(ir_value *self, unsigned int member)
size_t len;
ir_value *m;
if (member >= 3)
return NULL;
return nullptr;
if (self->members[member])
return self->members[member];
@ -1101,7 +1101,7 @@ ir_value* ir_value_vector_member(ir_value *self, unsigned int member)
name[len+2] = '\0';
}
else
name = NULL;
name = nullptr;
if (self->vtype == TYPE_VECTOR)
{
@ -1109,7 +1109,7 @@ ir_value* ir_value_vector_member(ir_value *self, unsigned int member)
if (name)
mem_d(name);
if (!m)
return NULL;
return nullptr;
m->context = self->context;
self->members[member] = m;
@ -1118,12 +1118,12 @@ ir_value* ir_value_vector_member(ir_value *self, unsigned int member)
else if (self->vtype == TYPE_FIELD)
{
if (self->fieldtype != TYPE_VECTOR)
return NULL;
return nullptr;
m = ir_value_var(name, self->store, TYPE_FIELD);
if (name)
mem_d(name);
if (!m)
return NULL;
return nullptr;
m->fieldtype = TYPE_FLOAT;
m->context = self->context;
@ -1133,7 +1133,7 @@ ir_value* ir_value_vector_member(ir_value *self, unsigned int member)
else
{
irerror(self->context, "invalid member access on %s", self->name);
return NULL;
return nullptr;
}
m->memberof = self;
@ -1151,7 +1151,7 @@ static ir_value* ir_value_out(ir_function *owner, const char *name, int storetyp
{
ir_value *v = ir_value_var(name, storetype, vtype);
if (!v)
return NULL;
return nullptr;
ir_function_collect_value(owner, v);
return v;
}
@ -1268,8 +1268,8 @@ static bool ir_value_life_merge(ir_value *self, size_t s)
{
size_t i;
const size_t vs = vec_size(self->life);
ir_life_entry_t *life = NULL;
ir_life_entry_t *before = NULL;
ir_life_entry_t *life = nullptr;
ir_life_entry_t *before = nullptr;
ir_life_entry_t new_entry;
/* Find the first range >= s */
@ -1644,19 +1644,19 @@ ir_instr* ir_block_create_phi(ir_block *self, lex_ctx_t ctx, const char *label,
ir_value *out;
ir_instr *in;
if (!ir_check_unreachable(self))
return NULL;
return nullptr;
in = ir_instr_new(ctx, self, VINSTR_PHI);
if (!in)
return NULL;
return nullptr;
out = ir_value_out(self->owner, label, store_value, ot);
if (!out) {
ir_instr_delete(in);
return NULL;
return nullptr;
}
if (!ir_instr_op(in, 0, out, true)) {
ir_instr_delete(in);
ir_value_delete(out);
return NULL;
return nullptr;
}
vec_push(self->instr, in);
return in;
@ -1671,7 +1671,7 @@ void ir_phi_add(ir_instr* self, ir_block *b, ir_value *v)
{
ir_phi_entry_t pe;
if (!vec_ir_block_find(self->owner->entries, b, NULL)) {
if (!vec_ir_block_find(self->owner->entries, b, nullptr)) {
/* Must not be possible to cause this, otherwise the AST
* is doing something wrong.
*/
@ -1691,10 +1691,10 @@ ir_instr* ir_block_create_call(ir_block *self, lex_ctx_t ctx, const char *label,
ir_value *out;
ir_instr *in;
if (!ir_check_unreachable(self))
return NULL;
return nullptr;
in = ir_instr_new(ctx, self, (noreturn ? VINSTR_NRCALL : INSTR_CALL0));
if (!in)
return NULL;
return nullptr;
if (noreturn) {
self->final = true;
self->is_return = true;
@ -1702,22 +1702,22 @@ ir_instr* ir_block_create_call(ir_block *self, lex_ctx_t ctx, const char *label,
out = ir_value_out(self->owner, label, (func->outtype == TYPE_VOID) ? store_return : store_value, func->outtype);
if (!out) {
ir_instr_delete(in);
return NULL;
return nullptr;
}
if (!ir_instr_op(in, 0, out, true) ||
!ir_instr_op(in, 1, func, false))
{
ir_instr_delete(in);
ir_value_delete(out);
return NULL;
return nullptr;
}
vec_push(self->instr, in);
/*
if (noreturn) {
if (!ir_block_create_return(self, ctx, NULL)) {
if (!ir_block_create_return(self, ctx, nullptr)) {
compile_error(ctx, "internal error: failed to generate dummy-return instruction");
ir_instr_delete(in);
return NULL;
return nullptr;
}
}
*/
@ -1850,7 +1850,7 @@ ir_value* ir_block_create_binop(ir_block *self, lex_ctx_t ctx,
};
if (ot == TYPE_VOID) {
/* The AST or parser were supposed to check this! */
return NULL;
return nullptr;
}
return ir_block_create_general_instr(self, ctx, label, opcode, left, right, ot);
@ -1876,9 +1876,9 @@ ir_value* ir_block_create_unary(ir_block *self, lex_ctx_t ctx,
* the operand for 0 already exists so we just source it from here.
*/
case VINSTR_NEG_F:
return ir_block_create_general_instr(self, ctx, label, INSTR_SUB_F, NULL, operand, ot);
return ir_block_create_general_instr(self, ctx, label, INSTR_SUB_F, nullptr, operand, ot);
case VINSTR_NEG_V:
return ir_block_create_general_instr(self, ctx, label, INSTR_SUB_V, NULL, operand, TYPE_VECTOR);
return ir_block_create_general_instr(self, ctx, label, INSTR_SUB_V, nullptr, operand, TYPE_VECTOR);
default:
ot = operand->vtype;
@ -1886,11 +1886,11 @@ ir_value* ir_block_create_unary(ir_block *self, lex_ctx_t ctx,
};
if (ot == TYPE_VOID) {
/* The AST or parser were supposed to check this! */
return NULL;
return nullptr;
}
/* let's use the general instruction creator and pass NULL for OPB */
return ir_block_create_general_instr(self, ctx, label, opcode, operand, NULL, ot);
/* let's use the general instruction creator and pass nullptr for OPB */
return ir_block_create_general_instr(self, ctx, label, opcode, operand, nullptr, ot);
}
static ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx_t ctx, const char *label,
@ -1901,12 +1901,12 @@ static ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx_t ctx, co
out = ir_value_out(self->owner, label, store_value, outype);
if (!out)
return NULL;
return nullptr;
instr = ir_instr_new(ctx, self, op);
if (!instr) {
ir_value_delete(out);
return NULL;
return nullptr;
}
if (!ir_instr_op(instr, 0, out, true) ||
@ -1922,7 +1922,7 @@ static ir_value* ir_block_create_general_instr(ir_block *self, lex_ctx_t ctx, co
on_error:
ir_instr_delete(instr);
ir_value_delete(out);
return NULL;
return nullptr;
}
ir_value* ir_block_create_fieldaddress(ir_block *self, lex_ctx_t ctx, const char *label, ir_value *ent, ir_value *field)
@ -1931,10 +1931,10 @@ ir_value* ir_block_create_fieldaddress(ir_block *self, lex_ctx_t ctx, const char
/* Support for various pointer types todo if so desired */
if (ent->vtype != TYPE_ENTITY)
return NULL;
return nullptr;
if (field->vtype != TYPE_FIELD)
return NULL;
return nullptr;
v = ir_block_create_general_instr(self, ctx, label, INSTR_ADDRESS, ent, field, TYPE_POINTER);
v->fieldtype = field->fieldtype;
@ -1945,11 +1945,11 @@ ir_value* ir_block_create_load_from_ent(ir_block *self, lex_ctx_t ctx, const cha
{
int op;
if (ent->vtype != TYPE_ENTITY)
return NULL;
return nullptr;
/* at some point we could redirect for TYPE_POINTER... but that could lead to carelessness */
if (field->vtype != TYPE_FIELD)
return NULL;
return nullptr;
switch (outype)
{
@ -1965,7 +1965,7 @@ ir_value* ir_block_create_load_from_ent(ir_block *self, lex_ctx_t ctx, const cha
#endif
default:
irerror(self->context, "invalid type for ir_block_create_load_from_ent: %s", type_name[outype]);
return NULL;
return nullptr;
}
return ir_block_create_general_instr(self, ctx, label, op, ent, field, outype);
@ -2169,14 +2169,14 @@ bool ir_function_allocate_locals(ir_function *self)
if (!vec_size(self->locals) && !vec_size(self->values))
return true;
globalloc.locals = NULL;
globalloc.sizes = NULL;
globalloc.positions = NULL;
globalloc.unique = NULL;
lockalloc.locals = NULL;
lockalloc.sizes = NULL;
lockalloc.positions = NULL;
lockalloc.unique = NULL;
globalloc.locals = nullptr;
globalloc.sizes = nullptr;
globalloc.positions = nullptr;
globalloc.unique = nullptr;
lockalloc.locals = nullptr;
lockalloc.sizes = nullptr;
lockalloc.positions = nullptr;
lockalloc.unique = nullptr;
for (i = 0; i < vec_size(self->locals); ++i)
{
@ -2473,7 +2473,7 @@ static bool ir_block_life_propagate(ir_block *self, bool *changed)
if (value->memberof) {
value = value->memberof;
for (mem = 0; mem < 3; ++mem) {
if (value->members[mem] && vec_ir_value_find(self->living, value->members[mem], NULL))
if (value->members[mem] && vec_ir_value_find(self->living, value->members[mem], nullptr))
break;
}
if (mem == 3 && vec_ir_value_find(self->living, value, &idx)) {
@ -2537,13 +2537,13 @@ static bool ir_block_life_propagate(ir_block *self, bool *changed)
/* read operands */
if (read & (1<<o))
{
if (!vec_ir_value_find(self->living, value, NULL))
if (!vec_ir_value_find(self->living, value, nullptr))
self->living.push_back(value);
/* reading adds the full vector */
if (value->memberof && !vec_ir_value_find(self->living, value->memberof, NULL))
if (value->memberof && !vec_ir_value_find(self->living, value->memberof, nullptr))
self->living.push_back(value->memberof);
for (mem = 0; mem < 3; ++mem) {
if (value->members[mem] && !vec_ir_value_find(self->living, value->members[mem], NULL))
if (value->members[mem] && !vec_ir_value_find(self->living, value->members[mem], nullptr))
self->living.push_back(value->members[mem]);
}
}
@ -2551,13 +2551,13 @@ static bool ir_block_life_propagate(ir_block *self, bool *changed)
/* PHI operands are always read operands */
for (auto &it : instr->phi) {
value = it.value;
if (!vec_ir_value_find(self->living, value, NULL))
if (!vec_ir_value_find(self->living, value, nullptr))
self->living.push_back(value);
/* reading adds the full vector */
if (value->memberof && !vec_ir_value_find(self->living, value->memberof, NULL))
if (value->memberof && !vec_ir_value_find(self->living, value->memberof, nullptr))
self->living.push_back(value->memberof);
for (mem = 0; mem < 3; ++mem) {
if (value->members[mem] && !vec_ir_value_find(self->living, value->members[mem], NULL))
if (value->members[mem] && !vec_ir_value_find(self->living, value->members[mem], nullptr))
self->living.push_back(value->members[mem]);
}
}
@ -2570,13 +2570,13 @@ static bool ir_block_life_propagate(ir_block *self, bool *changed)
/* call params are read operands too */
for (auto &it : instr->params) {
value = it;
if (!vec_ir_value_find(self->living, value, NULL))
if (!vec_ir_value_find(self->living, value, nullptr))
self->living.push_back(value);
/* reading adds the full vector */
if (value->memberof && !vec_ir_value_find(self->living, value->memberof, NULL))
if (value->memberof && !vec_ir_value_find(self->living, value->memberof, nullptr))
self->living.push_back(value->memberof);
for (mem = 0; mem < 3; ++mem) {
if (value->members[mem] && !vec_ir_value_find(self->living, value->members[mem], NULL))
if (value->members[mem] && !vec_ir_value_find(self->living, value->members[mem], nullptr))
self->living.push_back(value->members[mem]);
}
}
@ -2722,7 +2722,7 @@ static bool gen_global_pointer(code_t *code, ir_value *global)
ir_value *target = global->constval.vpointer;
if (!target) {
irerror(global->context, "Invalid pointer constant: %s", global->name);
/* NULL pointers are pointing to the NULL constant, which also
/* nullptr pointers are pointing to the nullptr constant, which also
* sits at address 0, but still has an ir_value for itself.
*/
return false;
@ -3856,7 +3856,7 @@ static bool ir_builder_gen_field(ir_builder *self, ir_value *field)
static void ir_builder_collect_reusables(ir_builder *builder) {
size_t i;
ir_value **reusables = NULL;
ir_value **reusables = nullptr;
for (i = 0; i < vec_size(builder->globals); ++i) {
ir_value *value = builder->globals[i];
if (value->vtype != TYPE_FLOAT || !value->hasvalue)
@ -3870,7 +3870,7 @@ static void ir_builder_collect_reusables(ir_builder *builder) {
static void ir_builder_split_vector(ir_builder *self, ir_value *vec) {
size_t i, count;
ir_value* found[3] = { NULL, NULL, NULL };
ir_value* found[3] = { nullptr, nullptr, nullptr };
/* must not be written to */
if (vec->writes.size())
@ -3953,7 +3953,7 @@ bool ir_builder_generate(ir_builder *self, const char *filename)
{
prog_section_statement_t stmt;
size_t i;
char *lnofile = NULL;
char *lnofile = nullptr;
if (OPTS_FLAG(SPLIT_VECTOR_PARAMETERS)) {
ir_builder_collect_reusables(self);
@ -4260,7 +4260,7 @@ void ir_instr_dump(ir_instr *in, char *ind,
int (*oprintf)(const char*, ...))
{
size_t i;
const char *comma = NULL;
const char *comma = nullptr;
oprintf("%s (%i) ", ind, (int)in->eid);

View file

@ -81,15 +81,15 @@ lex_file* lex_open(const char *file)
uint32_t read;
if (!in) {
lexerror(NULL, "open failed: '%s'\n", file);
return NULL;
lexerror(nullptr, "open failed: '%s'\n", file);
return nullptr;
}
lex = (lex_file*)mem_a(sizeof(*lex));
if (!lex) {
fclose(in);
lexerror(NULL, "out of memory\n");
return NULL;
lexerror(nullptr, "out of memory\n");
return nullptr;
}
memset(lex, 0, sizeof(*lex));
@ -124,13 +124,13 @@ lex_file* lex_open_string(const char *str, size_t len, const char *name)
lex = (lex_file*)mem_a(sizeof(*lex));
if (!lex) {
lexerror(NULL, "out of memory\n");
return NULL;
lexerror(nullptr, "out of memory\n");
return nullptr;
}
memset(lex, 0, sizeof(*lex));
lex->file = NULL;
lex->file = nullptr;
lex->open_string = str;
lex->open_string_length = len;
lex->open_string_pos = 0;
@ -329,9 +329,9 @@ static void lex_endtoken(lex_file *lex)
static bool lex_try_pragma(lex_file *lex)
{
int ch;
char *pragma = NULL;
char *command = NULL;
char *param = NULL;
char *pragma = nullptr;
char *command = nullptr;
char *param = nullptr;
size_t line;
if (lex->flags.preprocessing)
@ -396,7 +396,7 @@ static bool lex_try_pragma(lex_file *lex)
vec_push(lex_filenames, lex->name);
}
else if (!strcmp(command, "line")) {
line = strtol(param, NULL, 0)-1;
line = strtol(param, nullptr, 0)-1;
}
else
goto unroll;
@ -899,9 +899,9 @@ static int GMQCC_WARN lex_finish_digit(lex_file *lex, int lastch)
lex_endtoken(lex);
if (lex->tok.ttype == TOKEN_FLOATCONST)
lex->tok.constval.f = strtod(lex->tok.value, NULL);
lex->tok.constval.f = strtod(lex->tok.value, nullptr);
else
lex->tok.constval.i = strtol(lex->tok.value, NULL, 0);
lex->tok.constval.i = strtol(lex->tok.value, nullptr, 0);
return lex->tok.ttype;
}
@ -1042,11 +1042,11 @@ int lex_do(lex_file *lex)
frame_macro m;
m.value = lex->framevalue;
m.name = lex->modelname;
lex->modelname = NULL;
lex->modelname = nullptr;
vec_push(lex->frames, m);
}
lex->modelname = lex->tok.value;
lex->tok.value = NULL;
lex->tok.value = nullptr;
return lex_do(lex);
}

View file

@ -7,13 +7,13 @@
/* TODO: cleanup this whole file .. it's a fuckign mess */
/* set by the standard */
const oper_info *operators = NULL;
const oper_info *operators = nullptr;
size_t operator_count = 0;
static bool opts_output_wasset = false;
struct argitem { char *filename; int type; };
struct ppitem { char *name; char *value; };
static argitem *items = NULL;
static ppitem *ppems = NULL;
static argitem *items = nullptr;
static ppitem *ppems = nullptr;
#define TYPE_QC 0
#define TYPE_ASM 1
@ -120,7 +120,7 @@ static bool options_parse(int argc, char **argv) {
bool argend = false;
size_t itr;
char buffer[1024];
char *config = NULL;
char *config = nullptr;
while (!argend && argc > 1) {
char *argarg;
@ -187,11 +187,11 @@ static bool options_parse(int argc, char **argv) {
if (options_long_gcc("force-crc", &argc, &argv, &argarg)) {
OPTS_OPTION_BOOL(OPTION_FORCECRC) = true;
OPTS_OPTION_U16 (OPTION_FORCED_CRC) = strtol(argarg, NULL, 0);
OPTS_OPTION_U16 (OPTION_FORCED_CRC) = strtol(argarg, nullptr, 0);
continue;
}
if (options_long_gcc("state-fps", &argc, &argv, &argarg)) {
OPTS_OPTION_U32(OPTION_STATE_FPS) = strtol(argarg, NULL, 0);
OPTS_OPTION_U32(OPTION_STATE_FPS) = strtol(argarg, nullptr, 0);
opts_set(opts.flags, EMULATE_STATE, true);
continue;
}
@ -282,7 +282,7 @@ static bool options_parse(int argc, char **argv) {
if (!(argarg = strchr(argv[0] + 2, '='))) {
macro.name = util_strdup(argv[0]+2);
macro.value = NULL;
macro.value = nullptr;
} else {
*argarg='\0'; /* terminate for name */
macro.name = util_strdup(argv[0]+2);
@ -383,7 +383,7 @@ static bool options_parse(int argc, char **argv) {
return false;
}
if (util_isdigit(argarg[0])) {
uint32_t val = (uint32_t)strtol(argarg, NULL, 10);
uint32_t val = (uint32_t)strtol(argarg, nullptr, 10);
OPTS_OPTION_U32(OPTION_O) = val;
opts_setoptimlevel(val);
} else {
@ -518,9 +518,9 @@ int main(int argc, char **argv) {
int retval = 0;
bool operators_free = false;
bool progs_src = false;
FILE *outfile = NULL;
parser_t *parser = NULL;
ftepp_t *ftepp = NULL;
FILE *outfile = nullptr;
parser_t *parser = nullptr;
ftepp_t *ftepp = nullptr;
app_name = argv[0];
con_init ();
@ -624,7 +624,7 @@ int main(int argc, char **argv) {
if (!vec_size(items)) {
FILE *src;
char *line = NULL;
char *line = nullptr;
size_t linelen = 0;
bool hasline = false;
@ -714,12 +714,12 @@ int main(int argc, char **argv) {
if (progs_src) {
mem_d(items[itr].filename);
items[itr].filename = NULL;
items[itr].filename = nullptr;
}
}
ftepp_finish(ftepp);
ftepp = NULL;
ftepp = nullptr;
if (!OPTS_OPTION_BOOL(OPTION_PP_ONLY)) {
if (!parser_finish(parser, OPTS_OPTION_STR(OPTION_OUTPUT))) {
retval = 1;

View file

@ -14,21 +14,21 @@ const opts_flag_def_t opts_opt_list[COUNT_OPTIMIZATIONS+1] = {
# define GMQCC_TYPE_OPTIMIZATIONS
# define GMQCC_DEFINE_FLAG(NAME, MIN_O) { #NAME, LONGBIT(OPTIM_##NAME) },
# include "opts.def"
{ NULL, LONGBIT(0) }
{ nullptr, LONGBIT(0) }
};
const opts_flag_def_t opts_warn_list[COUNT_WARNINGS+1] = {
# define GMQCC_TYPE_WARNS
# define GMQCC_DEFINE_FLAG(X) { #X, LONGBIT(WARN_##X) },
# include "opts.def"
{ NULL, LONGBIT(0) }
{ nullptr, LONGBIT(0) }
};
const opts_flag_def_t opts_flag_list[COUNT_FLAGS+1] = {
# define GMQCC_TYPE_FLAGS
# define GMQCC_DEFINE_FLAG(X) { #X, LONGBIT(X) },
# include "opts.def"
{ NULL, LONGBIT(0) }
{ nullptr, LONGBIT(0) }
};
unsigned int opts_optimizationcount[COUNT_OPTIMIZATIONS];
@ -200,7 +200,7 @@ static size_t opts_ini_parse (
size_t linesize;
size_t lineno = 1;
size_t error = 0;
char *line = NULL;
char *line = nullptr;
char section_data[2048] = "";
char oldname_data[2048] = "";
@ -287,11 +287,11 @@ static size_t opts_ini_parse (
static bool opts_ini_bool(const char *value) {
if (!strcmp(value, "true")) return true;
if (!strcmp(value, "false")) return false;
return !!strtol(value, NULL, 10);
return !!strtol(value, nullptr, 10);
}
static char *opts_ini_load(const char *section, const char *name, const char *value, char **parse_file) {
char *error = NULL;
char *error = nullptr;
bool found = false;
/*
@ -396,8 +396,8 @@ void opts_ini_init(const char *file) {
* gmqcc.ini
* gmqcc.cfg
*/
char *error = NULL;
char *parse_file = NULL;
char *error = nullptr;
char *parse_file = nullptr;
size_t line;
FILE *ini;

File diff suppressed because it is too large Load diff

View file

@ -10,10 +10,10 @@
*/
char *stat_mem_strdup(const char *src, bool empty) {
size_t len = 0;
char *ptr = NULL;
char *ptr = nullptr;
if (!src)
return NULL;
return nullptr;
len = strlen(src);
if ((!empty ? len : true) && (ptr = (char*)mem_a(len + 1))) {
@ -30,7 +30,7 @@ char *stat_mem_strdup(const char *src, bool empty) {
void _util_vec_grow(void **a, size_t i, size_t s) {
vector_t *d = vec_meta(*a);
size_t m = 0;
void *p = NULL;
void *p = nullptr;
if (*a) {
m = 2 * d->allocated + i;
@ -70,15 +70,15 @@ size_t util_hthash(hash_table_t *ht, const char *key) {
static hash_node_t *_util_htnewpair(const char *key, void *value) {
hash_node_t *node;
if (!(node = (hash_node_t*)mem_a(sizeof(hash_node_t))))
return NULL;
return nullptr;
if (!(node->key = util_strdupe(key))) {
mem_d(node);
return NULL;
return nullptr;
}
node->value = value;
node->next = NULL;
node->next = nullptr;
return node;
}
@ -91,17 +91,17 @@ static hash_node_t *_util_htnewpair(const char *key, void *value) {
* util_htdel(table) -- to delete the table
*/
hash_table_t *util_htnew(size_t size) {
hash_table_t *hashtable = NULL;
hash_table_t *hashtable = nullptr;
if (size < 1)
return NULL;
return nullptr;
if (!(hashtable = (hash_table_t*)mem_a(sizeof(hash_table_t))))
return NULL;
return nullptr;
if (!(hashtable->table = (hash_node_t**)mem_a(sizeof(hash_node_t*) * size))) {
mem_d(hashtable);
return NULL;
return nullptr;
}
hashtable->size = size;
@ -111,9 +111,9 @@ hash_table_t *util_htnew(size_t size) {
}
void util_htseth(hash_table_t *ht, const char *key, size_t bin, void *value) {
hash_node_t *newnode = NULL;
hash_node_t *next = NULL;
hash_node_t *last = NULL;
hash_node_t *newnode = nullptr;
hash_node_t *next = nullptr;
hash_node_t *last = nullptr;
next = ht->table[bin];
@ -149,7 +149,7 @@ void *util_htgeth(hash_table_t *ht, const char *key, size_t bin) {
pair = pair->next;
if (!pair || !pair->key || strcmp(key, pair->key) != 0)
return NULL;
return nullptr;
return pair->value;
}
@ -178,7 +178,7 @@ void *code_util_str_htgeth(hash_table_t *ht, const char *key, size_t bin) {
if (cmp == 0)
return pair->value;
if (cmp < 0)
return NULL;
return nullptr;
pair = pair->next;
continue;
}
@ -190,7 +190,7 @@ void *code_util_str_htgeth(hash_table_t *ht, const char *key, size_t bin) {
}
pair = pair->next;
}
return NULL;
return nullptr;
}
/*
@ -245,5 +245,5 @@ void util_htrm(hash_table_t *ht, const char *key, void (*cb)(void*)) {
}
void util_htdel(hash_table_t *ht) {
util_htrem(ht, NULL);
util_htrem(ht, nullptr);
}

View file

@ -87,7 +87,7 @@ task_popen_error_2: close(outhandle[0]), close(outhandle[1]);
task_popen_error_1: close(inhandle [0]), close(inhandle [1]);
task_popen_error_0:
return NULL;
return nullptr;
}
static int task_pclose(FILE **handles) {
@ -199,7 +199,7 @@ struct task_template_t {
static bool task_template_generate(task_template_t *tmpl, char tag, const char *file, size_t line, char *value, size_t *pad) {
size_t desclen = 0;
size_t filelen = 0;
char **destval = NULL;
char **destval = nullptr;
if (!tmpl)
return false;
@ -270,8 +270,8 @@ static bool task_template_generate(task_template_t *tmpl, char tag, const char *
}
static bool task_template_parse(const char *file, task_template_t *tmpl, FILE *fp, size_t *pad) {
char *data = NULL;
char *back = NULL;
char *data = nullptr;
char *back = nullptr;
size_t size = 0;
size_t line = 1;
@ -376,7 +376,7 @@ static bool task_template_parse(const char *file, task_template_t *tmpl, FILE *f
/* update line and free old sata */
line++;
mem_d(back);
back = NULL;
back = nullptr;
}
if (back)
mem_d(back);
@ -395,22 +395,22 @@ static void task_template_nullify(task_template_t *tmpl) {
if (!tmpl)
return;
tmpl->description = NULL;
tmpl->proceduretype = NULL;
tmpl->compileflags = NULL;
tmpl->executeflags = NULL;
tmpl->sourcefile = NULL;
tmpl->tempfilename = NULL;
tmpl->rulesfile = NULL;
tmpl->testflags = NULL;
tmpl->description = nullptr;
tmpl->proceduretype = nullptr;
tmpl->compileflags = nullptr;
tmpl->executeflags = nullptr;
tmpl->sourcefile = nullptr;
tmpl->tempfilename = nullptr;
tmpl->rulesfile = nullptr;
tmpl->testflags = nullptr;
}
static task_template_t *task_template_compile(const char *file, const char *dir, size_t *pad) {
/* a page should be enough */
char fullfile[4096];
size_t filepadd = 0;
FILE *tempfile = NULL;
task_template_t *tmpl = NULL;
FILE *tempfile = nullptr;
task_template_t *tmpl = nullptr;
util_snprintf(fullfile, sizeof(fullfile), "%s/%s", dir, file);
@ -524,7 +524,7 @@ failure:
fclose(tempfile);
mem_d(tmpl);
return NULL;
return nullptr;
}
static void task_template_destroy(task_template_t *tmpl) {
@ -544,7 +544,7 @@ static void task_template_destroy(task_template_t *tmpl) {
mem_d(it);
/*
* Nullify all the template members otherwise NULL comparision
* Nullify all the template members otherwise nullptr comparision
* checks will fail if tmpl pointer is reused.
*/
mem_d(tmpl->tempfilename);
@ -600,7 +600,7 @@ static bool task_propagate(const char *curdir, size_t *pad, const char *defs) {
directories.push_back(claim);
} else {
mem_d(claim);
claim = NULL;
claim = nullptr;
}
}
closedir(dir);
@ -629,7 +629,7 @@ static bool task_propagate(const char *curdir, size_t *pad, const char *defs) {
if (strcmp(files->d_name + strlen(files->d_name) - 5, ".tmpl") == 0) {
task_template_t *tmpl = task_template_compile(files->d_name, it, pad);
char buf[4096]; /* one page should be enough */
const char *qcflags = NULL;
const char *qcflags = nullptr;
task_t task;
found ++;
@ -642,7 +642,7 @@ static bool task_propagate(const char *curdir, size_t *pad, const char *defs) {
* Generate a temportary file name for the output binary
* so we don't trample over an existing one.
*/
tmpl->tempfilename = NULL;
tmpl->tempfilename = nullptr;
util_asprintf(&tmpl->tempfilename, "%s/TMPDAT.%s.dat", it, files->d_name);
/*
@ -884,7 +884,7 @@ static bool task_trymatch(task_t &task, std::vector<char *> &line) {
* and handle accordingly.
*/
{
char *data = NULL;
char *data = nullptr;
size_t size = 0;
size_t compare = 0;
@ -941,7 +941,7 @@ static bool task_trymatch(task_t &task, std::vector<char *> &line) {
line.push_back(data);
/* reset */
data = NULL;
data = nullptr;
size = 0;
}
@ -949,7 +949,7 @@ static bool task_trymatch(task_t &task, std::vector<char *> &line) {
success = false;
mem_d(data);
data = NULL;
data = nullptr;
}
if (process)
@ -982,7 +982,7 @@ static const char *task_type(task_template_t *tmpl) {
static size_t task_schedualize(size_t *pad) {
char space[2][64];
bool execute = false;
char *data = NULL;
char *data = nullptr;
std::vector<char *> match;
size_t size = 0;
size_t i = 0;
@ -1248,7 +1248,7 @@ static bool parsecmd(const char *optname, int *argc_, char ***argv_, char **out,
int main(int argc, char **argv) {
bool succeed = false;
char *defs = NULL;
char *defs = nullptr;
con_init();

View file

@ -539,7 +539,7 @@ size_t util_optimizationtostr(const char *in, char *out, size_t outsz) {
static int util_vasprintf(char **dat, const char *fmt, va_list args) {
int ret;
int len;
char *tmp = NULL;
char *tmp = nullptr;
char buf[128];
va_list cpy;
@ -558,7 +558,7 @@ static int util_vasprintf(char **dat, const char *fmt, va_list args) {
tmp = (char*)mem_a(len + 1);
if ((ret = vsnprintf(tmp, len + 1, fmt, args)) != len) {
mem_d(tmp);
*dat = NULL;
*dat = nullptr;
return -1;
}