]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Use new console system everywhere.
authorDale Weiler <killfieldengine@gmail.com>
Thu, 15 Nov 2012 00:28:46 +0000 (00:28 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Thu, 15 Nov 2012 00:28:46 +0000 (00:28 +0000)
Makefile
ast.c
con.c
error.c [deleted file]
gmqcc.h
ir.c
lexer.c
parser.c
test [new file with mode: 0755]

index ce0bc8697702db02caf715af8c13360dfa3dd5d1..b2d65805d0a3ca7c0b67877b8fca386d90fc3f9d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,6 @@ OBJ     = \
           code.o      \
           ast.o       \
           ir.o        \
-          error.o     \
           con.o
 OBJ_A = test/ast-test.o
 OBJ_I = test/ir-test.o
diff --git a/ast.c b/ast.c
index 3f6c59eb577113a3f9753d879096dbd02e169b60..10c177ed09b59629c24b8d2b2d11f520cb140aef 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -40,14 +40,14 @@ static void asterror(lex_ctx ctx, const char *msg, ...)
 {
     va_list ap;
     va_start(ap, msg);
-    cvprintmsg(ctx, LVL_ERROR, "error", msg, ap);
+    con_cvprintmsg((void*)&ctx, LVL_ERROR, "error", msg, ap);
     va_end(ap);
 }
 
 /* It must not be possible to get here. */
 static GMQCC_NORETURN void _ast_node_destroy(ast_node *self)
 {
-    fprintf(stderr, "ast node missing destroy()\n");
+    con_err("ast node missing destroy()\n");
     abort();
 }
 
diff --git a/con.c b/con.c
index 623cb991d548adb7befef7a7963ed978cf5adfa3..7ab5fcbe4caa398dd9a81ab9d5ed389e32f6032e 100644 (file)
--- a/con.c
+++ b/con.c
@@ -291,6 +291,10 @@ int con_vout(const char *fmt, va_list va) {
     return con_write(console.handle_out, fmt, va);
 }
 
+/*
+ * Standard stdout/stderr printf functions used generally where they need
+ * to be used.
+ */
 int con_err(const char *fmt, ...) {
     va_list  va;
     int      ln = 0;
@@ -307,3 +311,55 @@ int con_out(const char *fmt, ...) {
     va_end  (va);
     return   ln;
 }
+
+
+/*
+ * Utility console message writes for lexer contexts.  These will allow
+ * 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) {
+    /* color selection table */
+    static int sel[] = {
+        CON_WHITE,
+        CON_CYAN,
+        CON_RED
+    };
+    
+    int   err   = !!(level == LVL_ERROR);
+    int   color = (err) ? console.color_err : console.color_out;
+    
+    /* this might confuse you :P */
+    ((err) ? &con_err : &con_out)(
+        (color) ? 
+            "\033[0;%dm%s:%d: \033[0;%dm%s: \033[0m" : 
+            "%s:%d: %s: ",
+            
+        CON_CYAN,
+        name,
+        (int)line,
+        sel[level],
+        msgtype
+    );
+        
+    con_verr(msg, ap);
+    fprintf (stderr, "\n");
+}
+
+void con_printmsg(int level, const char *name, size_t line, const char *msgtype, const char *msg, ...) {
+    va_list   va;
+    va_start(va, msg);
+    con_vprintmsg(level, name, line, msgtype, msg, va);
+    va_end  (va);
+}
+
+void con_cvprintmsg(void *ctx, int lvl, const char *msgtype, const char *msg, va_list ap) {
+    con_vprintmsg(lvl, ((lex_ctx*)ctx)->file, ((lex_ctx*)ctx)->line, msgtype, msg, ap);
+}
+
+void con_cprintmsg (void *ctx, int lvl, const char *msgtype, const char *msg, ...) {
+    va_list   va;
+    va_start(va, msg);
+    con_cvprintmsg(ctx, lvl, msgtype, msg, va);
+    va_end  (va);
+}
diff --git a/error.c b/error.c
deleted file mode 100644 (file)
index e6a1c7d..0000000
--- a/error.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2012
- *     Dale Weiler
- *     Wolfgang Bumiller
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
- * so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-#include "gmqcc.h"
-
-/*
- * Compiler error system, this handles the error printing, and managing
- * such as after so many errors just stop the compilation, and other
- * intereting like colors for the console.
- */
-
-#ifndef WIN32
-int levelcolor[] = {
-    CON_WHITE,
-    CON_CYAN,
-    CON_RED
-};
-#endif
-
-void vprintmsg(int level, const char *name, size_t line, const char *msgtype, const char *msg, va_list ap)
-{
-#ifndef WIN32
-    fprintf (stderr, "\033[0;%dm%s:%d: \033[0;%dm%s: \033[0m", CON_CYAN, name, (int)line, levelcolor[level], msgtype);
-#else
-    fprintf (stderr, "%s:%d: %s: ", name, line, msgtype);
-#endif
-    vfprintf(stderr, msg, ap);
-    fprintf (stderr, "\n");
-}
-
-void printmsg(int level, const char *name, size_t line, const char *msgtype, const char *msg, ...)
-{
-    va_list   va;
-    va_start(va, msg);
-    vprintmsg(level, name, line, msgtype, msg, va);
-    va_end  (va);
-}
-
-void cvprintmsg(lex_ctx ctx, int lvl, const char *msgtype, const char *msg, va_list ap)
-{
-    vprintmsg(lvl, ctx.file, ctx.line, msgtype, msg, ap);
-}
-
-void cprintmsg (lex_ctx ctx, int lvl, const char *msgtype, const char *msg, ...)
-{
-    va_list   va;
-    va_start(va, msg);
-    cvprintmsg(ctx, lvl, msgtype, msg, va);
-    va_end  (va);
-}
diff --git a/gmqcc.h b/gmqcc.h
index 9770929f8caaa104e04255dd5246bd656f0112c4..c8440cc6be007a92c9233de05f28619fda2a96e8 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -535,6 +535,30 @@ qcint    code_alloc_field (size_t qcsize);
 /*===================================================================*/
 /*============================ con.c ================================*/
 /*===================================================================*/
+enum {
+    CON_BLACK   = 30,
+    CON_RED,
+    CON_GREEN,
+    CON_BROWN,
+    CON_BLUE,
+    CON_MAGENTA,
+    CON_CYAN ,
+    CON_WHITE
+};
+
+/* message level */
+enum {
+    LVL_MSG,
+    LVL_WARNING,
+    LVL_ERROR
+};
+
+
+void con_vprintmsg (int level, const char *name, size_t line, const char *msgtype, const char *msg, va_list ap);
+void con_printmsg  (int level, const char *name, size_t line, const char *msgtype, const char *msg, ...);
+void con_cvprintmsg(void *ctx, int lvl, const char *msgtype, const char *msg, va_list ap);
+void con_cprintmsg (void *ctx, int lvl, const char *msgtype, const char *msg, ...);
+
 void con_close();
 void con_color(int state);
 void con_init ();
@@ -923,32 +947,6 @@ prog_section_def* prog_getdef    (qc_program *prog, qcint off);
 qcany*            prog_getedict  (qc_program *prog, qcint e);
 qcint             prog_tempstring(qc_program *prog, const char *_str);
 
-/*===================================================================*/
-/*===================== error.c message printer =====================*/
-/*===================================================================*/
-
-#ifndef WIN32
-enum {
-    CON_BLACK   = 30,
-    CON_RED,
-    CON_GREEN,
-    CON_BROWN,
-    CON_BLUE,
-    CON_MAGENTA,
-    CON_CYAN ,
-    CON_WHITE
-};
-#endif
-enum {
-    LVL_MSG,
-    LVL_WARNING,
-    LVL_ERROR
-};
-
-void vprintmsg (int level, const char *name, size_t line, const char *msgtype, const char *msg, va_list ap);
-void printmsg  (int level, const char *name, size_t line, const char *msgtype, const char *msg, ...);
-void cvprintmsg(lex_ctx ctx, int lvl, const char *msgtype, const char *msg, va_list ap);
-void cprintmsg (lex_ctx ctx, int lvl, const char *msgtype, const char *msg, ...);
 
 /*===================================================================*/
 /*===================== parser.c commandline ========================*/
diff --git a/ir.c b/ir.c
index 7af6162d524876a290ee1ff6a1edd0cd279b8323..4ae49d93968cd638f9c0328ecaae895811cf1f81 100644 (file)
--- a/ir.c
+++ b/ir.c
@@ -177,7 +177,7 @@ static void irerror(lex_ctx ctx, const char *msg, ...)
 {
     va_list ap;
     va_start(ap, msg);
-    cvprintmsg(ctx, LVL_ERROR, "internal error", msg, ap);
+    con_cvprintmsg((void*)&ctx, LVL_ERROR, "internal error", msg, ap);
     va_end(ap);
 }
 
@@ -193,7 +193,7 @@ static bool irwarning(lex_ctx ctx, int warntype, const char *fmt, ...)
            lvl = LVL_ERROR;
 
        va_start(ap, fmt);
-    vprintmsg(lvl, ctx.file, ctx.line, "warning", fmt, ap);
+    con_vprintmsg(lvl, ctx.file, ctx.line, "warning", fmt, ap);
        va_end(ap);
 
        return opts_werror;
@@ -2295,7 +2295,7 @@ static bool ir_block_life_propagate(ir_block *self, ir_block *prev, bool *change
                      * since this function is run multiple times.
                      */
                     /* For now: debug info: */
-                    /* fprintf(stderr, "Value only written %s\n", value->name); */
+                    /* con_err( "Value only written %s\n", value->name); */
                     tempbool = ir_value_life_merge(value, instr->eid);
                     *changed = *changed || tempbool;
                     /*
@@ -2310,7 +2310,7 @@ static bool ir_block_life_propagate(ir_block *self, ir_block *prev, bool *change
                     tempbool = ir_value_life_merge(value, instr->eid);
                     /*
                     if (tempbool)
-                        fprintf(stderr, "value added id %s %i\n", value->name, (int)instr->eid);
+                        con_err( "value added id %s %i\n", value->name, (int)instr->eid);
                     */
                     *changed = *changed || tempbool;
                     /* Then remove */
@@ -2321,7 +2321,7 @@ static bool ir_block_life_propagate(ir_block *self, ir_block *prev, bool *change
         }
         /* (A) */
         tempbool = ir_block_living_add_instr(self, instr->eid);
-        /*fprintf(stderr, "living added values\n");*/
+        /*con_err( "living added values\n");*/
         *changed = *changed || tempbool;
 
     }
diff --git a/lexer.c b/lexer.c
index e190da0779ca3349d69ecae7a0eae9f5a2eacbca..0ed938cdee494dd61def372ab858fe27840bdbe1 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -16,7 +16,7 @@ void lexerror(lex_file *lex, const char *fmt, ...)
        va_list ap;
 
        va_start(ap, fmt);
-    vprintmsg(LVL_ERROR, lex->name, lex->sline, "parse error", fmt, ap);
+    con_vprintmsg(LVL_ERROR, lex->name, lex->sline, "parse error", fmt, ap);
        va_end(ap);
 }
 
