]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Make compiler and virtual-machine compile as C++ code, also removed gmqcc_voidptr...
authorDale Weiler <killfieldengine@gmail.com>
Sun, 23 Dec 2012 07:51:19 +0000 (07:51 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Sun, 23 Dec 2012 07:51:19 +0000 (07:51 +0000)
ast.c
exec.c
ftepp.c
gmqcc.h
ir.c
main.c
opts.c
parser.c
util.c

diff --git a/ast.c b/ast.c
index 5dc131ea38bc617289aac9a5dae09d91985502d0..09c12a4c6957ce0efbe963a2083a389c9181002c 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -1098,9 +1098,9 @@ bool ast_value_codegen(ast_value *self, ast_function *func, bool lvalue, ir_valu
      * 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;
diff --git a/exec.c b/exec.c
index c1aa695f23c43f67813f69e775d51e9e69a14e6a..270bd149e2123e9fbd2621c2fbf52e63ea4dee6b 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -169,8 +169,9 @@ void prog_delete(qc_program *prog)
 
 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;
 }
 
diff --git a/ftepp.c b/ftepp.c
index ed501a50a43c7b229e80afcdabbdbb46d49e4e4d..763850169675aca88781a7c2e09a145c8173b4d6 100644 (file)
--- a/ftepp.c
+++ b/ftepp.c
@@ -1010,14 +1010,15 @@ static char *ftepp_include_find(ftepp_t *ftepp, const char *file)
     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) {
@@ -1025,13 +1026,13 @@ static void ftepp_directive_warning(ftepp_t *ftepp) {
             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) {
diff --git a/gmqcc.h b/gmqcc.h
index 3755a51384a1ee3cb0b2999d0630f418c6e04145..949559442021428f8555b8ce672dbb38c9d02330 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -260,40 +260,12 @@ size_t util_strtononcmd (const char *, char *, size_t);
 
 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
@@ -371,12 +343,12 @@ typedef struct hash_table_t {
  */
 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 ===============================*/
 /*===================================================================*/
diff --git a/ir.c b/ir.c
index 12f9a5115c4e14dfad82917cb8ae0dd92fe47868..2ac7ff1bdc7500a5090785b45206dc8edf13af71 100644 (file)
--- a/ir.c
+++ b/ir.c
@@ -1123,7 +1123,7 @@ static char *ir_strdup(const char *str)
 {
     if (str && !*str) {
         /* actually dup empty strings */
-        char *out = mem_a(1);
+        char *out = (char*)mem_a(1);
         *out = 0;
         return out;
     }
@@ -1543,7 +1543,7 @@ ir_instr* ir_block_create_phi(ir_block *self, lex_ctx ctx, const char *label, in
     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;
@@ -1590,7 +1590,7 @@ ir_instr* ir_block_create_call(ir_block *self, lex_ctx ctx, const char *label, i
     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;
diff --git a/main.c b/main.c
index 916a95e01ee52833b95fe029ab0fcb06effbfa04..5925cfa68c8a82b7ac501ba6107c04390271c98b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -536,7 +536,7 @@ int main(int argc, char **argv) {
                 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]));
diff --git a/opts.c b/opts.c
index 5c48286d2d9a7557fc7528efdacf678ffa082a1a..4d7d9a08debaed3e9fa9d96dac23e973d0b7d907 100644 (file)
--- a/opts.c
+++ b/opts.c
@@ -64,7 +64,7 @@ void opts_init(const char *output, int standard, size_t arraysize) {
     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;
 }
 
index 46f4291ce24a20b3114f5374446c462ee97e4876..a818cf567270f3f3fa5dcb2214128422a19810bf 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -32,6 +32,7 @@
 #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;
@@ -90,7 +91,7 @@ typedef struct {
      * 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;
@@ -234,7 +235,7 @@ static char *parser_strdup(const char *str)
 {
     if (str && !*str) {
         /* actually dup empty strings */
-        char *out = mem_a(1);
+        char *out = (char*)mem_a(1);
         *out = 0;
         return out;
     }
@@ -296,12 +297,12 @@ static ast_value* parser_const_vector_0(parser_t *parser)
 
 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)
@@ -328,7 +329,7 @@ static ast_expression* parser_find_local(parser_t *parser, const char *name, siz
     *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;
@@ -1479,7 +1480,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             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"));
 
@@ -1556,7 +1557,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             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));
         }
@@ -1569,7 +1570,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             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));
         }
@@ -1582,7 +1583,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             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"));
         }
@@ -1595,7 +1596,7 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
             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,
@@ -2966,7 +2967,7 @@ static bool create_vector_members(ast_value *var, ast_member **me)
     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;
@@ -3703,9 +3704,9 @@ static ast_value *parse_parameter_list(parser_t *parser, ast_value *var)
                 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;
             }
         }
diff --git a/util.c b/util.c
index 32b487ed94360126578d94a82980061d3619c220..bbd2799200914cb87854927aa06927c2b0c5a784 100644 (file)
--- a/util.c
+++ b/util.c
@@ -42,7 +42,7 @@ struct memblock_t {
 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;
@@ -170,7 +170,7 @@ char *util_strdup(const char *s) {
     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';
     }
@@ -426,7 +426,7 @@ GMQCC_INLINE size_t util_hthash(hash_table_t *ht, const char *key) {
 
 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))) {
@@ -452,10 +452,10 @@ hash_table_t *util_htnew(size_t size) {
     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;
     }