return generated_external_symbols.add (external_symbol);
}
+ public static DataType get_callable_creturn_type (Callable c) {
+ assert (c is Method || c is Delegate);
+ var creturn_type = c.return_type.copy ();
+ if (c is CreationMethod) {
+ unowned Class? cl = c.parent_symbol as Class;
+ if (cl != null) {
+ // object creation methods return the new object in C
+ // in Vala they have no return type
+ creturn_type = new ObjectType (cl);
+ }
+ } else if (c.return_type.is_real_non_null_struct_type ()) {
+ // structs are returned via out parameter
+ creturn_type = new VoidType ();
+ }
+ return creturn_type;
+ }
public CCodeExpression? default_value_for_type (DataType type, bool initializer_expression, bool on_error = false) {
unowned Struct? st = type.type_symbol as Struct;
generate_type_declaration (new DelegateType (d), decl_space);
- string return_type_cname = get_ccode_name (d.return_type);
+ var creturn_type = get_callable_creturn_type (d);
- if (d.return_type.is_real_non_null_struct_type ()) {
- // structs are returned via out parameter
- return_type_cname = "void";
- }
-
- if (return_type_cname == get_ccode_name (d)) {
+ if (creturn_type is DelegateType && ((DelegateType) creturn_type).delegate_symbol == d) {
// recursive delegate
- return_type_cname = "GCallback";
- } else {
- generate_type_declaration (d.return_type, decl_space);
+ creturn_type = new DelegateType ((Delegate) context.root.scope.lookup ("GLib").scope.lookup ("Callback"));
}
+ generate_type_declaration (creturn_type, decl_space);
+
var cparam_map = new HashMap<int,CCodeParameter> (direct_hash, direct_equal);
var cfundecl = new CCodeFunctionDeclarator (get_ccode_name (d));
last_pos = min_pos;
}
- var ctypedef = new CCodeTypeDefinition (return_type_cname, cfundecl);
+ var ctypedef = new CCodeTypeDefinition (get_ccode_name (creturn_type), cfundecl);
ctypedef.modifiers |= (d.version.deprecated ? CCodeModifiers.DEPRECATED : 0);
decl_space.add_type_declaration (ctypedef);
}
// declaration
+ var creturn_type = get_callable_creturn_type (d);
- 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";
- }
-
- var function = new CCodeFunction (wrapper_name, return_type_cname);
+ var function = new CCodeFunction (wrapper_name, get_ccode_name (creturn_type));
function.modifiers = CCodeModifiers.STATIC;
push_function (function);
ccode.add_expression (ccall);
if (!(d.return_type is VoidType || d.return_type.is_real_non_null_struct_type ())) {
// return a default value
- ccode.add_declaration (return_type_cname, new CCodeVariableDeclarator ("result", default_value_for_type (d.return_type, true)));
+ ccode.add_declaration (get_ccode_name (creturn_type), new CCodeVariableDeclarator ("result", default_value_for_type (d.return_type, true)));
}
} else {
CCodeExpression result = ccall;
if (d.return_type is GenericType) {
result = convert_to_generic_pointer (result, m.return_type);
}
- ccode.add_declaration (return_type_cname, new CCodeVariableDeclarator ("result", result));
+ ccode.add_declaration (get_ccode_name (creturn_type), new CCodeVariableDeclarator ("result", result));
}
if (d.has_target /* TODO: && dt.value_owned */ && dt.is_called_once) {
}
public virtual void generate_method_result_declaration (Method m, CCodeFile decl_space, CCodeFunction cfunc, Map<int,CCodeParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
- var creturn_type = m.return_type;
- if (m is CreationMethod) {
- var cl = m.parent_symbol as Class;
- if (cl != null) {
- // object creation methods return the new object in C
- // in Vala they have no return type
- creturn_type = new ObjectType (cl);
- }
- } else if (m.return_type.is_real_non_null_struct_type ()) {
- // structs are returned via out parameter
- creturn_type = new VoidType ();
- }
+ var creturn_type = get_callable_creturn_type (m);
cfunc.return_type = get_creturn_type (m, get_ccode_name (creturn_type));
generate_type_declaration (m.return_type, decl_space);
}
}
- var creturn_type = m.return_type;
- if (m.return_type.is_real_non_null_struct_type ()) {
- // structs are returned via out parameter
- creturn_type = new VoidType ();
- }
+ var creturn_type = get_callable_creturn_type (m);
foreach (Parameter param in m.get_parameters ()) {
param.accept (this);
}
if (m is CreationMethod) {
- if (current_type_symbol is Class) {
- creturn_type = new ObjectType (current_class);
- } else {
- creturn_type = new VoidType ();
- }
-
if (current_type_symbol is Class && !m.coroutine) {
CCodeExpression cresult = new CCodeIdentifier ("self");
if (get_ccode_type (m) != null) {
return;
}
- var creturn_type = m.return_type;
- if (m.return_type.is_real_non_null_struct_type ()) {
- // structs are returned via out parameter
- creturn_type = new VoidType ();
- }
+ var creturn_type = get_callable_creturn_type (m);
// add vfunc field to the type struct
var vdeclarator = new CCodeFunctionDeclarator (get_ccode_vfunc_name (m));
if (prop.get_accessor != null) {
var vdeclarator = new CCodeFunctionDeclarator ("get_%s".printf (prop.name));
vdeclarator.add_parameter (cselfparam);
- string creturn_type;
+ var creturn_type = get_callable_creturn_type (prop.get_accessor.get_method ());
if (prop.property_type.is_real_non_null_struct_type ()) {
var cvalueparam = new CCodeParameter ("result", "%s *".printf (get_ccode_name (prop.get_accessor.value_type)));
vdeclarator.add_parameter (cvalueparam);
- creturn_type = "void";
- } else {
- creturn_type = get_ccode_name (prop.get_accessor.value_type);
}
var array_type = prop.property_type as ArrayType;
vdeclarator.add_parameter (new CCodeParameter (get_delegate_target_cname ("result"), "gpointer*"));
}
- var vdecl = new CCodeDeclaration (creturn_type);
+ var vdecl = new CCodeDeclaration (get_ccode_name (creturn_type));
vdecl.add_declarator (vdeclarator);
type_struct.add_declaration (vdecl);
return;
}
- var creturn_type = m.return_type;
- if (m.return_type.is_real_non_null_struct_type ()) {
- // structs are returned via out parameter
- creturn_type = new VoidType ();
- }
+ var creturn_type = get_callable_creturn_type (m);
// add vfunc field to the type struct
var vdeclarator = new CCodeFunctionDeclarator (get_ccode_vfunc_name (m));
if (prop.get_accessor != null) {
var vdeclarator = new CCodeFunctionDeclarator ("get_%s".printf (prop.name));
vdeclarator.add_parameter (cselfparam);
- string creturn_type;
+ var creturn_type = get_callable_creturn_type (prop.get_accessor.get_method ());
if (returns_real_struct) {
var cvalueparam = new CCodeParameter ("value", "%s *".printf (get_ccode_name (prop.get_accessor.value_type)));
vdeclarator.add_parameter (cvalueparam);
- creturn_type = "void";
- } else {
- creturn_type = get_ccode_name (prop.get_accessor.value_type);
}
var array_type = prop.property_type as ArrayType;
}
}
- var vdecl = new CCodeDeclaration (creturn_type);
+ var vdecl = new CCodeDeclaration (get_ccode_name (creturn_type));
vdecl.add_declarator (vdeclarator);
type_struct.add_declaration (vdecl);
}