}
}
+ public bool is_in_coroutine () {
+ return current_method != null && current_method.coroutine;
+ }
+
public bool is_in_constructor () {
if (current_method != null) {
// make sure to not return true in lambda expression inside constructor
} else if (param.variable_type is DelegateType) {
CCodeExpression target_expr;
CCodeExpression delegate_target_destroy_notify;
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
target_expr = new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_cname (get_variable_cname (param.name)));
delegate_target_destroy_notify = new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
} else {
var data_alloc = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_new0"));
data_alloc.add_argument (new CCodeIdentifier (struct_name));
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
closure_struct.add_field (struct_name + "*", "_data%d_".printf (block_id));
} else {
ccode.add_declaration (struct_name + "*", new CCodeVariableDeclarator ("_data%d_".printf (block_id)));
}
public CCodeExpression get_variable_cexpression (string name) {
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
return new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_variable_cname (name));
} else {
return new CCodeIdentifier (get_variable_cname (name));
}
public CCodeExpression get_result_cexpression (string cname = "result") {
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
return new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), cname);
} else {
return new CCodeIdentifier (cname);
vardecl.init0 = true;
}
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
closure_struct.add_field (local.variable_type.get_cname (), local.name);
// even though closure struct is zerod, we need to initialize temporary variables
for (int dim = 1; dim <= array_type.rank; dim++) {
var len_l = get_result_cexpression (get_array_length_cname ("result", dim));
- if (current_method == null || !current_method.coroutine) {
+ if (!is_in_coroutine ()) {
len_l = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, len_l);
}
var len_r = get_array_length_cexpression (stmt.return_expression, dim);
ccode.add_assignment (get_variable_cexpression (return_expr_decl.name), get_cvalue (stmt.return_expression));
var target_l = get_result_cexpression (get_delegate_target_cname ("result"));
- if (current_method == null || !current_method.coroutine) {
+ if (!is_in_coroutine ()) {
target_l = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, target_l);
}
CCodeExpression target_r_destroy_notify;
ccode.add_assignment (target_l, target_r);
if (delegate_type.value_owned) {
var target_l_destroy_notify = get_result_cexpression (get_delegate_target_destroy_notify_cname ("result"));
- if (current_method == null || !current_method.coroutine) {
+ if (!is_in_coroutine ()) {
target_l_destroy_notify = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, target_l_destroy_notify);
}
ccode.add_assignment (target_l_destroy_notify, target_r_destroy_notify);
if (stmt.return_expression != null) {
// assign method result to `result'
CCodeExpression result_lhs = get_result_cexpression ();
- if (current_return_type.is_real_non_null_struct_type () && (current_method == null || !current_method.coroutine)) {
+ if (current_return_type.is_real_non_null_struct_type () && !is_in_coroutine ()) {
result_lhs = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, result_lhs);
}
ccode.add_assignment (result_lhs, get_cvalue (stmt.return_expression));
ccode.add_goto ("_return");
} else if (current_method is CreationMethod) {
ccode.add_return (new CCodeIdentifier ("self"));
- } else if (current_method != null && current_method.coroutine) {
+ } else if (is_in_coroutine ()) {
} else if (current_return_type is VoidType || current_return_type.is_real_non_null_struct_type ()) {
// structs are returned via out parameter
ccode.add_return ();
public override void visit_base_access (BaseAccess expr) {
CCodeExpression this_access;
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
// use closure
this_access = new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "self");
} else {
array_type.fixed_length = false;
}
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
closure_struct.add_field (collection_type.get_cname (), collection_backup.name);
} else {
var ccolvardecl = new CCodeVariableDeclarator (collection_backup.name);
var array_len = get_array_length_cexpression (stmt.collection);
// store array length for use by _vala_array_free
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
closure_struct.add_field ("int", get_array_length_cname (collection_backup.name, 1));
} else {
ccode.add_declaration ("int", new CCodeVariableDeclarator (get_array_length_cname (collection_backup.name, 1)));
var it_name = (stmt.variable_name + "_it");
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
closure_struct.add_field ("int", it_name);
} else {
ccode.add_declaration ("int", new CCodeVariableDeclarator (it_name));
element_type.value_owned = false;
element_expr = transform_expression (element_expr, element_type, stmt.type_reference);
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
closure_struct.add_field (stmt.type_reference.get_cname (), stmt.variable_name);
} else {
ccode.add_declaration (stmt.type_reference.get_cname (), new CCodeVariableDeclarator (stmt.variable_name));
if (stmt.type_reference is ArrayType) {
var inner_array_type = (ArrayType) stmt.type_reference;
for (int dim = 1; dim <= inner_array_type.rank; dim++) {
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
closure_struct.add_field ("int", get_array_length_cname (stmt.variable_name, dim));
ccode.add_assignment (get_variable_cexpression (get_array_length_cname (stmt.variable_name, dim)), new CCodeConstant ("-1"));
} else {
var it_name = "%s_it".printf (stmt.variable_name);
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
closure_struct.add_field (collection_type.get_cname (), it_name);
} else {
ccode.add_declaration (collection_type.get_cname (), new CCodeVariableDeclarator (it_name));
element_expr = convert_from_generic_pointer (element_expr, element_data_type);
element_expr = transform_expression (element_expr, element_data_type, stmt.type_reference);
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
closure_struct.add_field (stmt.type_reference.get_cname (), stmt.variable_name);
} else {
ccode.add_declaration (stmt.type_reference.get_cname (), new CCodeVariableDeclarator (stmt.variable_name));
var arr_index = "%s_index".printf (stmt.variable_name);
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
closure_struct.add_field (uint_type.get_cname (), arr_index);
} else {
ccode.add_declaration (uint_type.get_cname (), new CCodeVariableDeclarator (arr_index));
element_expr = get_ref_cexpression (stmt.type_reference, element_expr, null, new StructValueType (gvalue_type));
}
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
closure_struct.add_field (stmt.type_reference.get_cname (), stmt.variable_name);
} else {
ccode.add_declaration (stmt.type_reference.get_cname (), new CCodeVariableDeclarator (stmt.variable_name));
result.array_size_cvalue = get_variable_cexpression (get_array_size_cname (get_variable_cname (local.name)));
}
} else if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
result.delegate_target_cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_cname (get_variable_cname (local.name)));
result.delegate_target_destroy_notify_cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_destroy_notify_cname (get_variable_cname (local.name)));
} else {
/* Returns access values to the given parameter */
public TargetValue get_parameter_cvalue (Parameter param) {
var result = new GLibValue (param.variable_type.copy ());
- if (param.captured || current_method != null && current_method.coroutine) {
+ if (param.captured || is_in_coroutine ()) {
result.value_type.value_owned = true;
}
var delegate_type = result.value_type as DelegateType;
if (param.name == "this") {
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
// use closure
result.cvalue = new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "self");
} else {
result.delegate_target_cvalue = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_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_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
}
- } else if (current_method != null && current_method.coroutine) {
+ } else if (is_in_coroutine ()) {
// use closure
result.cvalue = get_variable_cexpression (param.name);
if (delegate_type != null && delegate_type.delegate_symbol.has_target) {
}
public override void visit_yield_statement (YieldStatement stmt) {
- if (current_method == null || !current_method.coroutine) {
+ if (!is_in_coroutine ()) {
return;
}
public override void return_with_exception (CCodeExpression error_expr)
{
- if (!current_method.coroutine) {
+ if (!is_in_coroutine ()) {
base.return_with_exception (error_expr);
return;
}
public override void visit_return_statement (ReturnStatement stmt) {
base.visit_return_statement (stmt);
- if (current_method == null || !current_method.coroutine) {
+ if (!is_in_coroutine ()) {
return;
}
var unref_call = get_unref_expression (new CCodeIdentifier ("self"), new ObjectType (cl), null);
ccode.add_expression (unref_call);
ccode.add_return (new CCodeConstant ("NULL"));
- } else if (current_method != null && current_method.coroutine) {
+ } else if (is_in_coroutine ()) {
ccode.add_return (new CCodeConstant ("FALSE"));
} else {
return_default_value (current_return_type);
} else {
ccode.add_return (new CCodeConstant ("NULL"));
}
- } else if (current_method != null && current_method.coroutine) {
+ } else if (is_in_coroutine ()) {
ccode.add_return (new CCodeConstant ("FALSE"));
} else if (current_return_type != null) {
return_default_value (current_return_type);
}
if (clause.variable_name != null) {
- if (current_method != null && current_method.coroutine) {
+ if (is_in_coroutine ()) {
closure_struct.add_field ("GError *", variable_name);
} else {
ccode.add_declaration ("GError *", new CCodeVariableDeclarator (variable_name));