3 * Copyright (C) 2006-2008 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Jürg Billeter <j@bitron.ch>
26 * Namespace to centralize reporting warnings and errors.
28 namespace Vala
.Report
{
32 public bool verbose_errors
;
35 * Set the error verbosity.
37 public void set_verbose_errors (bool verbose
) {
38 verbose_errors
= verbose
;
42 * Returns the total number of warnings reported.
44 public int get_warnings () {
49 * Returns the total number of errors reported.
51 public int get_errors () {
56 * Pretty-print the actual line of offending code if possible.
58 public void report_source (SourceReference source
) {
59 if (source
.first_line
!= source
.last_line
) {
60 // FIXME Cannot report multi-line issues currently
64 string offending_line
= source
.file
.get_source_line (source
.first_line
);
66 if (offending_line
!= null) {
67 stderr
.printf ("%s\n", offending_line
);
70 /* We loop in this manner so that we don't fall over on differing
71 * tab widths. This means we get the ^s in the right places.
73 for (idx
= 1; idx
< source
.first_column
; ++idx
) {
74 if (offending_line
[idx
- 1] == '\t') {
81 for (idx
= source
.first_column
; idx
<= source
.last_column
; ++idx
) {
82 if (offending_line
[idx
- 1] == '\t') {
94 * Reports the specified message as warning.
96 * @param source reference to source code
97 * @param message warning message
99 public void warning (SourceReference? source
, string message
) {
101 if (source
== null) {
102 stderr
.printf ("warning: %s\n", message
);
104 stderr
.printf ("%s: warning: %s\n", source
.to_string (), message
);
105 if (verbose_errors
) {
106 report_source (source
);
112 * Reports the specified message as error.
114 * @param source reference to source code
115 * @param message error message
117 public void error (SourceReference? source
, string message
) {
119 if (source
== null) {
120 stderr
.printf ("error: %s\n", message
);
122 stderr
.printf ("%s: error: %s\n", source
.to_string (), message
);
123 if (verbose_errors
) {
124 report_source (source
);