From: Juerg Billeter Date: Mon, 14 Apr 2008 16:49:37 +0000 (+0000) Subject: prepare support for nullable and boxed value types X-Git-Tag: VALA_0_3_1~80 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8cb0a533ffb9e9d1282336dc148cd4f1940e1b3c;p=platform%2Fupstream%2Fvala.git prepare support for nullable and boxed value types 2008-04-14 Juerg Billeter * vala/valaclass.vala, vala/valainterface.vala, vala/valatypesymbol.vala, vala/valavaluetype.vala, gobject/valaccodegenerator.vala: prepare support for nullable and boxed value types svn path=/trunk/; revision=1222 --- diff --git a/ChangeLog b/ChangeLog index 7b6a8a4..8d9bf35 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2008-04-14 Jürg Billeter + * vala/valaclass.vala, vala/valainterface.vala, + vala/valatypesymbol.vala, vala/valavaluetype.vala, + gobject/valaccodegenerator.vala: prepare support for nullable and + boxed value types + +2008-04-14 Jürg Billeter + * vala/Makefile.am, vala/valaarraytype.vala, vala/valaclasstype.vala, vala/valacodenode.vala, vala/valadatatype.vala, vala/valaerrortype.vala, diff --git a/gobject/valaccodegenerator.vala b/gobject/valaccodegenerator.vala index 84c2227..ff0cc00 100644 --- a/gobject/valaccodegenerator.vala +++ b/gobject/valaccodegenerator.vala @@ -695,7 +695,7 @@ public class Vala.CCodeGenerator : CodeGenerator { // pass non-simple structs always by reference if (p.type_reference.data_type is Struct) { var st = (Struct) p.type_reference.data_type; - if (!st.is_simple_type () && !p.type_reference.is_ref && !p.type_reference.is_out) { + if (!st.is_simple_type () && !p.type_reference.is_ref && !p.type_reference.is_out && !p.type_reference.nullable) { ctypename += "*"; } } @@ -3240,7 +3240,7 @@ public class Vala.CCodeGenerator : CodeGenerator { } public CCodeExpression get_implicit_cast_expression (CCodeExpression cexpr, DataType? expression_type, DataType target_type) { - if (null == expression_type) { + if (expression_type == null) { return cexpr; } diff --git a/vala/valaclass.vala b/vala/valaclass.vala index 5b39843..16b36a1 100644 --- a/vala/valaclass.vala +++ b/vala/valaclass.vala @@ -600,7 +600,7 @@ public class Vala.Class : Typesymbol { return get_ref_function () != null; } - public override string get_ref_function () { + public override string? get_ref_function () { if (ref_function == null && base_class != null) { return base_class.get_ref_function (); } else { @@ -608,11 +608,11 @@ public class Vala.Class : Typesymbol { } } - public void set_ref_function (string name) { + public void set_ref_function (string? name) { this.ref_function = name; } - public override string get_unref_function () { + public override string? get_unref_function () { if (unref_function == null && base_class != null) { return base_class.get_unref_function (); } else { @@ -620,15 +620,15 @@ public class Vala.Class : Typesymbol { } } - public void set_unref_function (string name) { + public void set_unref_function (string? name) { this.unref_function = name; } - public override string get_dup_function () { + public override string? get_dup_function () { return copy_function; } - public void set_dup_function (string name) { + public void set_dup_function (string? name) { this.copy_function = name; } @@ -636,7 +636,7 @@ public class Vala.Class : Typesymbol { return get_lower_case_cprefix () + "free"; } - public override string get_free_function () { + public override string? get_free_function () { if (free_function == null) { free_function = get_default_free_function (); } diff --git a/vala/valainterface.vala b/vala/valainterface.vala index 068c6d3..5b15add 100644 --- a/vala/valainterface.vala +++ b/vala/valainterface.vala @@ -371,11 +371,11 @@ public class Vala.Interface : Typesymbol { return true; } - public override string get_ref_function () { + public override string? get_ref_function () { return "g_object_ref"; } - public override string get_unref_function () { + public override string? get_unref_function () { return "g_object_unref"; } diff --git a/vala/valatypesymbol.vala b/vala/valatypesymbol.vala index 01bef96..a7d3055 100644 --- a/vala/valatypesymbol.vala +++ b/vala/valatypesymbol.vala @@ -1,6 +1,6 @@ /* valatype.vala * - * Copyright (C) 2006-2007 Jürg Billeter, Raffaele Sandrini + * Copyright (C) 2006-2008 Jürg Billeter, Raffaele Sandrini * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -58,23 +58,45 @@ public abstract class Vala.Typesymbol : Symbol { * * @return the name of the C function if supported or null otherwise */ - public virtual string get_dup_function () { + public virtual string? get_dup_function () { return null; } /** * Returns the C function name that frees instances of this data type. - * This is only valid for data types with reference type semantics that - * do not support reference counting. The specified C function must - * accept one argument pointing to the instance to be freed. + * The specified C function must accept one argument pointing to the + * instance to be freed. * - * @return the name of the C function or null if this data type is not a - * reference type or if it supports reference counting + * @return the name of the C function if supported or null otherwise */ - public virtual string get_free_function () { + public virtual string? get_free_function () { return null; } - + + /** + * Returns the C function name that copies contents of instances of + * this data type. This is only applicable to structs. The specified + * C function must accept two arguments, the first is the source value + * and the second is the destination value. + * + * @return the name of the C function if supported or null otherwise + */ + public virtual string? get_copy_function () { + return null; + } + + /** + * Returns the C function name that destroys the contents of instances + * of this data type. This is only applicable to structs. The specified + * C function must accept one argument pointing to the instance to be + * destroyed. + * + * @return the name of the C function if supported or null otherwise + */ + public virtual string? get_destroy_function () { + return null; + } + /** * Checks whether this data type supports reference counting. This is * only valid for reference types. @@ -95,7 +117,7 @@ public abstract class Vala.Typesymbol : Symbol { * @return the name of the C function or null if this data type does not * support reference counting */ - public virtual string get_ref_function () { + public virtual string? get_ref_function () { return null; } @@ -108,7 +130,7 @@ public abstract class Vala.Typesymbol : Symbol { * @return the name of the C function or null if this data type does not * support reference counting */ - public virtual string get_unref_function () { + public virtual string? get_unref_function () { return null; } diff --git a/vala/valavaluetype.vala b/vala/valavaluetype.vala index 29f582f..8f5e70a 100644 --- a/vala/valavaluetype.vala +++ b/vala/valavaluetype.vala @@ -52,4 +52,15 @@ public class Vala.ValueType : DataType { return result; } + + public override string get_cname (bool var_type, bool const_type) { + string ptr = ""; + if (is_ref || is_out) { + ptr += "*"; + } + if (nullable) { + ptr += "*"; + } + return type_symbol.get_cname (const_type) + ptr; + } }