Commit 82ae929d authored by Rico Tzschichholz's avatar Rico Tzschichholz

codegen: Use get_ccode_*name/get_parameter_cexpression() for Parameters

parent 1afce035
......@@ -118,7 +118,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
if (get_ccode_array_length_name (param) != null) {
return get_ccode_array_length_name (param);
} else {
return get_array_length_cname (get_variable_cname (param.name), dim);
return get_array_length_cname (get_ccode_name (param), dim);
}
}
......@@ -723,7 +723,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
}
string ctypename = get_ccode_name (param.variable_type);
string name = get_variable_cname (param.name);
string name = get_ccode_name (param);
var array_type = (ArrayType) param.variable_type;
if (array_type.fixed_length) {
......@@ -740,7 +740,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
cparam_map.set (get_param_pos (get_ccode_pos (param)), main_cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (get_ccode_pos (param)), get_variable_cexpression (param.name));
carg_map.set (get_param_pos (get_ccode_pos (param)), get_parameter_cexpression (param));
}
if (!array_type.fixed_length && get_ccode_array_length (param)) {
......@@ -753,7 +753,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
var cparam = new CCodeParameter (get_parameter_array_length_cname (param, dim), length_ctype);
cparam_map.set (get_param_pos (get_ccode_array_length_pos (param) + 0.01 * dim), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (get_ccode_array_length_pos (param) + 0.01 * dim), get_variable_cexpression (cparam.name));
carg_map.set (get_param_pos (get_ccode_array_length_pos (param) + 0.01 * dim), get_cexpression (cparam.name));
}
}
}
......
......@@ -1956,7 +1956,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
if (!param.variable_type.value_owned) {
param_type.value_owned = !no_implicit_copy (param.variable_type);
}
data.add_field (get_ccode_name (param_type), get_variable_cname (param.name));
data.add_field (get_ccode_name (param_type), get_ccode_name (param));
// create copy if necessary as captured variables may need to be kept alive
param.captured = false;
......@@ -1973,7 +1973,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
} else if (deleg_type != null && deleg_type.delegate_symbol.has_target) {
data.add_field (get_ccode_name (delegate_target_type), get_ccode_delegate_target_name (param));
if (param.variable_type.is_disposable ()) {
data.add_field (get_ccode_name (delegate_target_destroy_type), get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
data.add_field (get_ccode_name (delegate_target_destroy_type), get_ccode_delegate_target_destroy_notify_name (param));
// reference transfer for delegates
var lvalue = get_parameter_cvalue (param);
((GLibValue) value).delegate_target_destroy_notify_cvalue = get_delegate_target_destroy_notify_cvalue (lvalue);
......@@ -2357,6 +2357,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return get_cexpression (get_local_cname (local));
}
public CCodeExpression get_parameter_cexpression (Parameter param) {
return get_cexpression (get_ccode_name (param));
}
public CCodeExpression get_variable_cexpression (string name) {
return get_cexpression (get_variable_cname (name));
}
......@@ -3795,13 +3799,13 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var old_coroutine = is_in_coroutine ();
current_method.coroutine = false;
ccode.open_if (get_variable_cexpression (param.name));
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression (param.name)), get_cvalue_ (value));
ccode.open_if (get_parameter_cexpression (param));
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_parameter_cexpression (param)), get_cvalue_ (value));
if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression (get_ccode_delegate_target_name (param))), get_delegate_target_cvalue (value));
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_cexpression (get_ccode_delegate_target_name (param))), get_delegate_target_cvalue (value));
if (delegate_type.is_disposable ()) {
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression (get_delegate_target_destroy_notify_cname (param.name))), get_delegate_target_destroy_notify_cvalue (get_parameter_cvalue (param)));
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_cexpression (get_ccode_delegate_target_destroy_notify_name (param))), get_delegate_target_destroy_notify_cvalue (get_parameter_cvalue (param)));
}
}
......@@ -3816,8 +3820,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var array_type = param.variable_type as ArrayType;
if (array_type != null && !array_type.fixed_length && get_ccode_array_length (param)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
ccode.open_if (get_variable_cexpression (get_parameter_array_length_cname (param, dim)));
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression (get_parameter_array_length_cname (param, dim))), get_array_length_cvalue (value, dim));
ccode.open_if (get_cexpression (get_parameter_array_length_cname (param, dim)));
ccode.add_assignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, get_cexpression (get_parameter_array_length_cname (param, dim))), get_array_length_cvalue (value, dim));
ccode.close ();
}
}
......
......@@ -297,7 +297,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
Report.error (node != null ? node.source_reference : null, "Cannot create delegate without target for instance method or closure");
arg = new CCodeConstant ("NULL");
} else {
arg = new CCodeIdentifier (get_variable_cname (d_params.get (0).name));
arg = new CCodeIdentifier (get_ccode_name (d_params.get (0)));
i = 1;
}
}
......@@ -316,7 +316,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
}
CCodeExpression arg;
arg = new CCodeIdentifier (get_variable_cname (d_params.get (i).name));
arg = new CCodeIdentifier (get_ccode_name (d_params.get (i)));
if (d_params.get (i).variable_type is GenericType) {
arg = convert_from_generic_pointer (arg, param.variable_type);
}
......@@ -346,7 +346,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
var ctarget = new CCodeIdentifier (get_ccode_delegate_target_name (d_params.get (i)));
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), ctarget);
if (deleg_type.is_disposable ()) {
var ctarget_destroy_notify = new CCodeIdentifier (get_delegate_target_destroy_notify_cname (d_params.get (i).name));
var ctarget_destroy_notify = new CCodeIdentifier (get_ccode_delegate_target_destroy_notify_name (d_params.get (i)));
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (m) + 0.01), ctarget_destroy_notify);
}
}
......@@ -475,11 +475,11 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
target_destroy_notify_ctypename += "*";
}
var main_cparam = new CCodeParameter (get_variable_cname (param.name), ctypename);
var main_cparam = new CCodeParameter (get_ccode_name (param), ctypename);
cparam_map.set (get_param_pos (get_ccode_pos (param)), main_cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (get_ccode_pos (param)), get_variable_cexpression (param.name));
carg_map.set (get_param_pos (get_ccode_pos (param)), get_parameter_cexpression (param));
}
if (param.variable_type is DelegateType) {
......@@ -491,13 +491,13 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
var cparam = new CCodeParameter (get_ccode_delegate_target_name (param), target_ctypename);
cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), get_variable_cexpression (cparam.name));
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), get_cexpression (cparam.name));
}
if (deleg_type.is_disposable ()) {
cparam = new CCodeParameter (get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)), target_destroy_notify_ctypename);
cparam = new CCodeParameter (get_ccode_delegate_target_destroy_notify_name (param), target_destroy_notify_ctypename);
cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (param) + 0.01), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param) + 0.01), get_variable_cexpression (cparam.name));
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param) + 0.01), get_cexpression (cparam.name));
}
}
}
......@@ -505,7 +505,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
var cparam = new CCodeParameter (get_ccode_delegate_target_name (param), target_ctypename);
cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), get_variable_cexpression (cparam.name));
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), get_cexpression (cparam.name));
}
}
......
......@@ -460,7 +460,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
}
}
} else {
string name = param.name;
string name = get_ccode_name (param);
if (param.captured) {
// captured variables are stored on the heap
......@@ -468,7 +468,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
if (block == null) {
block = ((Method) param.parent_symbol).body;
}
result.cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_variable_cname (param.name));
result.cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_ccode_name (param));
if (array_type != null && get_ccode_array_length (param)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
result.append_array_length_cvalue (new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_parameter_array_length_cname (param, dim)));
......@@ -476,16 +476,16 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
} else if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
result.delegate_target_cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_ccode_delegate_target_name (param));
if (result.value_type.is_disposable ()) {
result.delegate_target_destroy_notify_cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
result.delegate_target_destroy_notify_cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_ccode_delegate_target_destroy_notify_name (param));
}
}
} else if (is_in_coroutine ()) {
// use closure
result.cvalue = get_variable_cexpression (param.name);
result.cvalue = get_parameter_cexpression (param);
if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
result.delegate_target_cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data_"), get_ccode_delegate_target_name (param));
if (delegate_type.is_disposable ()) {
result.delegate_target_destroy_notify_cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data_"), get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
result.delegate_target_destroy_notify_cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data_"), get_ccode_delegate_target_destroy_notify_name (param));
}
}
} else {
......@@ -497,7 +497,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
if (param.direction == ParameterDirection.REF ||
(param.direction == ParameterDirection.IN && type_as_struct != null && !type_as_struct.is_simple_type () && !result.value_type.nullable)) {
result.cvalue = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (get_variable_cname (name)));
result.cvalue = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (name));
} else {
// Property setters of non simple structs shall replace all occurrences
// of the "value" formal parameter with a dereferencing version of that
......@@ -514,11 +514,13 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
}
if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
var target_cname = get_ccode_delegate_target_name (param);
var destroy_cname = get_ccode_delegate_target_destroy_notify_name (param);
if (param.direction == ParameterDirection.OUT) {
target_cname = "_vala_%s".printf (target_cname);
destroy_cname = "_vala_%s".printf (destroy_cname);
}
CCodeExpression target_expr = new CCodeIdentifier (target_cname);
CCodeExpression delegate_target_destroy_notify = new CCodeIdentifier (get_delegate_target_destroy_notify_cname (get_variable_cname (name)));
CCodeExpression delegate_target_destroy_notify = new CCodeIdentifier (destroy_cname);
if (param.direction == ParameterDirection.REF) {
// accessing argument of ref param
target_expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, target_expr);
......@@ -533,9 +535,9 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
if (!param.captured && array_type != null) {
if (get_ccode_array_length (param) && !get_ccode_array_null_terminated (param)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
CCodeExpression length_expr = get_variable_cexpression (get_parameter_array_length_cname (param, dim));
CCodeExpression length_expr = get_cexpression (get_parameter_array_length_cname (param, dim));
if (param.direction == ParameterDirection.OUT) {
length_expr = get_variable_cexpression (get_array_length_cname (get_variable_cname (name), dim));
length_expr = get_cexpression (get_array_length_cname (name, dim));
} else if (param.direction == ParameterDirection.REF) {
// accessing argument of ref param
length_expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, length_expr);
......
......@@ -86,7 +86,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
var cparam = new CCodeParameter (get_array_length_cname ("result", dim), length_ctype);
cparam_map.set (get_param_pos (get_ccode_array_length_pos (m) + 0.01 * dim), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (get_ccode_array_length_pos (m) + 0.01 * dim), get_variable_cexpression (cparam.name));
carg_map.set (get_param_pos (get_ccode_array_length_pos (m) + 0.01 * dim), get_cexpression (cparam.name));
}
}
} else if (m.return_type is DelegateType) {
......@@ -96,13 +96,13 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
var cparam = new CCodeParameter (get_delegate_target_cname ("result"), get_ccode_name (delegate_target_type) + "*");
cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (m)), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (m)), get_variable_cexpression (cparam.name));
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (m)), get_cexpression (cparam.name));
}
if (deleg_type.is_disposable ()) {
cparam = new CCodeParameter (get_delegate_target_destroy_notify_cname ("result"), get_ccode_name (delegate_target_destroy_type) + "*");
cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (m) + 0.01), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (m) + 0.01), get_variable_cexpression (cparam.name));
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (m) + 0.01), get_cexpression (cparam.name));
}
}
}
......@@ -565,7 +565,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
if (param.direction != ParameterDirection.OUT) {
var t = param.variable_type.data_type;
if (t != null && (t.is_reference_type () || param.variable_type.is_real_struct_type ())) {
var cname = get_variable_cname (param.name);
var cname = get_ccode_name (param);
if (param.direction == ParameterDirection.REF && !param.variable_type.is_real_struct_type ()) {
cname = "*"+cname;
}
......@@ -573,7 +573,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
}
} else if (!m.coroutine) {
// declare local variable for out parameter to allow assignment even when caller passes NULL
var vardecl = new CCodeVariableDeclarator.zero (get_variable_cname ("_vala_%s".printf (param.name)), default_value_for_type (param.variable_type, true), get_ccode_declarator_suffix (param.variable_type));
var vardecl = new CCodeVariableDeclarator.zero ("_vala_%s".printf (get_ccode_name (param)), default_value_for_type (param.variable_type, true), get_ccode_declarator_suffix (param.variable_type));
ccode.add_declaration (get_ccode_name (param.variable_type), vardecl);
if (param.variable_type is ArrayType) {
......@@ -583,7 +583,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
if (!array_type.fixed_length) {
var length_ctype = get_ccode_array_length_type (array_type);
for (int dim = 1; dim <= array_type.rank; dim++) {
vardecl = new CCodeVariableDeclarator.zero (get_array_length_cname (get_variable_cname ("_vala_%s".printf (param.name)), dim), new CCodeConstant ("0"));
vardecl = new CCodeVariableDeclarator.zero (get_array_length_cname ("_vala_%s".printf (get_ccode_name (param)), dim), new CCodeConstant ("0"));
ccode.add_declaration (length_ctype, vardecl);
}
}
......@@ -595,7 +595,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
ccode.add_declaration (get_ccode_name (delegate_target_type), vardecl);
if (deleg_type.is_disposable ()) {
vardecl = new CCodeVariableDeclarator.zero (get_delegate_target_destroy_notify_cname (get_variable_cname ("_vala_%s".printf (param.name))), new CCodeConstant ("NULL"));
vardecl = new CCodeVariableDeclarator.zero ("_vala_%s".printf (get_ccode_delegate_target_destroy_notify_name (param)), new CCodeConstant ("NULL"));
ccode.add_declaration (get_ccode_name (delegate_target_destroy_type), vardecl);
}
}
......@@ -918,7 +918,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
ctypename += "*";
}
cparam = new CCodeParameter (get_variable_cname (param.name), ctypename);
cparam = new CCodeParameter (get_ccode_name (param), ctypename);
if (param.format_arg) {
cparam.modifiers = CCodeModifiers.FORMAT_ARG;
}
......@@ -930,7 +930,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
cparam_map.set (get_param_pos (get_ccode_pos (param), param.ellipsis), cparam);
if (carg_map != null && !param.ellipsis) {
carg_map.set (get_param_pos (get_ccode_pos (param), param.ellipsis), get_variable_cexpression (param.name));
carg_map.set (get_param_pos (get_ccode_pos (param), param.ellipsis), get_parameter_cexpression (param));
}
return cparam;
......
......@@ -53,7 +53,7 @@ public class Vala.GAsyncModule : GtkModule {
foreach (Parameter param in m.get_parameters ()) {
var param_type = param.variable_type.copy ();
param_type.value_owned = true;
data.add_field (get_ccode_name (param_type), get_variable_cname (param.name));
data.add_field (get_ccode_name (param_type), get_ccode_name (param));
if (param.variable_type is ArrayType) {
var array_type = (ArrayType) param.variable_type;
......@@ -68,7 +68,7 @@ public class Vala.GAsyncModule : GtkModule {
if (deleg_type.delegate_symbol.has_target) {
data.add_field (get_ccode_name (delegate_target_type), get_ccode_delegate_target_name (param));
if (deleg_type.is_disposable ()) {
data.add_field (get_ccode_name (delegate_target_destroy_type), get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
data.add_field (get_ccode_name (delegate_target_destroy_type), get_ccode_delegate_target_destroy_notify_name (param));
}
}
}
......@@ -290,7 +290,7 @@ public class Vala.GAsyncModule : GtkModule {
if (cancellable_param == null) {
create_result.add_argument (new CCodeConstant ("NULL"));
} else {
create_result.add_argument (new CCodeIdentifier (get_variable_cname (cancellable_param.name)));
create_result.add_argument (new CCodeIdentifier (get_ccode_name (cancellable_param)));
}
if (context.require_glib_version (2, 44)) {
......@@ -650,7 +650,7 @@ public class Vala.GAsyncModule : GtkModule {
if (param.direction != ParameterDirection.IN) {
return_out_parameter (param);
if (!(param.variable_type is ValueType) || param.variable_type.nullable) {
ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, get_variable_cname (param.name)), new CCodeConstant ("NULL"));
ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, get_ccode_name (param)), new CCodeConstant ("NULL"));
}
}
}
......
......@@ -37,14 +37,14 @@ public class Vala.GTypeModule : GErrorModule {
ctypename = "%s *".printf (ctypename);
}
var cparam = new CCodeParameter (get_variable_cname (param.name), ctypename);
var cparam = new CCodeParameter (get_ccode_name (param), ctypename);
if (param.format_arg) {
cparam.modifiers = CCodeModifiers.FORMAT_ARG;
}
cparam_map.set (get_param_pos (get_ccode_pos (param)), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (get_ccode_pos (param)), get_variable_cexpression (param.name));
carg_map.set (get_param_pos (get_ccode_pos (param)), get_parameter_cexpression (param));
}
return cparam;
......
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