return get_ccode_upper_case_name (sym);
}
- public static string get_ccode_interface_get_function (Interface iface) {
- return "%s_GET_INTERFACE".printf (get_ccode_upper_case_name (iface));
- }
-
- public static string get_ccode_class_get_function (Class cl) {
- assert (!cl.is_compact);
- return "%s_GET_CLASS".printf (get_ccode_upper_case_name (cl));
+ public static string get_ccode_type_get_function (ObjectTypeSymbol sym) {
+ var func_name = sym.get_attribute_string ("CCode", "type_get_function");
+ if (func_name != null) {
+ return func_name;
+ }
+ if (sym is Class) {
+ assert (!((Class) sym).is_compact);
+ return "%s_GET_CLASS".printf (get_ccode_upper_case_name (sym));
+ } else if (sym is Interface) {
+ return "%s_GET_INTERFACE".printf (get_ccode_upper_case_name (sym));
+ } else {
+ Report.error (sym.source_reference, "`CCode.type_get_function' not supported");
+ return "";
+ }
}
public static string get_ccode_class_get_private_function (Class cl) {
var iface = (Interface) prop.parent_symbol;
vcast = new CCodeIdentifier ("_iface_");
- var vcastcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_interface_get_function (iface)));
+ var vcastcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (iface)));
((CCodeFunctionCall) vcastcall).add_argument (new CCodeIdentifier ("self"));
ccode.add_declaration ("%s*".printf (get_ccode_type_name (iface)), new CCodeVariableDeclarator ("_iface_"));
ccode.add_assignment (vcast, vcastcall);
var cl = (Class) prop.parent_symbol;
if (!cl.is_compact) {
vcast = new CCodeIdentifier ("_klass_");
- var vcastcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_get_function (cl)));
+ var vcastcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (cl)));
((CCodeFunctionCall) vcastcall).add_argument (new CCodeIdentifier ("self"));
ccode.add_declaration ("%sClass*".printf (get_ccode_name (cl)), new CCodeVariableDeclarator ("_klass_"));
ccode.add_assignment (vcast, vcastcall);
require_generic_accessors (iface);
string method_name = "get_%s_type".printf (type_parameter.name.ascii_down ());
- var cast_self = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_interface_get_function (iface)));
+ var cast_self = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (iface)));
cast_self.add_argument (new CCodeIdentifier ("self"));
var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer (cast_self, method_name));
function_call.add_argument (new CCodeIdentifier ("self"));
require_generic_accessors (iface);
string method_name = "get_%s_dup_func".printf (type_parameter.name.ascii_down ());
- var cast_self = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_interface_get_function (iface)));
+ var cast_self = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (iface)));
cast_self.add_argument (new CCodeIdentifier ("self"));
var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer (cast_self, method_name));
function_call.add_argument (new CCodeIdentifier ("self"));
require_generic_accessors (iface);
string method_name = "get_%s_destroy_func".printf (type_parameter.name.ascii_down ());
- var cast_self = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_interface_get_function (iface)));
+ var cast_self = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (iface)));
cast_self.add_argument (new CCodeIdentifier ("self"));
var function_call = new CCodeFunctionCall (new CCodeMemberAccess.pointer (cast_self, method_name));
function_call.add_argument (new CCodeIdentifier ("self"));
if (m.base_method.get_attribute ("NoWrapper") != null) {
var base_class = (Class) m.base_method.parent_symbol;
if (!base_class.is_compact) {
- var vclass = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_get_function (base_class)));
+ var vclass = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (base_class)));
vclass.add_argument (pub_inst);
set_cvalue (expr, new CCodeMemberAccess.pointer (vclass, get_ccode_vfunc_name (m)));
} else {
} else if (m.base_interface_method != null) {
if (m.base_interface_method.get_attribute ("NoWrapper") != null) {
var base_iface = (Interface) m.base_interface_method.parent_symbol;
- var vclass = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_interface_get_function (base_iface)));
+ var vclass = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (base_iface)));
vclass.add_argument (pub_inst);
set_cvalue (expr, new CCodeMemberAccess.pointer (vclass, get_ccode_vfunc_name (m)));
} else {
if (m.parent_symbol is Interface) {
var iface = (Interface) m.parent_symbol;
- var vcastcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_interface_get_function (iface)));
+ var vcastcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (iface)));
((CCodeFunctionCall) vcastcall).add_argument (new CCodeIdentifier ("self"));
ccode.add_declaration ("%s*".printf (get_ccode_type_name (iface)), new CCodeVariableDeclarator ("_iface_"));
ccode.add_assignment (vcast, vcastcall);
} else {
var cl = (Class) m.parent_symbol;
if (!cl.is_compact) {
- var vcastcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_get_function (cl)));
+ var vcastcall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (cl)));
((CCodeFunctionCall) vcastcall).add_argument (new CCodeIdentifier ("self"));
ccode.add_declaration ("%sClass*".printf (get_ccode_name (cl)), new CCodeVariableDeclarator ("_klass_"));
ccode.add_assignment (vcast, vcastcall);
decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(klass)".printf (get_ccode_class_type_check_function (cl)), macro));
macro = "(G_TYPE_INSTANCE_GET_CLASS ((obj), %s, %sClass))".printf (get_ccode_type_id (cl), get_ccode_name (cl));
- decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (get_ccode_class_get_function (cl)), macro));
+ decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (get_ccode_type_get_function (cl)), macro));
decl_space.add_type_declaration (new CCodeNewline ());
}
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, ref_count));
ccode.open_if (ccall);
- var get_class = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_get_function (cl)));
+ var get_class = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (cl)));
get_class.add_argument (new CCodeIdentifier ("self"));
// finalize class
- var ccast = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_get_function (cl)));
+ var ccast = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_type_get_function (cl)));
ccast.add_argument (new CCodeIdentifier ("self"));
ccall = new CCodeFunctionCall (new CCodeMemberAccess.pointer (ccast, "finalize"));
ccall.add_argument (new CCodeIdentifier ("self"));
decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (get_ccode_type_check_function (iface)), macro));
macro = "(G_TYPE_INSTANCE_GET_INTERFACE ((obj), %s, %s))".printf (get_ccode_type_id (iface), get_ccode_type_name (iface));
- decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (get_ccode_interface_get_function (iface)), macro));
+ decl_space.add_type_declaration (new CCodeMacroReplacement ("%s(obj)".printf (get_ccode_type_get_function (iface)), macro));
decl_space.add_type_declaration (new CCodeNewline ());
decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (get_ccode_name (iface)), new CCodeVariableDeclarator (get_ccode_name (iface))));
if (!data.is_compact) {
this.is_class_type_macro_name = Vala.get_ccode_class_type_check_function (data);
this.class_type_macro_name = Vala.get_ccode_class_type_function (data);
- this.class_macro_name = Vala.get_ccode_class_get_function (data);
+ this.class_macro_name = Vala.get_ccode_type_get_function (data);
this.private_cname = _get_private_cname (data);
}
this.dbus_name = Vala.GDBusModule.get_dbus_name (data);
{
base (parent, file, name, accessibility, comment, false, data);
- this.interface_macro_name = Vala.get_ccode_interface_get_function (data);
+ this.interface_macro_name = Vala.get_ccode_type_get_function (data);
this.dbus_name = Vala.GDBusModule.get_dbus_name (data);
this.cname = Vala.get_ccode_name (data);
this.type_id = Vala.get_ccode_type_id (data);
"has_type_id", "instance_pos", "const_cname", "take_value_function", "copy_function", "free_function",
"param_spec_function", "has_target", "has_typedef", "type_cname", "ref_function", "ref_function_void", "unref_function", "type",
"has_construct_function", "returns_floating_reference", "gir_namespace", "gir_version", "construct_function",
- "lower_case_cprefix", "simple_generics", "sentinel", "scope", "has_destroy_function", "ordering", "type_check_function",
+ "lower_case_cprefix", "simple_generics", "sentinel", "scope", "has_destroy_function", "ordering", "type_check_function", "type_get_function",
"has_copy_function", "lower_case_csuffix", "ref_sink_function", "dup_function", "finish_function", "generic_type_pos",
"array_length_type", "array_length", "array_length_cname", "array_length_cexpr", "array_null_terminated",
"vfunc_name", "finish_vfunc_name", "finish_name", "free_function_address_of", "pos", "delegate_target", "delegate_target_cname",