From: Jürg Billeter Date: Sat, 26 Sep 2009 08:09:37 +0000 (+0200) Subject: valac: Add --main command-line option X-Git-Tag: 0.7.7~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ceb48be2ea2a18502787a692c028fe88400d4ba;p=thirdparty%2Fvala.git valac: Add --main command-line option This enables selecting a specific method as entry point. --- diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala index 4f8e31f48..3d7108429 100644 --- a/compiler/valacompiler.vala +++ b/compiler/valacompiler.vala @@ -69,6 +69,8 @@ class Vala.Compiler { static bool verbose_mode; static string profile; + static string entry_point; + private CodeContext context; const OptionEntry[] options = { @@ -90,6 +92,7 @@ class Vala.Compiler { { "debug", 'g', 0, OptionArg.NONE, ref debug, "Produce debug information", null }, { "thread", 0, 0, OptionArg.NONE, ref thread, "Enable multithreading support", null }, { "define", 'D', 0, OptionArg.STRING_ARRAY, ref defines, "Define SYMBOL", "SYMBOL..." }, + { "main", 0, 0, OptionArg.STRING, ref entry_point, "Use SYMBOL as entry point", "SYMBOL..." }, { "disable-assert", 0, 0, OptionArg.NONE, ref disable_assert, "Disable assertions", null }, { "enable-checking", 0, 0, OptionArg.NONE, ref enable_checking, "Enable additional run-time checks", null }, { "enable-deprecated", 0, 0, OptionArg.NONE, ref deprecated, "Enable deprecated features", null }, @@ -217,6 +220,8 @@ class Vala.Compiler { Report.error (null, "Unknown profile %s".printf (profile)); } + context.entry_point_name = entry_point; + if (defines != null) { foreach (string define in defines) { context.add_define (define); diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index 5add46885..3a1cbbaa4 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -152,6 +152,8 @@ public class Vala.CodeContext { public Method? entry_point { get; set; } + public string entry_point_name { get; set; } + private Gee.List source_files = new ArrayList (); private Gee.List c_source_files = new ArrayList (); private Namespace _root = new Namespace (null); diff --git a/vala/valamethod.vala b/vala/valamethod.vala index 5f60a2c6c..d64326b87 100644 --- a/vala/valamethod.vala +++ b/vala/valamethod.vala @@ -864,10 +864,6 @@ public class Vala.Method : Member { } } - if (tree_can_fail && name == "main") { - Report.error (source_reference, "\"main\" method cannot throw errors"); - } - // check that all errors that can be thrown in the method body are declared if (body != null) { foreach (DataType body_error_type in body.get_error_types ()) { @@ -891,6 +887,10 @@ public class Vala.Method : Member { } entry_point = true; analyzer.context.entry_point = this; + + if (tree_can_fail) { + Report.error (source_reference, "\"main\" method cannot throw errors"); + } } return !error; @@ -901,9 +901,16 @@ public class Vala.Method : Member { return false; } - if (name == null || name != "main") { - // method must be called "main" - return false; + if (analyzer.context.entry_point_name == null) { + if (name == null || name != "main") { + // method must be called "main" + return false; + } + } else { + // custom entry point name + if (get_full_name () != analyzer.context.entry_point_name) { + return false; + } } if (binding == MemberBinding.INSTANCE) {