]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Do not require libgee to support element access in custom types
authorJürg Billeter <j@bitron.ch>
Fri, 16 Jan 2009 21:49:06 +0000 (21:49 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Fri, 16 Jan 2009 21:49:06 +0000 (21:49 +0000)
2009-01-16  Jürg Billeter  <j@bitron.ch>

* vala/valaassignment.vala:
* vala/valaelementaccess.vala:
* vala/valasemanticanalyzer.vala:
* gobject/valaccodearraymodule.vala:
* gobject/valaccodeassignmentmodule.vala:
* gobject/valaccodebasemodule.vala:

Do not require libgee to support element access in custom types

svn path=/trunk/; revision=2366

ChangeLog
gobject/valaccodearraymodule.vala
gobject/valaccodeassignmentmodule.vala
gobject/valaccodebasemodule.vala
vala/valaassignment.vala
vala/valaelementaccess.vala
vala/valasemanticanalyzer.vala

index eaaae32d861168521ac9416e9945d1e8883b6e3b..eb1c5da657993d526dee4491afe978e5f0d3d295 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-01-16  Jürg Billeter  <j@bitron.ch>
+
+       * vala/valaassignment.vala:
+       * vala/valaelementaccess.vala:
+       * vala/valasemanticanalyzer.vala:
+       * gobject/valaccodearraymodule.vala:
+       * gobject/valaccodeassignmentmodule.vala:
+       * gobject/valaccodebasemodule.vala:
+
+       Do not require libgee to support element access in custom types
+
 2009-01-16  Jürg Billeter  <j@bitron.ch>
 
        * vala/valaexpression.vala:
index ffcfaf93a325e977200b491de2a9ac8b7d25f997..f3f2f5154559d9876917038d1b06c50a2db3d7a1 100644 (file)
@@ -338,32 +338,6 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                        ccall.add_argument (coffsetcall);
 
                        expr.ccodenode = ccall;
-               } else if (container_type != null && list_type != null && map_type != null &&
-                          (container_type.is_subtype_of (list_type) || container_type.is_subtype_of (map_type))) {
-                       // should be moved to a different module
-
-                       TypeSymbol collection_iface = null;
-                       if (container_type.is_subtype_of (list_type)) {
-                               collection_iface = list_type;
-                       } else if (container_type.is_subtype_of (map_type)) {
-                               collection_iface = map_type;
-                       }
-                       var get_method = (Method) collection_iface.scope.lookup ("get");
-                       Gee.List<FormalParameter> get_params = get_method.get_parameters ();
-                       Iterator<FormalParameter> get_params_it = get_params.iterator ();
-                       get_params_it.next ();
-                       var get_param = get_params_it.get ();
-
-                       if (get_param.parameter_type is GenericType) {
-                               var index_type = SemanticAnalyzer.get_actual_type (expr.container.value_type, (GenericType) get_param.parameter_type, expr);
-                               cindex = convert_to_generic_pointer (cindex, index_type);
-                       }
-
-                       var get_ccall = new CCodeFunctionCall (new CCodeIdentifier (get_method.get_cname ()));
-                       get_ccall.add_argument (new CCodeCastExpression (ccontainer, collection_iface.get_cname () + "*"));
-                       get_ccall.add_argument (cindex);
-
-                       expr.ccodenode = convert_from_generic_pointer (get_ccall, expr.value_type);
                } else {
                        // access to element in an array
                        for (int i = 1; i < rank; i++) {
index 90eb3d601a5a2caaa5c51ba3d9d2ac71f3bb22e7..6bf572d3661b6f2d97115e5285cf892ab259eb79 100644 (file)
@@ -92,52 +92,6 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
                }
        }
 
