summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-10-31 14:20:09 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-10-31 14:52:34 +0900
commitc1d21cef8958da5d8a6f643f57bea4a7906385b2 (patch)
treedf981278b4987e2b9e73796ed96bc1c37bc8d81f
parent1adb93b3e5ebee9ebc2c9d9a867d70099f27bbad (diff)
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.
-rw-r--r--src/Makefile_Eolian.am1
-rw-r--r--src/lib/eolian/database_class_api.c3
-rw-r--r--src/lib/eolian/database_expr.c3
-rw-r--r--src/lib/eolian/database_validate.c7
-rw-r--r--src/lib/eolian/eo_lexer.c9
-rw-r--r--src/lib/eolian/eo_parser.c57
-rw-r--r--src/lib/eolian/eolian_database.c3
-rw-r--r--src/lib/eolian/eolian_priv.h60
8 files changed, 98 insertions, 45 deletions
diff --git a/src/Makefile_Eolian.am b/src/Makefile_Eolian.am
index 09fa4d7085..a067ec0b7b 100644
--- a/src/Makefile_Eolian.am
+++ b/src/Makefile_Eolian.am
@@ -12,6 +12,7 @@ lib_eolian_libeolian_la_SOURCES = \
12 lib/eolian/eo_parser.c \ 12 lib/eolian/eo_parser.c \
13 lib/eolian/eo_parser.h \ 13 lib/eolian/eo_parser.h \
14 lib/eolian/eolian.c \ 14 lib/eolian/eolian.c \
15 lib/eolian/eolian_priv.h \
15 lib/eolian/eolian_database.c \ 16 lib/eolian/eolian_database.c \
16 lib/eolian/eolian_database.h \ 17 lib/eolian/eolian_database.h \
17 lib/eolian/database_class.c \ 18 lib/eolian/database_class.c \
diff --git a/src/lib/eolian/database_class_api.c b/src/lib/eolian/database_class_api.c
index 68e9338283..963a874f03 100644
--- a/src/lib/eolian/database_class_api.c
+++ b/src/lib/eolian/database_class_api.c
@@ -4,6 +4,7 @@
4 4
5#include <Eina.h> 5#include <Eina.h>
6#include "eolian_database.h" 6#include "eolian_database.h"
7#include "eolian_priv.h"
7 8
8EAPI Eina_Stringshare * 9EAPI Eina_Stringshare *
9eolian_class_file_get(const Eolian_Class *cl) 10eolian_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,
147 } 148 }
148 } 149 }
149 150
150 fprintf(stderr, "eolian: function '%s' not found in class '%s'\n", func_name, cl->name); 151 _eolian_log("function '%s' not found in class '%s'", func_name, cl->name);
151 return NULL; 152 return NULL;
152} 153}
153 154
diff --git a/src/lib/eolian/database_expr.c b/src/lib/eolian/database_expr.c
index 09be53e7f1..6a3b1d52f1 100644
--- a/src/lib/eolian/database_expr.c
+++ b/src/lib/eolian/database_expr.c
@@ -6,11 +6,12 @@
6 6
7#include <Eina.h> 7#include <Eina.h>
8#include "eolian_database.h" 8#include "eolian_database.h"
9#include "eolian_priv.h"
9 10
10static Eina_Bool 11static Eina_Bool
11node_error(const Eolian_Object *obj, const char *msg) 12node_error(const Eolian_Object *obj, const char *msg)
12{ 13{
13 fprintf(stderr, "eolian:%s:%d:%d: %s\n", obj->file, obj->line, obj->column, msg); 14 _eolian_log_line(obj->file, obj->line, obj->column, "%s", msg);
14 return EINA_FALSE; 15 return EINA_FALSE;
15} 16}
16 17
diff --git a/src/lib/eolian/database_validate.c b/src/lib/eolian/database_validate.c
index ed005edb3b..6ed286866b 100644
--- a/src/lib/eolian/database_validate.c
+++ b/src/lib/eolian/database_validate.c
@@ -6,6 +6,7 @@
6#endif 6#endif
7 7
8#include "eo_lexer.h" 8#include "eo_lexer.h"
9#include "eolian_priv.h"
9 10
10static Eina_Bool 11static Eina_Bool
11_validate(Eolian_Object *obj) 12_validate(Eolian_Object *obj)
@@ -33,8 +34,8 @@ _validate_docstr(Eina_Stringshare *str, const Eolian_Object *info)
33 if (eolian_doc_token_ref_get(NULL, &tok, NULL, NULL) == EOLIAN_DOC_REF_INVALID) 34 if (eolian_doc_token_ref_get(NULL, &tok, NULL, NULL) == EOLIAN_DOC_REF_INVALID)
34 { 35 {
35 char *refn = eolian_doc_token_text_get(&tok); 36 char *refn = eolian_doc_token_text_get(&tok);
36 fprintf(stderr, "eolian:%s:%d:%d: failed validating reference '%s'\n", 37 _eolian_log_line(info->file, info->line, info->column,
37 info->file, info->line, info->column, refn); 38 "failed validating reference '%s'", refn);
38 free(refn); 39 free(refn);
39 ret = EINA_FALSE; 40 ret = EINA_FALSE;
40 break; 41 break;
@@ -98,7 +99,7 @@ _ef_map_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED,
98static Eina_Bool 99static Eina_Bool
99_obj_error(const Eolian_Object *o, const char *msg) 100_obj_error(const Eolian_Object *o, const char *msg)
100{ 101{
101 fprintf(stderr, "eolian:%s:%d:%d: %s\n", o->file, o->line, o->column, msg); 102 _eolian_log_line(o->file, o->line, o->column, "%s", msg);
102 return EINA_FALSE; 103 return EINA_FALSE;
103} 104}
104 105
diff --git a/src/lib/eolian/eo_lexer.c b/src/lib/eolian/eo_lexer.c
index c081fce4a7..d3f3f09b03 100644
--- a/src/lib/eolian/eo_lexer.c
+++ b/src/lib/eolian/eo_lexer.c
@@ -10,6 +10,7 @@
10#include <assert.h> 10#include <assert.h>
11 11
12#include "eo_lexer.h" 12#include "eo_lexer.h"
13#include "eolian_priv.h"
13 14
14static int lastbytes = 0; 15static int lastbytes = 0;
15 16
@@ -107,8 +108,8 @@ throw(Eo_Lexer *ls, const char *fmt, ...)
107 for (i = 0; i < ls->column; ++i) 108 for (i = 0; i < ls->column; ++i)
108 eina_strbuf_append_char(buf, ' '); 109 eina_strbuf_append_char(buf, ' ');
109 eina_strbuf_append(buf, "^\n"); 110 eina_strbuf_append(buf, "^\n");
110 fprintf(stderr, "eolian:%s:%d:%d: %s\n", ls->source, ls->line_number, 111 _eolian_log_line(ls->source, ls->line_number, ls->column,
111 ls->column, eina_strbuf_string_get(buf)); 112 "%s", eina_strbuf_string_get(buf));
112 eina_strbuf_free(buf); 113 eina_strbuf_free(buf);
113 longjmp(ls->err_jmp, EINA_TRUE); 114 longjmp(ls->err_jmp, EINA_TRUE);
114} 115}
@@ -1018,7 +1019,7 @@ eo_lexer_set_input(Eo_Lexer *ls, const char *source)
1018 Eina_File *f = eina_file_open(source, EINA_FALSE); 1019 Eina_File *f = eina_file_open(source, EINA_FALSE);
1019 if (!f) 1020 if (!f)
1020 { 1021 {
1021 fprintf(stderr, "eolian: %s\n", strerror(errno)); 1022 _eolian_log("%s", strerror(errno));
1022 longjmp(ls->err_jmp, EINA_TRUE); 1023 longjmp(ls->err_jmp, EINA_TRUE);
1023 } 1024 }
1024 ls->lookahead.token = -1; 1025 ls->lookahead.token = -1;
@@ -1255,7 +1256,7 @@ eo_lexer_context_push(Eo_Lexer *ls)
1255 Lexer_Ctx *ctx = malloc(sizeof(Lexer_Ctx)); 1256 Lexer_Ctx *ctx = malloc(sizeof(Lexer_Ctx));
1256 if (!ctx) 1257 if (!ctx)
1257 { 1258 {
1258 fprintf(stderr, "eolian: out of memory pushing context\n"); 1259 _eolian_log("out of memory pushing context");
1259 longjmp(ls->err_jmp, EINA_TRUE); 1260 longjmp(ls->err_jmp, EINA_TRUE);
1260 } 1261 }
1261 ctx->line = ls->line_number; 1262 ctx->line = ls->line_number;
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index e6d8b6bbb4..aa46dd95f1 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -5,6 +5,7 @@
5#endif 5#endif
6 6
7#include "eo_parser.h" 7#include "eo_parser.h"
8#include "eolian_priv.h"
8 9
9#define CASE_LOCK(ls, var, msg) \ 10#define CASE_LOCK(ls, var, msg) \
10 if (has_##var) \ 11 if (has_##var) \
@@ -1118,10 +1119,10 @@ parse_accessor:
1118 { 1119 {
1119 if (getenv("EOLIAN_PROPERTY_DOC_WARN")) 1120 if (getenv("EOLIAN_PROPERTY_DOC_WARN"))
1120 { 1121 {
1121 fprintf(stderr, "eolian:%s:%d:%d: %s doc without property " 1122 _eolian_log_line(prop->base.file, line, col,
1122 "doc for '%s.%s'\n", 1123 "%s doc without property doc for '%s.%s'",
1123 prop->base.file, line, col, is_get ? "getter" : "setter", 1124 is_get ? "getter" : "setter",
1124 ls->tmp.kls->full_name, prop->name); 1125 ls->tmp.kls->full_name, prop->name);
1125 } 1126 }
1126 } 1127 }
1127 if (is_get) 1128 if (is_get)
@@ -2257,11 +2258,8 @@ _get_impl_class(const Eolian_Class *cl, const char *cln)
2257 return NULL; 2258 return NULL;
2258} 2259}
2259 2260
2260static void 2261#define _eo_parser_log(_base, ...) \
2261_print_linecol(const Eolian_Object *base) 2262 _eolian_log_line((_base)->file, (_base)->line, (_base)->column, __VA_ARGS__)
2262{
2263 fprintf(stderr, "eolian:%s:%d:%d: ", base->file, base->line, base->column);
2264}
2265 2263
2266static Eina_Bool 2264static Eina_Bool
2267_db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl) 2265_db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl)
@@ -2290,9 +2288,8 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl)
2290 const Eolian_Class *tcl = _get_impl_class(cl, clname); 2288 const Eolian_Class *tcl = _get_impl_class(cl, clname);
2291 if (!tcl) 2289 if (!tcl)
2292 { 2290 {
2293 _print_linecol(&impl->base); 2291 _eo_parser_log(&impl->base, "class '%s' not found within the inheritance tree of '%s'",
2294 fprintf(stderr, "class '%s' not found within the inheritance tree of '%s'\n", 2292 clname, cl->full_name);
2295 clname, cl->full_name);
2296 return EINA_FALSE; 2293 return EINA_FALSE;
2297 } 2294 }
2298 2295
@@ -2301,8 +2298,7 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl)
2301 const Eolian_Function *fid = eolian_class_function_get_by_name(tcl, fnname, EOLIAN_UNRESOLVED); 2298 const Eolian_Function *fid = eolian_class_function_get_by_name(tcl, fnname, EOLIAN_UNRESOLVED);
2302 if (!fid) 2299 if (!fid)
2303 { 2300 {
2304 _print_linecol(&impl->base); 2301 _eo_parser_log(&impl->base, "function '%s' not known in class '%s'", fnname, clname);
2305 fprintf(stderr, "function '%s' not known in class '%s'\n", fnname, clname);
2306 return EINA_FALSE; 2302 return EINA_FALSE;
2307 } 2303 }
2308 2304
@@ -2316,8 +2312,7 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl)
2316 /* property */ 2312 /* property */
2317 if (aftype != EOLIAN_PROPERTY) 2313 if (aftype != EOLIAN_PROPERTY)
2318 { 2314 {
2319 _print_linecol(&impl->base); 2315 _eo_parser_log(&impl->base, "function '%s' is not a complete property", fnname);
2320 fprintf(stderr, "function '%s' is not a complete property", fnname);
2321 return EINA_FALSE; 2316 return EINA_FALSE;
2322 } 2317 }
2323 auto_empty = auto_empty && (impl->set_auto || impl->set_empty); 2318 auto_empty = auto_empty && (impl->set_auto || impl->set_empty);
@@ -2327,8 +2322,7 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl)
2327 /* setter */ 2322 /* setter */
2328 if ((aftype != EOLIAN_PROP_SET) && (aftype != EOLIAN_PROPERTY)) 2323 if ((aftype != EOLIAN_PROP_SET) && (aftype != EOLIAN_PROPERTY))
2329 { 2324 {
2330 _print_linecol(&impl->base); 2325 _eo_parser_log(&impl->base, "function '%s' doesn't have a setter", fnname);
2331 fprintf(stderr, "function '%s' doesn't have a setter\n", fnname);
2332 return EINA_FALSE; 2326 return EINA_FALSE;
2333 } 2327 }
2334 auto_empty = (impl->set_auto || impl->set_empty); 2328 auto_empty = (impl->set_auto || impl->set_empty);
@@ -2338,15 +2332,13 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl)
2338 /* getter */ 2332 /* getter */
2339 if ((aftype != EOLIAN_PROP_GET) && (aftype != EOLIAN_PROPERTY)) 2333 if ((aftype != EOLIAN_PROP_GET) && (aftype != EOLIAN_PROPERTY))
2340 { 2334 {
2341 _print_linecol(&impl->base); 2335 _eo_parser_log(&impl->base, "function '%s' doesn't have a getter", fnname);
2342 fprintf(stderr, "function '%s' doesn't have a getter\n", fnname);
2343 return EINA_FALSE; 2336 return EINA_FALSE;
2344 } 2337 }
2345 } 2338 }
2346 else if (aftype != EOLIAN_METHOD) 2339 else if (aftype != EOLIAN_METHOD)
2347 { 2340 {
2348 _print_linecol(&impl->base); 2341 _eo_parser_log(&impl->base, "function '%s' is not a method", fnname);
2349 fprintf(stderr, "function '%s' is not a method\n", fnname);
2350 return EINA_FALSE; 2342 return EINA_FALSE;
2351 } 2343 }
2352 2344
@@ -2355,8 +2347,7 @@ _db_fill_implement(Eolian_Class *cl, Eolian_Implement *impl)
2355 /* only allow explicit implements from other classes, besides auto and 2347 /* only allow explicit implements from other classes, besides auto and
2356 * empty... also prevents pure virtuals from being implemented 2348 * empty... also prevents pure virtuals from being implemented
2357 */ 2349 */
2358 _print_linecol(&impl->base); 2350 _eo_parser_log(&impl->base, "invalid implement '%s'", impl->full_name);
2359 fprintf(stderr, "invalid implement '%s'\n", impl->full_name);
2360 return EINA_FALSE; 2351 return EINA_FALSE;
2361 } 2352 }
2362 2353
@@ -2380,8 +2371,7 @@ _db_fill_implements(Eolian_Class *cl)
2380 Eina_Bool prop = (impl->is_prop_get || impl->is_prop_set); 2371 Eina_Bool prop = (impl->is_prop_get || impl->is_prop_set);
2381 if (eina_hash_find(prop ? pth : th, impl->full_name)) 2372 if (eina_hash_find(prop ? pth : th, impl->full_name))
2382 { 2373 {
2383 _print_linecol(&impl->base); 2374 _eo_parser_log(&impl->base, "duplicate implement '%s'", impl->full_name);
2384 fprintf(stderr, "duplicate implement '%s'\n", impl->full_name);
2385 ret = EINA_FALSE; 2375 ret = EINA_FALSE;
2386 goto end; 2376 goto end;
2387 } 2377 }
@@ -2422,8 +2412,7 @@ _db_fill_ctors(Eolian_Class *cl)
2422 { 2412 {
2423 if (eina_hash_find(th, ctor->full_name)) 2413 if (eina_hash_find(th, ctor->full_name))
2424 { 2414 {
2425 _print_linecol(&ctor->base); 2415 _eo_parser_log(&ctor->base, "duplicate ctor '%s'", ctor->full_name);
2426 fprintf(stderr, "duplicate ctor '%s'\n", ctor->full_name);
2427 ret = EINA_FALSE; 2416 ret = EINA_FALSE;
2428 goto end; 2417 goto end;
2429 } 2418 }
@@ -2439,9 +2428,8 @@ _db_fill_ctors(Eolian_Class *cl)
2439 const Eolian_Class *tcl = _get_impl_class(cl, cnbuf); 2428 const Eolian_Class *tcl = _get_impl_class(cl, cnbuf);
2440 if (!tcl) 2429 if (!tcl)
2441 { 2430 {
2442 _print_linecol(&ctor->base); 2431 _eo_parser_log(&ctor->base, "class '%s' not found within the inheritance tree of '%s'",
2443 fprintf(stderr, "class '%s' not found within the inheritance " 2432 cnbuf, cl->full_name);
2444 "tree of '%s'\n", cnbuf, cl->full_name);
2445 ret = EINA_FALSE; 2433 ret = EINA_FALSE;
2446 goto end; 2434 goto end;
2447 } 2435 }
@@ -2449,8 +2437,7 @@ _db_fill_ctors(Eolian_Class *cl)
2449 const Eolian_Function *cfunc = eolian_constructor_function_get(ctor); 2437 const Eolian_Function *cfunc = eolian_constructor_function_get(ctor);
2450 if (!cfunc) 2438 if (!cfunc)
2451 { 2439 {
2452 _print_linecol(&ctor->base); 2440 _eo_parser_log(&ctor->base, "unable to find function '%s'", ctor->full_name);
2453 fprintf(stderr, "unable to find function '%s'\n", ctor->full_name);
2454 ret = EINA_FALSE; 2441 ret = EINA_FALSE;
2455 goto end; 2442 goto end;
2456 } 2443 }
@@ -2474,7 +2461,7 @@ eo_parser_database_fill(const char *filename, Eina_Bool eot)
2474 Eo_Lexer *ls = eo_lexer_new(filename); 2461 Eo_Lexer *ls = eo_lexer_new(filename);
2475 if (!ls) 2462 if (!ls)
2476 { 2463 {
2477 fprintf(stderr, "eolian: unable to create lexer for file '%s'\n", filename); 2464 _eolian_log("unable to create lexer for file '%s'", filename);
2478 goto error; 2465 goto error;
2479 } 2466 }
2480 2467
@@ -2491,7 +2478,7 @@ eo_parser_database_fill(const char *filename, Eina_Bool eot)
2491 2478
2492 if (!(cl = ls->tmp.kls)) 2479 if (!(cl = ls->tmp.kls))
2493 { 2480 {
2494 fprintf(stderr, "eolian: no class for file '%s'\n", filename); 2481 _eolian_log("eolian: no class for file '%s'", filename);
2495 goto error; 2482 goto error;
2496 } 2483 }
2497 ls->tmp.kls = NULL; 2484 ls->tmp.kls = NULL;
diff --git a/src/lib/eolian/eolian_database.c b/src/lib/eolian/eolian_database.c
index 4ba4b69f7d..eacc5b94fb 100644
--- a/src/lib/eolian/eolian_database.c
+++ b/src/lib/eolian/eolian_database.c
@@ -6,6 +6,7 @@
6#include <Eina.h> 6#include <Eina.h>
7#include "eo_parser.h" 7#include "eo_parser.h"
8#include "eolian_database.h" 8#include "eolian_database.h"
9#include "eolian_priv.h"
9 10
10Eina_Hash *_classes = NULL; 11Eina_Hash *_classes = NULL;
11Eina_Hash *_aliases = NULL; 12Eina_Hash *_aliases = NULL;
@@ -675,7 +676,7 @@ _eolian_file_parse_nodep(const char *filepath)
675 is_eo = eina_str_has_suffix(filepath, EO_SUFFIX); 676 is_eo = eina_str_has_suffix(filepath, EO_SUFFIX);
676 if (!is_eo && !eina_str_has_suffix(filepath, EOT_SUFFIX)) 677 if (!is_eo && !eina_str_has_suffix(filepath, EOT_SUFFIX))
677 { 678 {
678 fprintf(stderr, "eolian: file '%s' doesn't have a correct extension\n", filepath); 679 _eolian_log("file '%s' doesn't have a correct extension", filepath);
679 return EINA_FALSE; 680 return EINA_FALSE;
680 } 681 }
681 if (!(eopath = eina_hash_find(is_eo ? _filenames : _tfilenames, filepath))) 682 if (!(eopath = eina_hash_find(is_eo ? _filenames : _tfilenames, filepath)))
diff --git a/src/lib/eolian/eolian_priv.h b/src/lib/eolian/eolian_priv.h
new file mode 100644
index 0000000000..58c0f229ae
--- /dev/null
+++ b/src/lib/eolian/eolian_priv.h
@@ -0,0 +1,60 @@
1#ifndef EOLIAN_PRIV_H
2#define EOLIAN_PRIV_H
3
4#include <Eina.h>
5#include <stdio.h>
6#include <stdarg.h>
7
8static inline void _eolian_log_line(const char *file, int line, int column, const char *fmt, ...) EINA_ARG_NONNULL(1, 4) EINA_PRINTF(4, 5);
9static inline void _eolian_log(const char *fmt, ...) EINA_ARG_NONNULL(1) EINA_PRINTF(1, 2);
10
11static inline void
12_eolian_log_line(const char *file, int line, int column, const char *fmt, ...)
13{
14 Eina_Strbuf *sb = eina_strbuf_new();
15 va_list args;
16
17 va_start(args, fmt);
18 eina_strbuf_append_vprintf(sb, fmt, args);
19 va_end(args);
20
21 if (!eina_log_color_disable_get())
22 {
23 fprintf(stderr, EINA_COLOR_RED "eolian" EINA_COLOR_RESET ": "
24 EINA_COLOR_WHITE "%s" EINA_COLOR_RESET ":%d:%d: "
25 EINA_COLOR_ORANGE "%s\n" EINA_COLOR_RESET,
26 file, line, column, eina_strbuf_string_get(sb));
27 }
28 else
29 {
30 fprintf(stderr, "eolian: %s:%d:%d: %s\n", file, line, column,
31 eina_strbuf_string_get(sb));
32 }
33 eina_strbuf_free(sb);
34}
35
36static inline void
37_eolian_log(const char *fmt, ...)
38{
39 Eina_Strbuf *sb = eina_strbuf_new();
40 va_list args;
41
42 va_start(args, fmt);
43 eina_strbuf_append_vprintf(sb, fmt, args);
44 va_end(args);
45
46 if (!eina_log_color_disable_get())
47 {
48 fprintf(stderr, EINA_COLOR_RED "eolian" EINA_COLOR_RESET ": "
49 EINA_COLOR_ORANGE "%s\n" EINA_COLOR_RESET,
50 eina_strbuf_string_get(sb));
51 }
52 else
53 {
54 fprintf(stderr, "eolian: %s\n", eina_strbuf_string_get(sb));
55 }
56 eina_strbuf_free(sb);
57}
58
59#endif
60