Commit 0ae7748b authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

Generate code to support GValue and GParamSpec for fundamental classes,

2008-10-03  Jürg Billeter  <j@bitron.ch>

	* vala/valaclass.vala:
	* vala/valainterfacewriter.vala:
	* vala/valatypesymbol.vala:
	* gobject/valaccodeclassbinding.vala:
	* gobject/valaccodegenerator.vala:
	* gobject/valaccodegeneratorsourcefile.vala:
	* gobject/valaccodetypesymbolbinding.vala:
	* gobject/valaclassregisterfunction.vala:
	* gobject/valatyperegisterfunction.vala:
	* vapi/glib-2.0.vapi:

	Generate code to support GValue and GParamSpec for fundamental
	classes, patch by Florian Brosch, fixes bug 549480

svn path=/trunk/; revision=1818
parent cddff0b9
2008-10-03 Jürg Billeter <j@bitron.ch>
* vala/valaclass.vala:
* vala/valainterfacewriter.vala:
* vala/valatypesymbol.vala:
* gobject/valaccodeclassbinding.vala:
* gobject/valaccodegenerator.vala:
* gobject/valaccodegeneratorsourcefile.vala:
* gobject/valaccodetypesymbolbinding.vala:
* gobject/valaclassregisterfunction.vala:
* gobject/valatyperegisterfunction.vala:
* vapi/glib-2.0.vapi:
Generate code to support GValue and GParamSpec for fundamental
classes, patch by Florian Brosch, fixes bug 549480
2008-10-03 Jürg Billeter <j@bitron.ch>
* vapi/glib-2.0.vapi:
......
This diff is collapsed.
......@@ -58,6 +58,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
public CCodeFragment source_signal_marshaller_definition;
public CCodeFragment module_init_fragment;
public CCodeStruct param_spec_struct;
public CCodeStruct instance_struct;
public CCodeStruct type_struct;
public CCodeStruct instance_priv_struct;
......@@ -127,6 +128,7 @@ public class Vala.CCodeGenerator : CodeGenerator {
public string module_init_param_name;
public bool string_h_needed;
public bool gvaluecollector_h_needed;
private bool requires_free_checked;
private bool requires_array_free;
public bool requires_array_move;
......
......@@ -193,6 +193,7 @@ public class Vala.CCodeGenerator {
next_temp_var_id = 0;
string_h_needed = false;
gvaluecollector_h_needed = false;
dbus_glib_h_needed = false;
requires_free_checked = false;
requires_array_free = false;
......@@ -292,6 +293,10 @@ public class Vala.CCodeGenerator {
source_include_directives.append (new CCodeIncludeDirective ("string.h"));
}
if (gvaluecollector_h_needed) {
source_include_directives.append (new CCodeIncludeDirective ("gobject/gvaluecollector.h"));
}
if (dbus_glib_h_needed) {
source_include_directives.append (new CCodeIncludeDirective ("dbus/dbus-glib.h"));
}
......
......@@ -29,9 +29,17 @@ public abstract class Vala.CCodeTypeSymbolBinding : CCodeBinding {
cspec.add_argument (prop.get_canonical_cconstant ());
cspec.add_argument (new CCodeConstant ("\"%s\"".printf (prop.nick)));
cspec.add_argument (new CCodeConstant ("\"%s\"".printf (prop.blurb)));
if ((prop.property_type.data_type is Class && ((Class) prop.property_type.data_type).is_subtype_of (codegen.gobject_type)) || prop.property_type.data_type is Interface) {
cspec.call = new CCodeIdentifier ("g_param_spec_object");
cspec.add_argument (new CCodeIdentifier (prop.property_type.data_type.get_type_id ()));
if ((prop.property_type.data_type is Class && !(((Class) prop.property_type.data_type).is_compact)) || prop.property_type.data_type is Interface) {
//if ((prop.property_type.data_type is Class && ((Class) prop.property_type.data_type).is_subtype_of (codegen.gobject_type)) || prop.property_type.data_type is Interface) {
string param_spec_name = prop.property_type.data_type.get_param_spec_function ();
if ( param_spec_name == null ) {
cspec.call = new CCodeIdentifier ("g_param_spec_pointer");
} else {
cspec.call = new CCodeIdentifier ( param_spec_name );
cspec.add_argument (new CCodeIdentifier (prop.property_type.data_type.get_type_id ()));
}
} else if (prop.property_type.data_type == codegen.string_type.data_type) {
cspec.call = new CCodeIdentifier ("g_param_spec_string");
cspec.add_argument (new CCodeConstant ("NULL"));
......
......@@ -30,7 +30,7 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction {
* Specifies the class to be registered.
*/
public weak Class class_reference { get; set; }
/**
* Creates a new C function to register the specified class at runtime.
*
......@@ -86,6 +86,54 @@ public class Vala.ClassRegisterFunction : TypeRegisterFunction {
return class_reference.access;
}
public override string? get_gtype_value_table_init_function_name () {
bool is_fundamental = !class_reference.is_compact && !class_reference.is_static && class_reference.base_class == null;
if ( is_fundamental )
return "%svalue_%s_init".printf(class_reference.parent_symbol.get_lower_case_cprefix (), class_reference.name.down() );
return null;
}
public override string? get_gtype_value_table_free_function_name () {
bool is_fundamental = !class_reference.is_compact && !class_reference.is_static && class_reference.base_class == null;
if ( is_fundamental )
return "%svalue_%s_free_value".printf(class_reference.parent_symbol.get_lower_case_cprefix (), class_reference.name.down() );
return null;
}
public override string? get_gtype_value_table_copy_function_name () {
bool is_fundamental = !class_reference.is_compact && !class_reference.is_static && class_reference.base_class == null;
if ( is_fundamental )
return "%svalue_%s_copy_value".printf(class_reference.parent_symbol.get_lower_case_cprefix (), class_reference.name.down() );
return null;
}
public override string? get_gtype_value_table_peek_pointer_function_name () {
bool is_fundamental = !class_reference.is_compact && !class_reference.is_static && class_reference.base_class == null;
if ( is_fundamental )
return "%svalue_%s_peek_pointer".printf(class_reference.parent_symbol.get_lower_case_cprefix (), class_reference.name.down() );
return null;
}
public override string? get_gtype_value_table_collect_value_function_name () {
bool is_fundamental = !class_reference.is_compact && !class_reference.is_static && class_reference.base_class == null;
if ( is_fundamental )
return "%svalue_%s_collect_value".printf(class_reference.parent_symbol.get_lower_case_cprefix (), class_reference.name.down() );
return null;
}
public override string? get_gtype_value_table_lcopy_value_function_name () {
bool is_fundamental = !class_reference.is_compact && !class_reference.is_static && class_reference.base_class == null;
if ( is_fundamental )
return "%svalue_%s_lcopy_value".printf(class_reference.parent_symbol.get_lower_case_cprefix (), class_reference.name.down() );
return null;
}
public override CCodeFragment get_type_interface_init_declaration () {
var frag = new CCodeFragment ();
......
......@@ -89,10 +89,25 @@ public abstract class Vala.TypeRegisterFunction {
definition_fragment.append (get_fun);
}
string type_value_table_decl_name = null;
var type_init = new CCodeBlock ();
if ( fundamental ) {
var cgtypetabledecl = new CCodeDeclaration ("const GTypeValueTable");
cgtypetabledecl.modifiers = CCodeModifiers.STATIC;
cgtypetabledecl.add_declarator ( new CCodeVariableDeclarator.with_initializer ( "g_define_type_value_table", new CCodeConstant ("{ %s, %s, %s, %s, \"p\", %s, \"p\", %s }".printf ( get_gtype_value_table_init_function_name (), get_gtype_value_table_free_function_name (), get_gtype_value_table_copy_function_name (), get_gtype_value_table_peek_pointer_function_name (), get_gtype_value_table_collect_value_function_name (), get_gtype_value_table_lcopy_value_function_name () ))));
type_value_table_decl_name = "&g_define_type_value_table";
type_init.add_statement ( cgtypetabledecl );
}
else {
type_value_table_decl_name = "NULL";
}
var ctypedecl = new CCodeDeclaration ("const GTypeInfo");
ctypedecl.modifiers = CCodeModifiers.STATIC;
ctypedecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("g_define_type_info", new CCodeConstant ("{ sizeof (%s), (GBaseInitFunc) %s, (GBaseFinalizeFunc) NULL, (GClassInitFunc) %s, (GClassFinalizeFunc) NULL, NULL, %s, 0, (GInstanceInitFunc) %s }".printf (get_type_struct_name (), get_base_init_func_name (), get_class_init_func_name (), get_instance_struct_size (), get_instance_init_func_name ()))));
ctypedecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("g_define_type_info", new CCodeConstant ("{ sizeof (%s), (GBaseInitFunc) %s, (GBaseFinalizeFunc) NULL, (GClassInitFunc) %s, (GClassFinalizeFunc) NULL, NULL, %s, 0, (GInstanceInitFunc) %s, %s }".printf (get_type_struct_name (), get_base_init_func_name (), get_class_init_func_name (), get_instance_struct_size (), get_instance_init_func_name (), type_value_table_decl_name))));
type_init.add_statement (ctypedecl);
if (fundamental) {
var ctypefundamentaldecl = new CCodeDeclaration ("const GTypeFundamentalInfo");
......@@ -215,10 +230,66 @@ public abstract class Vala.TypeRegisterFunction {
/**
* Returns the name of the parent type in C code.
*
* @return C parent type name
* @return C function name
*/
public abstract string get_parent_type_name ();
/**
* Returns the C-name of the new generated GTypeValueTable init function or null when not available.
*
* @return C function name
*/
public virtual string? get_gtype_value_table_init_function_name () {
return null;
}
/**
* Returns the C-name of the new generated GTypeValueTable peek pointer function or null when not available.
*
* @return C function name
*/
public virtual string? get_gtype_value_table_peek_pointer_function_name () {
return null;
}
/**
* Returns the C-name of the new generated GTypeValueTable free function or null when not available.
*
* @return C function name
*/
public virtual string? get_gtype_value_table_free_function_name () {
return null;
}
/**
* Returns the C-name of the new generated GTypeValueTable copy function or null when not available.
*
* @return C function name
*/
public virtual string? get_gtype_value_table_copy_function_name () {
return null;
}
/**
* Returns the C-name of the new generated GTypeValueTable lcopy function or null when not available.
*
* @return C function name
*/
public virtual string? get_gtype_value_table_lcopy_value_function_name () {
return null;
}
/**
* Returns the C-name of the new generated GTypeValueTable collect value function or null when not available.
*
* @return C function name
*/
public virtual string? get_gtype_value_table_collect_value_function_name () {
return null;
}
/**
* Returns the set of type flags to be applied when registering.
*
......
......@@ -95,6 +95,7 @@ public class Vala.Class : ObjectTypeSymbol {
private string type_id;
private string ref_function;
private string unref_function;
private string param_spec_function;
private string copy_function;
private string free_function;
private string marshaller_type_name;
......@@ -626,8 +627,12 @@ public class Vala.Class : ObjectTypeSymbol {
if (a.has_argument ("type_check_function")) {
type_check_function = a.get_string ("type_check_function");
}
if (a.has_argument ("param_spec_function")) {
param_spec_function = a.get_string ("param_spec_function");
}
}
/**
* Process all associated attributes.
*/
......@@ -673,9 +678,25 @@ public class Vala.Class : ObjectTypeSymbol {
return marshaller_type_name;
}
public override string? get_param_spec_function () {
if (param_spec_function == null ) {
if (!(is_compact || base_class == null)) {
param_spec_function = base_class.get_param_spec_function ();
}
}
return param_spec_function;
}
public void set_param_spec_function ( string name ) {
param_spec_function = name;
}
public override string? get_get_value_function () {
if (get_value_function == null) {
if (base_class != null) {
if (is_fundamental()) {
get_value_function = "%svalue_get_%s".printf(parent_symbol.get_lower_case_cprefix (), name.down());
} else if (base_class != null) {
get_value_function = base_class.get_get_value_function ();
} else {
get_value_function = "g_value_get_pointer";
......@@ -687,7 +708,9 @@ public class Vala.Class : ObjectTypeSymbol {
public override string? get_set_value_function () {
if (set_value_function == null) {
if (base_class != null) {
if (is_fundamental()) {
set_value_function = "%svalue_set_%s".printf(parent_symbol.get_lower_case_cprefix (), name.down());
} else if (base_class != null) {
set_value_function = base_class.get_set_value_function ();
} else {
set_value_function = "g_value_set_pointer";
......@@ -701,7 +724,7 @@ public class Vala.Class : ObjectTypeSymbol {
return get_ref_function () != null;
}
bool is_fundamental () {
public bool is_fundamental () {
if (!is_compact && base_class == null) {
return true;
}
......
......@@ -141,6 +141,10 @@ public class Vala.InterfaceWriter : CodeVisitor {
write_string ("type_check_function = \"%s\", ".printf (cl.type_check_function ));
}
if (cl.get_param_spec_function () != null) {
write_string ("param_spec_function = \"%s\", ".printf ( cl.get_param_spec_function () ));
}
bool first = true;
string cheaders;
foreach (string cheader in cl.get_cheader_filenames ()) {
......
......@@ -150,16 +150,23 @@ public abstract class Vala.TypeSymbol : Symbol {
public virtual string? get_marshaller_type_name () {
return null;
}
/**
* Returns the cname of the GValue parameter spec function.
*/
public virtual string? get_param_spec_function () {
return null;
}
/**
* Returns the cname of the GValue getter function,
* Returns the cname of the GValue getter function.
*/
public virtual string? get_get_value_function () {
return null;
}
/**
* Returns the cname of the GValue setter function,
* Returns the cname of the GValue setter function.
*/
public virtual string? get_set_value_function () {
return null;
......
......@@ -936,7 +936,7 @@ namespace GLib {
public static delegate void ObjectSetPropertyFunc (Object object, uint property_id, Value value, ParamSpec pspec);
public static delegate void WeakNotify (void *data, Object object);
[CCode (ref_function = "g_object_ref", unref_function = "g_object_unref", marshaller_type_name = "OBJECT", get_value_function = "g_value_get_object", set_value_function = "g_value_set_object", cheader_filename = "glib-object.h")]
[CCode (ref_function = "g_object_ref", unref_function = "g_object_unref", marshaller_type_name = "OBJECT", get_value_function = "g_value_get_object", set_value_function = "g_value_set_object", param_spec_function = "g_param_spec_object", cheader_filename = "glib-object.h")]
public class Object : TypeInstance {
public uint ref_count;
......
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