vala r1262 - in trunk: . gobject vala
- From: juergbi svn gnome org
- To: svn-commits-list gnome org
- Subject: vala r1262 - in trunk: . gobject vala
- Date: Sat, 19 Apr 2008 07:59:53 +0100 (BST)
Author: juergbi
Date: Sat Apr 19 06:59:53 2008
New Revision: 1262
URL: http://svn.gnome.org/viewvc/vala?rev=1262&view=rev
Log:
2008-04-19 Juerg Billeter <j bitron ch>
* vala/valacodegenerator.vala, vala/valainvocationexpression.vala,
vala/valamemberaccess.vala, gobject/Makefile.am,
gobject/valaccodegenerator.vala,
gobject/valaccodeinvocationexpressionbinding.vala,
gobject/valaccodememberaccessbinding.vala:
Add CCodeInvocationExpressionBinding and CCodeMemberAccessBinding
classes
Added:
trunk/gobject/valaccodeinvocationexpressionbinding.vala
- copied, changed from r1256, /trunk/gobject/valaccodegeneratorinvocationexpression.vala
trunk/gobject/valaccodememberaccessbinding.vala
- copied, changed from r1259, /trunk/gobject/valaccodegeneratormemberaccess.vala
Removed:
trunk/gobject/valaccodegeneratorinvocationexpression.vala
trunk/gobject/valaccodegeneratormemberaccess.vala
Modified:
trunk/ChangeLog
trunk/gobject/Makefile.am
trunk/gobject/valaccodegenerator.vala
trunk/vala/valacodegenerator.vala
trunk/vala/valainvocationexpression.vala
trunk/vala/valamemberaccess.vala
Modified: trunk/gobject/Makefile.am
==============================================================================
--- trunk/gobject/Makefile.am (original)
+++ trunk/gobject/Makefile.am Sat Apr 19 06:59:53 2008
@@ -21,12 +21,12 @@
valaccodeelementaccessbinding.vala \
valaccodeexpressionbinding.vala \
valaccodegenerator.vala \
- valaccodegeneratorinvocationexpression.vala \
- valaccodegeneratormemberaccess.vala \
valaccodegeneratorsignal.vala \
valaccodegeneratorsourcefile.vala \
valaccodegeneratorstruct.vala \
valaccodeinterfacebinding.vala \
+ valaccodeinvocationexpressionbinding.vala \
+ valaccodememberaccessbinding.vala \
valaccodemethodbinding.vala \
valaccodetypesymbolbinding.vala \
valaclassregisterfunction.vala \
Modified: trunk/gobject/valaccodegenerator.vala
==============================================================================
--- trunk/gobject/valaccodegenerator.vala (original)
+++ trunk/gobject/valaccodegenerator.vala Sat Apr 19 06:59:53 2008
@@ -115,7 +115,7 @@
public Typesymbol map_type;
public Typesymbol connection_type;
- Method substring_method;
+ public Method substring_method;
public bool in_plugin = false;
public string module_init_param_name;
@@ -123,7 +123,7 @@
public bool string_h_needed;
private bool requires_free_checked;
private bool requires_array_free;
- private bool requires_array_move;
+ public bool requires_array_move;
private bool requires_strcmp0;
private Set<string> wrappers;
@@ -1084,7 +1084,7 @@
temp_vars.clear ();
}
- private string get_variable_cname (string name) {
+ public string get_variable_cname (string name) {
if (c_keywords.contains (name)) {
return name + "_";
} else {
@@ -2387,7 +2387,15 @@
visit_expression (expr);
}
-
+
+ public override void visit_member_access (MemberAccess expr) {
+ code_binding (expr).emit ();
+ }
+
+ public override void visit_invocation_expression (InvocationExpression expr) {
+ code_binding (expr).emit ();
+ }
+
public string get_array_length_cname (string array_cname, int dim) {
return "%s_length%d".printf (array_cname, dim);
}
@@ -3646,6 +3654,22 @@
return new CCodeExpressionStatement (ccheck);
}
+ public int get_param_pos (double param_pos, bool ellipsis = false) {
+ if (!ellipsis) {
+ if (param_pos >= 0) {
+ return (int) (param_pos * 1000);
+ } else {
+ return (int) ((100 + param_pos) * 1000);
+ }
+ } else {
+ if (param_pos >= 0) {
+ return (int) ((100 + param_pos) * 1000);
+ } else {
+ return (int) ((200 + param_pos) * 1000);
+ }
+ }
+ }
+
public override CodeBinding? create_namespace_binding (Namespace node) {
return null;
}
@@ -3847,15 +3871,11 @@
}
public override CodeBinding? create_member_access_binding (MemberAccess node) {
- return null;
- }
-
- public override CodeBinding? create_member_access_simple_binding (MemberAccess node) {
- return null;
+ return new CCodeMemberAccessBinding (this, node);
}
public override CodeBinding? create_invocation_expression_binding (InvocationExpression node) {
- return null;
+ return new CCodeInvocationExpressionBinding (this, node);
}
public override CodeBinding? create_element_access_binding (ElementAccess node) {
@@ -3918,10 +3938,6 @@
return null;
}
- public override CodeBinding? create_lambda_expression_with_statement_body_binding (LambdaExpression node) {
- return null;
- }
-
public override CodeBinding? create_assignment_binding (Assignment node) {
return new CCodeAssignmentBinding (this, node);
}
Copied: trunk/gobject/valaccodeinvocationexpressionbinding.vala (from r1256, /trunk/gobject/valaccodegeneratorinvocationexpression.vala)
==============================================================================
--- /trunk/gobject/valaccodegeneratorinvocationexpression.vala (original)
+++ trunk/gobject/valaccodeinvocationexpressionbinding.vala Sat Apr 19 06:59:53 2008
@@ -1,4 +1,4 @@
-/* valaccodegeneratorinvocationexpression.vala
+/* valaccodeinvocationexpressionbinding.vala
*
* Copyright (C) 2006-2008 JÃrg Billeter, Raffaele Sandrini
*
@@ -24,9 +24,18 @@
using GLib;
using Gee;
-public class Vala.CCodeGenerator {
- public override void visit_invocation_expression (InvocationExpression expr) {
- expr.accept_children (this);
+public class Vala.CCodeInvocationExpressionBinding : CCodeExpressionBinding {
+ public InvocationExpression invocation_expression { get; set; }
+
+ public CCodeInvocationExpressionBinding (CCodeGenerator codegen, InvocationExpression invocation_expression) {
+ this.invocation_expression = invocation_expression;
+ this.codegen = codegen;
+ }
+
+ public override void emit () {
+ var expr = invocation_expression;
+
+ expr.accept_children (codegen);
// the bare function call
var ccall = new CCodeFunctionCall ((CCodeExpression) expr.call.ccodenode);
@@ -58,9 +67,9 @@
if (m is ArrayResizeMethod) {
var array_type = (ArrayType) ma.inner.static_type;
- carg_map.set (get_param_pos (0), new CCodeIdentifier (array_type.element_type.get_cname ()));
+ carg_map.set (codegen.get_param_pos (0), new CCodeIdentifier (array_type.element_type.get_cname ()));
} else if (m is ArrayMoveMethod) {
- requires_array_move = true;
+ codegen.requires_array_move = true;
}
CCodeExpression instance;
@@ -75,13 +84,13 @@
DataType instance_expression_type;
if (ma.inner == null) {
instance = new CCodeIdentifier ("self");
- instance_expression_type = get_data_type_for_symbol (current_type_symbol);
+ instance_expression_type = codegen.get_data_type_for_symbol (codegen.current_type_symbol);
} else {
instance = (CCodeExpression) ma.inner.ccodenode;
instance_expression_type = ma.inner.static_type;
}
- if (instance_expression_type.data_type is Struct && !((Struct) instance_expression_type.data_type).is_simple_type () && instance_expression_type.data_type != current_type_symbol) {
+ if (instance_expression_type.data_type is Struct && !((Struct) instance_expression_type.data_type).is_simple_type () && instance_expression_type.data_type != codegen.current_type_symbol) {
if (instance is CCodeIdentifier) {
instance = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance);
} else {
@@ -89,8 +98,8 @@
// (tmp = expr, &tmp)
var ccomma = new CCodeCommaExpression ();
- var temp_var = get_temp_variable (instance_expression_type);
- temp_vars.insert (0, temp_var);
+ var temp_var = codegen.get_temp_variable (instance_expression_type);
+ codegen.temp_vars.insert (0, temp_var);
ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (temp_var.name), instance));
ccomma.append_expression (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (temp_var.name)));
@@ -102,17 +111,17 @@
if (base_method.parent_symbol != null) {
var instance_target_type = ma.static_type.copy ();
instance_target_type.data_type = (Typesymbol) base_method.parent_symbol;
- instance = get_implicit_cast_expression (instance, instance_expression_type, instance_target_type);
+ instance = codegen.get_implicit_cast_expression (instance, instance_expression_type, instance_target_type);
}
- carg_map.set (get_param_pos (m.cinstance_parameter_position), instance);
+ carg_map.set (codegen.get_param_pos (m.cinstance_parameter_position), instance);
}
if (m is ArrayMoveMethod) {
var array_type = (ArrayType) ma.inner.static_type;
var csizeof = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
csizeof.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
- carg_map.set (get_param_pos (0.1), csizeof);
+ carg_map.set (codegen.get_param_pos (0.1), csizeof);
} else if (m is DBusMethod) {
bool found_out = false;
Expression callback = null;
@@ -147,7 +156,7 @@
}
}
- carg_map.set (get_param_pos (0.1), new CCodeConstant ("\"%s\"".printf (m.name)));
+ carg_map.set (codegen.get_param_pos (0.1), new CCodeConstant ("\"%s\"".printf (m.name)));
if (callback != null) {
var reply_method = (Method) callback.symbol_reference;
@@ -174,7 +183,7 @@
// error parameter
break;
}
- if (param.type_reference is ArrayType && ((ArrayType) param.type_reference).element_type.data_type != string_type.data_type) {
+ if (param.type_reference is ArrayType && ((ArrayType) param.type_reference).element_type.data_type != codegen.string_type.data_type) {
var array_type = (ArrayType) param.type_reference;
var cdecl = new CCodeDeclaration ("GArray*");
cdecl.add_declarator (new CCodeVariableDeclarator (param.name));
@@ -187,7 +196,7 @@
var cdecl = new CCodeDeclaration (param.type_reference.get_cname ());
cdecl.add_declarator (new CCodeVariableDeclarator (param.name));
cb_fun.block.add_statement (cdecl);
- if (param.type_reference is ArrayType && ((ArrayType) param.type_reference).element_type.data_type == string_type.data_type) {
+ if (param.type_reference is ArrayType && ((ArrayType) param.type_reference).element_type.data_type == codegen.string_type.data_type) {
// special case string array
cend_call.add_argument (new CCodeIdentifier ("G_TYPE_STRV"));
var cstrvlen = new CCodeFunctionCall (new CCodeIdentifier ("g_strv_length"));
@@ -204,17 +213,17 @@
cb_fun.block.add_statement (new CCodeExpressionStatement (cend_call));
creply_call.add_argument (new CCodeIdentifier ("error"));
cb_fun.block.add_statement (new CCodeExpressionStatement (creply_call));
- source_type_member_definition.append (cb_fun);
+ codegen.source_type_member_definition.append (cb_fun);
- carg_map.set (get_param_pos (0.2), new CCodeIdentifier (cb_fun.name));
- carg_map.set (get_param_pos (0.3), new CCodeConstant ("self"));
- carg_map.set (get_param_pos (0.4), new CCodeConstant ("NULL"));
+ carg_map.set (codegen.get_param_pos (0.2), new CCodeIdentifier (cb_fun.name));
+ carg_map.set (codegen.get_param_pos (0.3), new CCodeConstant ("self"));
+ carg_map.set (codegen.get_param_pos (0.4), new CCodeConstant ("NULL"));
} else if (found_out || !(m.return_type is VoidType)) {
ccall.call = new CCodeIdentifier ("dbus_g_proxy_call");
// method can fail
- current_method_inner_error = true;
- carg_map.set (get_param_pos (0.2), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("inner_error")));
+ codegen.current_method_inner_error = true;
+ carg_map.set (codegen.get_param_pos (0.2), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("inner_error")));
} else {
ccall.call = new CCodeIdentifier ("dbus_g_proxy_call_no_reply");
}
@@ -232,7 +241,7 @@
break;
}
- carg_map.set (get_param_pos (i - 0.1, true), new CCodeIdentifier (arg.static_type.data_type.get_type_id ()));
+ carg_map.set (codegen.get_param_pos (i - 0.1, true), new CCodeIdentifier (arg.static_type.data_type.get_type_id ()));
}
CCodeExpression cexpr = (CCodeExpression) arg.ccodenode;
@@ -251,18 +260,18 @@
if (!param.no_array_length && param.type_reference is ArrayType) {
var array_type = (ArrayType) param.type_reference;
for (int dim = 1; dim <= array_type.rank; dim++) {
- carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), get_array_length_cexpression (arg, dim));
+ carg_map.set (codegen.get_param_pos (param.carray_length_parameter_position + 0.01 * dim), codegen.get_array_length_cexpression (arg, dim));
}
multiple_cargs = true;
} else if (param.type_reference is DelegateType) {
var deleg_type = (DelegateType) param.type_reference;
var d = deleg_type.delegate_symbol;
if (d.instance) {
- carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), get_delegate_target_cexpression (arg));
+ carg_map.set (codegen.get_param_pos (param.cdelegate_target_parameter_position), codegen.get_delegate_target_cexpression (arg));
multiple_cargs = true;
}
}
- cexpr = get_implicit_cast_expression (cexpr, arg.static_type, param.type_reference);
+ cexpr = codegen.get_implicit_cast_expression (cexpr, arg.static_type, param.type_reference);
// pass non-simple struct instances always by reference
if (!(arg.static_type is NullType) && param.type_reference.data_type is Struct && !((Struct) param.type_reference.data_type).is_simple_type ()) {
@@ -275,8 +284,8 @@
// (tmp = expr, &tmp)
var ccomma = new CCodeCommaExpression ();
- var temp_var = get_temp_variable (arg.static_type);
- temp_vars.insert (0, temp_var);
+ var temp_var = codegen.get_temp_variable (arg.static_type);
+ codegen.temp_vars.insert (0, temp_var);
ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (temp_var.name), cexpr));
ccomma.append_expression (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (temp_var.name)));
@@ -293,8 +302,8 @@
var ccomma = new CCodeCommaExpression ();
- var temp_decl = get_temp_variable (arg.static_type);
- temp_vars.insert (0, temp_decl);
+ var temp_decl = codegen.get_temp_variable (arg.static_type);
+ codegen.temp_vars.insert (0, temp_decl);
ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (temp_decl.name), cexpr));
cexpr = new CCodeIdentifier (temp_decl.name);
@@ -311,8 +320,8 @@
// (ret_tmp = call (&tmp), free (var1), var1 = tmp, ret_tmp)
var ccomma = new CCodeCommaExpression ();
- var temp_var = get_temp_variable (unary.inner.static_type);
- temp_vars.insert (0, temp_var);
+ var temp_var = codegen.get_temp_variable (unary.inner.static_type);
+ codegen.temp_vars.insert (0, temp_var);
cexpr = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (temp_var.name));
// call function
@@ -320,13 +329,13 @@
if (m.return_type is VoidType) {
ccomma.append_expression (ccall_expr);
} else {
- ret_temp_var = get_temp_variable (m.return_type);
- temp_vars.insert (0, ret_temp_var);
+ ret_temp_var = codegen.get_temp_variable (m.return_type);
+ codegen.temp_vars.insert (0, ret_temp_var);
ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (ret_temp_var.name), ccall_expr));
}
// unref old value
- ccomma.append_expression (get_unref_expression ((CCodeExpression) unary.inner.ccodenode, arg.static_type, arg));
+ ccomma.append_expression (codegen.get_unref_expression ((CCodeExpression) unary.inner.ccodenode, arg.static_type, arg));
// assign new value
ccomma.append_expression (new CCodeAssignment ((CCodeExpression) unary.inner.ccodenode, new CCodeIdentifier (temp_var.name)));
@@ -339,10 +348,10 @@
ccall_expr = ccomma;
}
}
- arg_pos = get_param_pos (param.cparameter_position, ellipsis);
+ arg_pos = codegen.get_param_pos (param.cparameter_position, ellipsis);
} else {
// default argument position
- arg_pos = get_param_pos (i, ellipsis);
+ arg_pos = codegen.get_param_pos (i, ellipsis);
}
carg_map.set (arg_pos, cexpr);
@@ -365,17 +374,17 @@
/* evaluate default expression here as the code
* generator might not have visited the formal
* parameter yet */
- param.default_expression.accept (this);
+ param.default_expression.accept (codegen);
if (!param.no_array_length && param.type_reference != null &&
param.type_reference is ArrayType) {
var array_type = (ArrayType) param.type_reference;
for (int dim = 1; dim <= array_type.rank; dim++) {
- carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), get_array_length_cexpression (param.default_expression, dim));
+ carg_map.set (codegen.get_param_pos (param.carray_length_parameter_position + 0.01 * dim), codegen.get_array_length_cexpression (param.default_expression, dim));
}
}
- carg_map.set (get_param_pos (param.cparameter_position), (CCodeExpression) param.default_expression.ccodenode);
+ carg_map.set (codegen.get_param_pos (param.cparameter_position), (CCodeExpression) param.default_expression.ccodenode);
i++;
}
@@ -384,12 +393,12 @@
var array_type = (ArrayType) m.return_type;
for (int dim = 1; dim <= array_type.rank; dim++) {
if (!m.no_array_length) {
- var temp_var = get_temp_variable (int_type);
+ var temp_var = codegen.get_temp_variable (codegen.int_type);
var temp_ref = new CCodeIdentifier (temp_var.name);
- temp_vars.insert (0, temp_var);
+ codegen.temp_vars.insert (0, temp_var);
- carg_map.set (get_param_pos (m.carray_length_parameter_position + 0.01 * dim), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
+ carg_map.set (codegen.get_param_pos (m.carray_length_parameter_position + 0.01 * dim), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
expr.append_array_size (temp_ref);
} else {
@@ -400,43 +409,43 @@
var deleg_type = (DelegateType) m.return_type;
var d = deleg_type.delegate_symbol;
if (d.instance) {
- var temp_var = get_temp_variable (new PointerType (new VoidType ()));
+ var temp_var = codegen.get_temp_variable (new PointerType (new VoidType ()));
var temp_ref = new CCodeIdentifier (temp_var.name);
- temp_vars.insert (0, temp_var);
+ codegen.temp_vars.insert (0, temp_var);
- carg_map.set (get_param_pos (m.cdelegate_target_parameter_position), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
+ carg_map.set (codegen.get_param_pos (m.cdelegate_target_parameter_position), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
expr.delegate_target = temp_ref;
}
}
- if (connection_type != null && ma.inner != null && ma.inner.static_type != null && ma.inner.static_type.data_type == connection_type && m.name == "get_object") {
+ if (codegen.connection_type != null && ma.inner != null && ma.inner.static_type != null && ma.inner.static_type.data_type == codegen.connection_type && m.name == "get_object") {
var dbus_iface = (Interface) m.return_type.data_type;
var dbus_attr = dbus_iface.get_attribute ("DBusInterface");
- carg_map.set (get_param_pos (-1), new CCodeConstant ("\"%s\"".printf (dbus_attr.get_string ("name"))));
+ carg_map.set (codegen.get_param_pos (-1), new CCodeConstant ("\"%s\"".printf (dbus_attr.get_string ("name"))));
} else if (m is DBusMethod) {
- carg_map.set (get_param_pos (-1, true), new CCodeIdentifier ("G_TYPE_INVALID"));
+ carg_map.set (codegen.get_param_pos (-1, true), new CCodeIdentifier ("G_TYPE_INVALID"));
}
if (expr.can_fail && !(m is DBusMethod)) {
// method can fail
- current_method_inner_error = true;
+ codegen.current_method_inner_error = true;
// add &inner_error before the ellipsis arguments
- carg_map.set (get_param_pos (-2), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("inner_error")));
+ carg_map.set (codegen.get_param_pos (-2), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("inner_error")));
}
if (ellipsis) {
/* ensure variable argument list ends with NULL
* except when using printf-style arguments */
if ((m == null || !m.printf_format) && !(m is DBusMethod)) {
- carg_map.set (get_param_pos (-1, true), new CCodeConstant (m.sentinel));
+ carg_map.set (codegen.get_param_pos (-1, true), new CCodeConstant (m.sentinel));
}
} else if (itype is DelegateType) {
var deleg_type = (DelegateType) itype;
var d = deleg_type.delegate_symbol;
if (d.instance) {
- carg_map.set (get_param_pos (d.cinstance_parameter_position), get_delegate_target_cexpression (expr.call));
+ carg_map.set (codegen.get_param_pos (d.cinstance_parameter_position), codegen.get_delegate_target_cexpression (expr.call));
}
}
@@ -462,12 +471,12 @@
} else {
/* cast pointer to actual type if this is a generic method return value */
if (m != null && m.return_type.type_parameter != null && expr.static_type.data_type != null) {
- expr.ccodenode = convert_from_generic_pointer (ccall_expr, expr.static_type);
+ expr.ccodenode = codegen.convert_from_generic_pointer (ccall_expr, expr.static_type);
} else {
expr.ccodenode = ccall_expr;
}
- visit_expression (expr);
+ codegen.visit_expression (expr);
}
if (m is ArrayResizeMethod) {
@@ -476,15 +485,15 @@
arg_it.next ();
var new_size = (CCodeExpression) arg_it.get ().ccodenode;
- var temp_decl = get_temp_variable (int_type);
+ var temp_decl = codegen.get_temp_variable (codegen.int_type);
var temp_ref = new CCodeIdentifier (temp_decl.name);
- temp_vars.insert (0, temp_decl);
+ codegen.temp_vars.insert (0, temp_decl);
/* memset needs string.h */
- string_h_needed = true;
+ codegen.string_h_needed = true;
- var clen = get_array_length_cexpression (ma.inner, 1);
+ var clen = codegen.get_array_length_cexpression (ma.inner, 1);
var celems = (CCodeExpression) ma.inner.ccodenode;
var array_type = (ArrayType) ma.inner.static_type;
var csizeof = new CCodeIdentifier ("sizeof (%s)".printf (array_type.element_type.get_cname ()));
@@ -500,14 +509,14 @@
ccomma.append_expression (new CCodeAssignment (temp_ref, new_size));
ccomma.append_expression ((CCodeExpression) expr.ccodenode);
ccomma.append_expression (new CCodeConditionalExpression (ccheck, czero, new CCodeConstant ("NULL")));
- ccomma.append_expression (new CCodeAssignment (get_array_length_cexpression (ma.inner, 1), temp_ref));
+ ccomma.append_expression (new CCodeAssignment (codegen.get_array_length_cexpression (ma.inner, 1), temp_ref));
expr.ccodenode = ccomma;
- } else if (m == substring_method) {
- var temp_decl = get_temp_variable (string_type);
+ } else if (m == codegen.substring_method) {
+ var temp_decl = codegen.get_temp_variable (codegen.string_type);
var temp_ref = new CCodeIdentifier (temp_decl.name);
- temp_vars.insert (0, temp_decl);
+ codegen.temp_vars.insert (0, temp_decl);
Gee.List<CCodeExpression> args = ccall.get_arguments ();
@@ -533,15 +542,15 @@
expr.ccodenode = ccomma;
} else if (m is DBusMethod && !(m.return_type is VoidType)) {
// synchronous D-Bus method call with reply
- if (m.return_type is ArrayType && ((ArrayType) m.return_type).element_type.data_type != string_type.data_type) {
+ if (m.return_type is ArrayType && ((ArrayType) m.return_type).element_type.data_type != codegen.string_type.data_type) {
// non-string arrays (use GArray)
var array_type = (ArrayType) m.return_type;
ccall.add_argument (get_dbus_array_type (array_type));
- var garray_type_reference = get_data_type_for_symbol (garray_type);
- var temp_decl = get_temp_variable (garray_type_reference);
- temp_vars.insert (0, temp_decl);
+ var garray_type_reference = codegen.get_data_type_for_symbol (codegen.garray_type);
+ var temp_decl = codegen.get_temp_variable (garray_type_reference);
+ codegen.temp_vars.insert (0, temp_decl);
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (temp_decl.name)));
ccall.add_argument (new CCodeIdentifier ("G_TYPE_INVALID"));
@@ -567,8 +576,8 @@
ccall.add_argument (new CCodeIdentifier (m.return_type.data_type.get_type_id ()));
}
- var temp_decl = get_temp_variable (m.return_type);
- temp_vars.insert (0, temp_decl);
+ var temp_decl = codegen.get_temp_variable (m.return_type);
+ codegen.temp_vars.insert (0, temp_decl);
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier (temp_decl.name)));
ccall.add_argument (new CCodeIdentifier ("G_TYPE_INVALID"));
@@ -578,7 +587,7 @@
ccomma.append_expression (new CCodeIdentifier (temp_decl.name));
expr.ccodenode = ccomma;
- if (m.return_type is ArrayType && ((ArrayType) m.return_type).element_type.data_type == string_type.data_type) {
+ if (m.return_type is ArrayType && ((ArrayType) m.return_type).element_type.data_type == codegen.string_type.data_type) {
// special case string array
if (!m.no_array_length) {
var cstrvlen = new CCodeFunctionCall (new CCodeIdentifier ("g_strv_length"));
@@ -598,21 +607,5 @@
carray_type.add_argument (new CCodeIdentifier (array_type.element_type.data_type.get_type_id ()));
return carray_type;
}
-
- public int get_param_pos (double param_pos, bool ellipsis = false) {
- if (!ellipsis) {
- if (param_pos >= 0) {
- return (int) (param_pos * 1000);
- } else {
- return (int) ((100 + param_pos) * 1000);
- }
- } else {
- if (param_pos >= 0) {
- return (int) ((100 + param_pos) * 1000);
- } else {
- return (int) ((200 + param_pos) * 1000);
- }
- }
- }
}
Copied: trunk/gobject/valaccodememberaccessbinding.vala (from r1259, /trunk/gobject/valaccodegeneratormemberaccess.vala)
==============================================================================
--- /trunk/gobject/valaccodegeneratormemberaccess.vala (original)
+++ trunk/gobject/valaccodememberaccessbinding.vala Sat Apr 19 06:59:53 2008
@@ -1,4 +1,4 @@
-/* valaccodegeneratormemberaccess.vala
+/* valaccodememberaccessbinding.vala
*
* Copyright (C) 2006-2008 JÃrg Billeter, Raffaele Sandrini
*
@@ -23,7 +23,14 @@
using GLib;
-public class Vala.CCodeGenerator {
+public class Vala.CCodeMemberAccessBinding : CCodeExpressionBinding {
+ public MemberAccess member_access { get; set; }
+
+ public CCodeMemberAccessBinding (CCodeGenerator codegen, MemberAccess member_access) {
+ this.member_access = member_access;
+ this.codegen = codegen;
+ }
+
private void process_cmember (MemberAccess expr, CCodeExpression? pub_inst, DataType? base_type) {
if (expr.symbol_reference is Method) {
var m = (Method) expr.symbol_reference;
@@ -32,13 +39,13 @@
if (m.base_method != null) {
var base_class = (Class) m.base_method.parent_symbol;
var vcast = new CCodeFunctionCall (new CCodeIdentifier ("%s_CLASS".printf (base_class.get_upper_case_cname (null))));
- vcast.add_argument (new CCodeIdentifier ("%s_parent_class".printf (current_class.get_lower_case_cname (null))));
+ vcast.add_argument (new CCodeIdentifier ("%s_parent_class".printf (codegen.current_class.get_lower_case_cname (null))));
expr.ccodenode = new CCodeMemberAccess.pointer (vcast, m.name);
return;
} else if (m.base_interface_method != null) {
var base_iface = (Interface) m.base_interface_method.parent_symbol;
- string parent_iface_var = "%s_%s_parent_iface".printf (current_class.get_lower_case_cname (null), base_iface.get_lower_case_cname (null));
+ string parent_iface_var = "%s_%s_parent_iface".printf (codegen.current_class.get_lower_case_cname (null), base_iface.get_lower_case_cname (null));
expr.ccodenode = new CCodeMemberAccess.pointer (new CCodeIdentifier (parent_iface_var), m.name);
return;
@@ -52,8 +59,8 @@
if (expr.inner != null && !expr.inner.is_pure ()) {
// instance expression has side-effects
// store in temp. variable
- var temp_var = get_temp_variable (expr.inner.static_type);
- temp_vars.insert (0, temp_var);
+ var temp_var = codegen.get_temp_variable (expr.inner.static_type);
+ codegen.temp_vars.insert (0, temp_var);
var ctemp = new CCodeIdentifier (temp_var.name);
inst = new CCodeAssignment (ctemp, pub_inst);
expr.inner.ccodenode = ctemp;
@@ -71,15 +78,15 @@
expr.ccodenode = new CCodeIdentifier (m.get_cname ());
}
} else if (expr.symbol_reference is ArrayLengthField) {
- expr.ccodenode = get_array_length_cexpression (expr.inner, 1);
+ expr.ccodenode = codegen.get_array_length_cexpression (expr.inner, 1);
} else if (expr.symbol_reference is Field) {
var f = (Field) expr.symbol_reference;
if (f.instance) {
var instance_expression_type = base_type;
- var instance_target_type = get_data_type_for_symbol ((Typesymbol) f.parent_symbol);
- CCodeExpression typed_inst = get_implicit_cast_expression (pub_inst, instance_expression_type, instance_target_type);
+ var instance_target_type = codegen.get_data_type_for_symbol ((Typesymbol) f.parent_symbol);
+ CCodeExpression typed_inst = codegen.get_implicit_cast_expression (pub_inst, instance_expression_type, instance_target_type);
- bool is_gtypeinstance = (instance_target_type.data_type.is_subtype_of (gtypeinstance_type));
+ bool is_gtypeinstance = (instance_target_type.data_type.is_subtype_of (codegen.gtypeinstance_type));
CCodeExpression inst;
if (is_gtypeinstance && f.access == SymbolAccessibility.PRIVATE) {
@@ -97,7 +104,7 @@
}
if (f.type_reference.type_parameter != null && expr.static_type.type_parameter == null) {
- expr.ccodenode = convert_from_generic_pointer ((CCodeExpression) expr.ccodenode, expr.static_type);
+ expr.ccodenode = codegen.convert_from_generic_pointer ((CCodeExpression) expr.ccodenode, expr.static_type);
}
} else if (expr.symbol_reference is Constant) {
var c = (Constant) expr.symbol_reference;
@@ -107,7 +114,7 @@
if (prop.get_accessor != null &&
prop.get_accessor.automatic_body &&
- current_type_symbol == prop.parent_symbol) {
+ codegen.current_type_symbol == prop.parent_symbol) {
CCodeExpression inst;
inst = new CCodeMemberAccess.pointer (pub_inst, "priv");
expr.ccodenode = new CCodeMemberAccess.pointer (inst, prop.field.get_cname());
@@ -122,8 +129,8 @@
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_get_%s".printf (base_property_type.get_lower_case_cname (null), base_property.name)));
var instance_expression_type = base_type;
- var instance_target_type = get_data_type_for_symbol (base_property_type);
- CCodeExpression typed_pub_inst = get_implicit_cast_expression (pub_inst, instance_expression_type, instance_target_type);
+ var instance_target_type = codegen.get_data_type_for_symbol (base_property_type);
+ CCodeExpression typed_pub_inst = codegen.get_implicit_cast_expression (pub_inst, instance_expression_type, instance_target_type);
ccall.add_argument (typed_pub_inst);
@@ -131,9 +138,9 @@
// They are returned as out parameter.
if (base_property.type_reference.is_real_struct_type ()) {
var ccomma = new CCodeCommaExpression ();
- var temp_var = get_temp_variable (base_property.type_reference);
+ var temp_var = codegen.get_temp_variable (base_property.type_reference);
var ctemp = new CCodeIdentifier (temp_var.name);
- temp_vars.add (temp_var);
+ codegen.temp_vars.add (temp_var);
ccall.add_argument (new CCodeUnaryExpression(CCodeUnaryOperator.ADDRESS_OF, ctemp));
ccomma.append_expression (ccall);
ccomma.append_expression (ctemp);
@@ -153,8 +160,8 @@
// we need a temporary variable to save the property value
- var temp_var = get_temp_variable (expr.static_type);
- temp_vars.insert (0, temp_var);
+ var temp_var = codegen.get_temp_variable (expr.static_type);
+ codegen.temp_vars.insert (0, temp_var);
var ctemp = new CCodeIdentifier (temp_var.name);
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, ctemp));
@@ -172,7 +179,7 @@
expr.ccodenode = new CCodeConstant (ev.get_cname ());
} else if (expr.symbol_reference is LocalVariable) {
var local = (LocalVariable) expr.symbol_reference;
- expr.ccodenode = new CCodeIdentifier (get_variable_cname (local.name));
+ expr.ccodenode = new CCodeIdentifier (codegen.get_variable_cname (local.name));
} else if (expr.symbol_reference is FormalParameter) {
var p = (FormalParameter) expr.symbol_reference;
if (p.name == "this") {
@@ -186,10 +193,10 @@
// Property setters of non simple structs shall replace all occurences
// of the "value" formal parameter with a dereferencing version of that
// parameter.
- if (current_property_accessor != null &&
- current_property_accessor.writable &&
- current_property_accessor.value_parameter == p &&
- current_property_accessor.prop.type_reference.is_real_struct_type ()) {
+ if (codegen.current_property_accessor != null &&
+ codegen.current_property_accessor.writable &&
+ codegen.current_property_accessor.value_parameter == p &&
+ codegen.current_property_accessor.prop.type_reference.is_real_struct_type ()) {
expr.ccodenode = new CCodeIdentifier ("(*value)");
} else {
expr.ccodenode = new CCodeIdentifier (p.name);
@@ -203,8 +210,8 @@
if (sig.has_emitter) {
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_%s".printf (cl.get_lower_case_cname (null), sig.name)));
var instance_expression_type = base_type;
- var instance_target_type = get_data_type_for_symbol (cl);
- CCodeExpression typed_pub_inst = get_implicit_cast_expression (pub_inst, instance_expression_type, instance_target_type);
+ var instance_target_type = codegen.get_data_type_for_symbol (cl);
+ CCodeExpression typed_pub_inst = codegen.get_implicit_cast_expression (pub_inst, instance_expression_type, instance_target_type);
ccall.add_argument (typed_pub_inst);
expr.ccodenode = ccall;
@@ -223,21 +230,23 @@
}
}
- public override void visit_member_access (MemberAccess expr) {
+ public override void emit () {
+ var expr = member_access;
+
CCodeExpression pub_inst = null;
DataType base_type = null;
if (expr.inner == null) {
pub_inst = new CCodeIdentifier ("self");
- if (current_type_symbol != null) {
+ if (codegen.current_type_symbol != null) {
/* base type is available if this is a type method */
- if (current_type_symbol is Class) {
- base_type = new ClassType ((Class) current_type_symbol);
- } else if (current_type_symbol is Interface) {
- base_type = new InterfaceType ((Interface) current_type_symbol);
+ if (codegen.current_type_symbol is Class) {
+ base_type = new ClassType ((Class) codegen.current_type_symbol);
+ } else if (codegen.current_type_symbol is Interface) {
+ base_type = new InterfaceType ((Interface) codegen.current_type_symbol);
} else {
- base_type = new ValueType (current_type_symbol);
+ base_type = new ValueType (codegen.current_type_symbol);
pub_inst = new CCodeIdentifier ("(*self)");
}
}
@@ -251,7 +260,7 @@
process_cmember (expr, pub_inst, base_type);
- visit_expression (expr);
+ codegen.visit_expression (expr);
}
}
Modified: trunk/vala/valacodegenerator.vala
==============================================================================
--- trunk/vala/valacodegenerator.vala (original)
+++ trunk/vala/valacodegenerator.vala Sat Apr 19 06:59:53 2008
@@ -238,10 +238,6 @@
return null;
}
- public virtual CodeBinding? create_member_access_simple_binding (MemberAccess node) {
- return null;
- }
-
public virtual CodeBinding? create_invocation_expression_binding (InvocationExpression node) {
return null;
}
@@ -306,10 +302,6 @@
return null;
}
- public virtual CodeBinding? create_lambda_expression_with_statement_body_binding (LambdaExpression node) {
- return null;
- }
-
public virtual CodeBinding? create_assignment_binding (Assignment node) {
return null;
}
Modified: trunk/vala/valainvocationexpression.vala
==============================================================================
--- trunk/vala/valainvocationexpression.vala (original)
+++ trunk/vala/valainvocationexpression.vala Sat Apr 19 06:59:53 2008
@@ -118,4 +118,8 @@
public override bool is_pure () {
return false;
}
+
+ public override CodeBinding? create_code_binding (CodeGenerator codegen) {
+ return codegen.create_invocation_expression_binding (this);
+ }
}
Modified: trunk/vala/valamemberaccess.vala
==============================================================================
--- trunk/vala/valamemberaccess.vala (original)
+++ trunk/vala/valamemberaccess.vala Sat Apr 19 06:59:53 2008
@@ -1,6 +1,6 @@
/* valamemberaccess.vala
*
- * Copyright (C) 2006-2007 JÃrg Billeter
+ * Copyright (C) 2006-2008 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
@@ -150,4 +150,8 @@
}
}
}
+
+ public override CodeBinding? create_code_binding (CodeGenerator codegen) {
+ return codegen.create_member_access_binding (this);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]