#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); \
{
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;
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;
}
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;
(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;
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;
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
{
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);
}
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);
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);
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);
if (name)
self->name = util_strdup(name);
else
- self->name = NULL;
+ self->name = nullptr;
return self;
}
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);
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;
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);
{
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);
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);
self->expression.vtype = TYPE_NOEXPR;
self->name = util_strdup(name);
- self->irblock = NULL;
+ self->irblock = nullptr;
self->undefined = undefined;
return self;
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;
}
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);
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;
}
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)
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*
*/
!OPTS_OPTION_BOOL(OPTION_DUMPFIN) &&
!OPTS_OPTION_BOOL(OPTION_DEBUG))
{
- return NULL;
+ return nullptr;
}
id = (self->labelcount++);
/*********************************************************************/
/* 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.
*/
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");
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");
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)
{
{
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;
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) {
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;
idx = (ast_value*)ai->index;
if (ast_istype(ai->index, ast_value) && idx->hasvalue && idx->cvq == CV_CONST)
- ai = NULL;
+ ai = nullptr;
}
if (ai) {
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;
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 */
ast_expression_codegen *cgen;
ir_value *operand;
- *out = NULL;
+ *out = nullptr;
/* In the context of a return operation, we don't actually return
* anything...
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;
}
*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)
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;
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 */
/* 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) {
/* 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)
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;
{
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;
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
return false;
bcontinue = bincrement; /* increment comes before the pre-loop-condition */
} else {
- bincrement = end_bincrement = NULL;
+ bincrement = end_bincrement = nullptr;
}
if (self->postcond) {
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);
{
ir_block *target;
- *out = NULL;
+ *out = nullptr;
if (lvalue) {
compile_error(ast_ctx(self), "break/continue expression is not an l-value");
{
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];
/* 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 */
return false;
}
- *out = NULL;
+ *out = nullptr;
if (lvalue) {
compile_error(ast_ctx(self), "internal error: ast_label cannot be an lvalue");
return false;
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;
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))
std::vector<ir_value*> params;
ir_instr *callinstr;
- ir_value *funval = NULL;
+ ir_value *funval = nullptr;
/* return values are never lvalues */
if (lvalue) {
/* 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.
*/
* 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.
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);
}
fclose(fp);
- fp = NULL;
+ fp = nullptr;
}
fp = fopen(filename, "wb");
/*
* 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
}
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, ...) {
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);
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));
mem_d(prog);
fclose(file);
- return NULL;
+ return nullptr;
}
void prog_delete(qc_program_t *prog)
}
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);
const char *value;
};
-static qcvm_parameter *main_params = NULL;
+static qcvm_parameter *main_params = nullptr;
#define CheckArgs(num) do { \
if (prog->argc != (num)) { \
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);
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;
}
}
static prog_builtin_t qc_builtins[] = {
- NULL,
+ nullptr,
&qc_print, /* 1 */
&qc_ftos, /* 2 */
&qc_spawn, /* 3 */
&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",
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];
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],
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())
{
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;
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);
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");
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)))
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;
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;
}
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) {
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) {
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) {
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) {
}
}
}
- return NULL;
+ return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_div(fold_t *fold, ast_value *a, ast_value *b) {
);
}
}
- 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) {
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) {
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) {
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) {
);
}
}
- return NULL;
+ return nullptr;
}
static GMQCC_INLINE ast_expression *fold_op_tern(fold_t *fold, ast_value *a, ast_value *b, ast_value *c) {
? (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) {
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) {
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) {
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) {
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) {
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) {
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;
}
}
}
#undef fold_op_case
compile_error(fold_ctx(fold), "internal error: attempted to constant-fold for unsupported operator");
- return NULL;
+ return nullptr;
}
/*
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];
/*#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))) {
}
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];
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];
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];
break;
}
- return NULL;
+ return nullptr;
}
ast_expression *fold_binary(lex_ctx_t ctx, int op, ast_expression *left, ast_expression *right) {
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
/* __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;
/* __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;
/* 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)
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");
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;
/* user defined ones take precedence */
if (macro && mathconstant) {
ftepp_macro_delete(ftepp, ftepp_tokval(ftepp));
- macro = NULL;
+ macro = nullptr;
}
}
/* 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;
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 != ',') {
}
}
vec_push(params, mp);
- mp.tokens = NULL;
+ mp.tokens = nullptr;
if (ftepp->token == ')')
break;
if (ftepp->token != ',') {
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);
}
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;
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) {
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);
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);
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;
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, '/');
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)
}
static bool ftepp_directive_warning(ftepp_t *ftepp) {
- char *message = NULL;
+ char *message = nullptr;
if (!ftepp_skipspace(ftepp))
return false;
}
static void ftepp_directive_error(ftepp_t *ftepp) {
- char *message = NULL;
+ char *message = nullptr;
if (!ftepp_skipspace(ftepp))
return;
}
static void ftepp_directive_message(ftepp_t *ftepp) {
- char *message = NULL;
+ char *message = nullptr;
if (!ftepp_skipspace(ftepp))
return;
lex_ctx_t ctx;
char lineno[128];
char *filename;
- char *parsename = NULL;
+ char *parsename = nullptr;
char *old_includename;
(void)ftepp_next(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;
bool newline = true;
/* predef stuff */
- char *expand = NULL;
+ char *expand = nullptr;
ftepp->lex->flags.preprocessing = true;
ftepp->lex->flags.mergelines = false;
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);
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;
}
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) {
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';
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';
/* 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)])
#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];
/*
* 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
*/
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;
}
* 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"));
* 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);
* 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));
* 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));
* 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);
* 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"));
* 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"));
* 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));
* 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);
(ast_expression*)fold_constgen_float(intrin->fold, 200.0f, false)
),
false,
- NULL,
+ nullptr,
false,
/* ++i; */
(ast_expression*)ast_binstore_new(
* 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));
* 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));
* 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 */
intrin_ctx(intrin),
(ast_expression*)intrin->fold->imm_float[1]
),
- NULL
+ nullptr
)
);
intrin_ctx(intrin),
(ast_expression*)base
),
- NULL
+ nullptr
)
);
(ast_expression*)callpow1
)
),
- NULL
+ nullptr
)
);
(ast_expression*)intrin->fold->imm_float[1]
),
(ast_expression*)expgt1,
- NULL
+ nullptr
)
);
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
/* init */
- NULL,
+ nullptr,
/* pre condition */
(ast_expression*)ast_binary_new(
intrin_ctx(intrin),
/* pre not */
false,
/* post condition */
- NULL,
+ nullptr,
/* post not */
false,
/* increment expression */
- NULL,
+ nullptr,
/* code block */
(ast_expression*)whileblock
)
* 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);
* 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);
* 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);
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),
(ast_expression*)intrin->fold->imm_float[1]
),
false,
- NULL,
+ nullptr,
(ast_expression*)ast_binstore_new(
intrin_ctx(intrin),
INSTR_STORE_F,
* 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));
* 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);
* }
*/
- 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);
intrin_func_self(intrin, "__builtin_nan", "ln")
)
),
- NULL
+ nullptr
)
);
(ast_expression*)intrin->fold->imm_float[1]
),
(ast_expression*)((i) ? blt1 : plt1),
- NULL
+ nullptr
)
);
}
whileloop->exprs.push_back(
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
- NULL,
+ nullptr,
(ast_expression*)ast_binary_new(
intrin_ctx(intrin),
INSTR_GE,
(ast_expression*)newbase2
),
false,
- NULL,
+ nullptr,
false,
- NULL,
+ nullptr,
(ast_expression*)nestwhile
)
);
forloop->exprs.push_back(
(ast_expression*)ast_loop_new(
intrin_ctx(intrin),
- NULL,
+ nullptr,
(ast_expression*)ast_binary_new(
intrin_ctx(intrin),
INSTR_GE,
(ast_expression*)base
),
false,
- NULL,
+ nullptr,
false,
- NULL,
+ nullptr,
(ast_expression*)whileloop
)
);
false,
0
),
- NULL
+ nullptr
)
);
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
)
);
}
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));
* 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);
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) {
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);
}
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;
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);
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();
{
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);
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;
{
ve = ir_builder_get_global(self, name);
if (ve) {
- return NULL;
+ return nullptr;
}
}
{
ir_value *ve = ir_builder_get_field(self, name);
if (ve) {
- return NULL;
+ return nullptr;
}
ve = ir_value_var(name, store_global, TYPE_FIELD);
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;
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;
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;
}
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)
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);
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;
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;
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);
}
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;
}
size_t len;
ir_value *m;
if (member >= 3)
- return NULL;
+ return nullptr;
if (self->members[member])
return self->members[member];
name[len+2] = '\0';
}
else
- name = NULL;
+ name = nullptr;
if (self->vtype == TYPE_VECTOR)
{
if (name)
mem_d(name);
if (!m)
- return NULL;
+ return nullptr;
m->context = self->context;
self->members[member] = m;
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;
else
{
irerror(self->context, "invalid member access on %s", self->name);
- return NULL;
+ return nullptr;
}
m->memberof = self;
{
ir_value *v = ir_value_var(name, storetype, vtype);
if (!v)
- return NULL;
+ return nullptr;
ir_function_collect_value(owner, v);
return v;
}
{
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 */
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;
{
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.
*/
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;
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;
}
}
*/
};
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);
* 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;
};
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,
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) ||
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)
/* 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;
{
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)
{
#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);
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)
{
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)) {
/* read operands */
if (read & (1<<o))
{
- if (!vec_ir_value_find(self->living, value, NULL))
+ if (!vec_ir_value_find(self->living, value, nullptr))
self->living.push_back(value);
/* reading adds the full vector */
- if (value->memberof && !vec_ir_value_find(self->living, value->memberof, NULL))
+ if (value->memberof && !vec_ir_value_find(self->living, value->memberof, nullptr))
self->living.push_back(value->memberof);
for (mem = 0; mem < 3; ++mem) {
- if (value->members[mem] && !vec_ir_value_find(self->living, value->members[mem], NULL))
+ if (value->members[mem] && !vec_ir_value_find(self->living, value->members[mem], nullptr))
self->living.push_back(value->members[mem]);
}
}
/* 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]);
}
}
/* 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]);
}
}
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;
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)
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())
{
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);
int (*oprintf)(const char*, ...))
{
size_t i;
- const char *comma = NULL;
+ const char *comma = nullptr;
oprintf("%s (%i) ", ind, (int)in->eid);
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));
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;
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)
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;
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;
}
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);
}
/* 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
bool argend = false;
size_t itr;
char buffer[1024];
- char *config = NULL;
+ char *config = nullptr;
while (!argend && argc > 1) {
char *argarg;
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;
}
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);
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 {
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 ();
if (!vec_size(items)) {
FILE *src;
- char *line = NULL;
+ char *line = nullptr;
size_t linelen = 0;
bool hasline = false;
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;
# 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];
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] = "";
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;
/*
* gmqcc.ini
* gmqcc.cfg
*/
- char *error = NULL;
- char *parse_file = NULL;
+ char *error = nullptr;
+ char *parse_file = nullptr;
size_t line;
FILE *ini;
{
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)
if ( (e = (ast_value*)util_htgeth(parser->typedefs[i], name, hash)) )
return e;
}
- return NULL;
+ return nullptr;
}
struct sy_elem {
e.etype = 0;
e.off = 0;
e.out = v;
- e.block = NULL;
+ e.block = nullptr;
e.ctx = ctx;
e.isparen = false;
return e;
sy_elem e;
e.etype = 1 + (op - operators);
e.off = 0;
- e.out = NULL;
- e.block = NULL;
+ e.out = nullptr;
+ e.block = nullptr;
e.ctx = ctx;
e.isparen = false;
return e;
sy_elem e;
e.etype = 0;
e.off = off;
- e.out = NULL;
- e.block = NULL;
+ e.out = nullptr;
+ e.block = nullptr;
e.ctx = ctx;
e.isparen = true;
return e;
entfield = ast_entfield_new(ctx, entity, (ast_expression*)index);
*out = (ast_expression*)entfield;
- oldindex->array = NULL;
- oldindex->index = NULL;
+ oldindex->array = nullptr;
+ oldindex->index = nullptr;
ast_delete(oldindex);
return true;
{
const oper_info *op;
lex_ctx_t ctx;
- ast_expression *out = NULL;
+ ast_expression *out = nullptr;
ast_expression *exprs[3];
ast_block *blocks[3];
ast_binstore *asbinstore;
exprs[1]->vtype == TYPE_NOEXPR)
{
if (exprs[1] == (ast_expression*)parser->const_vec[0])
- out = (ast_expression*)ast_member_new(ctx, exprs[0], 0, NULL);
+ out = (ast_expression*)ast_member_new(ctx, exprs[0], 0, nullptr);
else if (exprs[1] == (ast_expression*)parser->const_vec[1])
- out = (ast_expression*)ast_member_new(ctx, exprs[0], 1, NULL);
+ out = (ast_expression*)ast_member_new(ctx, exprs[0], 1, nullptr);
else if (exprs[1] == (ast_expression*)parser->const_vec[2])
- out = (ast_expression*)ast_member_new(ctx, exprs[0], 2, NULL);
+ out = (ast_expression*)ast_member_new(ctx, exprs[0], 2, nullptr);
else {
compile_error(ctx, "access to invalid vector component");
return false;
} 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);
if (!out) break;
out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_F, out);
if (!out) break;
- exprs[i] = out; out = NULL;
+ exprs[i] = out; out = nullptr;
if (OPTS_FLAG(PERL_LOGIC)) {
/* here we want to keep the right expressions' type */
break;
if (!out) break;
out = (ast_expression*)ast_unary_new(ctx, INSTR_NOT_F, out);
if (!out) break;
- exprs[i] = out; out = NULL;
+ exprs[i] = out; out = nullptr;
if (OPTS_FLAG(PERL_LOGIC)) {
/* here we want to keep the right expressions' type */
break;
{
/* was a function call */
ast_expression *fun;
- ast_value *funval = NULL;
+ ast_value *funval = nullptr;
ast_call *call;
size_t fid;
* 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);
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) {
if (!parser->function->varargs) {
parseerror(parser, "function has no variable argument list");
- return NULL;
+ return nullptr;
}
if (!parser_next(parser) || parser->tok != '(') {
parseerror(parser, "expected parameter index and type in parenthesis");
- return NULL;
+ return nullptr;
}
if (!parser_next(parser)) {
parseerror(parser, "error parsing parameter index");
- return NULL;
+ return nullptr;
}
idx = parse_expression_leave(parser, true, false, false);
if (!idx)
- return NULL;
+ return nullptr;
if (parser->tok != ',') {
if (parser->tok != ')') {
ast_unref(idx);
parseerror(parser, "expected comma after parameter index");
- return NULL;
+ return nullptr;
}
/* vararg piping: ...(start) */
out = (ast_expression*)ast_argpipe_new(ctx, idx);
if (!parser_next(parser) || (parser->tok != TOKEN_IDENT && parser->tok != TOKEN_TYPENAME)) {
ast_unref(idx);
parseerror(parser, "expected typename for vararg");
- return NULL;
+ return nullptr;
}
- typevar = parse_typename(parser, NULL, NULL, NULL);
+ typevar = parse_typename(parser, nullptr, nullptr, nullptr);
if (!typevar) {
ast_unref(idx);
- return NULL;
+ return nullptr;
}
if (parser->tok != ')') {
ast_unref(idx);
ast_delete(typevar);
parseerror(parser, "expected closing paren");
- return NULL;
+ return nullptr;
}
if (funtype->expression.varparam &&
else if (parser->tok == TOKEN_IDENT)
{
const char *ctoken = parser_tokval(parser);
- ast_expression *prev = sy->out.size() ? sy->out.back().out : NULL;
+ ast_expression *prev = sy->out.size() ? sy->out.back().out : nullptr;
ast_expression *var;
/* a_vector.{x,y,z} */
if (sy->ops.empty() ||
operators[sy->ops.back().etype-1].id != opid1('.'))
{
/* When adding more intrinsics, fix the above condition */
- prev = NULL;
+ prev = nullptr;
}
if (prev && prev->vtype == TYPE_VECTOR && ctoken[0] >= 'x' && ctoken[0] <= 'z' && !ctoken[1])
{
static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma, bool truthvalue, bool with_labels)
{
- ast_expression *expr = NULL;
+ ast_expression *expr = nullptr;
shunt sy;
bool wantop = false;
/* only warn once about an assignment in a truth value because the current code
{
/* classify the operator */
const oper_info *op;
- const oper_info *olast = NULL;
+ const oper_info *olast = nullptr;
size_t o;
for (o = 0; o < operator_count; ++o) {
if (((!(operators[o].flags & OP_PREFIX) == !!wantop)) &&
if (sy.ops.size() && !sy.ops.back().isparen)
olast = &operators[sy.ops.back().etype-1];
else
- olast = NULL;
+ olast = nullptr;
}
#define IsAssignOp(x) (\
if (sy.ops.size() && !sy.ops.back().isparen)
olast = &operators[sy.ops.back().etype-1];
else
- olast = NULL;
+ olast = nullptr;
}
if (op->id == opid1('(')) {
if (last->isimm == true && last->cvq == CV_CONST &&
last->hasvalue && last->expression.vtype == TYPE_STRING)
{
- char *newstr = NULL;
+ char *newstr = nullptr;
util_asprintf(&newstr, "%s%s", last->constval.vstring, parser_tokval(parser));
sy.out.back().out = (ast_expression*)fold_constgen_string(parser->fold, newstr, false);
mem_d(newstr);
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;
parser->lex->flags.noops = true;
for (auto &it : sy.out)
if (it.out) ast_unref(it.out);
- return NULL;
+ return nullptr;
}
static ast_expression* parse_expression(parser_t *parser, bool stopatcomma, bool with_labels)
{
ast_expression *e = parse_expression_leave(parser, stopatcomma, false, with_labels);
if (!e)
- return NULL;
+ return nullptr;
if (parser->tok != ';') {
parseerror(parser, "semicolon expected after expression");
ast_unref(e);
- return NULL;
+ return nullptr;
}
if (!parser_next(parser)) {
ast_unref(e);
- return NULL;
+ return nullptr;
}
return e;
}
if (!cond) {
ast_unref(prev);
parseerror(parser, "internal error: failed to process condition");
- return NULL;
+ return nullptr;
}
ifnot = !ifnot;
}
if (!cond) {
ast_unref(prev);
parseerror(parser, "internal error: failed to process condition");
- return NULL;
+ return nullptr;
}
ifnot = !ifnot;
}
while (cond && ast_istype(cond, ast_unary) && unary->op == INSTR_NOT_F)
{
cond = unary->operand;
- unary->operand = NULL;
+ unary->operand = nullptr;
ast_delete(unary);
ifnot = !ifnot;
unary = (ast_unary*)cond;
static bool parse_if(parser_t *parser, ast_block *block, ast_expression **out)
{
ast_ifthen *ifthen;
- ast_expression *cond, *ontrue = NULL, *onfalse = NULL;
+ ast_expression *cond, *ontrue = nullptr, *onfalse = nullptr;
bool ifnot = false;
lex_ctx_t ctx = parser_ctx(parser);
static bool parse_while(parser_t *parser, ast_block *block, ast_expression **out)
{
bool rv;
- char *label = NULL;
+ char *label = nullptr;
/* skip the 'while' and get the body */
if (!parser_next(parser)) {
parseerror(parser, "internal error: label stack corrupted");
rv = false;
ast_delete(*out);
- *out = NULL;
+ *out = nullptr;
}
else {
parser->breaks.pop_back();
ast_unref(ontrue);
return false;
}
- aloop = ast_loop_new(ctx, NULL, cond, ifnot, NULL, false, NULL, ontrue);
+ aloop = ast_loop_new(ctx, nullptr, cond, ifnot, nullptr, false, nullptr, ontrue);
*out = (ast_expression*)aloop;
return true;
}
static bool parse_dowhile(parser_t *parser, ast_block *block, ast_expression **out)
{
bool rv;
- char *label = NULL;
+ char *label = nullptr;
/* skip the 'do' and get the body */
if (!parser_next(parser)) {
parseerror(parser, "internal error: label stack corrupted");
rv = false;
/*
- * Test for NULL otherwise ast_delete dereferences null pointer
+ * Test for nullptr otherwise ast_delete dereferences null pointer
* and boom.
*/
if (*out)
ast_delete(*out);
- *out = NULL;
+ *out = nullptr;
}
else {
parser->breaks.pop_back();
ast_delete(ontrue);
return false;
}
- aloop = ast_loop_new(ctx, NULL, NULL, false, cond, ifnot, NULL, ontrue);
+ aloop = ast_loop_new(ctx, nullptr, nullptr, false, cond, ifnot, nullptr, ontrue);
*out = (ast_expression*)aloop;
return true;
}
static bool parse_for(parser_t *parser, ast_block *block, ast_expression **out)
{
bool rv;
- char *label = NULL;
+ char *label = nullptr;
/* skip the 'for' and check for opening paren */
if (!parser_next(parser)) {
parseerror(parser, "internal error: label stack corrupted");
rv = false;
ast_delete(*out);
- *out = NULL;
+ *out = nullptr;
}
else {
parser->breaks.pop_back();
parser_enterblock(parser);
- initexpr = NULL;
- cond = NULL;
- increment = NULL;
- ontrue = NULL;
+ initexpr = nullptr;
+ cond = nullptr;
+ increment = nullptr;
+ ontrue = nullptr;
/* parse into the expression */
if (!parser_next(parser)) {
goto onerr;
}
- typevar = NULL;
+ typevar = nullptr;
if (parser->tok == TOKEN_IDENT)
typevar = parser_find_typedef(parser, parser_tokval(parser), 0);
if (typevar || parser->tok == TOKEN_TYPENAME) {
- if (!parse_variable(parser, block, true, CV_VAR, typevar, false, false, 0, NULL))
+ if (!parse_variable(parser, block, true, CV_VAR, typevar, false, false, 0, nullptr))
goto onerr;
}
else if (parser->tok != ';')
if (!cond)
goto onerr;
}
- aloop = ast_loop_new(ctx, initexpr, cond, ifnot, NULL, false, increment, ontrue);
+ aloop = ast_loop_new(ctx, initexpr, cond, ifnot, nullptr, false, increment, ontrue);
*out = (ast_expression*)aloop;
if (!parser_leaveblock(parser)) {
static bool parse_return(parser_t *parser, ast_block *block, ast_expression **out)
{
- ast_expression *exp = NULL;
- ast_expression *var = NULL;
- ast_return *ret = NULL;
+ ast_expression *exp = nullptr;
+ ast_expression *var = nullptr;
+ ast_return *ret = nullptr;
ast_value *retval = parser->function->return_value;
ast_value *expected = parser->function->vtype;
}
else if (!strcmp(parser_tokval(parser), "alias") && !(flags & AST_FLAG_ALIAS)) {
flags |= AST_FLAG_ALIAS;
- *message = NULL;
+ *message = nullptr;
if (!parser_next(parser)) {
parseerror(parser, "parse error in attribute");
}
else if (!strcmp(parser_tokval(parser), "deprecated") && !(flags & AST_FLAG_DEPRECATED)) {
flags |= AST_FLAG_DEPRECATED;
- *message = NULL;
+ *message = nullptr;
if (!parser_next(parser)) {
parseerror(parser, "parse error in attribute");
argerr: /* ugly */
if (*message) mem_d(*message);
- *message = NULL;
+ *message = nullptr;
*cvq = CV_WRONG;
return false;
}
static bool parse_switch(parser_t *parser, ast_block *block, ast_expression **out)
{
bool rv;
- char *label = NULL;
+ char *label = nullptr;
/* skip the 'while' and get the body */
if (!parser_next(parser)) {
parseerror(parser, "internal error: label stack corrupted");
rv = false;
ast_delete(*out);
- *out = NULL;
+ *out = nullptr;
}
else {
parser->breaks.pop_back();
/* new block; allow some variables to be declared here */
parser_enterblock(parser);
while (true) {
- typevar = NULL;
+ typevar = nullptr;
if (parser->tok == TOKEN_IDENT)
typevar = parser_find_typedef(parser, parser_tokval(parser), 0);
if (typevar || parser->tok == TOKEN_TYPENAME) {
- if (!parse_variable(parser, block, true, CV_NONE, typevar, false, false, 0, NULL)) {
+ if (!parse_variable(parser, block, true, CV_NONE, typevar, false, false, 0, nullptr)) {
ast_delete(switchnode);
return false;
}
continue;
}
- if (parse_qualifiers(parser, true, &cvq, &noref, &is_static, &qflags, NULL))
+ if (parse_qualifiers(parser, true, &cvq, &noref, &is_static, &qflags, nullptr))
{
if (cvq == CV_WRONG) {
ast_delete(switchnode);
return false;
}
- if (!parse_variable(parser, block, true, cvq, NULL, noref, is_static, qflags, NULL)) {
+ if (!parse_variable(parser, block, true, cvq, nullptr, noref, is_static, qflags, nullptr)) {
ast_delete(switchnode);
return false;
}
}
}
else if (!strcmp(parser_tokval(parser), "default")) {
- swcase.value = NULL;
+ swcase.value = nullptr;
if (!parser_next(parser)) {
ast_delete(switchnode);
parseerror(parser, "expected colon");
ast_expression *cond;
if (!*side)
- return NULL;
+ return nullptr;
if (ast_istype(*side, ast_ternary)) {
ast_ternary *tern = (ast_ternary*)*side;
parseerror(parser, "expected label or expression in ternary");
if (on_true) ast_unref(on_true);
if (on_false) ast_unref(on_false);
- return NULL;
+ return nullptr;
}
cond = tern->cond;
- tern->cond = NULL;
+ tern->cond = nullptr;
ast_delete(tern);
- *side = NULL;
+ *side = nullptr;
return (ast_expression*)ast_ifthen_new(parser_ctx(parser), cond, on_true, on_false);
} else if (ast_istype(*side, ast_label)) {
ast_goto *gt = ast_goto_new(parser_ctx(parser), ((ast_label*)*side)->name);
ast_goto_set_label(gt, ((ast_label*)*side));
- *side = NULL;
+ *side = nullptr;
return (ast_expression*)gt;
}
- return NULL;
+ return nullptr;
}
static bool parse_goto(parser_t *parser, ast_expression **out)
{
- ast_goto *gt = NULL;
+ ast_goto *gt = nullptr;
ast_expression *lbl;
if (!parser_next(parser))
bool noref, is_static;
int cvq = CV_NONE;
uint32_t qflags = 0;
- ast_value *typevar = NULL;
- char *vstring = NULL;
+ ast_value *typevar = nullptr;
+ char *vstring = nullptr;
- *out = NULL;
+ *out = nullptr;
if (parser->tok == TOKEN_IDENT)
typevar = parser_find_typedef(parser, parser_tokval(parser), 0);
if (parsewarning(parser, WARN_EXTENSIONS, "missing 'local' keyword when declaring a local variable"))
return false;
}
- if (!parse_variable(parser, block, false, CV_NONE, typevar, false, false, 0, NULL))
+ if (!parse_variable(parser, block, false, CV_NONE, typevar, false, false, 0, nullptr))
return false;
return true;
}
{
if (cvq == CV_WRONG)
return false;
- return parse_variable(parser, block, false, cvq, NULL, noref, is_static, qflags, vstring);
+ return parse_variable(parser, block, false, cvq, nullptr, noref, is_static, qflags, vstring);
}
else if (parser->tok == TOKEN_KEYWORD)
{
bool flag = false;
bool reverse = false;
qcfloat_t num = 0;
- ast_value **values = NULL;
- ast_value *var = NULL;
+ ast_value **values = nullptr;
+ ast_value *var = nullptr;
ast_value *asvalue;
ast_expression *old;
while (parser->tok != TOKEN_EOF && parser->tok < TOKEN_ERROR)
{
- ast_expression *expr = NULL;
+ ast_expression *expr = nullptr;
if (parser->tok == '}')
break;
if (!parse_statement(parser, block, &expr, false)) {
/* parseerror(parser, "parse error"); */
- block = NULL;
+ block = nullptr;
goto cleanup;
}
if (!expr)
continue;
if (!ast_block_add_expr(block, expr)) {
ast_delete(block);
- block = NULL;
+ block = nullptr;
goto cleanup;
}
}
if (parser->tok != '}') {
- block = NULL;
+ block = nullptr;
} else {
(void)parser_next(parser);
}
ast_block *block;
block = ast_block_new(parser_ctx(parser));
if (!block)
- return NULL;
+ return nullptr;
if (!parse_block_into(parser, block)) {
ast_block_delete(block);
- return NULL;
+ return nullptr;
}
return block;
}
*out = (ast_expression*)parse_block(parser);
return !!*out;
}
- return parse_statement(parser, NULL, out, false);
+ return parse_statement(parser, nullptr, out, false);
}
static bool create_vector_members(ast_value *var, ast_member **me)
static bool parse_function_body(parser_t *parser, ast_value *var)
{
- ast_block *block = NULL;
+ ast_block *block = nullptr;
ast_function *func;
ast_function *old;
- ast_expression *framenum = NULL;
- ast_expression *nextthink = NULL;
+ ast_expression *framenum = nullptr;
+ ast_expression *nextthink = nullptr;
/* None of the following have to be deleted */
- ast_expression *fld_think = NULL, *fld_nextthink = NULL, *fld_frame = NULL;
- ast_expression *gbl_time = NULL, *gbl_self = NULL;
+ ast_expression *fld_think = nullptr, *fld_nextthink = nullptr, *fld_frame = nullptr;
+ ast_expression *gbl_time = nullptr, *gbl_self = nullptr;
bool has_frame_think;
bool retval = true;
* self.nextthink = time + 0.1;
* self.think = nextthink;
*/
- nextthink = NULL;
+ nextthink = nullptr;
fld_think = parser_find_field(parser, "think");
fld_nextthink = parser_find_field(parser, "nextthink");
func = var->constval.vfunc;
if (!func) {
- parseerror(parser, "internal error: NULL function: `%s`", var->name);
+ parseerror(parser, "internal error: nullptr function: `%s`", var->name);
ast_block_delete(block);
goto enderr;
}
char name[1024];
ast_value *varargs = ast_value_new(ast_ctx(var), "reserved:va_args", TYPE_ARRAY);
varargs->expression.flags |= AST_FLAG_IS_VARARG;
- varargs->expression.next = (ast_expression*)ast_value_new(ast_ctx(var), NULL, TYPE_VECTOR);
+ varargs->expression.next = (ast_expression*)ast_value_new(ast_ctx(var), nullptr, TYPE_VECTOR);
varargs->expression.count = 0;
util_snprintf(name, sizeof(name), "%s##va##SET", var->name);
if (!parser_create_array_setter_proto(parser, varargs, name)) {
(void)!parser_leaveblock(parser);
parser->functions.pop_back();
ast_function_delete(func);
- var->constval.vfunc = NULL;
+ var->constval.vfunc = nullptr;
enderr:
parser->function = old;
if (!left || !right) {
if (left) ast_delete(left);
if (right) ast_delete(right);
- return NULL;
+ return nullptr;
}
cmp = ast_binary_new(ctx, INSTR_LT,
ast_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;
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;
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;
(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;
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;
static bool parser_create_array_accessor(parser_t *parser, ast_value *array, const char *funcname, ast_value **out)
{
- ast_function *func = NULL;
- ast_value *fval = NULL;
- ast_block *body = NULL;
+ ast_function *func = nullptr;
+ ast_value *fval = nullptr;
+ ast_block *body = nullptr;
fval = ast_value_new(ast_ctx(array), funcname, TYPE_FUNCTION);
if (!fval) {
static ast_value* parser_create_array_setter_proto(parser_t *parser, ast_value *array, const char *funcname)
{
- ast_value *index = NULL;
- ast_value *value = NULL;
+ ast_value *index = nullptr;
+ ast_value *value = nullptr;
ast_function *func;
ast_value *fval;
if (!ast_istype(array->expression.next, ast_value)) {
parseerror(parser, "internal error: array accessor needs to build an ast_value with a copy of the element type");
- return NULL;
+ return nullptr;
}
if (!parser_create_array_accessor(parser, array, funcname, &fval))
- return NULL;
+ return nullptr;
func = fval->constval.vfunc;
fval->expression.next = (ast_expression*)ast_value_new(ast_ctx(array), "<void>", TYPE_VOID);
if (value) ast_delete(value);
ast_delete(func);
ast_delete(fval);
- return NULL;
+ return nullptr;
}
static bool parser_create_array_setter_impl(parser_t *parser, ast_value *array)
{
- ast_expression *root = NULL;
+ ast_expression *root = nullptr;
root = array_setter_node(parser, array,
array->setter->expression.params[0],
array->setter->expression.params[1],
static bool parser_create_array_field_setter(parser_t *parser, ast_value *array, const char *funcname)
{
- ast_expression *root = NULL;
- ast_value *entity = NULL;
- ast_value *index = NULL;
- ast_value *value = NULL;
+ ast_expression *root = nullptr;
+ ast_value *entity = nullptr;
+ ast_value *index = nullptr;
+ ast_value *value = nullptr;
ast_function *func;
ast_value *fval;
static ast_value* parser_create_array_getter_proto(parser_t *parser, ast_value *array, const ast_expression *elemtype, const char *funcname)
{
- ast_value *index = NULL;
+ ast_value *index = nullptr;
ast_value *fval;
ast_function *func;
*/
if (!ast_istype(array->expression.next, ast_value)) {
parseerror(parser, "internal error: array accessor needs to build an ast_value with a copy of the element type");
- return NULL;
+ return nullptr;
}
if (!parser_create_array_accessor(parser, array, funcname, &fval))
- return NULL;
+ return nullptr;
func = fval->constval.vfunc;
fval->expression.next = ast_type_copy(ast_ctx(array), elemtype);
if (index) ast_delete(index);
ast_delete(func);
ast_delete(fval);
- return NULL;
+ return nullptr;
}
static bool parser_create_array_getter_impl(parser_t *parser, ast_value *array)
{
- ast_expression *root = NULL;
+ ast_expression *root = nullptr;
root = array_getter_node(parser, array, array->getter->expression.params[0], 0, array->expression.count);
if (!root) {
ast_value *fval;
bool first = true;
bool variadic = false;
- ast_value *varparam = NULL;
- char *argcounter = NULL;
+ ast_value *varparam = nullptr;
+ char *argcounter = nullptr;
/* for the sake of less code we parse-in in this function */
if (!parser_next(parser)) {
ast_delete(var);
parseerror(parser, "expected parameter list");
- return NULL;
+ return nullptr;
}
/* parse variables until we hit a closing paren */
}
first = false;
- ast_value *param = parse_typename(parser, NULL, NULL, &is_varargs);
+ ast_value *param = parse_typename(parser, nullptr, nullptr, &is_varargs);
if (!param && !is_varargs)
goto on_error;
if (is_varargs) {
ast_delete(var);
for (auto &it : params)
ast_delete(it);
- return NULL;
+ return nullptr;
}
static ast_value *parse_arraysize(parser_t *parser, ast_value *var)
if (!parser_next(parser)) {
ast_delete(var);
parseerror(parser, "expected array-size");
- return NULL;
+ return nullptr;
}
if (parser->tok != ']') {
ast_unref(cexp);
ast_delete(var);
parseerror(parser, "expected array-size as constant positive integer");
- return NULL;
+ return nullptr;
}
cval = (ast_value*)cexp;
}
else {
- cexp = NULL;
- cval = NULL;
+ cexp = nullptr;
+ cval = nullptr;
}
tmp = ast_value_new(ctx, "<type[]>", TYPE_ARRAY);
ast_unref(cexp);
ast_delete(var);
parseerror(parser, "array-size must be a positive integer constant");
- return NULL;
+ return nullptr;
}
ast_unref(cexp);
if (parser->tok != ']') {
ast_delete(var);
parseerror(parser, "expected ']' after array-size");
- return NULL;
+ return nullptr;
}
if (!parser_next(parser)) {
ast_delete(var);
parseerror(parser, "error after parsing array size");
- return NULL;
+ return nullptr;
}
return var;
}
/* Parse a complete typename.
- * for single-variables (ie. function parameters or typedefs) storebase should be NULL
+ * for single-variables (ie. function parameters or typedefs) storebase should be nullptr
* but when parsing variables separated by comma
* 'storebase' should point to where the base-type should be kept.
* The base type makes up every bit of type information which comes *before* the
* variable name.
*
- * NOTE: The value must either be named, have a NULL name, or a name starting
+ * NOTE: The value must either be named, have a nullptr name, or a name starting
* with '<'. In the first case, this will be the actual variable or type
* name, in the other cases it is assumed that the name will appear
* later, and an error is generated otherwise.
ast_value *var, *tmp;
lex_ctx_t ctx;
- const char *name = NULL;
+ const char *name = nullptr;
bool isfield = false;
bool wasarray = false;
size_t morefields = 0;
/* if we parsed a dot we need a typename now */
if (!parser_next(parser)) {
parseerror(parser, "expected typename for field definition");
- return NULL;
+ return nullptr;
}
/* Further dots are handled seperately because they won't be part of the
vararg = false;
if (!parser_next(parser)) {
parseerror(parser, "expected typename for field definition");
- return NULL;
+ return nullptr;
}
}
}
if (!cached_typedef && parser->tok != TOKEN_TYPENAME) {
if (vararg && is_vararg) {
*is_vararg = true;
- return NULL;
+ return nullptr;
}
parseerror(parser, "expected typename");
- return NULL;
+ return nullptr;
}
/* generate the basic type value */
if (!parser_next(parser)) {
ast_delete(var);
parseerror(parser, "parse error after typename");
- return NULL;
+ return nullptr;
}
/* an opening paren now starts the parameter-list of a function
if (parser->tok == '(') {
var = parse_parameter_list(parser, var);
if (!var)
- return NULL;
+ return nullptr;
}
/* store the base if requested */
ast_delete(var);
mem_d(name);
parseerror(parser, "error after variable or field declaration");
- return NULL;
+ return nullptr;
}
}
var = parse_arraysize(parser, var);
if (!var) {
if (name) mem_d(name);
- return NULL;
+ return nullptr;
}
}
var = parse_parameter_list(parser, var);
if (!var) {
if (name) mem_d(name);
- return NULL;
+ return nullptr;
}
}
ast_delete(var);
mem_d(name);
parseerror(parser, "internal error: failed to set name");
- return NULL;
+ return nullptr;
}
/* free the name, ast_value_set_name duplicates */
mem_d(name);
ast_value *typevar, *oldtype;
ast_expression *old;
- typevar = parse_typename(parser, NULL, NULL, NULL);
+ typevar = parse_typename(parser, nullptr, nullptr, nullptr);
if (!typevar)
return false;
bool was_end;
size_t i;
- ast_value *basetype = NULL;
+ ast_value *basetype = nullptr;
bool retval = true;
bool isparam = false;
bool isvector = false;
bool cleanvar = true;
bool wasarray = false;
- ast_member *me[3] = { NULL, NULL, NULL };
- ast_member *last_me[3] = { NULL, NULL, NULL };
+ ast_member *me[3] = { nullptr, nullptr, nullptr };
+ ast_member *last_me[3] = { nullptr, nullptr, nullptr };
if (!localblock && is_static)
parseerror(parser, "`static` qualifier is not supported in global scope");
/* get the first complete variable */
- var = parse_typename(parser, &basetype, cached_typedef, NULL);
+ var = parse_typename(parser, &basetype, cached_typedef, nullptr);
if (!var) {
if (basetype)
ast_delete(basetype);
}
while (true) {
- proto = NULL;
+ proto = nullptr;
wasarray = false;
/* Part 0: finish the type */
goto cleanup;
}
ast_delete(var);
- var = NULL;
+ var = nullptr;
goto skipvar;
/*
parseerror(parser, "field `%s` already declared here: %s:%i",
retval = false;
if (proto->desc)
mem_d(proto->desc);
- proto = NULL;
+ proto = nullptr;
goto cleanup;
}
proto->expression.flags |= var->expression.flags;
if (!ast_istype(old, ast_value)) {
parseerror(parser, "internal error: not an ast_value");
retval = false;
- proto = NULL;
+ proto = nullptr;
goto cleanup;
}
if (!parser_check_qualifiers(parser, var, proto)) {
retval = false;
- proto = NULL;
+ proto = nullptr;
goto cleanup;
}
proto->expression.flags |= var->expression.flags;
if (ast_istype(old, ast_value))
var = proto = (ast_value*)old;
else {
- var = NULL;
+ var = nullptr;
goto skipvar;
}
}
/* a static adds itself to be generated like any other global
* but is added to the local namespace instead
*/
- char *defname = NULL;
+ char *defname = nullptr;
size_t prefix_len, ln;
size_t sn, sn_size;
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);
}
}
memcpy(last_me, me, sizeof(me));
- me[0] = me[1] = me[2] = NULL;
+ me[0] = me[1] = me[2] = nullptr;
cleanvar = false;
/* Part 2.2
* deal with arrays
}
if (parser->tok == '#') {
- ast_function *func = NULL;
- ast_value *number = NULL;
+ ast_function *func = nullptr;
+ ast_value *number = nullptr;
float fractional;
float integral;
int builtin_num;
parseerror(parser, "expected comma or semicolon");
if (func)
ast_function_delete(func);
- var->constval.vfunc = NULL;
+ var->constval.vfunc = nullptr;
break;
}
}
cexp = parse_expression_leave(parser, true, false, false);
if (!cexp)
break;
- cval = ast_istype(cexp, ast_value) ? (ast_value*)cexp : NULL;
+ cval = ast_istype(cexp, ast_value) ? (ast_value*)cexp : nullptr;
/* deal with foldable constants: */
if (localblock &&
bool noref = false;
bool is_static = false;
uint32_t qflags = 0;
- ast_value *istype = NULL;
- char *vstring = NULL;
+ ast_value *istype = nullptr;
+ char *vstring = nullptr;
if (parser->tok == TOKEN_IDENT)
istype = parser_find_typedef(parser, parser_tokval(parser), 0);
if (istype || parser->tok == TOKEN_TYPENAME || parser->tok == '.' || parser->tok == TOKEN_DOTS)
{
- return parse_variable(parser, NULL, false, CV_NONE, istype, false, false, 0, NULL);
+ return parse_variable(parser, nullptr, false, CV_NONE, istype, false, false, 0, nullptr);
}
else if (parse_qualifiers(parser, false, &cvq, &noref, &is_static, &qflags, &vstring))
{
if (cvq == CV_WRONG)
return false;
- return parse_variable(parser, NULL, false, cvq, NULL, noref, is_static, qflags, vstring);
+ return parse_variable(parser, nullptr, false, cvq, nullptr, noref, is_static, qflags, vstring);
}
else if (parser->tok == TOKEN_IDENT && !strcmp(parser_tokval(parser), "enum"))
{
parser = (parser_t*)mem_a(sizeof(parser_t));
if (!parser)
- return NULL;
+ return nullptr;
memset(parser, 0, sizeof(*parser));
if (!parser->assign_op) {
con_err("internal error: initializing parser: failed to find assign operator\n");
mem_d(parser);
- return NULL;
+ return nullptr;
}
vec_push(parser->variables, parser->htfields = util_htnew(PARSER_HT_SIZE));
parser->reserved_version->expression.flags |= AST_FLAG_INCLUDE_DEF;
parser->reserved_version->constval.vstring = util_strdup(GMQCC_FULL_VERSION_STRING);
} else {
- parser->reserved_version = NULL;
+ parser->reserved_version = nullptr;
}
parser->fold = fold_init (parser);
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;
}
}
} else {
ast_delete(f->varargs);
- f->varargs = NULL;
+ f->varargs = nullptr;
}
}
}
*/
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))) {
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;
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;
}
* 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;
}
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];
pair = pair->next;
if (!pair || !pair->key || strcmp(key, pair->key) != 0)
- return NULL;
+ return nullptr;
return pair->value;
}
if (cmp == 0)
return pair->value;
if (cmp < 0)
- return NULL;
+ return nullptr;
pair = pair->next;
continue;
}
}
pair = pair->next;
}
- return NULL;
+ return nullptr;
}
/*
}
void util_htdel(hash_table_t *ht) {
- util_htrem(ht, NULL);
+ util_htrem(ht, nullptr);
}
task_popen_error_1: close(inhandle [0]), close(inhandle [1]);
task_popen_error_0:
- return NULL;
+ return nullptr;
}
static int task_pclose(FILE **handles) {
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;
}
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;
/* update line and free old sata */
line++;
mem_d(back);
- back = NULL;
+ back = nullptr;
}
if (back)
mem_d(back);
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);
fclose(tempfile);
mem_d(tmpl);
- return NULL;
+ return nullptr;
}
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);
directories.push_back(claim);
} else {
mem_d(claim);
- claim = NULL;
+ claim = nullptr;
}
}
closedir(dir);
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 ++;
* 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);
/*
* and handle accordingly.
*/
{
- char *data = NULL;
+ char *data = nullptr;
size_t size = 0;
size_t compare = 0;
line.push_back(data);
/* reset */
- data = NULL;
+ data = nullptr;
size = 0;
}
success = false;
mem_d(data);
- data = NULL;
+ data = nullptr;
}
if (process)
static size_t task_schedualize(size_t *pad) {
char space[2][64];
bool execute = false;
- char *data = NULL;
+ char *data = nullptr;
std::vector<char *> match;
size_t size = 0;
size_t i = 0;
int main(int argc, char **argv) {
bool succeed = false;
- char *defs = NULL;
+ char *defs = nullptr;
con_init();
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;
tmp = (char*)mem_a(len + 1);
if ((ret = vsnprintf(tmp, len + 1, fmt, args)) != len) {
mem_d(tmp);
- *dat = NULL;
+ *dat = nullptr;
return -1;
}