diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2022-02-06 14:29:55 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2022-02-16 18:47:39 +0100 |
commit | d6ae6898a7148d34b7d32c2fa05c1dd7b29eca30 (patch) | |
tree | 84373e7d6f62e5634cdd14cf80e04de67f80b9a1 | |
parent | 491ea530de8ee33ee97d0b0cc829467cc10828ec (diff) | |
download | vala-d6ae6898a7148d34b7d32c2fa05c1dd7b29eca30.tar.gz |
parser: Clean up creation of constant declaration
-rw-r--r-- | vala/valaparser.vala | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/vala/valaparser.vala b/vala/valaparser.vala index d40994dac..8a7e59fc8 100644 --- a/vala/valaparser.vala +++ b/vala/valaparser.vala @@ -2757,6 +2757,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; @@ -2764,7 +2765,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; @@ -2782,11 +2789,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); } |