-       private CCodeExpression? emit_non_array_element_access (Assignment assignment) {
-               // custom element access
-               CCodeExpression rhs = (CCodeExpression) assignment.right.ccodenode;
-
-               var expr = (ElementAccess) assignment.left;
-               var container_type = expr.container.value_type.data_type;
-               Gee.List<Expression> indices = expr.get_indices ();
-               Iterator<Expression> indices_it = indices.iterator ();
-               indices_it.next ();
-
-               var ccontainer = (CCodeExpression) get_ccodenode (expr.container);
-               var cindex = (CCodeExpression) get_ccodenode (indices_it.get ());
-
-               if (container_type != null && list_type != null && map_type != null &&
-                   (container_type.is_subtype_of (list_type) || container_type.is_subtype_of (map_type))) {
-                       // lookup symbol in interface instead of class as implemented interface methods are not in VAPI files
-                       TypeSymbol collection_iface = null;
-                       if (container_type.is_subtype_of (list_type)) {
-                               collection_iface = list_type;
-                       } else if (container_type.is_subtype_of (map_type)) {
-                               collection_iface = map_type;
-                       }
-                       var set_method = (Method) collection_iface.scope.lookup ("set");
-                       Gee.List<FormalParameter> set_params = set_method.get_parameters ();
-                       Iterator<FormalParameter> set_params_it = set_params.iterator ();
-                       set_params_it.next ();
-                       var set_param = set_params_it.get ();
-
-                       if (set_param.parameter_type is GenericType) {
-                               var index_type = SemanticAnalyzer.get_actual_type (expr.container.value_type, (GenericType) set_param.parameter_type, assignment);
-                               cindex = convert_to_generic_pointer (cindex, index_type);
-                       }
-
-                       var set_ccall = new CCodeFunctionCall (new CCodeIdentifier (set_method.get_cname ()));
-                       set_ccall.add_argument (new CCodeCastExpression (ccontainer, collection_iface.get_cname () + "*"));
-                       set_ccall.add_argument (cindex);
-                       set_ccall.add_argument (convert_to_generic_pointer (rhs, expr.value_type));
-
-                       return set_ccall;
-               } else {
-                       Report.error (assignment.source_reference, "internal error: unsupported element access");
-                       assignment.error = true;
-                       return null;
-               }
-       }
-
        CCodeExpression emit_simple_assignment (Assignment assignment) {
                CCodeExpression rhs = (CCodeExpression) assignment.right.ccodenode;
 
@@ -246,10 +200,6 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
 
                if (assignment.left.symbol_reference is Property) {
                        assignment.ccodenode = emit_property_assignment (assignment);
-               } else if (assignment.left is ElementAccess
-                          && !(((ElementAccess) assignment.left).container.value_type is ArrayType)
-                          && !(((ElementAccess) assignment.left).container.value_type is PointerType)) {
-                       assignment.ccodenode = emit_non_array_element_access (assignment);
                } else {
                        assignment.ccodenode = emit_simple_assignment (assignment);
                }
index 8c81f9e5acf96b0b5861a234280bf2c511b94ccb..1692cc8613615ce3a718646cd439088107d5a22a 100644 (file)
@@ -127,8 +127,6 @@ public class Vala.CCodeBaseModule : CCodeModule {
        public Struct gvalue_type;
        public Struct mutex_type;
        public TypeSymbol type_module_type;
-       public Interface list_type;
-       public Interface map_type;
        public TypeSymbol dbus_object_type;
 
        public bool in_plugin = false;
@@ -613,12 +611,6 @@ public class Vala.CCodeBaseModule : CCodeModule {
                        }
                }
 
-               var gee_ns = root_symbol.scope.lookup ("Gee");
-               if (gee_ns != null) {
-                       list_type = (Interface) gee_ns.scope.lookup ("List");
-                       map_type = (Interface) gee_ns.scope.lookup ("Map");
-               }
-
                var dbus_ns = root_symbol.scope.lookup ("DBus");
                if (dbus_ns != null) {
                        dbus_object_type = (TypeSymbol) dbus_ns.scope.lookup ("Object");
index d24a7a39e55077fb07fa2e45ef03be3b5c39d6c8..98dc24c1bfe282695b0da708c6278772b529704b 100644 (file)
@@ -1,6 +1,6 @@
 /* valaassignment.vala
  *
- * Copyright (C) 2006-2008  Jürg Billeter
+ * Copyright (C) 2006-2009  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -148,6 +148,14 @@ public class Vala.Assignment : Expression {
                                var ma = (MemberAccess) ea.container;
                                var sig = (Signal) ea.container.symbol_reference;
                                right.target_type = new DelegateType (sig.get_delegate (ma.inner.value_type, this));
+                       } else if (ea.container.value_type.get_member ("set") is Method) {
+                               var set_call = new MethodCall (new MemberAccess (ea.container, "set"));
+                               foreach (Expression e in ea.get_indices ()) {
+                                       set_call.add_argument (e);
+                               }
+                               set_call.add_argument (right);
+                               parent_node.replace_expression (this, set_call);
+                               return set_call.check (analyzer);
                        } else {
                                right.target_type = left.value_type;
                        }
index c5cb02b189f65f84a70dc5926d200ff58071c86a..b651686686b4d52a9b396fc9a421cf96f7dcbaa4 100644 (file)
@@ -1,6 +1,7 @@
 /* valaelementaccess.vala
  *
- * Copyright (C) 2006-2008  Raffaele Sandrini, Jürg Billeter
+ * Copyright (C) 2006-2009  Jürg Billeter
+ * Copyright (C) 2006-2008  Raffaele Sandrini
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -148,56 +149,33 @@ public class Vala.ElementAccess : Expression {
                        }
 
                        value_type = analyzer.unichar_type;
-               } else if (container_type != null && analyzer.list_type != null && analyzer.map_type != null &&
-                          (container_type.is_subtype_of (analyzer.list_type) || container_type.is_subtype_of (analyzer.map_type))) {
-                       Gee.List<Expression> indices = get_indices ();
-                       if (indices.size != 1) {
-                               error = true;
-                               Report.error (source_reference, "Element access with more than one dimension is not supported for the specified type");
-                               return false;
-                       }
-                       Iterator<Expression> indices_it = indices.iterator ();
-                       indices_it.next ();
-                       var index = indices_it.get ();
-                       index_int_type_check = false;
-
-                       // lookup symbol in interface instead of class as implemented interface methods are not in VAPI files
-                       Symbol get_sym = null;
-                       if (container_type.is_subtype_of (analyzer.list_type)) {
-                               get_sym = analyzer.list_type.scope.lookup ("get");
-                       } else if (container_type.is_subtype_of (analyzer.map_type)) {
-                               get_sym = analyzer.map_type.scope.lookup ("get");
-                       }
-                       var get_method = (Method) get_sym;
-                       Gee.List<FormalParameter> get_params = get_method.get_parameters ();
-                       Iterator<FormalParameter> get_params_it = get_params.iterator ();
-                       get_params_it.next ();
-                       var get_param = get_params_it.get ();
-
-                       var index_type = get_param.parameter_type;
-                       if (index_type is GenericType) {
-                               index_type = analyzer.get_actual_type (container.value_type, (GenericType) index_type, this);
-                       }
-
-                       if (!index.value_type.compatible (index_type)) {
-                               error = true;
-                               Report.error (source_reference, "index expression: Cannot convert from `%s' to `%s'".printf (index.value_type.to_string (), index_type.to_string ()));
-                               return false;
-                       }
-
-                       value_type = analyzer.get_actual_type (container.value_type, (GenericType) get_method.return_type, this).copy ();
-                       if (lvalue) {
-                               // get () returns owned value, set () accepts unowned value
-                               value_type.value_owned = false;
-                       }
                } else if (container is MemberAccess && container.symbol_reference is Signal) {
                        index_int_type_check = false;
 
                        symbol_reference = container.symbol_reference;
                        value_type = container.value_type;
                } else {
+                       if (lvalue) {
+                               var set_method = container.value_type.get_member ("set") as Method;
+                               var assignment = parent_node as Assignment;
+                               if (set_method != null && assignment != null) {
+                                       return !error;
+                               }
+                       } else {
+                               var get_method = container.value_type.get_member ("get") as Method;
+                               if (get_method != null) {
+                                       var get_call = new MethodCall (new MemberAccess (container, "get"));
+                                       foreach (Expression e in get_indices ()) {
+                                               get_call.add_argument (e);
+                                       }
+                                       get_call.target_type = this.target_type;
+                                       parent_node.replace_expression (this, get_call);
+                                       return get_call.check (analyzer);
+                               }
+                       }
+
                        error = true;
-                       Report.error (source_reference, "The expression `%s' does not denote an Array".printf (container.value_type.to_string ()));
+                       Report.error (source_reference, "The expression `%s' does not denote an array".printf (container.value_type.to_string ()));
                }
 
                if (index_int_type_check) {
index 4efe18328aa417ae66c8c323e739c543f9e021ac..c708e95ad4ec2116e2dcc3f760d580e07abc7365 100644 (file)
@@ -62,8 +62,6 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        public DataType gslist_type;
        public DataType garray_type;
        public Class gerror_type;
-       public Interface list_type;
-       public Interface map_type;
 
        public int next_lambda_id = 0;
 
@@ -116,12 +114,6 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                        gerror_type = (Class) glib_ns.scope.lookup ("Error");
                }
 
-               var gee_ns = root_symbol.scope.lookup ("Gee");
-               if (gee_ns != null) {
-                       list_type = (Interface) gee_ns.scope.lookup ("List");
-                       map_type = (Interface) gee_ns.scope.lookup ("Map");
-               }
-
                current_symbol = root_symbol;
                context.root.check (this);
                context.accept (this);