Put some diagnostic functions into a separate file.
authorChristoph Mallon <christoph.mallon@gmx.de>
Wed, 5 Dec 2007 20:30:16 +0000 (20:30 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Wed, 5 Dec 2007 20:30:16 +0000 (20:30 +0000)
[r18619]

Makefile
diagnostic.c [new file with mode: 0644]
diagnostic.h [new file with mode: 0644]
parser.c

index 45920e3..bcc4b13 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -26,6 +26,7 @@ SOURCES := \
        adt/xmalloc.c \
        ast.c \
        ast2firm.c \
+       diagnostic.c \
        lexer.c \
        main.c \
        parser.c \
diff --git a/diagnostic.c b/diagnostic.c
new file mode 100644 (file)
index 0000000..952bf19
--- /dev/null
@@ -0,0 +1,33 @@
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "diagnostic.h"
+
+
+void parser_print_prefix_pos(const source_position_t pos)
+{
+       fprintf(stderr, "%s:%u: ", pos.input_name, pos.linenr);
+}
+
+void parser_print_warning_prefix_pos(const source_position_t pos)
+{
+       parser_print_prefix_pos(pos);
+       fputs("warning: ", stderr);
+}
+
+void parse_warning_pos(const source_position_t pos, const char *const message)
+{
+       parser_print_prefix_pos(pos);
+       fprintf(stderr, "warning: %s\n", message);
+}
+
+void parse_warning_posf(const source_position_t pos, const char *const fmt, ...)
+{
+       parser_print_prefix_pos(pos);
+       fputs("warning: ", stderr);
+       va_list ap;
+       va_start(ap, fmt);
+       vfprintf(stderr, fmt, ap);
+       va_end(ap);
+       fputc('\n', stderr);
+}
diff --git a/diagnostic.h b/diagnostic.h
new file mode 100644 (file)
index 0000000..44e74c8
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef DIAGNOSTIC_H
+#define DIAGNOSTIC_H
+
+#include "token_t.h"
+
+
+void parser_print_prefix_pos(source_position_t);
+void parser_print_warning_prefix_pos(source_position_t);
+void parse_warning_pos(source_position_t, const char *message);
+void parse_warning_posf(source_position_t, const char *fmt, ...);
+
+#endif
index b451a95..4adcec0 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -4,6 +4,7 @@
 #include <stdarg.h>
 #include <stdbool.h>
 
+#include "diagnostic.h"
 #include "parser.h"
 #include "lexer.h"
 #include "token_t.h"
@@ -304,14 +305,6 @@ static void error(void)
 #endif
 }
 
-static void parser_print_prefix_pos(const source_position_t source_position)
-{
-    fputs(source_position.input_name, stderr);
-    fputc(':', stderr);
-    fprintf(stderr, "%u", source_position.linenr);
-    fputs(": ", stderr);
-}
-
 static void parser_print_error_prefix_pos(
                const source_position_t source_position)
 {
@@ -331,25 +324,11 @@ static void parse_error(const char *message)
        fprintf(stderr, "parse error: %s\n", message);
 }
 
-static void parser_print_warning_prefix_pos(
-               const source_position_t source_position)
-{
-       parser_print_prefix_pos(source_position);
-       fputs("warning: ", stderr);
-}
-
 static void parser_print_warning_prefix(void)
 {
        parser_print_warning_prefix_pos(token.source_position);
 }
 
-static void parse_warning_pos(const source_position_t source_position,
-                              const char *const message)
-{
-       parser_print_prefix_pos(source_position);
-       fprintf(stderr, "warning: %s\n", message);
-}
-
 static void parse_warning(const char *message)
 {
        parse_warning_pos(token.source_position, message);