[vala/wip/foreach: 6/7] vala: Additionally look for "length" property for "foreach with index"
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/foreach: 6/7] vala: Additionally look for "length" property for "foreach with index"
- Date: Tue, 10 Nov 2020 07:47:00 +0000 (UTC)
commit 616a5b19f172ff9c2a8cccc334b18d795d254cda
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Nov 9 15:06:20 2020 +0100
vala: Additionally look for "length" property for "foreach with index"
vala/valaforeachstatement.vala | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
---
diff --git a/vala/valaforeachstatement.vala b/vala/valaforeachstatement.vala
index 66dbbdc50..94f6b9dc9 100644
--- a/vala/valaforeachstatement.vala
+++ b/vala/valaforeachstatement.vala
@@ -206,6 +206,9 @@ public class Vala.ForeachStatement : Block {
}
var size_property = collection_type.get_member ("size") as Property;
if (size_property == null) {
+ size_property = collection_type.get_member ("length") as Property;
+ }
+ if (size_property == null || !(size_property.property_type is IntegerType)) {
return false;
}
@@ -214,7 +217,7 @@ public class Vala.ForeachStatement : Block {
list_type.value_owned = false;
}
add_statement (new DeclarationStatement (new LocalVariable (list_type, "_%s_list".printf
(variable_name), collection, source_reference), source_reference));
- add_statement (new DeclarationStatement (new LocalVariable (null, "_%s_size".printf
(variable_name), new MemberAccess (new MemberAccess.simple ("_%s_list".printf (variable_name),
source_reference), "size", source_reference), source_reference), source_reference));
+ add_statement (new DeclarationStatement (new LocalVariable (null, "_%s_size".printf
(variable_name), new MemberAccess (new MemberAccess.simple ("_%s_list".printf (variable_name),
source_reference), size_property.name, source_reference), source_reference), source_reference));
add_statement (new DeclarationStatement (new LocalVariable (null, "_%s_index".printf
(variable_name), new UnaryExpression (UnaryOperator.MINUS, new IntegerLiteral ("1", source_reference),
source_reference), source_reference), source_reference));
var next = new UnaryExpression (UnaryOperator.INCREMENT, new MemberAccess.simple
("_%s_index".printf (variable_name), source_reference), source_reference);
var conditional = new BinaryExpression (BinaryOperator.LESS_THAN, next, new
MemberAccess.simple ("_%s_size".printf (variable_name), source_reference), source_reference);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]