code.o \
ast.o \
ir.o \
- error.o \
con.o
OBJ_A = test/ast-test.o
OBJ_I = test/ir-test.o
{
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();
}
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;
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);
+}
+++ /dev/null
-/*
- * 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);
-}
/*===================================================================*/
/*============================ 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 ();
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 ========================*/
{
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);
}
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;
* 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;
/*
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 */
}
/* (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;
}
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);
}
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;
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);
}
}
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;
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;