]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - con.c
ast_return needs the correct context...
[xonotic/gmqcc.git] / con.c
diff --git a/con.c b/con.c
index 1cd7b326d10956192bb16983f538ac6744c65767..3fca6ef76fbdd8a576e85beaec822e700581e704 100644 (file)
--- a/con.c
+++ b/con.c
  */
 #include "gmqcc.h"
 
-uint32_t    opts_warn [1 + (COUNT_WARNINGS / 32)];
-bool        opts_werror   = false;
-
 /*
  * isatty/STDERR_FILENO/STDOUT_FILNO
  * + some other things likewise.
  */
 #ifndef _WIN32
-#include <unistd.h>
+#   include <unistd.h>
+#else
+#   include <io.h>
+    /*
+     * Windows and it's posix underscore bullshit.  We simply fix this
+     * with yay, another macro :P
+     */
+#   define isatty _isatty
 #endif
 
 #define GMQCC_IS_STDOUT(X) ((FILE*)((void*)X) == stdout)
@@ -49,7 +53,7 @@ typedef struct {
  * Doing colored output on windows is fucking stupid.  The linux way is
  * the real way. So we emulate it on windows :)
  */
-#ifdef _WIN32
+#ifdef _MSC_VER
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 
@@ -62,12 +66,6 @@ typedef struct {
 #define STDERR_FILENO 2
 #define STDOUT_FILENO 1
 
-/*
- * Windows and it's posix underscore bullshit.  We simply fix this
- * with yay, another macro :P
- */
-#define isatty _isatty
-
 enum {
     RESET = 0,
     BOLD  = 1,
@@ -105,7 +103,7 @@ static const ansi2win[] = {
     WWHITE
 };
 
-static void win_fputs(char *str, FILE *f) {
+static void win_fputs(char *str, FILE *h) {
     /* state for translate */
     int acolor;
     int wcolor;
@@ -120,7 +118,7 @@ static void win_fputs(char *str, FILE *f) {
     int colorpos = 1;
 
     CONSOLE_SCREEN_BUFFER_INFO cinfo;
-    GetConsoleScreenBufferInfo(
+    GetConsoleScreenBufferInfo (
         (GMQCC_IS_STDOUT(h)) ?
             GetStdHandle(STD_OUTPUT_HANDLE) :
             GetStdHandle(STD_ERROR_HANDLE), &cinfo
@@ -159,7 +157,7 @@ static void win_fputs(char *str, FILE *f) {
                     intense = WBLACK;
                 }
 
-                SetConsoleTextattribute(
+                SetConsoleTextAttribute (
                     (h == stdout) ?
                     GetStdHandle(STD_OUTPUT_HANDLE) :
                     GetStdHandle(STD_ERROR_HANDLE),
@@ -211,7 +209,7 @@ static void con_enablecolor() {
  */
 static int con_write(FILE *handle, const char *fmt, va_list va) {
     int      ln;
-    #ifndef _WIN32
+    #ifndef _MSC_VER
     ln = vfprintf(handle, fmt, va);
     #else
     {
@@ -324,7 +322,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,
@@ -334,7 +332,7 @@ void con_vprintmsg(int level, const char *name, size_t line, const char *msgtype
 
     int  err                         = !!(level == LVL_ERROR);
     int  color                       = (err) ? console.color_err : console.color_out;
-    int (*print)(const char *, ...)  = (err) ? &con_err          : &con_out;
+    int (*print) (const char *, ...)  = (err) ? &con_err          : &con_out;
     int (*vprint)(const char *, va_list) = (err) ? &con_verr : &con_vout;
 
     if (color)
@@ -343,7 +341,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, ...) {
@@ -368,33 +373,50 @@ void con_cprintmsg (void *ctx, int lvl, const char *msgtype, const char *msg, ..
 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;
-    ++compile_errors;
     va_start(ap, msg);
-    con_cvprintmsg((void*)&ctx, LVL_ERROR, "error", msg, ap);
+    vcompile_error(ctx, msg, ap);
     va_end(ap);
 }
 
-bool GMQCC_WARN compile_warning(lex_ctx ctx, int warntype, const char *fmt, ...)
+bool GMQCC_WARN vcompile_warning(lex_ctx ctx, int warntype, const char *fmt, va_list ap)
 {
-    va_list ap;
     int lvl = LVL_WARNING;
+    char warn_name[1024];
 
     if (!OPTS_WARN(warntype))
         return false;
 
-    if (opts_werror) {
+    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);
-    con_vprintmsg(lvl, ctx.file, ctx.line, (opts_werror ? "error" : "warning"), fmt, ap);
+    r = vcompile_warning(ctx, warntype, fmt, ap);
     va_end(ap);
-
-    return opts_werror;
+    return r;
 }