eolian: Add some color to those warning messages

Note: This is not using eina_log, not entirely sure why, but this
doesn't prevent us from adding some color.
This commit is contained in:
Jean-Philippe Andre 2017-10-31 14:20:09 +09:00
parent 1adb93b3e5
commit c1d21cef89
8 changed files with 98 additions and 45 deletions

View File

@ -12,6 +12,7 @@ lib_eolian_libeolian_la_SOURCES = \
lib/eolian/eo_parser.c \
lib/eolian/eo_parser.h \
lib/eolian/eolian.c \
lib/eolian/eolian_priv.h \
lib/eolian/eolian_database.c \
lib/eolian/eolian_database.h \
lib/eolian/database_class.c \

View File

@ -4,6 +4,7 @@
#include <Eina.h>
#include "eolian_database.h"
#include "eolian_priv.h"
EAPI Eina_Stringshare *
eolian_class_file_get(const Eolian_Class *cl)
@ -147,7 +148,7 @@ eolian_class_function_get_by_name(const Eolian_Class *cl, const char *func_name,
}
}
fprintf(stderr, "eolian: function '%s' not found in class '%s'\n", func_name, cl->name);
_eolian_log("function '%s' not found in class '%s'", func_name, cl->name);
return NULL;
}

View File

@ -6,11 +6,12 @@
#include <Eina.h>
#include "eolian_database.h"
#include "eolian_priv.h"
static Eina_Bool
node_error(const Eolian_Object *obj, const char *msg)
{
fprintf(stderr, "eolian:%s:%d:%d: %s\n", obj->file, obj->line, obj->column, msg);
_eolian_log_line(obj->file, obj->line, obj->column, "%s", msg);
return EINA_FALSE;
}

View File

@ -6,6 +6,7 @@
#endif
#include "eo_lexer.h"
#include "eolian_priv.h"
static Eina_Bool
_validate(Eolian_Object *obj)
@ -33,8 +34,8 @@ _validate_docstr(Eina_Stringshare *str, const Eolian_Object *info)
if (eolian_doc_token_ref_get(NULL, &tok, NULL, NULL) == EOLIAN_DOC_REF_INVALID)
{
char *refn = eolian_doc_token_text_get(&tok);
fprintf(stderr, "eolian:%s:%d:%d: failed validating reference '%s'\n",
info->file, info->line, info->column, refn);
_eolian_log_line(info->file, info->line, info->column,
"failed validating reference '%s'", refn);
free(refn);
ret = EINA_FALSE;
break;
@ -98,7 +99,7 @@ _ef_map_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED,
static Eina_Bool
_obj_error(const Eolian_Object *o, const char *msg)
{
fprintf(stderr, "eolian:%s:%d:%d: %s\n", o->file, o->line, o->column, msg);
_eolian_log_line(o->file, o->line, o->column, "%s", msg);
return EINA_FALSE;
}

View File

@ -10,6 +10,7 @@
#include <assert.h>
#include "eo_lexer.h"
#include "eolian_priv.h"
static int lastbytes = 0;
@ -107,8 +108,8 @@ throw(Eo_Lexer *ls, const char *fmt, ...)
for (i = 0; i < ls->column; ++i)
eina_strbuf_append_char(buf, ' ');
eina_strbuf_append(buf, "^\n");
fprintf(stderr, "eolian:%s:%d:%d: %s\n", ls->source, ls->line_number,
ls->column, eina_strbuf_string_get(buf));
_eolian_log_line(ls->source, ls->line_number, ls->column,
"%s", eina_strbuf_string_get(buf));
eina_strbuf_free(buf);
longjmp(ls->err_jmp, EINA_TRUE);
}
@ -1018,7 +1019,7 @@ eo_lexer_set_input(Eo_Lexer *ls, const char *source)
Eina_File *f = eina_file_open(source, EINA_FALSE);
if (!f)
{
fprintf(stderr, "eolian: %s\n", strerror(errno));
_eolian_log("%s", strerror(errno));
longjmp(ls->err_jmp, EINA_TRUE);
}
ls->lookahead.token = -1;
@ -1255,7 +1256,7 @@ eo_lexer_context_push(Eo_Lexer *ls)
Lexer_Ctx *ctx = malloc(sizeof(Lexer_Ctx));
if (!ctx)
{
fprintf(stderr, "eolian: out of memory pushing context\n");
_eolian_log("out of memory pushing context");
longjmp(ls->err_jmp, EINA_TRUE);
}
ctx->line = ls->line_number;

View File

