[vala/wip/foreach: 3/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: 3/7] vala: Additionally look for "length" property for "foreach with index"
- Date: Mon, 9 Nov 2020 18:28:16 +0000 (UTC)
commit 20275936dad4dddd625b78b68ce247821bac2571
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 da80b24aa..7d421c711 100644
--- a/vala/valaforeachstatement.vala
+++ b/vala/valaforeachstatement.vala
@@ -202,11 +202,14 @@ 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;
}
add_statement (new DeclarationStatement (new LocalVariable (null, "_%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]