From 76278e8b97578f210b34784a55925b043098def9 Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Thu, 15 Jan 2015 15:18:33 -0500 Subject: [PATCH] s/NULL/nullptr/ --- ast.cpp | 206 ++++++++++++++-------------- ast.h | 8 +- code.cpp | 4 +- conout.cpp | 4 +- exec.cpp | 30 ++-- fold.cpp | 108 +++++++-------- ftepp.cpp | 74 +++++----- gmqcc.h | 2 +- intrin.cpp | 110 +++++++-------- ir.cpp | 210 ++++++++++++++-------------- lexer.cpp | 30 ++-- main.cpp | 28 ++-- opts.cpp | 16 +-- parser.cpp | 396 ++++++++++++++++++++++++++--------------------------- stat.cpp | 34 ++--- test.cpp | 50 +++---- util.cpp | 4 +- 17 files changed, 657 insertions(+), 657 deletions(-) diff --git a/ast.cpp b/ast.cpp index 85244f4..366d2a9 100644 --- a/ast.cpp +++ b/ast.cpp @@ -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 params; ir_instr *callinstr; - ir_value *funval = NULL; + ir_value *funval = nullptr; /* return values are never lvalues */ if (lvalue) { diff --git a/ast.h b/ast.h index 1627047..09f901a 100644 --- a/ast.h +++ b/ast.h @@ -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. diff --git a/code.cpp b/code.cpp index d0ab7e5..2f55535 100644 --- a/code.cpp +++ b/code.cpp @@ -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"); diff --git a/conout.cpp b/conout.cpp index 98c4289..28d1a43 100644 --- a/conout.cpp +++ b/conout.cpp @@ -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, ...) { diff --git a/exec.cpp b/exec.cpp index 4fb1cda..bfb090c 100644 --- a/exec.cpp +++ b/exec.cpp @@ -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()) { diff --git a/fold.cpp b/fold.cpp index 1e4bcd4..a4bc878 100644 --- a/fold.cpp +++ b/fold.cpp @@ -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 diff --git a/ftepp.cpp b/ftepp.cpp index 649a553..f1d5f36 100644 --- a/ftepp.cpp +++ b/ftepp.cpp @@ -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'; diff --git a/gmqcc.h b/gmqcc.h index 34fefaa..48570ff 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -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)]) diff --git a/intrin.cpp b/intrin.cpp index 643301e..14cbf73 100644 --- a/intrin.cpp +++ b/intrin.cpp @@ -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); } diff --git a/ir.cpp b/ir.cpp index dafc946..92cd11d 100644 --- a/ir.cpp +++ b/ir.cpp @@ -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<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); diff --git a/lexer.cpp b/lexer.cpp index 3dc6981..79ad182 100644 --- a/lexer.cpp +++ b/lexer.cpp @@ -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); } diff --git a/main.cpp b/main.cpp index d44d4d4..449067d 100644 --- a/main.cpp +++ b/main.cpp @@ -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; diff --git a/opts.cpp b/opts.cpp index bc72824..b2517a0 100644 --- a/opts.cpp +++ b/opts.cpp @@ -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; diff --git a/parser.cpp b/parser.cpp index fd7bad9..4c24cac 100644 --- a/parser.cpp +++ b/parser.cpp @@ -98,13 +98,13 @@ static ast_expression* parser_find_param(parser_t *parser, const char *name) { ast_value *fun; if (!parser->function) - return NULL; + return nullptr; fun = parser->function->vtype; for (auto &it : fun->expression.params) { if (!strcmp(it->name, name)) return (ast_expression*)it; } - return NULL; + return nullptr; } static ast_expression* parser_find_local(parser_t *parser, const char *name, size_t upto, bool *isparam) @@ -144,7 +144,7 @@ static ast_value* parser_find_typedef(parser_t *parser, const char *name, size_t if ( (e = (ast_value*)util_htgeth(parser->typedefs[i], name, hash)) ) return e; } - return NULL; + return nullptr; } struct sy_elem { @@ -176,7 +176,7 @@ static sy_elem syexp(lex_ctx_t ctx, ast_expression *v) { e.etype = 0; e.off = 0; e.out = v; - e.block = NULL; + e.block = nullptr; e.ctx = ctx; e.isparen = false; return e; @@ -197,8 +197,8 @@ static sy_elem syop(lex_ctx_t ctx, const oper_info *op) { sy_elem e; e.etype = 1 + (op - operators); e.off = 0; - e.out = NULL; - e.block = NULL; + e.out = nullptr; + e.block = nullptr; e.ctx = ctx; e.isparen = false; return e; @@ -208,8 +208,8 @@ static sy_elem syparen(lex_ctx_t ctx, size_t off) { sy_elem e; e.etype = 0; e.off = off; - e.out = NULL; - e.block = NULL; + e.out = nullptr; + e.block = nullptr; e.ctx = ctx; e.isparen = true; return e; @@ -250,8 +250,8 @@ static bool rotate_entfield_array_index_nodes(ast_expression **out) entfield = ast_entfield_new(ctx, entity, (ast_expression*)index); *out = (ast_expression*)entfield; - oldindex->array = NULL; - oldindex->index = NULL; + oldindex->array = nullptr; + oldindex->index = nullptr; ast_delete(oldindex); return true; @@ -284,7 +284,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) { const oper_info *op; lex_ctx_t ctx; - ast_expression *out = NULL; + ast_expression *out = nullptr; ast_expression *exprs[3]; ast_block *blocks[3]; ast_binstore *asbinstore; @@ -358,11 +358,11 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) exprs[1]->vtype == TYPE_NOEXPR) { if (exprs[1] == (ast_expression*)parser->const_vec[0]) - out = (ast_expression*)ast_member_new(ctx, exprs[0], 0, NULL); + out = (ast_expression*)ast_member_new(ctx, exprs[0], 0, nullptr); else if (exprs[1] == (ast_expression*)parser->const_vec[1]) - out = (ast_expression*)ast_member_new(ctx, exprs[0], 1, NULL); + out = (ast_expression*)ast_member_new(ctx, exprs[0], 1, nullptr); else if (exprs[1] == (ast_expression*)parser->const_vec[2]) - out = (ast_expression*)ast_member_new(ctx, exprs[0], 2, NULL); + out = (ast_expression*)ast_member_new(ctx, exprs[0], 2, nullptr); else { compile_error(ctx, "access to invalid vector component"); return false; @@ -589,7 +589,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) } else if (!(out = fold_op(parser->fold, op, exprs))) { /* generate a call to __builtin_mod */ ast_expression *mod = intrin_func(parser->intrin, "mod"); - ast_call *call = NULL; + ast_call *call = nullptr; if (!mod) return false; /* can return null for missing floor */ call = ast_call_new(parser_ctx(parser), mod); @@ -707,7 +707,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) if (!out) break; out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_F, out); if (!out) break; - exprs[i] = out; out = NULL; + exprs[i] = out; out = nullptr; if (OPTS_FLAG(PERL_LOGIC)) { /* here we want to keep the right expressions' type */ break; @@ -718,7 +718,7 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy) if (!out) break; out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_F, out); if (!out) break; - exprs[i] = out; out = NULL; + exprs[i] = out; out = nullptr; if (OPTS_FLAG(PERL_LOGIC)) { /* here we want to keep the right expressions' type */ break; @@ -1156,7 +1156,7 @@ static bool parser_close_call(parser_t *parser, shunt *sy) { /* was a function call */ ast_expression *fun; - ast_value *funval = NULL; + ast_value *funval = nullptr; ast_call *call; size_t fid; @@ -1227,8 +1227,8 @@ static bool parser_close_call(parser_t *parser, shunt *sy) * intrinsic call and just evaluate it i.e constant fold it. */ if (fold && ast_istype(fun, ast_value) && ((ast_value*)fun)->intrinsic) { - ast_expression **exprs = NULL; - ast_expression *foldval = NULL; + ast_expression **exprs = nullptr; + ast_expression *foldval = nullptr; for (i = 0; i < paramcount; i++) vec_push(exprs, sy->out[fid+1 + i].out); @@ -1291,7 +1291,7 @@ static bool parser_close_call(parser_t *parser, shunt *sy) parseerror(parser, "could not determine function return type"); return false; } else { - ast_value *fval = (ast_istype(fun, ast_value) ? ((ast_value*)fun) : NULL); + ast_value *fval = (ast_istype(fun, ast_value) ? ((ast_value*)fun) : nullptr); if (fun->flags & AST_FLAG_DEPRECATED) { if (!fval) { @@ -1407,27 +1407,27 @@ static ast_expression* parse_vararg_do(parser_t *parser) if (!parser->function->varargs) { parseerror(parser, "function has no variable argument list"); - return NULL; + return nullptr; } if (!parser_next(parser) || parser->tok != '(') { parseerror(parser, "expected parameter index and type in parenthesis"); - return NULL; + return nullptr; } if (!parser_next(parser)) { parseerror(parser, "error parsing parameter index"); - return NULL; + return nullptr; } idx = parse_expression_leave(parser, true, false, false); if (!idx) - return NULL; + return nullptr; if (parser->tok != ',') { if (parser->tok != ')') { ast_unref(idx); parseerror(parser, "expected comma after parameter index"); - return NULL; + return nullptr; } /* vararg piping: ...(start) */ out = (ast_expression*)ast_argpipe_new(ctx, idx); @@ -1437,20 +1437,20 @@ static ast_expression* parse_vararg_do(parser_t *parser) if (!parser_next(parser) || (parser->tok != TOKEN_IDENT && parser->tok != TOKEN_TYPENAME)) { ast_unref(idx); parseerror(parser, "expected typename for vararg"); - return NULL; + return nullptr; } - typevar = parse_typename(parser, NULL, NULL, NULL); + typevar = parse_typename(parser, nullptr, nullptr, nullptr); if (!typevar) { ast_unref(idx); - return NULL; + return nullptr; } if (parser->tok != ')') { ast_unref(idx); ast_delete(typevar); parseerror(parser, "expected closing paren"); - return NULL; + return nullptr; } if (funtype->expression.varparam && @@ -1560,7 +1560,7 @@ static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels) else if (parser->tok == TOKEN_IDENT) { const char *ctoken = parser_tokval(parser); - ast_expression *prev = sy->out.size() ? sy->out.back().out : NULL; + ast_expression *prev = sy->out.size() ? sy->out.back().out : nullptr; ast_expression *var; /* a_vector.{x,y,z} */ if (sy->ops.empty() || @@ -1568,7 +1568,7 @@ static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels) operators[sy->ops.back().etype-1].id != opid1('.')) { /* When adding more intrinsics, fix the above condition */ - prev = NULL; + prev = nullptr; } if (prev && prev->vtype == TYPE_VECTOR && ctoken[0] >= 'x' && ctoken[0] <= 'z' && !ctoken[1]) { @@ -1650,7 +1650,7 @@ static bool parse_sya_operand(parser_t *parser, shunt *sy, bool with_labels) static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma, bool truthvalue, bool with_labels) { - ast_expression *expr = NULL; + ast_expression *expr = nullptr; shunt sy; bool wantop = false; /* only warn once about an assignment in a truth value because the current code @@ -1680,7 +1680,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma { /* classify the operator */ const oper_info *op; - const oper_info *olast = NULL; + const oper_info *olast = nullptr; size_t o; for (o = 0; o < operator_count; ++o) { if (((!(operators[o].flags & OP_PREFIX) == !!wantop)) && @@ -1727,7 +1727,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma if (sy.ops.size() && !sy.ops.back().isparen) olast = &operators[sy.ops.back().etype-1]; else - olast = NULL; + olast = nullptr; } #define IsAssignOp(x) (\ @@ -1776,7 +1776,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma if (sy.ops.size() && !sy.ops.back().isparen) olast = &operators[sy.ops.back().etype-1]; else - olast = NULL; + olast = nullptr; } if (op->id == opid1('(')) { @@ -1889,7 +1889,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma if (last->isimm == true && last->cvq == CV_CONST && last->hasvalue && last->expression.vtype == TYPE_STRING) { - char *newstr = NULL; + char *newstr = nullptr; util_asprintf(&newstr, "%s%s", last->constval.vstring, parser_tokval(parser)); sy.out.back().out = (ast_expression*)fold_constgen_string(parser->fold, newstr, false); mem_d(newstr); @@ -1922,12 +1922,12 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma parser->lex->flags.noops = true; if (sy.out.size() != 1) { parseerror(parser, "expression expected"); - expr = NULL; + expr = nullptr; } else expr = sy.out[0].out; if (sy.paren.size()) { parseerror(parser, "internal error: sy.paren.size() = %zu", sy.paren.size()); - return NULL; + return nullptr; } return expr; @@ -1935,22 +1935,22 @@ onerr: parser->lex->flags.noops = true; for (auto &it : sy.out) if (it.out) ast_unref(it.out); - return NULL; + return nullptr; } static ast_expression* parse_expression(parser_t *parser, bool stopatcomma, bool with_labels) { ast_expression *e = parse_expression_leave(parser, stopatcomma, false, with_labels); if (!e) - return NULL; + return nullptr; if (parser->tok != ';') { parseerror(parser, "semicolon expected after expression"); ast_unref(e); - return NULL; + return nullptr; } if (!parser_next(parser)) { ast_unref(e); - return NULL; + return nullptr; } return e; } @@ -2038,7 +2038,7 @@ static ast_expression* process_condition(parser_t *parser, ast_expression *cond, if (!cond) { ast_unref(prev); parseerror(parser, "internal error: failed to process condition"); - return NULL; + return nullptr; } ifnot = !ifnot; } @@ -2054,7 +2054,7 @@ static ast_expression* process_condition(parser_t *parser, ast_expression *cond, if (!cond) { ast_unref(prev); parseerror(parser, "internal error: failed to process condition"); - return NULL; + return nullptr; } ifnot = !ifnot; } @@ -2065,7 +2065,7 @@ static ast_expression* process_condition(parser_t *parser, ast_expression *cond, while (cond && ast_istype(cond, ast_unary) && unary->op == INSTR_NOT_F) { cond = unary->operand; - unary->operand = NULL; + unary->operand = nullptr; ast_delete(unary); ifnot = !ifnot; unary = (ast_unary*)cond; @@ -2081,7 +2081,7 @@ static ast_expression* process_condition(parser_t *parser, ast_expression *cond, static bool parse_if(parser_t *parser, ast_block *block, ast_expression **out) { ast_ifthen *ifthen; - ast_expression *cond, *ontrue = NULL, *onfalse = NULL; + ast_expression *cond, *ontrue = nullptr, *onfalse = nullptr; bool ifnot = false; lex_ctx_t ctx = parser_ctx(parser); @@ -2166,7 +2166,7 @@ static bool parse_while_go(parser_t *parser, ast_block *block, ast_expression ** static bool parse_while(parser_t *parser, ast_block *block, ast_expression **out) { bool rv; - char *label = NULL; + char *label = nullptr; /* skip the 'while' and get the body */ if (!parser_next(parser)) { @@ -2207,7 +2207,7 @@ static bool parse_while(parser_t *parser, ast_block *block, ast_expression **out parseerror(parser, "internal error: label stack corrupted"); rv = false; ast_delete(*out); - *out = NULL; + *out = nullptr; } else { parser->breaks.pop_back(); @@ -2258,7 +2258,7 @@ static bool parse_while_go(parser_t *parser, ast_block *block, ast_expression ** ast_unref(ontrue); return false; } - aloop = ast_loop_new(ctx, NULL, cond, ifnot, NULL, false, NULL, ontrue); + aloop = ast_loop_new(ctx, nullptr, cond, ifnot, nullptr, false, nullptr, ontrue); *out = (ast_expression*)aloop; return true; } @@ -2267,7 +2267,7 @@ static bool parse_dowhile_go(parser_t *parser, ast_block *block, ast_expression static bool parse_dowhile(parser_t *parser, ast_block *block, ast_expression **out) { bool rv; - char *label = NULL; + char *label = nullptr; /* skip the 'do' and get the body */ if (!parser_next(parser)) { @@ -2303,12 +2303,12 @@ static bool parse_dowhile(parser_t *parser, ast_block *block, ast_expression **o parseerror(parser, "internal error: label stack corrupted"); rv = false; /* - * Test for NULL otherwise ast_delete dereferences null pointer + * Test for nullptr otherwise ast_delete dereferences null pointer * and boom. */ if (*out) ast_delete(*out); - *out = NULL; + *out = nullptr; } else { parser->breaks.pop_back(); @@ -2383,7 +2383,7 @@ static bool parse_dowhile_go(parser_t *parser, ast_block *block, ast_expression ast_delete(ontrue); return false; } - aloop = ast_loop_new(ctx, NULL, NULL, false, cond, ifnot, NULL, ontrue); + aloop = ast_loop_new(ctx, nullptr, nullptr, false, cond, ifnot, nullptr, ontrue); *out = (ast_expression*)aloop; return true; } @@ -2392,7 +2392,7 @@ static bool parse_for_go(parser_t *parser, ast_block *block, ast_expression **ou static bool parse_for(parser_t *parser, ast_block *block, ast_expression **out) { bool rv; - char *label = NULL; + char *label = nullptr; /* skip the 'for' and check for opening paren */ if (!parser_next(parser)) { @@ -2433,7 +2433,7 @@ static bool parse_for(parser_t *parser, ast_block *block, ast_expression **out) parseerror(parser, "internal error: label stack corrupted"); rv = false; ast_delete(*out); - *out = NULL; + *out = nullptr; } else { parser->breaks.pop_back(); @@ -2453,10 +2453,10 @@ static bool parse_for_go(parser_t *parser, ast_block *block, ast_expression **ou parser_enterblock(parser); - initexpr = NULL; - cond = NULL; - increment = NULL; - ontrue = NULL; + initexpr = nullptr; + cond = nullptr; + increment = nullptr; + ontrue = nullptr; /* parse into the expression */ if (!parser_next(parser)) { @@ -2464,12 +2464,12 @@ static bool parse_for_go(parser_t *parser, ast_block *block, ast_expression **ou goto onerr; } - typevar = NULL; + typevar = nullptr; if (parser->tok == TOKEN_IDENT) typevar = parser_find_typedef(parser, parser_tokval(parser), 0); if (typevar || parser->tok == TOKEN_TYPENAME) { - if (!parse_variable(parser, block, true, CV_VAR, typevar, false, false, 0, NULL)) + if (!parse_variable(parser, block, true, CV_VAR, typevar, false, false, 0, nullptr)) goto onerr; } else if (parser->tok != ';') @@ -2537,7 +2537,7 @@ static bool parse_for_go(parser_t *parser, ast_block *block, ast_expression **ou if (!cond) goto onerr; } - aloop = ast_loop_new(ctx, initexpr, cond, ifnot, NULL, false, increment, ontrue); + aloop = ast_loop_new(ctx, initexpr, cond, ifnot, nullptr, false, increment, ontrue); *out = (ast_expression*)aloop; if (!parser_leaveblock(parser)) { @@ -2555,9 +2555,9 @@ onerr: static bool parse_return(parser_t *parser, ast_block *block, ast_expression **out) { - ast_expression *exp = NULL; - ast_expression *var = NULL; - ast_return *ret = NULL; + ast_expression *exp = nullptr; + ast_expression *var = nullptr; + ast_return *ret = nullptr; ast_value *retval = parser->function->return_value; ast_value *expected = parser->function->vtype; @@ -2774,7 +2774,7 @@ static bool parse_qualifiers(parser_t *parser, bool with_local, int *cvq, bool * } else if (!strcmp(parser_tokval(parser), "alias") && !(flags & AST_FLAG_ALIAS)) { flags |= AST_FLAG_ALIAS; - *message = NULL; + *message = nullptr; if (!parser_next(parser)) { parseerror(parser, "parse error in attribute"); @@ -2812,7 +2812,7 @@ static bool parse_qualifiers(parser_t *parser, bool with_local, int *cvq, bool * } else if (!strcmp(parser_tokval(parser), "deprecated") && !(flags & AST_FLAG_DEPRECATED)) { flags |= AST_FLAG_DEPRECATED; - *message = NULL; + *message = nullptr; if (!parser_next(parser)) { parseerror(parser, "parse error in attribute"); @@ -2848,7 +2848,7 @@ static bool parse_qualifiers(parser_t *parser, bool with_local, int *cvq, bool * argerr: /* ugly */ if (*message) mem_d(*message); - *message = NULL; + *message = nullptr; *cvq = CV_WRONG; return false; } @@ -2947,7 +2947,7 @@ static bool parse_switch_go(parser_t *parser, ast_block *block, ast_expression * static bool parse_switch(parser_t *parser, ast_block *block, ast_expression **out) { bool rv; - char *label = NULL; + char *label = nullptr; /* skip the 'while' and get the body */ if (!parser_next(parser)) { @@ -2987,7 +2987,7 @@ static bool parse_switch(parser_t *parser, ast_block *block, ast_expression **ou parseerror(parser, "internal error: label stack corrupted"); rv = false; ast_delete(*out); - *out = NULL; + *out = nullptr; } else { parser->breaks.pop_back(); @@ -3047,23 +3047,23 @@ static bool parse_switch_go(parser_t *parser, ast_block *block, ast_expression * /* new block; allow some variables to be declared here */ parser_enterblock(parser); while (true) { - typevar = NULL; + typevar = nullptr; if (parser->tok == TOKEN_IDENT) typevar = parser_find_typedef(parser, parser_tokval(parser), 0); if (typevar || parser->tok == TOKEN_TYPENAME) { - if (!parse_variable(parser, block, true, CV_NONE, typevar, false, false, 0, NULL)) { + if (!parse_variable(parser, block, true, CV_NONE, typevar, false, false, 0, nullptr)) { ast_delete(switchnode); return false; } continue; } - if (parse_qualifiers(parser, true, &cvq, &noref, &is_static, &qflags, NULL)) + if (parse_qualifiers(parser, true, &cvq, &noref, &is_static, &qflags, nullptr)) { if (cvq == CV_WRONG) { ast_delete(switchnode); return false; } - if (!parse_variable(parser, block, true, cvq, NULL, noref, is_static, qflags, NULL)) { + if (!parse_variable(parser, block, true, cvq, nullptr, noref, is_static, qflags, nullptr)) { ast_delete(switchnode); return false; } @@ -3097,7 +3097,7 @@ static bool parse_switch_go(parser_t *parser, ast_block *block, ast_expression * } } else if (!strcmp(parser_tokval(parser), "default")) { - swcase.value = NULL; + swcase.value = nullptr; if (!parser_next(parser)) { ast_delete(switchnode); parseerror(parser, "expected colon"); @@ -3180,7 +3180,7 @@ static ast_expression *parse_goto_computed(parser_t *parser, ast_expression **si ast_expression *cond; if (!*side) - return NULL; + return nullptr; if (ast_istype(*side, ast_ternary)) { ast_ternary *tern = (ast_ternary*)*side; @@ -3191,26 +3191,26 @@ static ast_expression *parse_goto_computed(parser_t *parser, ast_expression **si parseerror(parser, "expected label or expression in ternary"); if (on_true) ast_unref(on_true); if (on_false) ast_unref(on_false); - return NULL; + return nullptr; } cond = tern->cond; - tern->cond = NULL; + tern->cond = nullptr; ast_delete(tern); - *side = NULL; + *side = nullptr; return (ast_expression*)ast_ifthen_new(parser_ctx(parser), cond, on_true, on_false); } else if (ast_istype(*side, ast_label)) { ast_goto *gt = ast_goto_new(parser_ctx(parser), ((ast_label*)*side)->name); ast_goto_set_label(gt, ((ast_label*)*side)); - *side = NULL; + *side = nullptr; return (ast_expression*)gt; } - return NULL; + return nullptr; } static bool parse_goto(parser_t *parser, ast_expression **out) { - ast_goto *gt = NULL; + ast_goto *gt = nullptr; ast_expression *lbl; if (!parser_next(parser)) @@ -3344,10 +3344,10 @@ static bool parse_statement(parser_t *parser, ast_block *block, ast_expression * bool noref, is_static; int cvq = CV_NONE; uint32_t qflags = 0; - ast_value *typevar = NULL; - char *vstring = NULL; + ast_value *typevar = nullptr; + char *vstring = nullptr; - *out = NULL; + *out = nullptr; if (parser->tok == TOKEN_IDENT) typevar = parser_find_typedef(parser, parser_tokval(parser), 0); @@ -3363,7 +3363,7 @@ static bool parse_statement(parser_t *parser, ast_block *block, ast_expression * if (parsewarning(parser, WARN_EXTENSIONS, "missing 'local' keyword when declaring a local variable")) return false; } - if (!parse_variable(parser, block, false, CV_NONE, typevar, false, false, 0, NULL)) + if (!parse_variable(parser, block, false, CV_NONE, typevar, false, false, 0, nullptr)) return false; return true; } @@ -3371,7 +3371,7 @@ static bool parse_statement(parser_t *parser, ast_block *block, ast_expression * { if (cvq == CV_WRONG) return false; - return parse_variable(parser, block, false, cvq, NULL, noref, is_static, qflags, vstring); + return parse_variable(parser, block, false, cvq, nullptr, noref, is_static, qflags, vstring); } else if (parser->tok == TOKEN_KEYWORD) { @@ -3543,8 +3543,8 @@ static bool parse_enum(parser_t *parser) bool flag = false; bool reverse = false; qcfloat_t num = 0; - ast_value **values = NULL; - ast_value *var = NULL; + ast_value **values = nullptr; + ast_value *var = nullptr; ast_value *asvalue; ast_expression *old; @@ -3687,26 +3687,26 @@ static bool parse_block_into(parser_t *parser, ast_block *block) while (parser->tok != TOKEN_EOF && parser->tok < TOKEN_ERROR) { - ast_expression *expr = NULL; + ast_expression *expr = nullptr; if (parser->tok == '}') break; if (!parse_statement(parser, block, &expr, false)) { /* parseerror(parser, "parse error"); */ - block = NULL; + block = nullptr; goto cleanup; } if (!expr) continue; if (!ast_block_add_expr(block, expr)) { ast_delete(block); - block = NULL; + block = nullptr; goto cleanup; } } if (parser->tok != '}') { - block = NULL; + block = nullptr; } else { (void)parser_next(parser); } @@ -3722,10 +3722,10 @@ static ast_block* parse_block(parser_t *parser) ast_block *block; block = ast_block_new(parser_ctx(parser)); if (!block) - return NULL; + return nullptr; if (!parse_block_into(parser, block)) { ast_block_delete(block); - return NULL; + return nullptr; } return block; } @@ -3736,7 +3736,7 @@ static bool parse_statement_or_block(parser_t *parser, ast_expression **out) *out = (ast_expression*)parse_block(parser); return !!*out; } - return parse_statement(parser, NULL, out, false); + return parse_statement(parser, nullptr, out, false); } static bool create_vector_members(ast_value *var, ast_member **me) @@ -3765,15 +3765,15 @@ static bool create_vector_members(ast_value *var, ast_member **me) static bool parse_function_body(parser_t *parser, ast_value *var) { - ast_block *block = NULL; + ast_block *block = nullptr; ast_function *func; ast_function *old; - ast_expression *framenum = NULL; - ast_expression *nextthink = NULL; + ast_expression *framenum = nullptr; + ast_expression *nextthink = nullptr; /* None of the following have to be deleted */ - ast_expression *fld_think = NULL, *fld_nextthink = NULL, *fld_frame = NULL; - ast_expression *gbl_time = NULL, *gbl_self = NULL; + ast_expression *fld_think = nullptr, *fld_nextthink = nullptr, *fld_frame = nullptr; + ast_expression *gbl_time = nullptr, *gbl_self = nullptr; bool has_frame_think; bool retval = true; @@ -3806,7 +3806,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var) * self.nextthink = time + 0.1; * self.think = nextthink; */ - nextthink = NULL; + nextthink = nullptr; fld_think = parser_find_field(parser, "think"); fld_nextthink = parser_find_field(parser, "nextthink"); @@ -4012,7 +4012,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var) func = var->constval.vfunc; if (!func) { - parseerror(parser, "internal error: NULL function: `%s`", var->name); + parseerror(parser, "internal error: nullptr function: `%s`", var->name); ast_block_delete(block); goto enderr; } @@ -4061,7 +4061,7 @@ static bool parse_function_body(parser_t *parser, ast_value *var) char name[1024]; ast_value *varargs = ast_value_new(ast_ctx(var), "reserved:va_args", TYPE_ARRAY); varargs->expression.flags |= AST_FLAG_IS_VARARG; - varargs->expression.next = (ast_expression*)ast_value_new(ast_ctx(var), NULL, TYPE_VECTOR); + varargs->expression.next = (ast_expression*)ast_value_new(ast_ctx(var), nullptr, TYPE_VECTOR); varargs->expression.count = 0; util_snprintf(name, sizeof(name), "%s##va##SET", var->name); if (!parser_create_array_setter_proto(parser, varargs, name)) { @@ -4105,7 +4105,7 @@ enderrfn: (void)!parser_leaveblock(parser); parser->functions.pop_back(); ast_function_delete(func); - var->constval.vfunc = NULL; + var->constval.vfunc = nullptr; enderr: parser->function = old; @@ -4129,7 +4129,7 @@ static ast_expression *array_accessor_split( if (!left || !right) { if (left) ast_delete(left); if (right) ast_delete(right); - return NULL; + return nullptr; } cmp = ast_binary_new(ctx, INSTR_LT, @@ -4139,14 +4139,14 @@ static ast_expression *array_accessor_split( ast_delete(left); ast_delete(right); parseerror(parser, "internal error: failed to create comparison for array setter"); - return NULL; + return nullptr; } ifthen = ast_ifthen_new(ctx, (ast_expression*)cmp, left, right); if (!ifthen) { ast_delete(cmp); /* will delete left and right */ parseerror(parser, "internal error: failed to create conditional jump for array setter"); - return NULL; + return nullptr; } return (ast_expression*)ifthen; @@ -4169,34 +4169,34 @@ static ast_expression *array_setter_node(parser_t *parser, ast_value *array, ast subscript = ast_array_index_new(ctx, (ast_expression*)array, (ast_expression*)fold_constgen_float(parser->fold, from, false)); if (!subscript) - return NULL; + return nullptr; st = ast_store_new(ctx, assignop, (ast_expression*)subscript, (ast_expression*)value); if (!st) { ast_delete(subscript); - return NULL; + return nullptr; } block = ast_block_new(ctx); if (!block) { ast_delete(st); - return NULL; + return nullptr; } if (!ast_block_add_expr(block, (ast_expression*)st)) { ast_delete(block); - return NULL; + return nullptr; } - ret = ast_return_new(ctx, NULL); + ret = ast_return_new(ctx, nullptr); if (!ret) { ast_delete(block); - return NULL; + return nullptr; } if (!ast_block_add_expr(block, (ast_expression*)ret)) { ast_delete(block); - return NULL; + return nullptr; } return (ast_expression*)block; @@ -4235,7 +4235,7 @@ static ast_expression *array_field_setter_node( subscript = ast_array_index_new(ctx, (ast_expression*)array, (ast_expression*)fold_constgen_float(parser->fold, from, false)); if (!subscript) - return NULL; + return nullptr; subscript->expression.next = ast_type_copy(ast_ctx(subscript), (ast_expression*)subscript); subscript->expression.vtype = TYPE_FIELD; @@ -4246,35 +4246,35 @@ static ast_expression *array_field_setter_node( (ast_expression*)subscript); if (!entfield) { ast_delete(subscript); - return NULL; + return nullptr; } st = ast_store_new(ctx, assignop, (ast_expression*)entfield, (ast_expression*)value); if (!st) { ast_delete(entfield); - return NULL; + return nullptr; } block = ast_block_new(ctx); if (!block) { ast_delete(st); - return NULL; + return nullptr; } if (!ast_block_add_expr(block, (ast_expression*)st)) { ast_delete(block); - return NULL; + return nullptr; } - ret = ast_return_new(ctx, NULL); + ret = ast_return_new(ctx, nullptr); if (!ret) { ast_delete(block); - return NULL; + return nullptr; } if (!ast_block_add_expr(block, (ast_expression*)ret)) { ast_delete(block); - return NULL; + return nullptr; } return (ast_expression*)block; @@ -4298,12 +4298,12 @@ static ast_expression *array_getter_node(parser_t *parser, ast_value *array, ast subscript = ast_array_index_new(ctx, (ast_expression*)array, (ast_expression*)fold_constgen_float(parser->fold, from, false)); if (!subscript) - return NULL; + return nullptr; ret = ast_return_new(ctx, (ast_expression*)subscript); if (!ret) { ast_delete(subscript); - return NULL; + return nullptr; } return (ast_expression*)ret; @@ -4319,9 +4319,9 @@ static ast_expression *array_getter_node(parser_t *parser, ast_value *array, ast static bool parser_create_array_accessor(parser_t *parser, ast_value *array, const char *funcname, ast_value **out) { - ast_function *func = NULL; - ast_value *fval = NULL; - ast_block *body = NULL; + ast_function *func = nullptr; + ast_value *fval = nullptr; + ast_block *body = nullptr; fval = ast_value_new(ast_ctx(array), funcname, TYPE_FUNCTION); if (!fval) { @@ -4355,18 +4355,18 @@ static bool parser_create_array_accessor(parser_t *parser, ast_value *array, con static ast_value* parser_create_array_setter_proto(parser_t *parser, ast_value *array, const char *funcname) { - ast_value *index = NULL; - ast_value *value = NULL; + ast_value *index = nullptr; + ast_value *value = nullptr; ast_function *func; ast_value *fval; if (!ast_istype(array->expression.next, ast_value)) { parseerror(parser, "internal error: array accessor needs to build an ast_value with a copy of the element type"); - return NULL; + return nullptr; } if (!parser_create_array_accessor(parser, array, funcname, &fval)) - return NULL; + return nullptr; func = fval->constval.vfunc; fval->expression.next = (ast_expression*)ast_value_new(ast_ctx(array), "", TYPE_VOID); @@ -4388,12 +4388,12 @@ cleanup: if (value) ast_delete(value); ast_delete(func); ast_delete(fval); - return NULL; + return nullptr; } static bool parser_create_array_setter_impl(parser_t *parser, ast_value *array) { - ast_expression *root = NULL; + ast_expression *root = nullptr; root = array_setter_node(parser, array, array->setter->expression.params[0], array->setter->expression.params[1], @@ -4418,10 +4418,10 @@ static bool parser_create_array_setter(parser_t *parser, ast_value *array, const static bool parser_create_array_field_setter(parser_t *parser, ast_value *array, const char *funcname) { - ast_expression *root = NULL; - ast_value *entity = NULL; - ast_value *index = NULL; - ast_value *value = NULL; + ast_expression *root = nullptr; + ast_value *entity = nullptr; + ast_value *index = nullptr; + ast_value *value = nullptr; ast_function *func; ast_value *fval; @@ -4467,7 +4467,7 @@ cleanup: static ast_value* parser_create_array_getter_proto(parser_t *parser, ast_value *array, const ast_expression *elemtype, const char *funcname) { - ast_value *index = NULL; + ast_value *index = nullptr; ast_value *fval; ast_function *func; @@ -4476,11 +4476,11 @@ static ast_value* parser_create_array_getter_proto(parser_t *parser, ast_value * */ if (!ast_istype(array->expression.next, ast_value)) { parseerror(parser, "internal error: array accessor needs to build an ast_value with a copy of the element type"); - return NULL; + return nullptr; } if (!parser_create_array_accessor(parser, array, funcname, &fval)) - return NULL; + return nullptr; func = fval->constval.vfunc; fval->expression.next = ast_type_copy(ast_ctx(array), elemtype); @@ -4498,12 +4498,12 @@ cleanup: if (index) ast_delete(index); ast_delete(func); ast_delete(fval); - return NULL; + return nullptr; } static bool parser_create_array_getter_impl(parser_t *parser, ast_value *array) { - ast_expression *root = NULL; + ast_expression *root = nullptr; root = array_getter_node(parser, array, array->getter->expression.params[0], 0, array->expression.count); if (!root) { @@ -4531,14 +4531,14 @@ static ast_value *parse_parameter_list(parser_t *parser, ast_value *var) ast_value *fval; bool first = true; bool variadic = false; - ast_value *varparam = NULL; - char *argcounter = NULL; + ast_value *varparam = nullptr; + char *argcounter = nullptr; /* for the sake of less code we parse-in in this function */ if (!parser_next(parser)) { ast_delete(var); parseerror(parser, "expected parameter list"); - return NULL; + return nullptr; } /* parse variables until we hit a closing paren */ @@ -4558,7 +4558,7 @@ static ast_value *parse_parameter_list(parser_t *parser, ast_value *var) } first = false; - ast_value *param = parse_typename(parser, NULL, NULL, &is_varargs); + ast_value *param = parse_typename(parser, nullptr, nullptr, &is_varargs); if (!param && !is_varargs) goto on_error; if (is_varargs) { @@ -4642,7 +4642,7 @@ on_error: ast_delete(var); for (auto &it : params) ast_delete(it); - return NULL; + return nullptr; } static ast_value *parse_arraysize(parser_t *parser, ast_value *var) @@ -4656,7 +4656,7 @@ static ast_value *parse_arraysize(parser_t *parser, ast_value *var) if (!parser_next(parser)) { ast_delete(var); parseerror(parser, "expected array-size"); - return NULL; + return nullptr; } if (parser->tok != ']') { @@ -4667,13 +4667,13 @@ static ast_value *parse_arraysize(parser_t *parser, ast_value *var) ast_unref(cexp); ast_delete(var); parseerror(parser, "expected array-size as constant positive integer"); - return NULL; + return nullptr; } cval = (ast_value*)cexp; } else { - cexp = NULL; - cval = NULL; + cexp = nullptr; + cval = nullptr; } tmp = ast_value_new(ctx, "", TYPE_ARRAY); @@ -4689,7 +4689,7 @@ static ast_value *parse_arraysize(parser_t *parser, ast_value *var) ast_unref(cexp); ast_delete(var); parseerror(parser, "array-size must be a positive integer constant"); - return NULL; + return nullptr; } ast_unref(cexp); @@ -4701,24 +4701,24 @@ static ast_value *parse_arraysize(parser_t *parser, ast_value *var) if (parser->tok != ']') { ast_delete(var); parseerror(parser, "expected ']' after array-size"); - return NULL; + return nullptr; } if (!parser_next(parser)) { ast_delete(var); parseerror(parser, "error after parsing array size"); - return NULL; + return nullptr; } return var; } /* Parse a complete typename. - * for single-variables (ie. function parameters or typedefs) storebase should be NULL + * for single-variables (ie. function parameters or typedefs) storebase should be nullptr * but when parsing variables separated by comma * 'storebase' should point to where the base-type should be kept. * The base type makes up every bit of type information which comes *before* the * variable name. * - * NOTE: The value must either be named, have a NULL name, or a name starting + * NOTE: The value must either be named, have a nullptr name, or a name starting * with '<'. In the first case, this will be the actual variable or type * name, in the other cases it is assumed that the name will appear * later, and an error is generated otherwise. @@ -4735,7 +4735,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va ast_value *var, *tmp; lex_ctx_t ctx; - const char *name = NULL; + const char *name = nullptr; bool isfield = false; bool wasarray = false; size_t morefields = 0; @@ -4752,7 +4752,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va /* if we parsed a dot we need a typename now */ if (!parser_next(parser)) { parseerror(parser, "expected typename for field definition"); - return NULL; + return nullptr; } /* Further dots are handled seperately because they won't be part of the @@ -4768,7 +4768,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va vararg = false; if (!parser_next(parser)) { parseerror(parser, "expected typename for field definition"); - return NULL; + return nullptr; } } } @@ -4777,10 +4777,10 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va if (!cached_typedef && parser->tok != TOKEN_TYPENAME) { if (vararg && is_vararg) { *is_vararg = true; - return NULL; + return nullptr; } parseerror(parser, "expected typename"); - return NULL; + return nullptr; } /* generate the basic type value */ @@ -4805,7 +4805,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va if (!parser_next(parser)) { ast_delete(var); parseerror(parser, "parse error after typename"); - return NULL; + return nullptr; } /* an opening paren now starts the parameter-list of a function @@ -4816,7 +4816,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va if (parser->tok == '(') { var = parse_parameter_list(parser, var); if (!var) - return NULL; + return nullptr; } /* store the base if requested */ @@ -4843,7 +4843,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va ast_delete(var); mem_d(name); parseerror(parser, "error after variable or field declaration"); - return NULL; + return nullptr; } } @@ -4854,7 +4854,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va var = parse_arraysize(parser, var); if (!var) { if (name) mem_d(name); - return NULL; + return nullptr; } } @@ -4875,7 +4875,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va var = parse_parameter_list(parser, var); if (!var) { if (name) mem_d(name); - return NULL; + return nullptr; } } @@ -4885,7 +4885,7 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va ast_delete(var); mem_d(name); parseerror(parser, "internal error: failed to set name"); - return NULL; + return nullptr; } /* free the name, ast_value_set_name duplicates */ mem_d(name); @@ -4899,7 +4899,7 @@ static bool parse_typedef(parser_t *parser) ast_value *typevar, *oldtype; ast_expression *old; - typevar = parse_typename(parser, NULL, NULL, NULL); + typevar = parse_typename(parser, nullptr, nullptr, nullptr); if (!typevar) return false; @@ -5056,21 +5056,21 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield bool was_end; size_t i; - ast_value *basetype = NULL; + ast_value *basetype = nullptr; bool retval = true; bool isparam = false; bool isvector = false; bool cleanvar = true; bool wasarray = false; - ast_member *me[3] = { NULL, NULL, NULL }; - ast_member *last_me[3] = { NULL, NULL, NULL }; + ast_member *me[3] = { nullptr, nullptr, nullptr }; + ast_member *last_me[3] = { nullptr, nullptr, nullptr }; if (!localblock && is_static) parseerror(parser, "`static` qualifier is not supported in global scope"); /* get the first complete variable */ - var = parse_typename(parser, &basetype, cached_typedef, NULL); + var = parse_typename(parser, &basetype, cached_typedef, nullptr); if (!var) { if (basetype) ast_delete(basetype); @@ -5086,7 +5086,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield } while (true) { - proto = NULL; + proto = nullptr; wasarray = false; /* Part 0: finish the type */ @@ -5190,7 +5190,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield goto cleanup; } ast_delete(var); - var = NULL; + var = nullptr; goto skipvar; /* parseerror(parser, "field `%s` already declared here: %s:%i", @@ -5237,7 +5237,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield retval = false; if (proto->desc) mem_d(proto->desc); - proto = NULL; + proto = nullptr; goto cleanup; } proto->expression.flags |= var->expression.flags; @@ -5265,12 +5265,12 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield if (!ast_istype(old, ast_value)) { parseerror(parser, "internal error: not an ast_value"); retval = false; - proto = NULL; + proto = nullptr; goto cleanup; } if (!parser_check_qualifiers(parser, var, proto)) { retval = false; - proto = NULL; + proto = nullptr; goto cleanup; } proto->expression.flags |= var->expression.flags; @@ -5319,7 +5319,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield if (ast_istype(old, ast_value)) var = proto = (ast_value*)old; else { - var = NULL; + var = nullptr; goto skipvar; } } @@ -5414,7 +5414,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield /* a static adds itself to be generated like any other global * but is added to the local namespace instead */ - char *defname = NULL; + char *defname = nullptr; size_t prefix_len, ln; size_t sn, sn_size; @@ -5441,7 +5441,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield break; } if (sn != sn_size) { - char *num = NULL; + char *num = nullptr; int len = util_asprintf(&num, "#%u", parser->function->static_count); vec_append(defname, len, num); mem_d(num); @@ -5481,7 +5481,7 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield } } memcpy(last_me, me, sizeof(me)); - me[0] = me[1] = me[2] = NULL; + me[0] = me[1] = me[2] = nullptr; cleanvar = false; /* Part 2.2 * deal with arrays @@ -5567,8 +5567,8 @@ skipvar: } if (parser->tok == '#') { - ast_function *func = NULL; - ast_value *number = NULL; + ast_function *func = nullptr; + ast_value *number = nullptr; float fractional; float integral; int builtin_num; @@ -5649,7 +5649,7 @@ skipvar: parseerror(parser, "expected comma or semicolon"); if (func) ast_function_delete(func); - var->constval.vfunc = NULL; + var->constval.vfunc = nullptr; break; } } @@ -5691,7 +5691,7 @@ skipvar: cexp = parse_expression_leave(parser, true, false, false); if (!cexp) break; - cval = ast_istype(cexp, ast_value) ? (ast_value*)cexp : NULL; + cval = ast_istype(cexp, ast_value) ? (ast_value*)cexp : nullptr; /* deal with foldable constants: */ if (localblock && @@ -5833,21 +5833,21 @@ static bool parser_global_statement(parser_t *parser) bool noref = false; bool is_static = false; uint32_t qflags = 0; - ast_value *istype = NULL; - char *vstring = NULL; + ast_value *istype = nullptr; + char *vstring = nullptr; if (parser->tok == TOKEN_IDENT) istype = parser_find_typedef(parser, parser_tokval(parser), 0); if (istype || parser->tok == TOKEN_TYPENAME || parser->tok == '.' || parser->tok == TOKEN_DOTS) { - return parse_variable(parser, NULL, false, CV_NONE, istype, false, false, 0, NULL); + return parse_variable(parser, nullptr, false, CV_NONE, istype, false, false, 0, nullptr); } else if (parse_qualifiers(parser, false, &cvq, &noref, &is_static, &qflags, &vstring)) { if (cvq == CV_WRONG) return false; - return parse_variable(parser, NULL, false, cvq, NULL, noref, is_static, qflags, vstring); + return parse_variable(parser, nullptr, false, cvq, nullptr, noref, is_static, qflags, vstring); } else if (parser->tok == TOKEN_IDENT && !strcmp(parser_tokval(parser), "enum")) { @@ -5967,7 +5967,7 @@ parser_t *parser_create() parser = (parser_t*)mem_a(sizeof(parser_t)); if (!parser) - return NULL; + return nullptr; memset(parser, 0, sizeof(*parser)); @@ -5983,7 +5983,7 @@ parser_t *parser_create() if (!parser->assign_op) { con_err("internal error: initializing parser: failed to find assign operator\n"); mem_d(parser); - return NULL; + return nullptr; } vec_push(parser->variables, parser->htfields = util_htnew(PARSER_HT_SIZE)); @@ -6014,7 +6014,7 @@ parser_t *parser_create() parser->reserved_version->expression.flags |= AST_FLAG_INCLUDE_DEF; parser->reserved_version->constval.vstring = util_strdup(GMQCC_FULL_VERSION_STRING); } else { - parser->reserved_version = NULL; + parser->reserved_version = nullptr; } parser->fold = fold_init (parser); @@ -6037,19 +6037,19 @@ static bool parser_compile(parser_t *parser) else if (compile_errors) parseerror(parser, "there have been errors, bailing out"); lex_close(parser->lex); - parser->lex = NULL; + parser->lex = nullptr; return false; } } } else { parseerror(parser, "parse error"); lex_close(parser->lex); - parser->lex = NULL; + parser->lex = nullptr; return false; } lex_close(parser->lex); - parser->lex = NULL; + parser->lex = nullptr; return !compile_errors; } @@ -6239,7 +6239,7 @@ bool parser_finish(parser_t *parser, const char *output) } } else { ast_delete(f->varargs); - f->varargs = NULL; + f->varargs = nullptr; } } } diff --git a/stat.cpp b/stat.cpp index 8943a2b..1797536 100644 --- a/stat.cpp +++ b/stat.cpp @@ -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); } diff --git a/test.cpp b/test.cpp index 5fe22dc..840e6b6 100644 --- a/test.cpp +++ b/test.cpp @@ -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 &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 &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 &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 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(); diff --git a/util.cpp b/util.cpp index 9c1ef6a..ead50dd 100644 --- a/util.cpp +++ b/util.cpp @@ -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; } -- 2.39.2