Fixed error message.
[cparser] / diagnostic.c
index 782c657..b2ba266 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "diagnostic.h"
 #include "adt/error.h"
+#include "entity_t.h"
 #include "symbol_t.h"
 #include "token_t.h"
 #include "ast.h"
 #include "warning.h"
 
 /** Number of occurred diagnostics. */
-unsigned diagnostic_count = 0;
+unsigned diagnostic_count        = 0;
 /** Number of occurred errors. */
-unsigned error_count      = 0;
+unsigned error_count             = 0;
 /** Number of occurred warnings. */
-unsigned warning_count    = 0;
-bool     show_column      = true;
+unsigned warning_count           = 0;
+bool     show_column             = true;
+bool     diagnostics_show_option = true;
 
 static const source_position_t *curr_pos = NULL;
 
@@ -168,6 +170,22 @@ static void diagnosticvf(const char *const fmt, va_list ap)
                                        break;
                                }
 
+                               case 'N': {
+                                       entity_t const *const ent = va_arg(ap, entity_t const*);
+                                       if (extended && is_declaration(ent)) {
+                                               print_type_ext(ent->declaration.type, ent->base.symbol, NULL);
+                                       } else {
+                                               char     const *const kind = get_entity_kind_name(ent->kind);
+                                               symbol_t const *const sym  = ent->base.symbol;
+                                               if (sym) {
+                                                       fprintf(stderr, "%s %s", kind, sym->string);
+                                               } else {
+                                                       fprintf(stderr, "anonymous %s", kind);
+                                               }
+                                       }
+                                       break;
+                               }
+
                                case 'P': {
                                        const source_position_t *pos = va_arg(ap, const source_position_t *);
                                        print_source_position(stderr, pos);
@@ -202,15 +220,16 @@ static void diagnosticposvf(source_position_t const *const pos, char const *cons
        fprintf(out, " %s: ", kind);
        curr_pos = pos;
        diagnosticvf(fmt, ap);
-       fputc('\n', out);
 }
 
 static void errorvf(const source_position_t *pos,
                     const char *const fmt, va_list ap)
 {
+       curr_pos = pos;
        ++error_count;
        diagnosticposvf(pos, "error", fmt, ap);
-       if (warning.fatal_errors)
+       fputc('\n', stderr);
+       if (is_warn_on(WARN_FATAL_ERRORS))
                exit(EXIT_FAILURE);
 }
 
@@ -218,27 +237,34 @@ void errorf(const source_position_t *pos, const char *const fmt, ...)
 {
        va_list ap;
        va_start(ap, fmt);
-       curr_pos = pos;
        errorvf(pos, fmt, ap);
        va_end(ap);
 }
 
-static void warningvf(const source_position_t *pos,
-                      const char *const fmt, va_list ap)
-{
-       ++warning_count;
-       diagnosticposvf(pos, "warning", fmt, ap);
-}
-
-void warningf(const source_position_t *pos, const char *const fmt, ...)
+void warningf(warning_t const warn, source_position_t const* pos, char const *const fmt, ...)
 {
        va_list ap;
        va_start(ap, fmt);
-       curr_pos = pos;
-       if (warning.s_are_errors) {
-               errorvf(pos, fmt, ap);
-       } else {
-               warningvf(pos, fmt, ap);
+       warning_switch_t const *const s = get_warn_switch(warn);
+       switch (s->state) {
+                       char const* kind;
+               case WARN_STATE_ON:
+                       if (is_warn_on(WARN_ERROR)) {
+               case WARN_STATE_ON | WARN_STATE_ERROR:
+                               ++error_count;
+                               kind = "error";
+                       } else {
+               case WARN_STATE_ON | WARN_STATE_NO_ERROR:
+                               ++warning_count;
+                               kind = "warning";
+                       }
+                       diagnosticposvf(pos, kind, fmt, ap);
+                       if (diagnostics_show_option)
+                               fprintf(stderr, " [-W%s]\n", s->name);
+                       break;
+
+               default:
+                       break;
        }
        va_end(ap);
 }
@@ -247,6 +273,7 @@ static void internal_errorvf(const source_position_t *pos,
                     const char *const fmt, va_list ap)
 {
        diagnosticposvf(pos, "internal error", fmt, ap);
+       fputc('\n', stderr);
 }
 
 void internal_errorf(const source_position_t *pos, const char *const fmt, ...)