]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - gmqcc.h
ast_unary::make: safer double-negation optimization check
[xonotic/gmqcc.git] / gmqcc.h
diff --git a/gmqcc.h b/gmqcc.h
index 1c189599d0cf4dda3981db9bea2c6e2a0a8d7120..4e3fb399eba42b7604ac7b76b413d6cd74ec8e92 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -502,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;
@@ -510,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;
 };
 
 /*
@@ -585,12 +589,28 @@ extern size_t compile_errors;
 extern size_t compile_Werrors;
 extern size_t compile_warnings;
 
-void /********/ compile_error   (lex_ctx_t ctx, /*LVL_ERROR*/ const char *msg, ...);
+void /********/ compile_error_  (lex_ctx_t ctx, /*LVL_ERROR*/ const char *msg, ...);
 void /********/ vcompile_error  (lex_ctx_t ctx, /*LVL_ERROR*/ const char *msg, va_list ap);
-bool GMQCC_WARN compile_warning (lex_ctx_t ctx, int warntype, const char *fmt, ...);
+bool GMQCC_WARN compile_warning_(lex_ctx_t ctx, int warntype, const char *fmt, ...);
 bool GMQCC_WARN vcompile_warning(lex_ctx_t ctx, int warntype, const char *fmt, va_list ap);
 void            compile_show_werrors(void);
 
+template <typename T>
+inline constexpr const T formatNormalize(const T argument) { return argument; }
+
+inline const char *formatNormalize(const std::string &argument) {
+    return argument.c_str();
+}
+
+template<typename... Ts>
+inline bool GMQCC_WARN compile_warning(lex_ctx_t ctx, int warntype, const char *fmt, const Ts&... ts) {
+    return compile_warning_(ctx, warntype, fmt, formatNormalize(ts)...);
+}
+template<typename... Ts>
+inline void /********/ compile_error   (lex_ctx_t ctx, /*LVL_ERROR*/ const char *msg, const Ts&... ts) {
+    return compile_error_(ctx, msg, formatNormalize(ts)...);
+}
+
 /* ir.c */
 /* TODO: cleanup */
 enum store_type {