+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:
};
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;
}
private int run () {
context = new CodeContext ();
+ CodeContext.push (context);
// default to build executable
if (!ccode_only && !compile_only && output == null) {
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;
packages = null;
}
- if (Report.get_errors () > 0) {
+ if (context.report.get_errors () > 0) {
return quit ();
}
}
sources = null;
- if (Report.get_errors () > 0) {
+ if (context.report.get_errors () > 0) {
return quit ();
}
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 ();
}
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 ();
}
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 ();
}
source_file.accept_children (codegen);
- if (Report.get_errors () > 0) {
+ if (context.report.get_errors () > 0) {
return;
}
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);
private Gee.List<string> packages = new ArrayList<string> (str_equal);
+ static Gee.List<CodeContext> context_stack;
+
/**
* The root namespace of the symbol tree.
*
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.
*
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");
}
}
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");
}
}
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 `}'");
}
}
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 `}'");
}
}
/**
* 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.
*/
/**
* 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;
* @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);
* @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);
}
}
}
+
+ /* 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);
+ }
}
};
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;
}
private int run () {
context = new CodeContext ();
+ CodeContext.push (context);
/* default package */
if (!add_package ("glib-2.0")) {
packages = null;
}
- if (Report.get_errors () > 0) {
+ if (context.report.get_errors () > 0) {
return quit ();
}
}
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 ();
}
}
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 ();
}