Commit 957d11ce authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

Add virtual generate_parameter method. Move array and delegate type

2009-01-23  Jürg Billeter  <j@bitron.ch>

	* gobject/valaccodearraymodule.vala:
	* gobject/valaccodedelegatemodule.vala:
	* gobject/valaccodemethodmodule.vala:

	Add virtual generate_parameter method. Move array and delegate type
	specific parameter generation to corresponding modules.

svn path=/trunk/; revision=2397
parent cec9b6dd
2009-01-23 Jürg Billeter <j@bitron.ch>
* gobject/valaccodearraymodule.vala:
* gobject/valaccodedelegatemodule.vala:
* gobject/valaccodemethodmodule.vala:
Add virtual generate_parameter method. Move array and delegate type
specific parameter generation to corresponding modules.
2009-01-20 Jürg Billeter <j@bitron.ch>
* vapigen/valagirparser.vala:
......
......@@ -682,4 +682,33 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
assignment.ccodenode = ccall;
}
public override void generate_parameter (FormalParameter param, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
if (!(param.parameter_type is ArrayType)) {
base.generate_parameter (param, cparam_map, carg_map);
return;
}
var array_type = (ArrayType) param.parameter_type;
cparam_map.set (get_param_pos (param.cparameter_position), (CCodeFormalParameter) param.ccodenode);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cparameter_position), new CCodeIdentifier (param.name));
}
if (!param.no_array_length) {
var length_ctype = "int";
if (param.direction != ParameterDirection.IN) {
length_ctype = "int*";
}
for (int dim = 1; dim <= array_type.rank; dim++) {
var cparam = new CCodeFormalParameter (head.get_array_length_cname (param.name, dim), length_ctype);
cparam_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), new CCodeIdentifier (cparam.name));
}
}
}
}
}
......@@ -380,4 +380,41 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
return wrapper_name;
}
public override void generate_parameter (FormalParameter param, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
if (!(param.parameter_type is DelegateType || param.parameter_type is MethodType)) {
base.generate_parameter (param, cparam_map, carg_map);
return;
}
cparam_map.set (get_param_pos (param.cparameter_position), (CCodeFormalParameter) param.ccodenode);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cparameter_position), new CCodeIdentifier (param.name));
}
if (param.parameter_type is DelegateType) {
var deleg_type = (DelegateType) param.parameter_type;
var d = deleg_type.delegate_symbol;
if (d.has_target) {
var cparam = new CCodeFormalParameter (get_delegate_target_cname (param.name), "void*");
cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), new CCodeIdentifier (cparam.name));
}
if (deleg_type.value_owned) {
cparam = new CCodeFormalParameter (get_delegate_target_destroy_notify_cname (param.name), "GDestroyNotify");
cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position + 0.01), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cdelegate_target_parameter_position + 0.01), new CCodeIdentifier (cparam.name));
}
}
}
} else if (param.parameter_type is MethodType) {
var cparam = new CCodeFormalParameter (get_delegate_target_cname (param.name), "void*");
cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), new CCodeIdentifier (cparam.name));
}
}
}
}
......@@ -515,6 +515,13 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
}
}
public virtual void generate_parameter (FormalParameter param, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
cparam_map.set (get_param_pos (param.cparameter_position), (CCodeFormalParameter) param.ccodenode);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cparameter_position), new CCodeIdentifier (param.name));
}
}
public override void generate_cparameters (Method m, DataType creturn_type, bool in_gtypeinstance_creation_method, Map<int,CCodeFormalParameter> cparam_map, CCodeFunction func, CCodeFunctionDeclarator? vdeclarator = null, Map<int,CCodeExpression>? carg_map = null, CCodeFunctionCall? vcall = null, int direction = 3) {
if (m.parent_symbol is Class && m is CreationMethod) {
var cl = (Class) m.parent_symbol;
......@@ -588,52 +595,7 @@ public class Vala.CCodeMethodModule : CCodeStructModule {
}
}
if (!param.no_array_length && param.parameter_type is ArrayType) {
var array_type = (ArrayType) param.parameter_type;
var length_ctype = "int";
if (param.direction != ParameterDirection.IN) {
length_ctype = "int*";
}
for (int dim = 1; dim <= array_type.rank; dim++) {
var cparam = new CCodeFormalParameter (head.get_array_length_cname (param.name, dim), length_ctype);
cparam_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), new CCodeIdentifier (cparam.name));
}
}
}
cparam_map.set (get_param_pos (param.cparameter_position), (CCodeFormalParameter) param.ccodenode);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cparameter_position), new CCodeIdentifier (param.name));
}
if (param.parameter_type is DelegateType) {
var deleg_type = (DelegateType) param.parameter_type;
var d = deleg_type.delegate_symbol;
if (d.has_target) {
var cparam = new CCodeFormalParameter (get_delegate_target_cname (param.name), "void*");
cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), new CCodeIdentifier (cparam.name));
}
if (deleg_type.value_owned) {
cparam = new CCodeFormalParameter (get_delegate_target_destroy_notify_cname (param.name), "GDestroyNotify");
cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position + 0.01), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cdelegate_target_parameter_position + 0.01), new CCodeIdentifier (cparam.name));
}
}
}
} else if (param.parameter_type is MethodType) {
var cparam = new CCodeFormalParameter (get_delegate_target_cname (param.name), "void*");
cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), new CCodeIdentifier (cparam.name));
}
}
generate_parameter (param, cparam_map, carg_map);
}
if ((direction & 2) != 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment