[vala/staging] parser: Clean up creation of constant declaration



commit fab202fdec0abbf166743c0c316e5d61d049c46a
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Feb 6 14:29:55 2022 +0100

    parser: Clean up creation of constant declaration

 vala/valaparser.vala | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
---
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index a8f083a82..d81fc3544 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -3116,6 +3116,7 @@ public class Vala.Parser : CodeVisitor {
                string id = parse_identifier ();
 
                type = parse_inline_array_type (type);
+               var src = get_src (begin);
 
                // constant arrays don't own their element
                unowned ArrayType? array_type = type as ArrayType;
@@ -3123,7 +3124,13 @@ public class Vala.Parser : CodeVisitor {
                        array_type.element_type.value_owned = false;
                }
 
-               var c = new Constant (id, type, null, get_src (begin), comment);
+               Expression? initializer = null;
+               if (accept (TokenType.ASSIGN)) {
+                       initializer = parse_expression ();
+               }
+               expect (TokenType.SEMICOLON);
+
+               var c = new Constant (id, type, initializer, src, comment);
                c.access = access;
                if (ModifierFlags.EXTERN in flags) {
                        c.is_extern = true;
@@ -3141,11 +3148,6 @@ public class Vala.Parser : CodeVisitor {
                        Report.error (c.source_reference, "`owned' is not allowed on constants");
                }
 
-               if (accept (TokenType.ASSIGN)) {
-                       c.value = parse_expression ();
-               }
-               expect (TokenType.SEMICOLON);
-
                parent.add_constant (c);
        }
 


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