]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Support context-specific error reporting and add a context stack, based on
authorJürg Billeter <j@bitron.ch>
Fri, 20 Feb 2009 15:04:57 +0000 (15:04 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 20 Feb 2009 15:04:57 +0000 (15:04 +0000)
2009-02-20  Jürg Billeter  <j@bitron.ch>

* 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

ChangeLog
compiler/valacompiler.vala
gobject/valaccodebasemodule.vala
vala/valacodecontext.vala
vala/valagenieparser.vala
vala/valaparser.vala
vala/valareport.vala
vapigen/valavapigen.vala

index ca5e2c0dacef2db0e48f3f4c91aeda24a8769456..f679034917c61ba3fb6b8b652b0ef91de61aef2f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2009-02-20  Jürg Billeter  <j@bitron.ch>
+
+       * 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  <j@bitron.ch>
 
        * vapi/Makefile.am:
index 2ac8f73ca1f4b722120f53f30862b4e38575edef..200cc40016a1875d69117a651684329c2f491bbc 100644 (file)
@@ -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 ();
                }
                
index bbb3d669b8e1d57dabe2f67202fd61fa0b070750..d4413971f0885bb6c20d66b79cdd3c66911e22b2 100644 (file)
@@ -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;
                }
 
index 0dcc2168a85b5c0a9da470f9e7271fa5176e5262..c74097d4b8711ec333674b4d91b8dbc2810f79b6 100644 (file)
@@ -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<SourceFile> source_files = new ArrayList<SourceFile> ();
        private Gee.List<string> c_source_files = new ArrayList<string> ();
        private Namespace _root = new Namespace (null);
@@ -166,6 +168,8 @@ public class Vala.CodeContext {
 
        private Gee.List<string> packages = new ArrayList<string> (str_equal);
 
+       static Gee.List<CodeContext> 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<CodeContext> ();
+               }
+               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.
         *
index 3734a692c68243a608b36c9abc00b5554faa1e6e..b90acb92bac4dfae981728c618834197f8e7a4b8 100644 (file)
@@ -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");
                                }
                        }
index e7cf088a047f01be299601e0e79751cc982bebde..ee9e696efc5eb1d0cb98a8a439dff64227476bf8 100644 (file)
@@ -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 `}'");
                                }
                        }
index c77c8975dfe8a3ef4d6591217563f4360eb53720..0e839a3c9bffa36a911db1fcf9305938a4c3926b 100644 (file)
@@ -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);
+       }
 }
index 410d45df417fdfa83174e998544b6305138db156..4160302002fe6a1bf8d69d0fd93f857ae04fa254 100644 (file)
@@ -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 ();
                }