vala r2461 - in trunk: . compiler gobject vala vapigen



Author: juergbi
Date: Fri Feb 20 15:04:57 2009
New Revision: 2461
URL: http://svn.gnome.org/viewvc/vala?rev=2461&view=rev

Log:
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


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

Modified: trunk/compiler/valacompiler.vala
==============================================================================
--- trunk/compiler/valacompiler.vala	(original)
+++ trunk/compiler/valacompiler.vala	Fri Feb 20 15:04:57 2009
@@ -91,17 +91,17 @@
 	};
 	
 	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 @@
 	
 	private int run () {
 		context = new CodeContext ();
+		CodeContext.push (context);
 
 		// default to build executable
 		if (!ccode_only && !compile_only && output == null) {
@@ -164,7 +165,7 @@
 		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 @@
 			packages = null;
 		}
 		
-		if (Report.get_errors () > 0) {
+		if (context.report.get_errors () > 0) {
 			return quit ();
 		}
 		
@@ -240,7 +241,7 @@
 		}
 		sources = null;
 		
-		if (Report.get_errors () > 0) {
+		if (context.report.get_errors () > 0) {
 			return quit ();
 		}
 		
@@ -250,14 +251,14 @@
 		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 @@
 			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 @@
 			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 ();
 		}
 		

Modified: trunk/gobject/valaccodebasemodule.vala
==============================================================================
--- trunk/gobject/valaccodebasemodule.vala	(original)
+++ trunk/gobject/valaccodebasemodule.vala	Fri Feb 20 15:04:57 2009
@@ -374,7 +374,7 @@
 
 		source_file.accept_children (codegen);
 
-		if (Report.get_errors () > 0) {
+		if (context.report.get_errors () > 0) {
 			return;
 		}
 

Modified: trunk/vala/valacodecontext.vala
==============================================================================
--- trunk/vala/valacodecontext.vala	(original)
+++ trunk/vala/valacodecontext.vala	Fri Feb 20 15:04:57 2009
@@ -158,6 +158,8 @@
 		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 @@
 
 	private Gee.List<string> packages = new ArrayList<string> (str_equal);
 
+	static Gee.List<CodeContext> context_stack;
+
 	/**
 	 * The root namespace of the symbol tree.
 	 *
@@ -184,6 +188,30 @@
 	}
 
 	/**
+	 * 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.
 	 *
 	 * @return list of source files

Modified: trunk/vala/valagenieparser.vala
==============================================================================
--- trunk/vala/valagenieparser.vala	(original)
+++ trunk/vala/valagenieparser.vala	Fri Feb 20 15:04:57 2009
@@ -1660,7 +1660,7 @@
 		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 @@
 		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");
 				}
 			}

Modified: trunk/vala/valaparser.vala
==============================================================================
--- trunk/vala/valaparser.vala	(original)
+++ trunk/vala/valaparser.vala	Fri Feb 20 15:04:57 2009
@@ -1378,7 +1378,7 @@
 		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 @@
 		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 `}'");
 				}
 			}

Modified: trunk/vala/valareport.vala
==============================================================================
--- trunk/vala/valareport.vala	(original)
+++ trunk/vala/valareport.vala	Fri Feb 20 15:04:57 2009
@@ -25,12 +25,12 @@
 /**
  * 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 @@
 	/**
 	 * 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 @@
 	 * @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 @@
 	 * @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 @@
 			}
 		}
 	}
+
+	/* 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);
+	}
 }

Modified: trunk/vapigen/valavapigen.vala
==============================================================================
--- trunk/vapigen/valavapigen.vala	(original)
+++ trunk/vapigen/valavapigen.vala	Fri Feb 20 15:04:57 2009
@@ -52,14 +52,14 @@
 	};
 	
 	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 @@
 
 	private int run () {
 		context = new CodeContext ();
+		CodeContext.push (context);
 		
 		/* default package */
 		if (!add_package ("glib-2.0")) {
@@ -134,7 +135,7 @@
 			packages = null;
 		}
 		
-		if (Report.get_errors () > 0) {
+		if (context.report.get_errors () > 0) {
 			return quit ();
 		}
 		
@@ -147,14 +148,14 @@
 		}
 		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 @@
 		}
 		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 ();
 		}
 		



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]