[vala] Report error on missing or duplicate entry point



commit fc6154a777481a441bdf0e444a47107045a4fb81
Author: Jürg Billeter <j bitron ch>
Date:   Sat Aug 15 16:11:11 2009 +0200

    Report error on missing or duplicate entry point
    
    Fixes bug 591819.

 compiler/valacompiler.vala |    7 +++++++
 vala/valacodecontext.vala  |    2 ++
 vala/valamethod.vala       |    6 ++++++
 3 files changed, 15 insertions(+), 0 deletions(-)
---
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index 06c8bf6..cc74b5c 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -313,6 +313,13 @@ class Vala.Compiler {
 		var analyzer = new SemanticAnalyzer ();
 		analyzer.analyze (context);
 
+		if (!ccode_only && !compile_only) {
+			// building program, require entry point
+			if (context.entry_point == null) {
+				Report.error (null, "program does not contain a static `main' method");
+			}
+		}
+
 		if (dump_tree != null) {
 			var code_writer = new CodeWriter (true);
 			code_writer.write_file (context, dump_tree);
diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala
index 62a6ac6..a6d783c 100644
--- a/vala/valacodecontext.vala
+++ b/vala/valacodecontext.vala
@@ -145,6 +145,8 @@ public class Vala.CodeContext {
 
 	public Report report { get; set; default = new Report ();}
 
+	public Method? entry_point { get; set; }
+
 	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);
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index b575c8f..7b28042 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -850,7 +850,13 @@ public class Vala.Method : Member {
 		}
 
 		if (is_possible_entry_point (analyzer)) {
+			if (analyzer.context.entry_point != null) {
+				error = true;
+				Report.error (source_reference, "program already has an entry point `%s'".printf (analyzer.context.entry_point.get_full_name ()));
+				return false;
+			}
 			entry_point = true;
+			analyzer.context.entry_point = this;
 		}
 
 		return !error;



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