]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - gmqcc.h
more c++ migration for ast/ir/code; reached a working condition here
[xonotic/gmqcc.git] / gmqcc.h
diff --git a/gmqcc.h b/gmqcc.h
index 34fefaae5dec5e984cbfce56c0c02eaece80813a..88cf7ff21831336c15f1d6d87515af82176fb6f6 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -1,6 +1,10 @@
 #ifndef GMQCC_HDR
 #define GMQCC_HDR
 #include <vector>
+#include <string>
+#include <utility>
+#include <memory>
+using std::move;
 #include <stdarg.h>
 #include <stddef.h>
 #include <stdlib.h>
@@ -227,7 +231,7 @@ void _util_vec_delete(void *vec);
 
 /* exposed interface */
 #define vec_meta(A)       ((vector_t*)(((char *)(A)) - sizeof(vector_t)))
-#define vec_free(A)       ((void)((A) ? (_util_vec_delete((void *)(A)), (A) = NULL) : 0))
+#define vec_free(A)       ((void)((A) ? (_util_vec_delete((void *)(A)), (A) = nullptr) : 0))
 #define vec_push(A,V)     (GMQCC_VEC_WILLGROW((A),1), (A)[vec_meta(A)->used++] = (V))
 #define vec_size(A)       ((A) ? vec_meta(A)->used : 0)
 #define vec_add(A,N)      (GMQCC_VEC_WILLGROW((A),(N)), vec_meta(A)->used += (N), &(A)[vec_meta(A)->used-(N)])
@@ -259,7 +263,7 @@ int util_getline(char  **, size_t *, FILE *);
 /* code.c */
 
 /* Note: if you change the order, fix type_sizeof in ir.c */
-enum {
+enum qc_type {
     TYPE_VOID     ,
     TYPE_STRING   ,
     TYPE_FLOAT    ,
@@ -498,6 +502,10 @@ typedef int32_t qcint_t;
 typedef uint32_t qcuint_t;
 
 struct code_t {
+    void* operator new(std::size_t);
+    void operator delete(void*);
+    code_t();
+    ~code_t();
     std::vector<prog_section_statement_t> statements;
     std::vector<int> linenums;
     std::vector<int> columnnums;
@@ -506,10 +514,10 @@ struct code_t {
     std::vector<prog_section_function_t> functions;
     std::vector<int> globals;
     std::vector<char> chars;
-    uint16_t crc;
-    uint32_t entfields;
+    uint16_t crc = 0;
+    uint32_t entfields = 0;
     ht string_cache;
-    qcint_t string_cached_empty;
+    qcint_t string_cached_empty = 0;
 };
 
 /*
@@ -589,7 +597,7 @@ void            compile_show_werrors(void);
 
 /* ir.c */
 /* TODO: cleanup */
-enum store_types {
+enum store_type {
     store_global,
     store_local,  /* local, assignable for now, should get promoted later */
     store_param,  /* parameters, they are locals with a fixed position */