[vala] valac: Add --main command-line option
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] valac: Add --main command-line option
- Date: Sat, 26 Sep 2009 12:47:22 +0000 (UTC)
commit 9ceb48be2ea2a18502787a692c028fe88400d4ba
Author: Jürg Billeter <j bitron ch>
Date: Sat Sep 26 10:09:37 2009 +0200
valac: Add --main command-line option
This enables selecting a specific method as entry point.
compiler/valacompiler.vala | 5 +++++
vala/valacodecontext.vala | 2 ++
vala/valamethod.vala | 21 ++++++++++++++-------
3 files changed, 21 insertions(+), 7 deletions(-)
---
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index 4f8e31f..3d71084 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 5add468..3a1cbba 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<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 5f60a2c..d64326b 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) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]