Commit 5956bf50 authored by Luca Bruno's avatar Luca Bruno

codegen: Use CCodeAttribute instead of C specific methods of code nodes

parent 4a0db456
......@@ -62,7 +62,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
gnew = new CCodeFunctionCall (new CCodeIdentifier ("calloc"));
} else {
gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
gnew.add_argument (new CCodeIdentifier (expr.element_type.get_cname ()));
gnew.add_argument (new CCodeIdentifier (get_ccode_name (expr.element_type)));
}
bool first = true;
......@@ -90,7 +90,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
if (context.profile == Profile.POSIX) {
var csizeof = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
csizeof.add_argument (new CCodeIdentifier (expr.element_type.get_cname ()));
csizeof.add_argument (new CCodeIdentifier (get_ccode_name (expr.element_type)));
gnew.add_argument (csizeof);
}
......@@ -114,8 +114,8 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
}
public override string get_parameter_array_length_cname (Parameter param, int dim) {
if (param.has_array_length_cname) {
return param.get_array_length_cname ();
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);
}
......@@ -215,7 +215,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
}
public override string? append_struct_array_free (Struct st) {
string cname = "_vala_%s_array_free".printf (st.get_cname ());;
string cname = "_vala_%s_array_free".printf (get_ccode_name (st));
if (cfile.add_declaration (cname)) {
return cname;
......@@ -223,7 +223,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
var fun = new CCodeFunction (cname, "void");
fun.modifiers = CCodeModifiers.STATIC;
fun.add_parameter (new CCodeParameter ("array", "%s*".printf (st.get_cname ())));
fun.add_parameter (new CCodeParameter ("array", "%s*".printf (get_ccode_name (st))));
fun.add_parameter (new CCodeParameter ("array_length", "gint"));
push_function (fun);
......@@ -473,10 +473,10 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
// declaration
var function = new CCodeFunction (dup_func, array_type.get_cname ());
var function = new CCodeFunction (dup_func, get_ccode_name (array_type));
function.modifiers = CCodeModifiers.STATIC;
function.add_parameter (new CCodeParameter ("self", array_type.get_cname ()));
function.add_parameter (new CCodeParameter ("self", get_ccode_name (array_type)));
// total length over all dimensions
function.add_parameter (new CCodeParameter ("length", "int"));
if (array_type.element_type is GenericType) {
......@@ -493,7 +493,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
if (requires_copy (array_type.element_type)) {
var cvardecl = new CCodeVariableDeclarator ("result");
var gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
gnew.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
gnew.add_argument (new CCodeIdentifier (get_ccode_name (array_type.element_type)));
CCodeExpression length_expr = new CCodeIdentifier ("length");
// add extra item to have array NULL-terminated for all reference types
......@@ -502,7 +502,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
}
gnew.add_argument (length_expr);
ccode.add_declaration (array_type.get_cname (), cvardecl);
ccode.add_declaration (get_ccode_name (array_type), cvardecl);
ccode.add_assignment (new CCodeIdentifier ("result"), gnew);
ccode.add_declaration ("int", new CCodeVariableDeclarator ("i"));
......@@ -520,7 +520,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
dup_call.add_argument (new CCodeIdentifier ("self"));
var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
sizeof_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
sizeof_call.add_argument (new CCodeIdentifier (get_ccode_name (array_type.element_type)));
dup_call.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeIdentifier ("length"), sizeof_call));
ccode.add_return (dup_call);
......@@ -549,8 +549,8 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
var function = new CCodeFunction (dup_func, "void");
function.modifiers = CCodeModifiers.STATIC;
function.add_parameter (new CCodeParameter ("self", array_type.get_cname () + "*"));
function.add_parameter (new CCodeParameter ("dest", array_type.get_cname () + "*"));
function.add_parameter (new CCodeParameter ("self", get_ccode_name (array_type) + "*"));
function.add_parameter (new CCodeParameter ("dest", get_ccode_name (array_type) + "*"));
// definition
......@@ -574,7 +574,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
dup_call.add_argument (new CCodeIdentifier ("self"));
var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
sizeof_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
sizeof_call.add_argument (new CCodeIdentifier (get_ccode_name (array_type.element_type)));
dup_call.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeConstant ("%d".printf (array_type.length)), sizeof_call));
ccode.add_expression (dup_call);
......@@ -601,13 +601,13 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
var function = new CCodeFunction (add_func, "void");
function.modifiers = CCodeModifiers.STATIC;
function.add_parameter (new CCodeParameter ("array", array_type.get_cname () + "*"));
function.add_parameter (new CCodeParameter ("array", get_ccode_name (array_type) + "*"));
function.add_parameter (new CCodeParameter ("length", "int*"));
function.add_parameter (new CCodeParameter ("size", "int*"));
push_function (function);
string typename = array_type.element_type.get_cname ();
string typename = get_ccode_name (array_type.element_type);
CCodeExpression value = new CCodeIdentifier ("value");
if (array_type.element_type.is_real_struct_type ()) {
if (!array_type.element_type.nullable || !array_type.element_type.value_owned) {
......@@ -625,7 +625,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
var size = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("size"));
var renew_call = new CCodeFunctionCall (new CCodeIdentifier ("g_renew"));
renew_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
renew_call.add_argument (new CCodeIdentifier (get_ccode_name (array_type.element_type)));
renew_call.add_argument (array);
if (array_type.element_type.is_reference_type_or_type_parameter ()) {
// NULL terminate array
......@@ -705,7 +705,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
return base.generate_parameter (param, decl_space, cparam_map, carg_map);
}
string ctypename = param.variable_type.get_cname ();
string ctypename = get_ccode_name (param.variable_type);
if (param.direction != ParameterDirection.IN) {
ctypename += "*";
......@@ -717,15 +717,15 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
generate_type_declaration (array_type.element_type, decl_space);
cparam_map.set (get_param_pos (param.cparameter_position), main_cparam);
cparam_map.set (get_param_pos (get_ccode_pos (param)), main_cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cparameter_position), get_variable_cexpression (param.name));
carg_map.set (get_param_pos (get_ccode_pos (param)), get_variable_cexpression (param.name));
}
if (!param.no_array_length) {
if (get_ccode_array_length (param)) {
string length_ctype = "int";
if (param.array_length_type != null) {
length_ctype = param.array_length_type;
if (get_ccode_array_length_type (param) != null) {
length_ctype = get_ccode_array_length_type (param);
}
if (param.direction != ParameterDirection.IN) {
length_ctype = "%s*".printf (length_ctype);
......@@ -733,9 +733,9 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
for (int dim = 1; dim <= array_type.rank; dim++) {
var cparam = new CCodeParameter (get_parameter_array_length_cname (param, dim), length_ctype);
cparam_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), cparam);
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 (param.carray_length_parameter_position + 0.01 * dim), get_variable_cexpression (cparam.name));
carg_map.set (get_param_pos (get_ccode_array_length_pos (param) + 0.01 * dim), get_variable_cexpression (cparam.name));
}
}
}
......
......@@ -101,7 +101,7 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
// it is necessary to use memcpy for fixed-length (stack-allocated) arrays
// simple assignments do not work in C
var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
sizeof_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
sizeof_call.add_argument (new CCodeIdentifier (get_ccode_name (array_type.element_type)));
var size = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeConstant ("%d".printf (array_type.length)), sizeof_call);
var ccopy = new CCodeFunctionCall (new CCodeIdentifier ("memcpy"));
......
This diff is collapsed.
......@@ -73,7 +73,7 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule {
if (is_constant_ccode_expression (cexpr)) {
var cname = "_tmp%d_label%d".printf (label_temp_id, label_count++);
ccode.add_declaration (gquark_type.get_cname (), new CCodeVariableDeclarator (cname, czero), CCodeModifiers.STATIC);
ccode.add_declaration (get_ccode_name (gquark_type), new CCodeVariableDeclarator (cname, czero), CCodeModifiers.STATIC);
}
}
}
......
......@@ -28,32 +28,32 @@
*/
public class Vala.CCodeDelegateModule : CCodeArrayModule {
public override void generate_delegate_declaration (Delegate d, CCodeFile decl_space) {
if (add_symbol_declaration (decl_space, d, d.get_cname ())) {
if (add_symbol_declaration (decl_space, d, get_ccode_name (d))) {
return;
}
string return_type_cname = d.return_type.get_cname ();
string return_type_cname = get_ccode_name (d.return_type);
if (d.return_type.is_real_non_null_struct_type ()) {
// structs are returned via out parameter
return_type_cname = "void";
}
if (return_type_cname == d.get_cname ()) {
if (return_type_cname == get_ccode_name (d)) {
// recursive delegate
return_type_cname = "GCallback";
} else {
generate_type_declaration (d.return_type, decl_space);
}
var cfundecl = new CCodeFunctionDeclarator (d.get_cname ());
var cfundecl = new CCodeFunctionDeclarator (get_ccode_name (d));
foreach (Parameter param in d.get_parameters ()) {
var cparam = generate_parameter (param, decl_space, new HashMap<int,CCodeParameter> (), null);
cfundecl.add_parameter (cparam);
// handle array parameters
if (!param.no_array_length && param.variable_type is ArrayType) {
if (get_ccode_array_length (param) && param.variable_type is ArrayType) {
var array_type = (ArrayType) param.variable_type;
var length_ctype = "int";
......@@ -80,10 +80,10 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
}
}
}
if (!d.no_array_length && d.return_type is ArrayType) {
if (get_ccode_array_length (d) && d.return_type is ArrayType) {
// return array length if appropriate
var array_type = (ArrayType) d.return_type;
var array_length_type = d.array_length_type != null ? d.array_length_type : "int";
var array_length_type = get_ccode_array_length_type (d) != null ? get_ccode_array_length_type (d) : "int";
array_length_type += "*";
for (int dim = 1; dim <= array_type.rank; dim++) {
......@@ -103,7 +103,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
}
}
} else if (d.return_type.is_real_non_null_struct_type ()) {
var cparam = new CCodeParameter ("result", "%s*".printf (d.return_type.get_cname ()));
var cparam = new CCodeParameter ("result", "%s*".printf (get_ccode_name (d.return_type)));
cfundecl.add_parameter (cparam);
}
if (d.has_target) {
......@@ -181,12 +181,12 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
if (dynamic_sig != null) {
delegate_name = get_dynamic_signal_cname (dynamic_sig);
} else if (sig != null) {
delegate_name = sig.parent_symbol.get_lower_case_cprefix () + sig.get_cname ();
delegate_name = get_ccode_lower_case_prefix (sig.parent_symbol) + get_ccode_name (sig);
} else {
delegate_name = Symbol.camel_case_to_lower_case (d.get_cname ());
delegate_name = Symbol.camel_case_to_lower_case (get_ccode_name (d));
}
string wrapper_name = "_%s_%s".printf (m.get_cname (), delegate_name);
string wrapper_name = "_%s_%s".printf (get_ccode_name (m), delegate_name);
if (!add_wrapper (wrapper_name)) {
// wrapper already defined
......@@ -195,7 +195,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
// declaration
string return_type_cname = d.return_type.get_cname ();
string return_type_cname = get_ccode_name (d.return_type);
if (d.return_type.is_real_non_null_struct_type ()) {
// structs are returned via out parameter
......@@ -211,7 +211,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
if (d.has_target) {
var cparam = new CCodeParameter ("self", "gpointer");
cparam_map.set (get_param_pos (d.cinstance_parameter_position), cparam);
cparam_map.set (get_param_pos (get_ccode_instance_pos (d)), cparam);
}
if (d.sender_type != null) {
......@@ -225,21 +225,21 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
&& param.variable_type is ArrayType
&& ((ArrayType) param.variable_type).element_type.data_type == string_type.data_type) {
// use null-terminated string arrays for dynamic signals for compatibility reasons
param.no_array_length = true;
param.array_null_terminated = true;
param.set_attribute_bool ("CCode", "array_length", false);
param.set_attribute_bool ("CCode", "array_null_terminated", true);
}
generate_parameter (param, cfile, cparam_map, null);
}
if (!d.no_array_length && d.return_type is ArrayType) {
if (get_ccode_array_length (d) && d.return_type is ArrayType) {
// return array length if appropriate
var array_type = (ArrayType) d.return_type;
var array_length_type = d.array_length_type != null ? d.array_length_type : "int";
var array_length_type = get_ccode_array_length_type (d) != null ? get_ccode_array_length_type (d) : "int";
array_length_type += "*";
for (int dim = 1; dim <= array_type.rank; dim++) {
var cparam = new CCodeParameter (get_array_length_cname ("result", dim), array_length_type);
cparam_map.set (get_param_pos (d.carray_length_parameter_position + 0.01 * dim), cparam);
cparam_map.set (get_param_pos (get_ccode_array_length_pos (d) + 0.01 * dim), cparam);
}
} else if (d.return_type is DelegateType) {
// return delegate target if appropriate
......@@ -247,14 +247,14 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
if (deleg_type.delegate_symbol.has_target) {
var cparam = new CCodeParameter (get_delegate_target_cname ("result"), "void**");
cparam_map.set (get_param_pos (d.cdelegate_target_parameter_position), cparam);
cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (d)), cparam);
if (deleg_type.value_owned) {
cparam = new CCodeParameter (get_delegate_target_destroy_notify_cname ("result"), "GDestroyNotify*");
cparam_map.set (get_param_pos (d.cdelegate_target_parameter_position + 0.01), cparam);
cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (d) + 0.01), cparam);
}
}
} else if (d.return_type.is_real_non_null_struct_type ()) {
var cparam = new CCodeParameter ("result", "%s*".printf (d.return_type.get_cname ()));
var cparam = new CCodeParameter ("result", "%s*".printf (get_ccode_name (d.return_type)));
cparam_map.set (get_param_pos (-3), cparam);
}
......@@ -300,7 +300,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
i = 1;
}
}
carg_map.set (get_param_pos (m.cinstance_parameter_position), arg);
carg_map.set (get_param_pos (get_ccode_instance_pos (m)), arg);
}
bool first = true;
......@@ -308,7 +308,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
foreach (Parameter param in m.get_parameters ()) {
if (first && d.sender_type != null && m.get_parameters ().size == d.get_parameters ().size + 1) {
// sender parameter
carg_map.set (get_param_pos (param.cparameter_position), new CCodeIdentifier ("_sender"));
carg_map.set (get_param_pos (get_ccode_pos (param)), new CCodeIdentifier ("_sender"));
first = false;
continue;
......@@ -316,60 +316,60 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
CCodeExpression arg;
arg = new CCodeIdentifier (get_variable_cname (d_params.get (i).name));
carg_map.set (get_param_pos (param.cparameter_position), arg);
carg_map.set (get_param_pos (get_ccode_pos (param)), arg);
// handle array arguments
if (!param.no_array_length && param.variable_type is ArrayType) {
if (get_ccode_array_length (param) && param.variable_type is ArrayType) {
var array_type = (ArrayType) param.variable_type;
for (int dim = 1; dim <= array_type.rank; dim++) {
CCodeExpression clength;
if (d_params.get (i).array_null_terminated) {
if (get_ccode_array_null_terminated (d_params.get (i))) {
requires_array_length = true;
var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
len_call.add_argument (new CCodeIdentifier (d_params.get (i).name));
clength = len_call;
} else if (d_params.get (i).no_array_length) {
} else if (!get_ccode_array_length (d_params.get (i))) {
clength = new CCodeConstant ("-1");
} else {
clength = new CCodeIdentifier (get_parameter_array_length_cname (d_params.get (i), dim));
}
carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), clength);
carg_map.set (get_param_pos (get_ccode_array_length_pos (param) + 0.01 * dim), clength);
}
} else if (param.variable_type is DelegateType) {
var deleg_type = (DelegateType) param.variable_type;
if (deleg_type.delegate_symbol.has_target) {
var ctarget = new CCodeIdentifier (get_delegate_target_cname (d_params.get (i).name));
carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), ctarget);
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), ctarget);
if (deleg_type.value_owned) {
var ctarget_destroy_notify = new CCodeIdentifier (get_delegate_target_destroy_notify_cname (d_params.get (i).name));
carg_map.set (get_param_pos (m.cdelegate_target_parameter_position + 0.01), ctarget_destroy_notify);
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (m) + 0.01), ctarget_destroy_notify);
}
}
}
i++;
}
if (!m.no_array_length && m.return_type is ArrayType) {
if (get_ccode_array_length (m) && m.return_type is ArrayType) {
var array_type = (ArrayType) m.return_type;
for (int dim = 1; dim <= array_type.rank; dim++) {
CCodeExpression clength;
if (d.no_array_length) {
if (!get_ccode_array_length (d)) {
clength = new CCodeConstant ("NULL");
} else {
clength = new CCodeIdentifier (get_array_length_cname ("result", dim));
}
carg_map.set (get_param_pos (m.carray_length_parameter_position + 0.01 * dim), clength);
carg_map.set (get_param_pos (get_ccode_array_length_pos (m) + 0.01 * dim), clength);
}
} else if (m.return_type is DelegateType) {
var deleg_type = (DelegateType) m.return_type;
if (deleg_type.delegate_symbol.has_target) {
var ctarget = new CCodeIdentifier (get_delegate_target_cname ("result"));
carg_map.set (get_param_pos (m.cdelegate_target_parameter_position), ctarget);
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (m)), ctarget);
if (deleg_type.value_owned) {
var ctarget_destroy_notify = new CCodeIdentifier (get_delegate_target_destroy_notify_cname ("result"));
carg_map.set (get_param_pos (m.cdelegate_target_parameter_position + 0.01), ctarget_destroy_notify);
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (m) + 0.01), ctarget_destroy_notify);
}
}
} else if (m.return_type.is_real_non_null_struct_type ()) {
......@@ -380,7 +380,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
carg_map.set (get_param_pos (-1), new CCodeIdentifier ("error"));
}
var ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_cname ()));
var ccall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_name (m)));
// append C arguments in the right order
last_pos = -1;
......@@ -414,7 +414,7 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
if (m.closure) {
int block_id = get_block_id (current_closure_block);
destroy_notify = new CCodeIdentifier ("block%d_data_unref".printf (block_id));
} else if (get_this_type () != null && m.binding != MemberBinding.STATIC && !m.is_async_callback && m.this_parameter.variable_type.data_type.is_reference_counting ()) {
} else if (get_this_type () != null && m.binding != MemberBinding.STATIC && !m.is_async_callback && is_reference_counting (m.this_parameter.variable_type.data_type)) {
destroy_notify = get_destroy_func_expression (m.this_parameter.variable_type);
} else if (in_constructor) {
destroy_notify = new CCodeIdentifier ("g_object_unref");
......@@ -445,12 +445,12 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
return base.generate_parameter (param, decl_space, cparam_map, carg_map);
}
string ctypename = param.variable_type.get_cname ();
string ctypename = get_ccode_name (param.variable_type);
string target_ctypename = "void*";
string target_destroy_notify_ctypename = "GDestroyNotify";
if (param.parent_symbol is Delegate
&& param.variable_type.get_cname () == ((Delegate) param.parent_symbol).get_cname ()) {
&& get_ccode_name (param.variable_type) == get_ccode_name (param.parent_symbol)) {
// recursive delegate
ctypename = "GCallback";
}
......@@ -463,9 +463,9 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
var main_cparam = new CCodeParameter (get_variable_cname (param.name), ctypename);
cparam_map.set (get_param_pos (param.cparameter_position), main_cparam);
cparam_map.set (get_param_pos (get_ccode_pos (param)), main_cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cparameter_position), get_variable_cexpression (param.name));
carg_map.set (get_param_pos (get_ccode_pos (param)), get_variable_cexpression (param.name));
}
if (param.variable_type is DelegateType) {
......@@ -476,23 +476,23 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
if (d.has_target) {
var cparam = new CCodeParameter (get_delegate_target_cname (get_variable_cname (param.name)), target_ctypename);
cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position), cparam);
cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), get_variable_cexpression (cparam.name));
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), get_variable_cexpression (cparam.name));
}
if (deleg_type.value_owned) {
cparam = new CCodeParameter (get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)), target_destroy_notify_ctypename);
cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position + 0.01), cparam);
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 (param.cdelegate_target_parameter_position + 0.01), get_variable_cexpression (cparam.name));
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param) + 0.01), get_variable_cexpression (cparam.name));
}
}
}
} else if (param.variable_type is MethodType) {
var cparam = new CCodeParameter (get_delegate_target_cname (get_variable_cname (param.name)), target_ctypename);
cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position), cparam);
cparam_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), cparam);
if (carg_map != null) {
carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), get_variable_cexpression (cparam.name));
carg_map.set (get_param_pos (get_ccode_delegate_target_pos (param)), get_variable_cexpression (cparam.name));
}
}
......
......@@ -51,16 +51,16 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
if (expr.inner is BaseAccess) {
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))));
var vcast = new CCodeFunctionCall (new CCodeIdentifier ("%s_CLASS".printf (get_ccode_upper_case_name (base_class, null))));
vcast.add_argument (new CCodeIdentifier ("%s_parent_class".printf (get_ccode_lower_case_name (current_class, null))));
set_cvalue (expr, new CCodeMemberAccess.pointer (vcast, m.vfunc_name));
set_cvalue (expr, new CCodeMemberAccess.pointer (vcast, get_ccode_vfunc_name (m)));
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 (get_ccode_lower_case_name (current_class), get_ccode_lower_case_name (base_iface));
set_cvalue (expr, new CCodeMemberAccess.pointer (new CCodeIdentifier (parent_iface_var), m.vfunc_name));
set_cvalue (expr, new CCodeMemberAccess.pointer (new CCodeIdentifier (parent_iface_var), get_ccode_vfunc_name (m)));
return;
}
}
......@@ -68,18 +68,18 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
if (m.base_method != null) {
if (!method_has_wrapper (m.base_method)) {
var base_class = (Class) m.base_method.parent_symbol;
var vclass = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_CLASS".printf (base_class.get_upper_case_cname (null))));
var vclass = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_CLASS".printf (get_ccode_upper_case_name (base_class))));
vclass.add_argument (pub_inst);
set_cvalue (expr, new CCodeMemberAccess.pointer (vclass, m.name));
} else {
set_cvalue (expr, new CCodeIdentifier (m.base_method.get_cname ()));
set_cvalue (expr, new CCodeIdentifier (get_ccode_name (m.base_method)));
}
} else if (m.base_interface_method != null) {
set_cvalue (expr, new CCodeIdentifier (m.base_interface_method.get_cname ()));
set_cvalue (expr, new CCodeIdentifier (get_ccode_name (m.base_interface_method)));
} else if (m is CreationMethod) {
set_cvalue (expr, new CCodeIdentifier (m.get_real_cname ()));
set_cvalue (expr, new CCodeIdentifier (get_ccode_real_name (m)));
} else {
set_cvalue (expr, new CCodeIdentifier (m.get_cname ()));
set_cvalue (expr, new CCodeIdentifier (get_ccode_name (m)));
}
set_delegate_target_destroy_notify (expr, new CCodeConstant ("NULL"));
......@@ -96,7 +96,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
// expr.inner is null in the special case of referencing the method in a constant initializer
var delegate_target = (CCodeExpression) get_ccodenode (expr.inner);
delegate_type = expr.target_type as DelegateType;
if ((expr.value_type.value_owned || (delegate_type != null && delegate_type.is_called_once)) && expr.inner.value_type.data_type != null && expr.inner.value_type.data_type.is_reference_counting ()) {
if ((expr.value_type.value_owned || (delegate_type != null && delegate_type.is_called_once)) && expr.inner.value_type.data_type != null && is_reference_counting (expr.inner.value_type.data_type)) {
var ref_call = new CCodeFunctionCall (get_dup_func_expression (expr.inner.value_type, expr.source_reference));
ref_call.add_argument (delegate_target);
delegate_target = ref_call;
......@@ -121,7 +121,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
generate_enum_declaration ((Enum) ev.parent_symbol, cfile);
set_cvalue (expr, new CCodeConstant (ev.get_cname ()));
set_cvalue (expr, new CCodeConstant (get_ccode_name (ev)));
} else if (expr.symbol_reference is Constant) {
var c = (Constant) expr.symbol_reference;
......@@ -143,12 +143,12 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
}
set_cvalue (expr, new CCodeConstant ("\"%s\"".printf (s)));
} else {
set_cvalue (expr, new CCodeIdentifier (c.get_cname ()));
set_cvalue (expr, new CCodeIdentifier (get_ccode_name (c)));
}
if (array_type != null) {
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("G_N_ELEMENTS"));
ccall.add_argument (new CCodeIdentifier (c.get_cname ()));
ccall.add_argument (new CCodeIdentifier (get_ccode_name (c)));
append_array_length (expr, ccall);
}
} else if (expr.symbol_reference is Property) {
......@@ -169,15 +169,15 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
if (expr.inner is BaseAccess) {
if (prop.base_property != null) {
var base_class = (Class) prop.base_property.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))));
var vcast = new CCodeFunctionCall (new CCodeIdentifier ("%s_CLASS".printf (get_ccode_upper_case_name (base_class, null))));
vcast.add_argument (new CCodeIdentifier ("%s_parent_class".printf (get_ccode_lower_case_name (current_class, null))));
var ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (vcast, "get_%s".printf (prop.name)));
ccall.add_argument (get_cvalue (expr.inner));
set_cvalue (expr, ccall);
} else if (prop.base_interface_property != null) {
var base_iface = (Interface) prop.base_interface_property.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 (get_ccode_lower_case_name (current_class), get_ccode_lower_case_name (base_iface));
var ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (new CCodeIdentifier (parent_iface_var), "get_%s".printf (prop.name)));
ccall.add_argument (get_cvalue (expr.inner));
......@@ -192,8 +192,8 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
!(prop.property_type is ArrayType || prop.property_type is DelegateType)) {
CCodeExpression inst;
inst = new CCodeMemberAccess.pointer (pub_inst, "priv");
set_cvalue (expr, new CCodeMemberAccess.pointer (inst, prop.field.get_cname()));
} else if (!prop.no_accessor_method) {
set_cvalue (expr, new CCodeMemberAccess.pointer (inst, get_ccode_name (prop.field)));
} else if (!get_ccode_no_accessor_method (prop)) {
var base_property = prop;
if (prop.base_property != null) {
base_property = prop.base_property;
......@@ -204,7 +204,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
if (prop is DynamicProperty) {
getter_cname = get_dynamic_property_getter_cname ((DynamicProperty) prop);
} else {
getter_cname = base_property.get_accessor.get_cname ();
getter_cname = get_ccode_name (base_property.get_accessor);
}
var ccall = new CCodeFunctionCall (new CCodeIdentifier (getter_cname));
......@@ -234,7 +234,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
ccode.add_assignment (ctemp, ccall);
array_type = base_property.property_type as ArrayType;
if (array_type != null && !base_property.no_array_length) {
if (array_type != null && get_ccode_array_length (base_property)) {
for (int dim = 1; dim <= array_type.rank; dim++) {
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_array_length_cvalue (temp_value, dim)));
}
......@@ -250,7 +250,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
ccall.add_argument (pub_inst);
// property name is second argument of g_object_get
ccall.add_argument (prop.get_canonical_cconstant ());
ccall.add_argument (get_property_canonical_cconstant (prop));
// g_object_get always returns owned values
// therefore, property getters of properties
......@@ -381,11 +381,11 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
public override TargetValue get_parameter_cvalue (Parameter param) {
var result = new GLibValue (param.variable_type.copy ());
result.lvalue = true;
result.array_null_terminated = param.array_null_terminated;
if (param.has_array_length_cexpr) {
result.array_length_cexpr = new CCodeConstant (param.get_array_length_cexpr ());
result.array_null_terminated = get_ccode_array_null_terminated (param);
if (get_ccode_array_length_expr (param) != null) {
result.array_length_cexpr = new CCodeConstant (get_ccode_array_length_expr (param));
}
result.ctype = param.ctype;
result.ctype = get_ccode_type (param);
var array_type = result.value_type as ArrayType;
var delegate_type = result.value_type as DelegateType;
......@@ -417,7 +417,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
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));
if (array_type != null && !param.no_array_length) {
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)));
}
......@@ -475,7 +475,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
}
}
if (!param.captured && array_type != null) {
if (!param.no_array_length && !param.array_null_terminated) {
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));
if (param.direction == ParameterDirection.OUT) {
......@@ -502,11 +502,11 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
result.actual_value_type = field.variable_type.get_actual_type (instance.value_type, null, field);
}
result.lvalue = true;
result.array_null_terminated = field.array_null_terminated;