[vala/staging] genie: Allow the main function "init" to return an integer as exit status



commit 50225a7fe6b1b8f3644852c65dc4d3484d7fc09f
Author: Alistair Thomas <astavale yahoo co uk>
Date:   Wed Mar 22 20:28:42 2017 +0000

    genie: Allow the main function "init" to return an integer as exit status
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/402

 tests/Makefile.am         |  1 +
 tests/genie/init-int.gs   |  2 ++
 vala/valagenieparser.vala | 19 +++++++++++++------
 3 files changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1a5adc7f7..a33342403 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -733,6 +733,7 @@ GENIE_TESTS = \
        genie/function-with-return-value.gs \
        genie/indentation-with-spaces.gs \
        genie/init.gs \
+       genie/init-int.gs \
        genie/literal-boolean-assignment.gs \
        genie/literal-boolean.gs \
        genie/literal-character.gs \
diff --git a/tests/genie/init-int.gs b/tests/genie/init-int.gs
new file mode 100644
index 000000000..7aade9b97
--- /dev/null
+++ b/tests/genie/init-int.gs
@@ -0,0 +1,2 @@
+init:int
+       return 0
diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala
index 30a5fb3a0..f979128ba 100644
--- a/vala/valagenieparser.vala
+++ b/vala/valagenieparser.vala
@@ -2852,17 +2852,24 @@ public class Vala.Genie.Parser : CodeVisitor {
 
 
        Method parse_main_method_declaration (List<Attribute>? attrs) throws ParseError {
-               var id = "main";
                var begin = get_location ();
-               DataType type = new VoidType ();
-               expect (TokenType.INIT);
+               DataType type;
 
-               var method = new Method (id, type, get_src (begin), comment);
-               method.access = SymbolAccessibility.PUBLIC;
+               expect (TokenType.INIT);
 
-               set_attributes (method, attrs);
+               if (accept (TokenType.COLON)) {
+                       type = parse_type (true, false);
+                       if (type.to_string () != "int") {
+                               throw new ParseError.SYNTAX ("main `init' must return void or `int', but got 
`%s'".printf (type.to_string ()));
+                       }
+               } else {
+                       type = new VoidType ();
+               }
 
+               var method = new Method ("main", type, get_src (begin), comment);
+               method.access = SymbolAccessibility.PUBLIC;
                method.binding = MemberBinding.STATIC;
+               set_attributes (method, attrs);
 
                var sym = new UnresolvedSymbol (null, "string", get_src (begin));
                type = new UnresolvedType.from_symbol (sym, get_src (begin));


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