]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - con.c
Don't generate IF/IFNOT with +1 offsets
[xonotic/gmqcc.git] / con.c
diff --git a/con.c b/con.c
index 2bd8e397de579096f017b421ce5ba783ff4cecf2..53fc308e6df8583c54e107ecb326df7d3dd4781c 100644 (file)
--- a/con.c
+++ b/con.c
@@ -321,7 +321,7 @@ int con_out(const char *fmt, ...) {
  * for reporting of file:line based on lexer context, These are used
  * heavily in the parser/ir/ast.
  */
-void con_vprintmsg(int level, const char *name, size_t line, const char *msgtype, const char *msg, va_list ap) {
+void con_vprintmsg_c(int level, const char *name, size_t line, const char *msgtype, const char *msg, va_list ap, const char *condname) {
     /* color selection table */
     static int sel[] = {
         CON_WHITE,
@@ -340,7 +340,14 @@ void con_vprintmsg(int level, const char *name, size_t line, const char *msgtype
         print("%s:%d: %s: ", name, (int)line, msgtype);
 
     vprint(msg, ap);
-    print("\n");
+    if (condname)
+        print(" [%s]\n", condname);
+    else
+        print("\n");
+}
+
+void con_vprintmsg(int level, const char *name, size_t line, const char *msgtype, const char *msg, va_list ap) {
+    con_vprintmsg_c(level, name, line, msgtype, msg, ap, NULL);
 }
 
 void con_printmsg(int level, const char *name, size_t line, const char *msgtype, const char *msg, ...) {
@@ -360,3 +367,55 @@ void con_cprintmsg (void *ctx, int lvl, const char *msgtype, const char *msg, ..
     con_cvprintmsg(ctx, lvl, msgtype, msg, va);
     va_end  (va);
 }
+
+/* General error interface */
+size_t compile_errors = 0;
+size_t compile_warnings = 0;
+
+void vcompile_error(lex_ctx ctx, const char *msg, va_list ap)
+{
+    ++compile_errors;
+    con_cvprintmsg((void*)&ctx, LVL_ERROR, "error", msg, ap);
+}
+
+void compile_error(lex_ctx ctx, const char *msg, ...)
+{
+    va_list ap;
+    va_start(ap, msg);
+    vcompile_error(ctx, msg, ap);
+    va_end(ap);
+}
+
+bool GMQCC_WARN vcompile_warning(lex_ctx ctx, int warntype, const char *fmt, va_list ap)
+{
+    int lvl = LVL_WARNING;
+    char warn_name[1024];
+
+    if (!OPTS_WARN(warntype))
+        return false;
+
+    warn_name[0] = '-';
+    warn_name[1] = 'W';
+    (void)util_strtononcmd(opts_warn_list[warntype].name, warn_name+2, sizeof(warn_name)-2);
+
+    if (opts.werror) {
+        ++compile_errors;
+        lvl = LVL_ERROR;
+    }
+    else
+        ++compile_warnings;
+
+    con_vprintmsg_c(lvl, ctx.file, ctx.line, (opts.werror ? "error" : "warning"), fmt, ap, warn_name);
+
+    return opts.werror;
+}
+
+bool GMQCC_WARN compile_warning(lex_ctx ctx, int warntype, const char *fmt, ...)
+{
+    bool r;
+    va_list ap;
+    va_start(ap, fmt);
+    r = vcompile_warning(ctx, warntype, fmt, ap);
+    va_end(ap);
+    return r;
+}