@ -5,6 +5,7 @@
#endif
#include "eo_parser.h"
#include "eolian_priv.h"
#define CASE_LOCK(ls, var, msg) \
if (has_##var) \
@ -1118,10 +1119,10 @@ parse_accessor:
{
if (getenv("EOLIAN_PROPERTY_DOC_WARN"))
{
fprintf(stderr, "eolian:%s:%d:%d: %s doc without property "
"doc for '%s.%s'\n",
prop->base.file, line, col, is_get ? "getter" : "setter",
ls->tmp.kls->full_name, prop->name);
_eolian_log_line(prop->base.file, line, col,
"%s doc without property doc for '%s.%s'",
is_get ? "getter" : "setter",
ls->tmp.kls->full_name, prop->name);
}
}
if (is_get)
@ -2257,11 +2258,8 @@ _get_impl_class(const Eolian_Class *cl, const char *cln)
return NULL;
}
static void
_print_linecol(const Eolian_Object *base)
{
fprintf(stderr, "eolian:%s:%d:%d: ", base->file, base->line, base->column);
}
#define _eo_parser_log(_base, ...) \
_eolian_log_line((_base)->file, (_base)->line, (_base)->column, __VA_ARGS__)
static Eina_Bool
_db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl)
@ -2290,9 +2288,8 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl)
const Eolian_Class *tcl = _get_impl_class(cl, clname);
if (!tcl)
{
_print_linecol(&impl->base);
fprintf(stderr, "class '%s' not found within the inheritance tree of '%s'\n",
clname, cl->full_name);
_eo_parser_log(&impl->base, "class '%s' not found within the inheritance tree of '%s'",
clname, cl->full_name);
return EINA_FALSE;
}
@ -2301,8 +2298,7 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl)
const Eolian_Function *fid = eolian_class_function_get_by_name(tcl, fnname, EOLIAN_UNRESOLVED);
if (!fid)
{
_print_linecol(&impl->base);
fprintf(stderr, "function '%s' not known in class '%s'\n", fnname, clname);
_eo_parser_log(&impl->base, "function '%s' not known in class '%s'", fnname, clname);
return EINA_FALSE;
}
@ -2316,8 +2312,7 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl)
/* property */
if (aftype != EOLIAN_PROPERTY)
{
_print_linecol(&impl->base);
fprintf(stderr, "function '%s' is not a complete property", fnname);
_eo_parser_log(&impl->base, "function '%s' is not a complete property", fnname);
return EINA_FALSE;
}
auto_empty = auto_empty && (impl->set_auto || impl->set_empty);
@ -2327,8 +2322,7 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl)
/* setter */
if ((aftype != EOLIAN_PROP_SET) && (aftype != EOLIAN_PROPERTY))
{
_print_linecol(&impl->base);
fprintf(stderr, "function '%s' doesn't have a setter\n", fnname);
_eo_parser_log(&impl->base, "function '%s' doesn't have a setter", fnname);
return EINA_FALSE;
}
auto_empty = (impl->set_auto || impl->set_empty);
@ -2338,15 +2332,13 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl)
/* getter */
if ((aftype != EOLIAN_PROP_GET) && (aftype != EOLIAN_PROPERTY))
{
_print_linecol(&impl->base);
fprintf(stderr, "function '%s' doesn't have a getter\n", fnname);
_eo_parser_log(&impl->base, "function '%s' doesn't have a getter", fnname);
return EINA_FALSE;
}
}
else if (aftype != EOLIAN_METHOD)
{
_print_linecol(&impl->base);
fprintf(stderr, "function '%s' is not a method\n", fnname);
_eo_parser_log(&impl->base, "function '%s' is not a method", fnname);
return EINA_FALSE;
}
@ -2355,8 +2347,7 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl)
/* only allow explicit implements from other classes, besides auto and
* empty... also prevents pure virtuals from being implemented
*/
_print_linecol(&impl->base);
fprintf(stderr, "invalid implement '%s'\n", impl->full_name);
_eo_parser_log(&impl->base, "invalid implement '%s'", impl->full_name);
return EINA_FALSE;
}
@ -2380,8 +2371,7 @@ _db_fill_implements(Eolian_Class *cl)
Eina_Bool prop = (impl->is_prop_get || impl->is_prop_set);
if (eina_hash_find(prop ? pth : th, impl->full_name))
{
_print_linecol(&impl->base);
fprintf(stderr, "duplicate implement '%s'\n", impl->full_name);
_eo_parser_log(&impl->base, "duplicate implement '%s'", impl->full_name);
ret = EINA_FALSE;
goto end;
}
@ -2422,8 +2412,7 @@ _db_fill_ctors(Eolian_Class *cl)
{
if (eina_hash_find(th, ctor->full_name))
{
_print_linecol(&ctor->base);
fprintf(stderr, "duplicate ctor '%s'\n", ctor->full_name);
_eo_parser_log(&ctor->base, "duplicate ctor '%s'", ctor->full_name);
ret = EINA_FALSE;
goto end;
}
@ -2439,9 +2428,8 @@ _db_fill_ctors(Eolian_Class *cl)
const Eolian_Class *tcl = _get_impl_class(cl, cnbuf);
if (!tcl)
{
_print_linecol(&ctor->base);
fprintf(stderr, "class '%s' not found within the inheritance "
"tree of '%s'\n", cnbuf, cl->full_name);
_eo_parser_log(&ctor->base, "class '%s' not found within the inheritance tree of '%s'",
cnbuf, cl->full_name);
ret = EINA_FALSE;
goto end;
}
@ -2449,8 +2437,7 @@ _db_fill_ctors(Eolian_Class *cl)
const Eolian_Function *cfunc = eolian_constructor_function_get(ctor);
if (!cfunc)
{
_print_linecol(&ctor->base);
fprintf(stderr, "unable to find function '%s'\n", ctor->full_name);
_eo_parser_log(&ctor->base, "unable to find function '%s'", ctor->full_name);
ret = EINA_FALSE;
goto end;
}
@ -2474,7 +2461,7 @@ eo_parser_database_fill(const char *filename, Eina_Bool eot)
Eo_Lexer *ls = eo_lexer_new(filename);
if (!ls)
{
fprintf(stderr, "eolian: unable to create lexer for file '%s'\n", filename);
_eolian_log("unable to create lexer for file '%s'", filename);
goto error;
}
@ -2491,7 +2478,7 @@ eo_parser_database_fill(const char *filename, Eina_Bool eot)
if (!(cl = ls->tmp.kls))
{
fprintf(stderr, "eolian: no class for file '%s'\n", filename);
_eolian_log("eolian: no class for file '%s'", filename);
goto error;
}
ls->tmp.kls = NULL;

View File

@ -6,6 +6,7 @@
#include <Eina.h>
#include "eo_parser.h"
#include "eolian_database.h"
#include "eolian_priv.h"
Eina_Hash *_classes = NULL;
Eina_Hash *_aliases = NULL;
@ -675,7 +676,7 @@ _eolian_file_parse_nodep(const char *filepath)
is_eo = eina_str_has_suffix(filepath, EO_SUFFIX);
if (!is_eo && !eina_str_has_suffix(filepath, EOT_SUFFIX))
{
fprintf(stderr, "eolian: file '%s' doesn't have a correct extension\n", filepath);
_eolian_log("file '%s' doesn't have a correct extension", filepath);
return EINA_FALSE;
}
if (!(eopath = eina_hash_find(is_eo ? _filenames : _tfilenames, filepath)))

View File

@ -0,0 +1,60 @@
#ifndef EOLIAN_PRIV_H
#define EOLIAN_PRIV_H
#include <Eina.h>
#include <stdio.h>
#include <stdarg.h>
static inline void _eolian_log_line(const char *file, int line, int column, const char *fmt, ...) EINA_ARG_NONNULL(1, 4) EINA_PRINTF(4, 5);
static inline void _eolian_log(const char *fmt, ...) EINA_ARG_NONNULL(1) EINA_PRINTF(1, 2);
static inline void
_eolian_log_line(const char *file, int line, int column, const char *fmt, ...)
{
Eina_Strbuf *sb = eina_strbuf_new();
va_list args;
va_start(args, fmt);
eina_strbuf_append_vprintf(sb, fmt, args);
va_end(args);
if (!eina_log_color_disable_get())
{
fprintf(stderr, EINA_COLOR_RED "eolian" EINA_COLOR_RESET ": "
EINA_COLOR_WHITE "%s" EINA_COLOR_RESET ":%d:%d: "
EINA_COLOR_ORANGE "%s\n" EINA_COLOR_RESET,
file, line, column, eina_strbuf_string_get(sb));
}
else
{
fprintf(stderr, "eolian: %s:%d:%d: %s\n", file, line, column,
eina_strbuf_string_get(sb));
}
eina_strbuf_free(sb);
}
static inline void
_eolian_log(const char *fmt, ...)
{
Eina_Strbuf *sb = eina_strbuf_new();
va_list args;
va_start(args, fmt);
eina_strbuf_append_vprintf(sb, fmt, args);
va_end(args);
if (!eina_log_color_disable_get())
{
fprintf(stderr, EINA_COLOR_RED "eolian" EINA_COLOR_RESET ": "
EINA_COLOR_ORANGE "%s\n" EINA_COLOR_RESET,
eina_strbuf_string_get(sb));
}
else
{
fprintf(stderr, "eolian: %s\n", eina_strbuf_string_get(sb));
}
eina_strbuf_free(sb);
}
#endif