]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - code.cpp
Add -Wunused-component like -Wunused-variable but warns about unused components of...
[xonotic/gmqcc.git] / code.cpp
index d0ab7e5ff05349f4fda831c6b093a7757d0aeef3..645ad257042b5973c20d4b08e5701e7be9e812a0 100644 (file)
--- a/code.cpp
+++ b/code.cpp
@@ -106,35 +106,39 @@ void code_pop_statement(code_t *code)
     code->columnnums.pop_back();
 }
 
-code_t *code_init() {
+void *code_t::operator new(std::size_t bytes) {
+  return mem_a(bytes);
+}
+
+void code_t::operator delete(void *ptr) {
+  mem_d(ptr);
+}
+
+code_t::code_t()
+{
     static lex_ctx_t                empty_ctx       = {0, 0, 0};
     static prog_section_function_t  empty_function  = {0,0,0,0,0,0,0,{0,0,0,0,0,0,0,0}};
     static prog_section_statement_t empty_statement = {0,{0},{0},{0}};
     static prog_section_def_t       empty_def       = {0, 0, 0};
 
-    code_t *code       = (code_t*)mem_a(sizeof(code_t));
-    int     i          = 0;
+    string_cache = util_htnew(OPTS_OPTIMIZATION(OPTIM_OVERLAP_STRINGS) ? 0x100 : 1024);
 
-    memset(code, 0, sizeof(code_t));
-    code->entfields    = 0;
-    code->string_cache = util_htnew(OPTS_OPTIMIZATION(OPTIM_OVERLAP_STRINGS) ? 0x100 : 1024);
+    // The way progs.dat is suppose to work is odd, there needs to be
+    // some null (empty) statements, functions, and 28 globals
+    globals.insert(globals.begin(), 28, 0);
 
-    /*
-     * The way progs.dat is suppose to work is odd, there needs to be
-     * some null (empty) statements, functions, and 28 globals
-     */
-    for(; i < 28; i++)
-        code->globals.push_back(0);
+    chars.push_back('\0');
+    functions.push_back(empty_function);
 
-    code->chars.push_back('\0');
-    code->functions.push_back(empty_function);
+    code_push_statement(this, &empty_statement, empty_ctx);
 
-    code_push_statement(code, &empty_statement, empty_ctx);
-
-    code->defs.push_back(empty_def);
-    code->fields.push_back(empty_def);
+    defs.push_back(empty_def);
+    fields.push_back(empty_def);
+}
 
-    return code;
+code_t::~code_t()
+{
+    util_htdel(string_cache);
 }
 
 void *code_util_str_htgeth(hash_table_t *ht, const char *key, size_t bin);
@@ -291,7 +295,7 @@ static void code_stats(const char *filename, const char *lnofile, code_t *code,
 
 bool code_write(code_t *code, const char *filename, const char *lnofile) {
     prog_header_t code_header;
-    FILE *fp = NULL;
+    FILE *fp = nullptr;
 
     code_create_header(code, &code_header, filename, lnofile);
 
@@ -319,7 +323,7 @@ bool code_write(code_t *code, const char *filename, const char *lnofile) {
         }
 
         fclose(fp);
-        fp = NULL;
+        fp = nullptr;
     }
 
     fp = fopen(filename, "wb");
@@ -342,8 +346,3 @@ bool code_write(code_t *code, const char *filename, const char *lnofile) {
     code_stats(filename, lnofile, code, &code_header);
     return true;
 }
-
-void code_cleanup(code_t *code) {
-    util_htdel(code->string_cache);
-    mem_d(code);
-}