[vala] Infer array length of inline allocated arrays
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Infer array length of inline allocated arrays
- Date: Sat, 25 Oct 2014 12:04:03 +0000 (UTC)
commit 0f0bca7e0519af13d9217fbca2c20ce67cd3baba
Author: Florian Brosch <flo brosch gmail com>
Date: Thu Sep 18 05:09:03 2014 +0200
Infer array length of inline allocated arrays
Fixes bug 644046.
vala/valalocalvariable.vala | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/vala/valalocalvariable.vala b/vala/valalocalvariable.vala
index 17732ad..7c12224 100644
--- a/vala/valalocalvariable.vala
+++ b/vala/valalocalvariable.vala
@@ -89,9 +89,18 @@ public class Vala.LocalVariable : Variable {
variable_type.check (context);
}
+ // Catch initializer list transformation:
+ bool is_initializer_list = false;
+ int initializer_size = -1;
+
if (initializer != null) {
initializer.target_type = variable_type;
+ if (initializer is InitializerList) {
+ initializer_size = ((InitializerList) initializer).size;
+ is_initializer_list = true;
+ }
+
initializer.check (context);
}
@@ -156,6 +165,20 @@ public class Vala.LocalVariable : Variable {
return false;
}
+
+ ArrayType variable_array_type = variable_type as ArrayType;
+ if (variable_array_type != null && variable_array_type.inline_allocated &&
!variable_array_type.fixed_length && is_initializer_list) {
+ variable_array_type.length = new IntegerLiteral (initializer_size.to_string
());
+ variable_array_type.fixed_length = true;
+ variable_array_type.nullable = false;
+ }
+
+ if (variable_array_type != null && variable_array_type.inline_allocated &&
initializer.value_type is ArrayType == false) {
+ error = true;
+ Report.error (source_reference, "only arrays are allowed as initializer for
arrays with fixed length");
+ return false;
+ }
+
if (initializer.value_type.is_disposable ()) {
/* rhs transfers ownership of the expression */
if (!(variable_type is PointerType) && !variable_type.value_owned) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]