Made Vala.Report a class instead of a namespace. diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala --- a/compiler/valacompiler.vala +++ b/compiler/valacompiler.vala @@ -80,17 +80,17 @@ class Vala.Compiler : Object { }; private int quit () { - if (Report.get_errors () == 0 && Report.get_warnings () == 0) { + if (context.report.get_errors () == 0 && context.report.get_warnings () == 0) { return 0; } - if (Report.get_errors () == 0) { + if (context.report.get_errors () == 0) { if (!quiet_mode) { - stdout.printf ("Compilation succeeded - %d warning(s)\n", Report.get_warnings ()); + stdout.printf ("Compilation succeeded - %d warning(s)\n", context.report.get_warnings ()); } return 0; } else { if (!quiet_mode) { - stdout.printf ("Compilation failed: %d error(s), %d warning(s)\n", Report.get_errors (), Report.get_warnings ()); + stdout.printf ("Compilation failed: %d error(s), %d warning(s)\n", context.report.get_errors (), context.report.get_warnings ()); } return 1; } @@ -121,12 +121,12 @@ class Vala.Compiler : Object { foreach (string dep in deps_content.split ("\n")) { if (dep != "") { if (!add_package (context, dep)) { - Report.error (null, "%s, dependency of %s, not found in specified Vala API directories".printf (dep, pkg)); + context.report.err (null, "%s, dependency of %s, not found in specified Vala API directories".printf (dep, pkg)); } } } } catch (FileError e) { - Report.error (null, "Unable to read dependency file: %s".printf (e.message)); + context.report.err (null, "Unable to read dependency file: %s".printf (e.message)); } } @@ -178,19 +178,19 @@ class Vala.Compiler : Object { /* default package */ if (!add_package (context, "glib-2.0")) { - Report.error (null, "glib-2.0 not found in specified Vala API directories"); + context.report.err (null, "glib-2.0 not found in specified Vala API directories"); } if (packages != null) { foreach (string package in packages) { if (!add_package (context, package)) { - Report.error (null, "%s not found in specified Vala API directories".printf (package)); + context.report.err (null, "%s not found in specified Vala API directories".printf (package)); } } packages = null; } - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } @@ -209,15 +209,15 @@ class Vala.Compiler : Object { } else if (source.has_suffix (".c")) { context.add_c_source_file (rpath); } else { - Report.error (null, "%s is not a supported source file type. Only .vala, .vapi, .gs, and .c files are supported.".printf (source)); + context.report.err (null, "%s is not a supported source file type. Only .vala, .vapi, .gs, and .c files are supported.".printf (source)); } } else { - Report.error (null, "%s not found".printf (source)); + context.report.err (null, "%s not found".printf (source)); } } sources = null; - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } @@ -227,35 +227,35 @@ class Vala.Compiler : Object { var genie_parser = new Genie.Parser (); genie_parser.parse (context); - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } var attributeprocessor = new AttributeProcessor (); attributeprocessor.process (context); - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } var resolver = new SymbolResolver (); resolver.resolve (context); - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } var analyzer = new SemanticAnalyzer (); analyzer.analyze (context); - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } var cfg_builder = new CFGBuilder (); cfg_builder.build_cfg (context); - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } @@ -263,14 +263,14 @@ class Vala.Compiler : Object { var null_checker = new NullChecker (); null_checker.check (context); - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } } context.codegen.emit (context); - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } diff --git a/gobject/valaccodecompiler.vala b/gobject/valaccodecompiler.vala --- a/gobject/valaccodecompiler.vala +++ b/gobject/valaccodecompiler.vala @@ -67,11 +67,11 @@ public class Vala.CCodeCompiler : Object try { Process.spawn_command_line_sync (pc, out pkgflags, null, out exit_status); if (exit_status != 0) { - Report.error (null, "pkg-config exited with status %d".printf (exit_status)); + context.report.err (null, "pkg-config exited with status %d".printf (exit_status)); return; } } catch (SpawnError e) { - Report.error (null, e.message); + context.report.err (null, e.message); return; } @@ -118,10 +118,10 @@ public class Vala.CCodeCompiler : Object try { Process.spawn_command_line_sync (cmdline, null, null, out exit_status); if (exit_status != 0) { - Report.error (null, "cc exited with status %d".printf (exit_status)); + context.report.err (null, "cc exited with status %d".printf (exit_status)); } } catch (SpawnError e) { - Report.error (null, e.message); + context.report.err (null, e.message); } /* remove generated C source and header files */ diff --git a/gobject/valaccodegeneratorsourcefile.vala b/gobject/valaccodegeneratorsourcefile.vala --- a/gobject/valaccodegeneratorsourcefile.vala +++ b/gobject/valaccodegeneratorsourcefile.vala @@ -268,7 +268,7 @@ public class Vala.CCodeGenerator { source_file.accept_children (this); - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return; } @@ -303,7 +303,7 @@ public class Vala.CCodeGenerator { var writer = new CCodeWriter (source_file.get_cheader_filename ()); if (!writer.open ()) { - Report.error (null, "unable to open `%s' for writing".printf (writer.filename)); + context.report.err (null, "unable to open `%s' for writing".printf (writer.filename)); return; } if (comment != null) { @@ -333,7 +333,7 @@ public class Vala.CCodeGenerator { writer = new CCodeWriter (source_file.get_csource_filename ()); if (!writer.open ()) { - Report.error (null, "unable to open `%s' for writing".printf (writer.filename)); + context.report.err (null, "unable to open `%s' for writing".printf (writer.filename)); return; } writer.line_directives = context.debug; diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -117,6 +117,8 @@ public class Vala.CodeContext : Object { public bool save_cheaders { get { return save_csources || null != library; } } + + public Report report { get; construct set; } private Gee.List source_files = new ArrayList (); private Gee.List c_source_files = new ArrayList (); @@ -142,11 +144,15 @@ public class Vala.CodeContext : Object { */ public CodeGenerator codegen { get; set; } - public CodeContext () { + public CodeContext (Report? report = null) { + this.report = report; } construct { codegen = new CodeGenerator (); + if (report == null) { + report = Report.get(); + } } /** diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala --- a/vala/valagenieparser.vala +++ b/vala/valagenieparser.vala @@ -1690,7 +1690,7 @@ public class Vala.Genie.Parser : CodeVis parse_statements (block); if (!accept (TokenType.DEDENT)) { // only report error if it's not a secondary error - if (Report.get_errors () == 0) { + if (context.report.get_errors () == 0) { Report.error (get_current_src (), "tab indentation is incorrect"); } } @@ -2229,7 +2229,7 @@ public class Vala.Genie.Parser : CodeVis if (!root) { if (!accept (TokenType.DEDENT)) { // only report error if it's not a secondary error - if (Report.get_errors () == 0) { + if (context.report.get_errors () == 0) { Report.error (get_current_src (), "expected dedent"); } } diff --git a/vala/valaparser.vala b/vala/valaparser.vala --- a/vala/valaparser.vala +++ b/vala/valaparser.vala @@ -1339,7 +1339,7 @@ public class Vala.Parser : CodeVisitor { parse_statements (block); if (!accept (TokenType.CLOSE_BRACE)) { // only report error if it's not a secondary error - if (Report.get_errors () == 0) { + if (context.report.get_errors () == 0) { Report.error (get_current_src (), "expected `}'"); } } @@ -1785,7 +1785,7 @@ public class Vala.Parser : CodeVisitor { if (!root) { if (!accept (TokenType.CLOSE_BRACE)) { // only report error if it's not a secondary error - if (Report.get_errors () == 0) { + if (context.report.get_errors () == 0) { Report.error (get_current_src (), "expected `}'"); } } diff --git a/vala/valareport.vala b/vala/valareport.vala --- a/vala/valareport.vala +++ b/vala/valareport.vala @@ -25,16 +25,29 @@ using GLib; /** * Namespace to centralize reporting warnings and errors. */ -namespace Vala.Report { - public int warnings; - public int errors; +public class Vala.Report : Object { + /* should not be accessed directly */ + int warnings; + int errors; - public bool verbose_errors; + static bool verbose_errors; + static Report default_instance; + + /** + * Returns the default Report instance + */ + public static Report get () { + if (default_instance != null) + return default_instance; + else + return default_instance = new Report(); + } + /** * Set the error verbosity. */ - public void set_verbose_errors (bool verbose) { + public static void set_verbose_errors (bool verbose) { verbose_errors = verbose; } @@ -55,7 +68,7 @@ namespace Vala.Report { /** * Pretty-print the actual line of offending code if possible. */ - public void report_source (SourceReference source) { + public static void report_source (SourceReference source) { if (source.first_line != source.last_line) { // FIXME Cannot report multi-line issues currently return; @@ -96,7 +109,7 @@ namespace Vala.Report { * @param source reference to source code * @param message warning message */ - public void warning (SourceReference? source, string message) { + public virtual void warn (SourceReference? source, string message) { warnings++; if (source == null) { stderr.printf ("warning: %s\n", message); @@ -114,7 +127,7 @@ namespace Vala.Report { * @param source reference to source code * @param message error message */ - public void error (SourceReference? source, string message) { + public virtual void err (SourceReference? source, string message) { errors++; if (source == null) { stderr.printf ("error: %s\n", message); @@ -125,4 +138,12 @@ namespace Vala.Report { } } } + + /* Convenience methods calling warn and err on correct instance */ + public static void warning (SourceReference source, string message) { + source.file.context.report.warn(source, message); + } + public static void error (SourceReference source, string message) { + source.file.context.report.err(source, message); + } } diff --git a/vala/valasourcefile.vala b/vala/valasourcefile.vala --- a/vala/valasourcefile.vala +++ b/vala/valasourcefile.vala @@ -426,7 +426,7 @@ public class Vala.SourceFile : Object { try { mapped_file = new MappedFile (filename, false); } catch (FileError e) { - Report.error (null, "Unable to map file `%s': %s".printf (filename, e.message)); + context.report.err (null, "Unable to map file `%s': %s".printf (filename, e.message)); return null; } } diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala --- a/vapigen/valagidlparser.vala +++ b/vapigen/valagidlparser.vala @@ -131,7 +131,7 @@ public class Vala.GIdlParser : CodeVisit codenode_attributes_map[tokens[0]] = tokens[1]; } } catch (FileError e) { - Report.error (null, "Unable to read metadata file: %s".printf (e.message)); + context.report.err (null, "Unable to read metadata file: %s".printf (e.message)); } } diff --git a/vapigen/valavapicheck.vala b/vapigen/valavapicheck.vala --- a/vapigen/valavapicheck.vala +++ b/vapigen/valavapicheck.vala @@ -146,19 +146,19 @@ class Vala.VAPICheck : Object { return 0; } catch (FileError error) { - Report.error (null, "%s: %s".printf (metadata.filename, error.message)); + context.report.err (null, "%s: %s".printf (metadata.filename, error.message)); return 1; } } public int run () { if (!FileUtils.test (gidl.filename, FileTest.IS_REGULAR)) { - Report.error (null, "%s not found".printf (gidl.filename)); + context.report.err (null, "%s not found".printf (gidl.filename)); return 2; } if (!FileUtils.test (metadata.filename, FileTest.IS_REGULAR)) { - Report.error (null, "%s not found".printf (metadata.filename)); + context.report.err (null, "%s not found".printf (metadata.filename)); return 2; } diff --git a/vapigen/valavapigen.vala b/vapigen/valavapigen.vala --- a/vapigen/valavapigen.vala +++ b/vapigen/valavapigen.vala @@ -47,14 +47,14 @@ class Vala.VAPIGen : Object { }; private int quit () { - if (Report.get_errors () == 0) { + if (context.report.get_errors () == 0) { if (!quiet_mode) { - stdout.printf ("Generation succeeded - %d warning(s)\n", Report.get_warnings ()); + stdout.printf ("Generation succeeded - %d warning(s)\n", context.report.get_warnings ()); } return 0; } else { if (!quiet_mode) { - stdout.printf ("Generation failed: %d error(s), %d warning(s)\n", Report.get_errors (), Report.get_warnings ()); + stdout.printf ("Generation failed: %d error(s), %d warning(s)\n", context.report.get_errors (), context.report.get_warnings ()); } return 1; } @@ -95,7 +95,7 @@ class Vala.VAPIGen : Object { /* default package */ if (!add_package ("glib-2.0")) { - Report.error (null, "glib-2.0 not found in specified Vala API directories"); + context.report.err (null, "glib-2.0 not found in specified Vala API directories"); } /* load packages from .deps file */ @@ -112,7 +112,7 @@ class Vala.VAPIGen : Object { foreach (string dep in deps) { if (!add_package (dep)) { - Report.error (null, "%s not found in specified Vala API directories".printf (dep)); + context.report.err (null, "%s not found in specified Vala API directories".printf (dep)); } } } @@ -120,13 +120,13 @@ class Vala.VAPIGen : Object { if (packages != null) { foreach (string package in packages) { if (!add_package (package)) { - Report.error (null, "%s not found in specified Vala API directories".printf (package)); + context.report.err (null, "%s not found in specified Vala API directories".printf (package)); } } packages = null; } - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } @@ -134,40 +134,40 @@ class Vala.VAPIGen : Object { if (FileUtils.test (source, FileTest.EXISTS)) { context.add_source_file (new SourceFile (context, source)); } else { - Report.error (null, "%s not found".printf (source)); + context.report.err (null, "%s not found".printf (source)); } } sources = null; - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } var parser = new Parser (); parser.parse (context); - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } var attributeprocessor = new AttributeProcessor (); attributeprocessor.process (context); - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } var gidlparser = new GIdlParser (); gidlparser.parse (context); - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } var resolver = new SymbolResolver (); resolver.resolve (context); - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); }