From: Jürg Billeter Date: Fri, 16 Jan 2009 21:49:06 +0000 (+0000) Subject: Do not require libgee to support element access in custom types X-Git-Tag: VALA_0_5_6~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=878eaacf8b24d080e660ea4779b2b1a1a2045443;p=thirdparty%2Fvala.git Do not require libgee to support element access in custom types 2009-01-16 Jürg Billeter * 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 --- diff --git a/ChangeLog b/ChangeLog index eaaae32d8..eb1c5da65 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2009-01-16 Jürg Billeter + + * 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 * vala/valaexpression.vala: diff --git a/gobject/valaccodearraymodule.vala b/gobject/valaccodearraymodule.vala index ffcfaf93a..f3f2f5154 100644 --- a/gobject/valaccodearraymodule.vala +++ b/gobject/valaccodearraymodule.vala @@ -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 get_params = get_method.get_parameters (); - Iterator 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++) { diff --git a/gobject/valaccodeassignmentmodule.vala b/gobject/valaccodeassignmentmodule.vala index 90eb3d601..6bf572d36 100644 --- a/gobject/valaccodeassignmentmodule.vala +++ b/gobject/valaccodeassignmentmodule.vala @@ -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 indices = expr.get_indices (); - Iterator 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 set_params = set_method.get_parameters (); - Iterator 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); } diff --git a/gobject/valaccodebasemodule.vala b/gobject/valaccodebasemodule.vala index 8c81f9e5a..1692cc861 100644 --- a/gobject/valaccodebasemodule.vala +++ b/gobject/valaccodebasemodule.vala @@ -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"); diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala index d24a7a39e..98dc24c1b 100644 --- a/vala/valaassignment.vala +++ b/vala/valaassignment.vala @@ -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; } diff --git a/vala/valaelementaccess.vala b/vala/valaelementaccess.vala index c5cb02b18..b65168668 100644 --- a/vala/valaelementaccess.vala +++ b/vala/valaelementaccess.vala @@ -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 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 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 get_params = get_method.get_parameters (); - Iterator 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) { diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 4efe18328..c708e95ad 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -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);