From: Jürg Billeter Date: Fri, 20 Feb 2009 15:04:57 +0000 (+0000) Subject: Support context-specific error reporting and add a context stack, based on X-Git-Tag: 0.5.7~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4820129afadf99b643e41bbf8a27ecb782c704c;p=thirdparty%2Fvala.git Support context-specific error reporting and add a context stack, based on 2009-02-20 Jürg Billeter * vala/valacodecontext.vala: * vala/valareport.vala: Support context-specific error reporting and add a context stack, based on patch by Abderrahim Kitouni, fixes bug 542920 * vala/valagenieparser.vala: * vala/valaparser.vala: * gobject/valaccodebasemodule.vala: * compiler/valacompiler.vala: * vapigen/valavapigen.vala: Adapt to interface changes svn path=/trunk/; revision=2461 --- diff --git a/ChangeLog b/ChangeLog index ca5e2c0da..f67903491 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2009-02-20 Jürg Billeter + + * vala/valacodecontext.vala: + * vala/valareport.vala: + + Support context-specific error reporting and add a context stack, + based on patch by Abderrahim Kitouni, fixes bug 542920 + + * vala/valagenieparser.vala: + * vala/valaparser.vala: + * gobject/valaccodebasemodule.vala: + * compiler/valacompiler.vala: + * vapigen/valavapigen.vala: + + Adapt to interface changes + 2009-02-20 Jürg Billeter * vapi/Makefile.am: diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala index 2ac8f73ca..200cc4001 100644 --- a/compiler/valacompiler.vala +++ b/compiler/valacompiler.vala @@ -91,17 +91,17 @@ class Vala.Compiler { }; 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; } @@ -146,6 +146,7 @@ class Vala.Compiler { private int run () { context = new CodeContext (); + CodeContext.push (context); // default to build executable if (!ccode_only && !compile_only && output == null) { @@ -164,7 +165,7 @@ class Vala.Compiler { context.experimental = experimental; context.non_null_experimental = non_null_experimental; context.dbus_transformation = !disable_dbus_transformation; - Report.set_verbose_errors (!quiet_mode); + context.report.set_verbose_errors (!quiet_mode); context.ccode_only = ccode_only; context.compile_only = compile_only; @@ -213,7 +214,7 @@ class Vala.Compiler { packages = null; } - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } @@ -240,7 +241,7 @@ class Vala.Compiler { } sources = null; - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } @@ -250,14 +251,14 @@ class Vala.Compiler { var genie_parser = new Genie.Parser (); genie_parser.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 (); } @@ -269,14 +270,14 @@ class Vala.Compiler { code_writer.write_file (context, dump_tree); } - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } var flow_analyzer = new FlowAnalyzer (); flow_analyzer.analyze (context); - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } @@ -284,14 +285,14 @@ class Vala.Compiler { 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/valaccodebasemodule.vala b/gobject/valaccodebasemodule.vala index bbb3d669b..d4413971f 100644 --- a/gobject/valaccodebasemodule.vala +++ b/gobject/valaccodebasemodule.vala @@ -374,7 +374,7 @@ internal class Vala.CCodeBaseModule : CCodeModule { source_file.accept_children (codegen); - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return; } diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index 0dcc2168a..c74097d4b 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -158,6 +158,8 @@ public class Vala.CodeContext { get { return save_csources || null != library; } } + public Report report { get; set; default = new Report ();} + private Gee.List source_files = new ArrayList (); private Gee.List c_source_files = new ArrayList (); private Namespace _root = new Namespace (null); @@ -166,6 +168,8 @@ public class Vala.CodeContext { private Gee.List packages = new ArrayList (str_equal); + static Gee.List context_stack; + /** * The root namespace of the symbol tree. * @@ -183,6 +187,30 @@ public class Vala.CodeContext { public CodeContext () { } + /** + * Return the topmost context from the context stack. + */ + public static CodeContext get () { + return context_stack[context_stack.size - 1]; + } + + /** + * Push the specified context to the context stack. + */ + public static void push (CodeContext context) { + if (context_stack == null) { + context_stack = new ArrayList (); + } + context_stack.add (context); + } + + /** + * Remove the topmost context from the context stack. + */ + public static void pop () { + context_stack.remove_at (context_stack.size - 1); + } + /** * Returns a copy of the list of source files. * diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala index 3734a692c..b90acb92b 100644 --- a/vala/valagenieparser.vala +++ b/vala/valagenieparser.vala @@ -1660,7 +1660,7 @@ public class Vala.Genie.Parser : CodeVisitor { 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"); } } @@ -2199,7 +2199,7 @@ public class Vala.Genie.Parser : CodeVisitor { 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 index e7cf088a0..ee9e696ef 100644 --- a/vala/valaparser.vala +++ b/vala/valaparser.vala @@ -1378,7 +1378,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 `}'"); } } @@ -1830,7 +1830,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 index c77c8975d..0e839a3c9 100644 --- a/vala/valareport.vala +++ b/vala/valareport.vala @@ -25,12 +25,12 @@ using GLib; /** * Namespace to centralize reporting warnings and errors. */ -namespace Vala.Report { - public int warnings; - public int errors; +public class Vala.Report : Object { + int warnings; + int errors; + + bool verbose_errors; - public bool verbose_errors; - /** * Set the error verbosity. */ @@ -55,7 +55,7 @@ namespace Vala.Report { /** * Pretty-print the actual line of offending code if possible. */ - public void report_source (SourceReference source) { + static void report_source (SourceReference source) { if (source.first_line != source.last_line) { // FIXME Cannot report multi-line issues currently return; @@ -96,7 +96,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 +114,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 +125,12 @@ namespace Vala.Report { } } } + + /* Convenience methods calling warn and err on correct instance */ + public static void warning (SourceReference? source, string message) { + CodeContext.get ().report.warn (source, message); + } + public static void error (SourceReference? source, string message) { + CodeContext.get ().report.err (source, message); + } } diff --git a/vapigen/valavapigen.vala b/vapigen/valavapigen.vala index 410d45df4..416030200 100644 --- a/vapigen/valavapigen.vala +++ b/vapigen/valavapigen.vala @@ -52,14 +52,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; } @@ -97,6 +97,7 @@ class Vala.VAPIGen : Object { private int run () { context = new CodeContext (); + CodeContext.push (context); /* default package */ if (!add_package ("glib-2.0")) { @@ -134,7 +135,7 @@ class Vala.VAPIGen : Object { packages = null; } - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); } @@ -147,14 +148,14 @@ class Vala.VAPIGen : Object { } 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 (); } @@ -164,28 +165,28 @@ class Vala.VAPIGen : Object { } girparser.parse (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 (); } var analyzer = new SemanticAnalyzer (); analyzer.analyze (context); - if (Report.get_errors () > 0) { + if (context.report.get_errors () > 0) { return quit (); }