* on all the globals.
*/
if (!self->ir_v) {
- char typename[1024];
- ast_type_to_string((ast_expression*)self, typename, sizeof(typename));
- compile_error(ast_ctx(self), "ast_value used before generated %s %s", typename, self->name);
+ char tname[1024]; /* typename is reserved in C++ */
+ ast_type_to_string((ast_expression*)self, tname, sizeof(tname));
+ compile_error(ast_ctx(self), "ast_value used before generated %s %s", tname, self->name);
return false;
}
*out = self->ir_v;
char* prog_getstring(qc_program *prog, qcint str)
{
+ /* cast for return required for C++ */
if (str < 0 || str >= (qcint)vec_size(prog->strings))
- return "<<<invalid string>>>";
+ return (char*)"<<<invalid string>>>";
return prog->strings + str;
}
return filename;
}
-static void ftepp_directive_warning(ftepp_t *ftepp) {
+static bool ftepp_directive_warning(ftepp_t *ftepp) {
char *message = NULL;
if (!ftepp_skipspace(ftepp))
- return;
+ return false;
/* handle the odd non string constant case so it works like C */
if (ftepp->token != TOKEN_STRINGCONST) {
+ bool store = false;
vec_upload(message, "#warning", 8);
ftepp_next(ftepp);
while (ftepp->token != TOKEN_EOL) {
ftepp_next(ftepp);
}
vec_push(message, '\0');
- (void)!!ftepp_warn(ftepp, WARN_CPP, message);
+ store = ftepp_warn(ftepp, WARN_CPP, message);
vec_free(message);
- return;
+ return store;
}
unescape (ftepp_tokval(ftepp), ftepp_tokval(ftepp));
- (void)!!ftepp_warn(ftepp, WARN_CPP, "#warning %s", ftepp_tokval(ftepp));
+ return ftepp_warn(ftepp, WARN_CPP, "#warning %s", ftepp_tokval(ftepp));
}
static void ftepp_directive_error(ftepp_t *ftepp) {
uint16_t util_crc16(uint16_t crc, const char *data, size_t len);
-/*
- * If we're compiling as C++ code we need to fix some subtle issues regarding casts between mem_a/mem_d
- * since C++ doesn't allow implicit conversions between void*
- */
-#ifdef __cplusplus
- /*
- * void * will be implicitally converted to gmqcc_voidptr using gmqcc_voidptr(void*). This is what
- * essentially allows us to allow implicit conversion to whatever pointer type we're trying to assign
- * to because it acks as a default assignment constructor.
- */
- class gmqcc_voidptr {
- void *m_pointer;
- public:
- gmqcc_voidptr(void *pointer) :
- m_pointer(pointer)
- { };
-
- template <typename T>
- GMQCC_INLINE operator T *() {
- return m_pointer;
- }
- };
-
-# define GMQCC_IMPLICIT_POINTER(X) (gmqcc_voidptr(X))
-#else
-# define GMQCC_IMPLICIT_POINTER(X) (X)
-#endif
-
#ifdef NOTRACK
-# define mem_a(x) GMQCC_IMPLICIT_POINTER(malloc (x))
+# define mem_a(x) malloc (x)
# define mem_d(x) free ((void*)x)
# define mem_r(x, n) realloc((void*)x, n)
#else
-# define mem_a(x) GMQCC_IMPLICIT_POINTER(util_memory_a((x), __LINE__, __FILE__))
+# define mem_a(x) util_memory_a((x), __LINE__, __FILE__)
# define mem_d(x) util_memory_d((void*)(x), __LINE__, __FILE__)
# define mem_r(x, n) util_memory_r((void*)(x), (n), __LINE__, __FILE__)
#endif
*/
hash_table_t *util_htnew (size_t size);
void util_htset (hash_table_t *ht, const char *key, void *value);
-void *util_htget (hash_table_t *ht, const char *key);
void util_htdel (hash_table_t *ht);
size_t util_hthash(hash_table_t *ht, const char *key);
-void *util_htgeth(hash_table_t *ht, const char *key, size_t hash);
void util_htseth(hash_table_t *ht, const char *key, size_t hash, void *value);
+void *util_htget (hash_table_t *ht, const char *key);
+void *util_htgeth(hash_table_t *ht, const char *key, size_t hash);
/*===================================================================*/
/*============================ file.c ===============================*/
/*===================================================================*/
{
if (str && !*str) {
/* actually dup empty strings */
- char *out = mem_a(1);
+ char *out = (char*)mem_a(1);
*out = 0;
return out;
}
ir_value *out;
ir_instr *in;
if (!ir_check_unreachable(self))
- return false;
+ return NULL;
in = ir_instr_new(ctx, self, VINSTR_PHI);
if (!in)
return NULL;
ir_value *out;
ir_instr *in;
if (!ir_check_unreachable(self))
- return false;
+ return NULL;
in = ir_instr_new(ctx, self, (noreturn ? VINSTR_NRCALL : INSTR_CALL0));
if (!in)
return NULL;
exit(1);
}
operators_free = true;
- newops = mem_a(sizeof(operators[0]) * operator_count);
+ newops = (oper_info*)mem_a(sizeof(operators[0]) * operator_count);
memcpy(newops, operators, sizeof(operators[0]) * operator_count);
memcpy(&newops[operator_count-2], &operators[operator_count-1], sizeof(newops[0]));
memcpy(&newops[operator_count-1], &operators[operator_count-2], sizeof(newops[0]));
opts_setdefault();
opts.output = output;
- opts.standard = standard;
+ opts.standard = (opts_std_t)standard; /* C++ ... y u no like me? */
opts.max_array_size = arraysize;
}
#define PARSER_HT_SIZE 1024
#define TYPEDEF_HT_SIZE 16
+enum parser_pot { POT_PAREN, POT_TERNARY1, POT_TERNARY2 };
typedef struct {
lex_file *lex;
int tok;
* If we reach a 'comma' operator in a ternary without a paren,
* we shall trigger -Wternary-precedence.
*/
- enum { POT_PAREN, POT_TERNARY1, POT_TERNARY2 } *pot;
+ enum parser_pot *pot;
/* pragma flags */
bool noref;
{
if (str && !*str) {
/* actually dup empty strings */
- char *out = mem_a(1);
+ char *out = (char*)mem_a(1);
*out = 0;
return out;
}
static ast_expression* parser_find_field(parser_t *parser, const char *name)
{
- return util_htget(parser->htfields, name);
+ return ( ast_expression*)util_htget(parser->htfields, name);
}
static ast_expression* parser_find_global(parser_t *parser, const char *name)
{
- return util_htget(parser->htglobals, name);
+ return (ast_expression*)util_htget(parser->htglobals, name);
}
static ast_expression* parser_find_param(parser_t *parser, const char *name)
*isparam = false;
for (i = vec_size(parser->variables); i > upto;) {
--i;
- if ( (e = util_htgeth(parser->variables[i], name, hash)) )
+ if ( (e = (ast_expression*)util_htgeth(parser->variables[i], name, hash)) )
return e;
}
*isparam = true;
val = parser_const_string(parser, parser_tokval(parser), true);
wantop = true;
if (!val)
- return false;
+ return NULL;
vec_push(sy.out, syexp(parser_ctx(parser), (ast_expression*)val));
DEBUGSHUNTDO(con_out("push string\n"));
wantop = true;
val = parser_const_float(parser, (parser_token(parser)->constval.f));
if (!val)
- return false;
+ return NULL;
vec_push(sy.out, syexp(parser_ctx(parser), (ast_expression*)val));
DEBUGSHUNTDO(con_out("push %g\n", parser_token(parser)->constval.f));
}
wantop = true;
val = parser_const_float(parser, (double)(parser_token(parser)->constval.i));
if (!val)
- return false;
+ return NULL;
vec_push(sy.out, syexp(parser_ctx(parser), (ast_expression*)val));
DEBUGSHUNTDO(con_out("push %i\n", parser_token(parser)->constval.i));
}
wantop = true;
val = parser_const_string(parser, parser_tokval(parser), false);
if (!val)
- return false;
+ return NULL;
vec_push(sy.out, syexp(parser_ctx(parser), (ast_expression*)val));
DEBUGSHUNTDO(con_out("push string\n"));
}
wantop = true;
val = parser_const_vector(parser, parser_token(parser)->constval.v);
if (!val)
- return false;
+ return NULL;
vec_push(sy.out, syexp(parser_ctx(parser), (ast_expression*)val));
DEBUGSHUNTDO(con_out("push '%g %g %g'\n",
parser_token(parser)->constval.v.x,
size_t len = strlen(var->name);
for (i = 0; i < 3; ++i) {
- char *name = mem_a(len+3);
+ char *name = (char*)mem_a(len+3);
memcpy(name, var->name, len);
name[len+0] = '_';
name[len+1] = 'x'+i;
goto on_error;
vec_push(params, param);
if (param->expression.vtype >= TYPE_VARIANT) {
- char typename[1024];
- ast_type_to_string((ast_expression*)param, typename, sizeof(typename));
- parseerror(parser, "type not supported as part of a parameter list: %s", typename);
+ char tname[1024]; /* typename is reserved in C++ */
+ ast_type_to_string((ast_expression*)param, tname, sizeof(tname));
+ parseerror(parser, "type not supported as part of a parameter list: %s", tname);
goto on_error;
}
}
static struct memblock_t *mem_start = NULL;
void *util_memory_a(size_t byte, unsigned int line, const char *file) {
- struct memblock_t *info = malloc(sizeof(struct memblock_t) + byte);
+ struct memblock_t *info = (struct memblock_t*)malloc(sizeof(struct memblock_t) + byte);
void *data = (void*)(info+1);
if (!info) return NULL;
info->line = line;
if (!s)
return NULL;
- if ((len = strlen(s)) && (ptr = mem_a(len+1))) {
+ if ((len = strlen(s)) && (ptr = (char*)mem_a(len+1))) {
memcpy(ptr, s, len);
ptr[len] = '\0';
}
hash_node_t *_util_htnewpair(const char *key, void *value) {
hash_node_t *node;
- if (!(node = mem_a(sizeof(hash_node_t))))
+ if (!(node = (hash_node_t*)mem_a(sizeof(hash_node_t))))
return NULL;
if (!(node->key = util_strdup(key))) {
if (size < 1)
return NULL;
- if (!(hashtable = mem_a(sizeof(hash_table_t))))
+ if (!(hashtable = (hash_table_t*)mem_a(sizeof(hash_table_t))))
return NULL;
- if (!(hashtable->table = mem_a(sizeof(hash_node_t*) * size))) {
+ if (!(hashtable->table = (hash_node_t**)mem_a(sizeof(hash_node_t*) * size))) {
mem_d(hashtable);
return NULL;
}