@@ -32,7 +32,7 @@ bool lexwarn(lex_file *lex, int warntype, const char *fmt, ...)
            lvl = LVL_ERROR;
 
        va_start(ap, fmt);
-    vprintmsg(lvl, lex->name, lex->sline, "warning", fmt, ap);
+    con_vprintmsg(lvl, lex->name, lex->sline, "warning", fmt, ap);
        va_end(ap);
 
        return opts_werror;
index 534f007db4d2ba65d0071a8408088ec8e5346f2a..59d4a33e772a4668b4ee753d151be8b2f527eea5 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -65,7 +65,7 @@ static void parseerror(parser_t *parser, const char *fmt, ...)
        parser->errors++;
 
        va_start(ap, fmt);
-    vprintmsg(LVL_ERROR, parser->lex->tok.ctx.file, parser->lex->tok.ctx.line, "parse error", fmt, ap);
+    con_vprintmsg(LVL_ERROR, parser->lex->tok.ctx.file, parser->lex->tok.ctx.line, "parse error", fmt, ap);
        va_end(ap);
 }
 
@@ -84,7 +84,7 @@ static bool GMQCC_WARN parsewarning(parser_t *parser, int warntype, const char *
        }
 
        va_start(ap, fmt);
-    vprintmsg(lvl, parser->lex->tok.ctx.file, parser->lex->tok.ctx.line, "warning", fmt, ap);
+    con_vprintmsg(lvl, parser->lex->tok.ctx.file, parser->lex->tok.ctx.line, "warning", fmt, ap);
        va_end(ap);
 
        return opts_werror;
@@ -102,7 +102,7 @@ static bool GMQCC_WARN genwarning(lex_ctx ctx, int warntype, const char *fmt, ..
            lvl = LVL_ERROR;
 
        va_start(ap, fmt);
-    vprintmsg(lvl, ctx.file, ctx.line, "warning", fmt, ap);
+    con_vprintmsg(lvl, ctx.file, ctx.line, "warning", fmt, ap);
        va_end(ap);
 
        return opts_werror;
diff --git a/test b/test
new file mode 100755 (executable)
index 0000000..e859b47
Binary files /dev/null and b/test differ