]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
valac: Add --main command-line option
authorJürg Billeter <j@bitron.ch>
Sat, 26 Sep 2009 08:09:37 +0000 (10:09 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 26 Sep 2009 11:51:16 +0000 (13:51 +0200)
This enables selecting a specific method as entry point.

compiler/valacompiler.vala
vala/valacodecontext.vala
vala/valamethod.vala

index 4f8e31f48362304774c3f7ab41ccf752883ec389..3d7108429fd29f7d55a0e15f83ebf387460a6c7a 100644 (file)
@@ -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);
index 5add46885d6d4c59b92947d814240062d0d91b8a..3a1cbbaa4a64fc0cb6a7aa2d4e4194895445b663 100644 (file)
@@ -152,6 +152,8 @@ public class Vala.CodeContext {
 
        public Method? entry_point { get; set; }
 
+       public string entry_point_name { 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);
index 5f60a2c6c29016b30ec996c216cc6afd6e94c327..d64326b87f9333e9801f0cb7a5a3aafa0d86836e 100644 (file)
@@ -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) {