+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:
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++) {
}
}
- 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;
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);
}
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;
}
}
- 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");
/* 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
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;
}
/* 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
}
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) {
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;
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);