]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Use append_array_size for constant access
authorJürg Billeter <j@bitron.ch>
Sat, 9 Oct 2010 15:42:32 +0000 (17:42 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 9 Oct 2010 16:12:17 +0000 (18:12 +0200)
codegen/valaccodearraymodule.vala
codegen/valaccodememberaccessmodule.vala

index 3aa662849a6f4a03a7eccf010a10eaed7874b76c..96b9696b42c8cb56dc5eaff9040dd037163e7848 100644 (file)
@@ -181,28 +181,13 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                                return size[dim - 1];
                        }
                } else if (array_expr.symbol_reference != null) {
-                       if (array_expr.symbol_reference is FormalParameter || array_expr.symbol_reference is LocalVariable || array_expr.symbol_reference is Field) {
-                               List<CCodeExpression> size = get_array_sizes (array_expr);
-                               if (size != null && size.size >= dim) {
-                                       if (is_out) {
-                                               // passing array as out/ref
-                                               return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, size[dim - 1]);
-                                       } else {
-                                               return size[dim - 1];
-                                       }
-                               }
-                       } else if (array_expr.symbol_reference is Constant) {
-                               var constant = (Constant) array_expr.symbol_reference;
-                               var ccall = new CCodeFunctionCall (new CCodeIdentifier ("G_N_ELEMENTS"));
-                               ccall.add_argument (new CCodeIdentifier (constant.get_cname ()));
-                               return ccall;
-                       } else if (array_expr.symbol_reference is Property) {
-                               var prop = (Property) array_expr.symbol_reference;
-                               if (!prop.no_array_length) {
-                                       List<CCodeExpression> size = get_array_sizes (array_expr);
-                                       if (size != null && size.size >= dim) {
-                                               return size[dim - 1];
-                                       }
+                       List<CCodeExpression> size = get_array_sizes (array_expr);
+                       if (size != null && size.size >= dim) {
+                               if (is_out) {
+                                       // passing array as out/ref
+                                       return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, size[dim - 1]);
+                               } else {
+                                       return size[dim - 1];
                                }
                        }
                } else if (array_expr is NullLiteral) {
index a3cec43bb9e6ed60ef45fe9d8eeb6d1c8f4b6054..10a72d6d9d28873cdc84e27333fdc8e49beec2cd 100644 (file)
@@ -258,6 +258,12 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                        } else {
                                set_cvalue (expr, new CCodeIdentifier (c.get_cname ()));
                        }
+
+                       if (array_type != null) {
+                               var ccall = new CCodeFunctionCall (new CCodeIdentifier ("G_N_ELEMENTS"));
+                               ccall.add_argument (new CCodeIdentifier (c.get_cname ()));
+                               append_array_size (expr, ccall);
+                       }
                } else if (expr.symbol_reference is Property) {
                        var prop = (Property) expr.symbol_reference;