vala r1958 - in trunk: . gobject
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1958 - in trunk: . gobject
- Date: Mon, 3 Nov 2008 07:34:59 +0000 (UTC)
Author: juergbi
Date: Mon Nov 3 07:34:59 2008
New Revision: 1958
URL: http://svn.gnome.org/viewvc/vala?rev=1958&view=rev
Log:
2008-11-03 JÃrg Billeter <j bitron ch>
* gobject/Makefile.am:
* gobject/valaccodearraymodule.vala:
* gobject/valaccodeelementaccessmodule.vala:
* gobject/valaccodegenerator.vala:
Move element access handling to CCodeArrayModule
Removed:
trunk/gobject/valaccodeelementaccessmodule.vala
Modified:
trunk/ChangeLog
trunk/gobject/Makefile.am
trunk/gobject/valaccodearraymodule.vala
trunk/gobject/valaccodegenerator.vala
Modified: trunk/gobject/Makefile.am
==============================================================================
--- trunk/gobject/Makefile.am (original)
+++ trunk/gobject/Makefile.am Mon Nov 3 07:34:59 2008
@@ -18,7 +18,6 @@
valaccodecompiler.vala \
valaccodedynamicpropertymodule.vala \
valaccodedynamicsignalmodule.vala \
- valaccodeelementaccessmodule.vala \
valaccodegenerator.vala \
valaccodeinvocationexpressionmodule.vala \
valaccodememberaccessmodule.vala \
Modified: trunk/gobject/valaccodearraymodule.vala
==============================================================================
--- trunk/gobject/valaccodearraymodule.vala (original)
+++ trunk/gobject/valaccodearraymodule.vala Mon Nov 3 07:34:59 2008
@@ -223,4 +223,90 @@
return new CCodeConstant ("NULL");
}
}
+
+ public override void visit_element_access (ElementAccess expr) {
+ expr.accept_children (codegen);
+
+ Gee.List<Expression> indices = expr.get_indices ();
+ int rank = indices.size;
+
+ var container_type = expr.container.value_type.data_type;
+
+ var ccontainer = (CCodeExpression) expr.container.ccodenode;
+ var cindex = (CCodeExpression) indices[0].ccodenode;
+ if (expr.container.symbol_reference is ArrayLengthField) {
+ /* Figure if cindex is a constant expression and calculate dim...*/
+ var lit = indices[0] as IntegerLiteral;
+ var memberaccess = expr.container as MemberAccess;
+ if (lit != null && memberaccess != null) {
+ int dim = lit.value.to_int ();
+ expr.ccodenode = head.get_array_length_cexpression (memberaccess.inner, dim + 1);
+ }
+ } else if (container_type == codegen.string_type.data_type) {
+ // should be moved to a different module
+
+ // access to unichar in a string
+ var coffsetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_utf8_offset_to_pointer"));
+ coffsetcall.add_argument (ccontainer);
+ coffsetcall.add_argument (cindex);
+
+ var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_utf8_get_char"));
+ ccall.add_argument (coffsetcall);
+
+ expr.ccodenode = ccall;
+ } else if (container_type != null && codegen.list_type != null && codegen.map_type != null &&
+ (container_type.is_subtype_of (codegen.list_type) || container_type.is_subtype_of (codegen.map_type))) {
+ // should be moved to a different module
+
+ TypeSymbol collection_iface = null;
+ if (container_type.is_subtype_of (codegen.list_type)) {
+ collection_iface = codegen.list_type;
+ } else if (container_type.is_subtype_of (codegen.map_type)) {
+ collection_iface = codegen.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.type_parameter != null) {
+ var index_type = SemanticAnalyzer.get_actual_type (expr.container.value_type, get_method, get_param.parameter_type, expr);
+ cindex = codegen.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 = codegen.convert_from_generic_pointer (get_ccall, expr.value_type);
+ } else if (expr.container is MemberAccess && expr.container.symbol_reference is Signal) {
+ // should be moved to the GSignal module
+
+ // detailed signal emission
+ var sig = (Signal) expr.symbol_reference;
+ var ma = (MemberAccess) expr.container;
+
+ var detail_expr = expr.get_indices ().get (0) as StringLiteral;
+ string signal_detail = detail_expr.eval ();
+
+ var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_signal_emit_by_name"));
+
+ // FIXME: use C cast if debugging disabled
+ var ccast = new CCodeFunctionCall (new CCodeIdentifier ("G_OBJECT"));
+ ccast.add_argument ((CCodeExpression) ma.inner.ccodenode);
+ ccall.add_argument (ccast);
+
+ ccall.add_argument (sig.get_canonical_cconstant (signal_detail));
+
+ expr.ccodenode = ccall;
+ } else {
+ // access to element in an array
+ for (int i = 1; i < rank; i++) {
+ var cmul = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeParenthesizedExpression (cindex), head.get_array_length_cexpression (expr.container, i + 1));
+ cindex = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, cmul, new CCodeParenthesizedExpression ((CCodeExpression) indices[i].ccodenode));
+ }
+ expr.ccodenode = new CCodeElementAccess (ccontainer, cindex);
+ }
+ }
}
Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala (original)
+++ trunk/gobject/valaccodegenerator.vala Mon Nov 3 07:34:59 2008
@@ -147,7 +147,6 @@
head = new CCodeStructModule (this, head);
head = new CCodeMethodModule (this, head);
head = new CCodeMemberAccessModule (this, head);
- head = new CCodeElementAccessModule (this, head);
head = new CCodeAssignmentModule (this, head);
head = new CCodeInvocationExpressionModule (this, head);
head = new CCodeArrayModule (this, head);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]