From: Juerg Billeter Date: Sat, 15 Sep 2007 19:44:20 +0000 (+0000) Subject: support creation methods in structs, replace InstanceByReference method X-Git-Tag: VALA_0_1_4~40 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=087945bcf71247fbba63bd92cc232c8e0d009b8a;p=thirdparty%2Fvala.git support creation methods in structs, replace InstanceByReference method 2007-09-15 Juerg Billeter * vala/valainterfacewriter.vala, vala/valamethod.vala, vala/valasemanticanalyzer.vala, vala/valastruct.vala, gobject/valacodegenerator.vala, gobject/valacodegeneratorinvocationexpression.vala, gobject/valacodegeneratormethod.vala, vapigen/valagidlparser.vala, vapi/glib-2.0.vala: support creation methods in structs, replace InstanceByReference method attribute by SimpleType type attribute (inverse effect) * tests/Makefile.am, tests/structs.exp, tests/structs.vala: add struct declaration test * vapi/gdk-2.0.vala, vapi/gtk+-2.0.vala, vapi/pango.vala: regenerated svn path=/trunk/; revision=608 --- diff --git a/ChangeLog b/ChangeLog index d8b0b85d6..049e4d06e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2007-09-15 Jürg Billeter + + * vala/valainterfacewriter.vala, vala/valamethod.vala, + vala/valasemanticanalyzer.vala, vala/valastruct.vala, + gobject/valacodegenerator.vala, + gobject/valacodegeneratorinvocationexpression.vala, + gobject/valacodegeneratormethod.vala, vapigen/valagidlparser.vala, + vapi/glib-2.0.vala: support creation methods in structs, replace + InstanceByReference method attribute by SimpleType type attribute + (inverse effect) + + * tests/Makefile.am, tests/structs.exp, tests/structs.vala: add struct + declaration test + + * vapi/gdk-2.0.vala, vapi/gtk+-2.0.vala, vapi/pango.vala: regenerated + 2007-09-15 Jürg Billeter * vala/scanner.l: support real literals with exponent diff --git a/gobject/valacodegenerator.vala b/gobject/valacodegenerator.vala index c9d572a1b..3c8b0befe 100644 --- a/gobject/valacodegenerator.vala +++ b/gobject/valacodegenerator.vala @@ -2408,44 +2408,58 @@ public class Vala.CodeGenerator : CodeVisitor { } public override void visit_end_object_creation_expression (ObjectCreationExpression! expr) { + CCodeExpression struct_instance = null; + CCodeFunctionCall creation_call = null; + + if (expr.type_reference.data_type is Struct) { + // value-type initialization + var temp_decl = get_temp_variable_declarator (expr.type_reference, false, expr); + temp_vars.add (temp_decl); + + struct_instance = new CCodeIdentifier (get_variable_cname (temp_decl.name)); + } + if (expr.symbol_reference == null) { // no creation method if (expr.type_reference.data_type == glist_type || - expr.type_reference.data_type == gslist_type) { + expr.type_reference.data_type == gslist_type) { // NULL is an empty list expr.ccodenode = new CCodeConstant ("NULL"); } else if (expr.type_reference.data_type is Class && expr.type_reference.data_type.is_subtype_of (gobject_type)) { - var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_new")); - - ccall.add_argument (new CCodeConstant (expr.type_reference.data_type.get_type_id ())); - - ccall.add_argument (new CCodeConstant ("NULL")); - - expr.ccodenode = ccall; - } else { - var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_new0")); - - ccall.add_argument (new CCodeConstant (expr.type_reference.data_type.get_cname ())); - - ccall.add_argument (new CCodeConstant ("1")); - - expr.ccodenode = ccall; + creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_new")); + creation_call.add_argument (new CCodeConstant (expr.type_reference.data_type.get_type_id ())); + creation_call.add_argument (new CCodeConstant ("NULL")); + } else if (expr.type_reference.data_type is Class) { + creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_new0")); + creation_call.add_argument (new CCodeConstant (expr.type_reference.data_type.get_cname ())); + creation_call.add_argument (new CCodeConstant ("1")); + } else if (expr.type_reference.data_type is Struct) { + // memset needs string.h + string_h_needed = true; + creation_call = new CCodeFunctionCall (new CCodeIdentifier ("memset")); + creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, struct_instance)); + creation_call.add_argument (new CCodeConstant ("0")); + creation_call.add_argument (new CCodeIdentifier ("sizeof (%s)".printf (expr.type_reference.get_cname ()))); } } else if (expr.symbol_reference is Method) { // use creation method var m = (Method) expr.symbol_reference; var params = m.get_parameters (); - var ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_cname ())); + creation_call = new CCodeFunctionCall (new CCodeIdentifier (m.get_cname ())); + + if (struct_instance != null) { + creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, struct_instance)); + } if (expr.type_reference.data_type is Class && expr.type_reference.data_type.is_subtype_of (gobject_type)) { foreach (TypeReference type_arg in expr.type_reference.get_type_arguments ()) { if (type_arg.takes_ownership) { - ccall.add_argument (get_dup_func_expression (type_arg)); - ccall.add_argument (get_destroy_func_expression (type_arg)); + creation_call.add_argument (get_dup_func_expression (type_arg)); + creation_call.add_argument (get_destroy_func_expression (type_arg)); } else { - ccall.add_argument (new CCodeConstant ("NULL")); - ccall.add_argument (new CCodeConstant ("NULL")); + creation_call.add_argument (new CCodeConstant ("NULL")); + creation_call.add_argument (new CCodeConstant ("NULL")); } } } @@ -2464,7 +2478,7 @@ public class Vala.CodeGenerator : CodeVisitor { } } - ccall.add_argument (cexpr); + creation_call.add_argument (cexpr); i++; } while (params_it.next ()) { @@ -2485,41 +2499,47 @@ public class Vala.CodeGenerator : CodeVisitor { * parameter yet */ param.default_expression.accept (this); - ccall.add_argument ((CCodeExpression) param.default_expression.ccodenode); + creation_call.add_argument ((CCodeExpression) param.default_expression.ccodenode); i++; } if (expr.can_fail) { // method can fail current_method_inner_error = true; - ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("inner_error"))); + creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("inner_error"))); } if (ellipsis) { // ensure variable argument list ends with NULL - ccall.add_argument (new CCodeConstant ("NULL")); + creation_call.add_argument (new CCodeConstant ("NULL")); } - - expr.ccodenode = ccall; } else if (expr.symbol_reference is EnumValue) { // error code var ev = (EnumValue) expr.symbol_reference; var en = (Enum) ev.parent_symbol; - var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_set_error")); - ccall.add_argument (new CCodeIdentifier ("error")); - ccall.add_argument (new CCodeIdentifier (en.get_upper_case_cname ())); - ccall.add_argument (new CCodeIdentifier (ev.get_cname ())); + creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_set_error")); + creation_call.add_argument (new CCodeIdentifier ("error")); + creation_call.add_argument (new CCodeIdentifier (en.get_upper_case_cname ())); + creation_call.add_argument (new CCodeIdentifier (ev.get_cname ())); foreach (Expression arg in expr.get_argument_list ()) { - ccall.add_argument ((CCodeExpression) arg.ccodenode); + creation_call.add_argument ((CCodeExpression) arg.ccodenode); } - - expr.ccodenode = ccall; } else { assert (false); } + if (expr.type_reference.data_type is Struct) { + var ccomma = new CCodeCommaExpression (); + ccomma.append_expression (creation_call); + ccomma.append_expression (struct_instance); + + expr.ccodenode = ccomma; + } else if (creation_call != null) { + expr.ccodenode = creation_call; + } + visit_expression (expr); } diff --git a/gobject/valacodegeneratorinvocationexpression.vala b/gobject/valacodegeneratorinvocationexpression.vala index 77e309e1d..3f6e2f4bc 100644 --- a/gobject/valacodegeneratorinvocationexpression.vala +++ b/gobject/valacodegeneratorinvocationexpression.vala @@ -56,10 +56,7 @@ public class Vala.CodeGenerator { } else if (m is ArrayMoveMethod) { requires_array_move = true; } - - /* explicitly use strong reference as ccall gets unrefed - * at end of inner block - */ + CCodeExpression instance; if (m != null && m.instance) { var base_method = m; @@ -79,7 +76,7 @@ public class Vala.CodeGenerator { instance_expression_type = ma.inner.static_type; } - if (m.instance_by_reference && (ma.inner != null || m.parent_symbol != current_type_symbol)) { + if (m.parent_symbol is Struct && !((Struct) m.parent_symbol).is_simple_type () && (ma.inner != null || m.parent_symbol != current_type_symbol)) { instance = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance); } diff --git a/gobject/valacodegeneratormethod.vala b/gobject/valacodegeneratormethod.vala index a0399d7e7..9d69adc59 100644 --- a/gobject/valacodegeneratormethod.vala +++ b/gobject/valacodegeneratormethod.vala @@ -99,7 +99,7 @@ public class Vala.CodeGenerator { CCodeFormalParameter instance_param = null; - if (m.instance) { + if (m.instance || (m.parent_symbol is Struct && m is CreationMethod)) { var this_type = new TypeReference (); this_type.data_type = find_parent_type (m); if (m.base_interface_method != null) { @@ -111,7 +111,7 @@ public class Vala.CodeGenerator { base_type.data_type = (DataType) m.base_method.parent_symbol; instance_param = new CCodeFormalParameter ("base", base_type.get_cname ()); } else { - if (m.instance_by_reference) { + if (m.parent_symbol is Struct && !((Struct) m.parent_symbol).is_simple_type ()) { instance_param = new CCodeFormalParameter ("*self", this_type.get_cname ()); } else { instance_param = new CCodeFormalParameter ("self", this_type.get_cname ()); @@ -308,11 +308,14 @@ public class Vala.CodeGenerator { cinit.append (cdecl); } else { var st = (Struct) m.parent_symbol; - var cdecl = new CCodeDeclaration (st.get_cname () + "*"); - var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_new0")); - ccall.add_argument (new CCodeIdentifier (st.get_cname ())); - cdecl.add_declarator (new CCodeVariableDeclarator.with_initializer ("self", ccall)); - cinit.append (cdecl); + + // memset needs string.h + string_h_needed = true; + var czero = new CCodeFunctionCall (new CCodeIdentifier ("memset")); + czero.add_argument (new CCodeIdentifier ("self")); + czero.add_argument (new CCodeConstant ("0")); + czero.add_argument (new CCodeIdentifier ("sizeof (%s)".printf (st.get_cname ()))); + cinit.append (new CCodeExpressionStatement (czero)); } } @@ -428,9 +431,11 @@ public class Vala.CodeGenerator { function.block.add_statement (new CCodeExpressionStatement (cfreeparams)); } - var creturn = new CCodeReturnStatement (); - creturn.return_expression = new CCodeIdentifier ("self"); - function.block.add_statement (creturn); + if (current_type_symbol is Class) { + var creturn = new CCodeReturnStatement (); + creturn.return_expression = new CCodeIdentifier ("self"); + function.block.add_statement (creturn); + } } bool return_value = true; diff --git a/tests/Makefile.am b/tests/Makefile.am index f09e61a5b..6f3edf74a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -35,6 +35,7 @@ TESTS_ENVIRONMENT = $(srcdir)/testrunner.sh TESTS = \ hello.vala \ classes.vala \ + structs.vala \ property-sample.vala \ \ test-001.vala \ @@ -82,6 +83,7 @@ EXTRA_DIST = \ \ hello.exp \ classes.exp \ + structs.exp \ property-sample.exp \ \ test-001.exp \ diff --git a/tests/structs.exp b/tests/structs.exp new file mode 100644 index 000000000..bbcf3cd5d --- /dev/null +++ b/tests/structs.exp @@ -0,0 +1,8 @@ +Structs Test: +new SimpleStruct () +new PublicStruct () +new StructWithCreationMethod () +StructWithCreationMethod +new StructWithNamedCreationMethod () +StructWithNamedCreationMethod +. diff --git a/tests/structs.vala b/tests/structs.vala new file mode 100644 index 000000000..a5873a10b --- /dev/null +++ b/tests/structs.vala @@ -0,0 +1,39 @@ +using GLib; + +struct SimpleStruct { +} + +public struct PublicStruct { +} + +struct StructWithCreationMethod { + public StructWithCreationMethod () { + stdout.printf ("StructWithCreationMethod\n"); + } +} + +struct StructWithNamedCreationMethod { + public StructWithNamedCreationMethod.named () { + stdout.printf ("StructWithNamedCreationMethod\n"); + } +} + +static class StructsTest { + static int main (string[] args) { + stdout.printf ("Structs Test:\n"); + + stdout.printf ("new SimpleStruct ()\n"); + var simple_struct = new SimpleStruct (); + stdout.printf ("new PublicStruct ()\n"); + var public_struct = new PublicStruct (); + stdout.printf ("new StructWithCreationMethod ()\n"); + var struct_with_creation_method = new StructWithCreationMethod (); + stdout.printf ("new StructWithNamedCreationMethod ()\n"); + var struct_with_named_creation_method = new StructWithNamedCreationMethod.named (); + + stdout.printf (".\n"); + + return 0; + } +} + diff --git a/vala/valainterfacewriter.vala b/vala/valainterfacewriter.vala index 9128ee40f..153dc4558 100644 --- a/vala/valainterfacewriter.vala +++ b/vala/valainterfacewriter.vala @@ -480,10 +480,6 @@ public class Vala.InterfaceWriter : CodeVisitor { write_indent (); write_string ("[InstanceLast]"); } - if (m.instance_by_reference) { - write_indent (); - write_string ("[InstanceByReference]"); - } var ccode_params = new String (); var separator = ""; diff --git a/vala/valamethod.vala b/vala/valamethod.vala index 727cd9c2e..2fb73460d 100644 --- a/vala/valamethod.vala +++ b/vala/valamethod.vala @@ -113,13 +113,7 @@ public class Vala.Method : Member, Invokable { * or as the last argument in C code. Defaults to first. */ public bool instance_last { get; set; } - - /** - * Specifies whether the instance of a value type should be passed by - * reference. Only valid for instance methods of value types. - */ - public bool instance_by_reference { get; set; } - + /** * Specifies the virtual or abstract method this method overrides. * Reference must be weak as virtual methods set base_method to @@ -305,8 +299,6 @@ public class Vala.Method : Member, Invokable { returns_modified_pointer = true; } else if (a.name == "InstanceLast") { instance_last = true; - } else if (a.name == "InstanceByReference") { - instance_by_reference = true; } else if (a.name == "FloatingReference") { return_type.floating_reference = true; } else if (a.name == "NoArrayLength") { diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index a1e3d36c6..7ee813747 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -435,10 +435,11 @@ public class Vala.SemanticAnalyzer : CodeVisitor { public override void visit_creation_method (CreationMethod! m) { m.return_type = new TypeReference (); - m.return_type.data_type = (DataType) m.parent_symbol; - m.return_type.transfers_ownership = true; if (current_symbol is Class) { + m.return_type.data_type = (DataType) m.parent_symbol; + m.return_type.transfers_ownership = true; + // check for floating reference var cl = (Class) current_symbol; while (cl != null) { @@ -1876,12 +1877,6 @@ public class Vala.SemanticAnalyzer : CodeVisitor { type = expr.type_reference.data_type; } - if (!type.is_reference_type () && !(type is Enum)) { - expr.error = true; - Report.error (expr.source_reference, "Can't create instance of value type `%s'".printf (expr.type_reference.to_string ())); - return; - } - current_source_file.add_symbol_dependency (type, SourceFileDependencyType.SOURCE); expr.static_type = expr.type_reference.copy (); @@ -1912,6 +1907,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } else if (type is Struct) { var st = (Struct) type; + expr.static_type.transfers_ownership = false; + if (expr.symbol_reference == null) { expr.symbol_reference = st.default_construction_method; } diff --git a/vala/valastruct.vala b/vala/valastruct.vala index 6e851df26..5f65d21d0 100644 --- a/vala/valastruct.vala +++ b/vala/valastruct.vala @@ -48,7 +48,8 @@ public class Vala.Struct : DataType { private string get_value_function; private string set_value_function; private string default_value = null; - + private bool simple_type; + /** * Specifies the default construction method. */ @@ -139,6 +140,10 @@ public class Vala.Struct : DataType { } public override void accept_children (CodeVisitor! visitor) { + foreach (TypeReference type in base_types) { + type.accept (visitor); + } + foreach (TypeParameter p in type_parameters) { p.accept (visitor); } @@ -281,6 +286,8 @@ public class Vala.Struct : DataType { foreach (Attribute a in attributes) { if (a.name == "CCode") { process_ccode_attribute (a); + } else if (a.name == "SimpleType") { + simple_type = true; } else if (a.name == "IntegerType") { process_integer_type_attribute (a); } else if (a.name == "FloatingType") { @@ -375,4 +382,18 @@ public class Vala.Struct : DataType { return -1; } + + /** + * Returns whether this struct is a simple type, i.e. whether + * instances are passed by value. + */ + public bool is_simple_type () { + foreach (TypeReference type in base_types) { + var st = type.data_type as Struct; + if (st != null && st.is_simple_type ()) { + return true; + } + } + return simple_type; + } } diff --git a/vapi/gdk-2.0.vala b/vapi/gdk-2.0.vala index a9356288f..a46b939d2 100644 --- a/vapi/gdk-2.0.vala +++ b/vapi/gdk-2.0.vala @@ -1799,17 +1799,12 @@ namespace Gdk { public ushort red; public ushort green; public ushort blue; - [InstanceByReference] public Gdk.Color copy (); - [InstanceByReference] public bool equal (out Gdk.Color colorb); - [InstanceByReference] public void free (); public static GLib.Type get_type (); - [InstanceByReference] public uint hash (); public static bool parse (string spec, out Gdk.Color color); - [InstanceByReference] public weak string to_string (); } [CCode (cheader_filename = "gdk/gdk.h")] @@ -1819,9 +1814,7 @@ namespace Gdk { public int width; public int height; public static GLib.Type get_type (); - [InstanceByReference] public bool intersect (out Gdk.Rectangle src2, out Gdk.Rectangle dest); - [InstanceByReference] public void union (out Gdk.Rectangle src2, out Gdk.Rectangle dest); } [CCode (cheader_filename = "gdk/gdk.h")] diff --git a/vapi/glib-2.0.vala b/vapi/glib-2.0.vala index aae6c1fbd..3122a888b 100644 --- a/vapi/glib-2.0.vala +++ b/vapi/glib-2.0.vala @@ -23,10 +23,12 @@ * Mathias Hasselmann */ +[SimpleType] [CCode (cname = "gboolean", cheader_filename = "glib.h", type_id = "G_TYPE_BOOLEAN", marshaller_type_name = "BOOLEAN", get_value_function = "g_value_get_boolean", set_value_function = "g_value_set_boolean", default_value = "FALSE")] public struct bool { } +[SimpleType] [CCode (cname = "gpointer", cheader_filename = "glib.h", type_id = "G_TYPE_POINTER", marshaller_type_name = "POINTER", get_value_function = "g_value_get_pointer", set_value_function = "g_value_set_pointer", default_value = "NULL")] public struct pointer { [CCode (cname ="GPOINTER_TO_INT")] @@ -35,10 +37,12 @@ public struct pointer { public uint to_uint (); } +[SimpleType] [CCode (cname = "gconstpointer", cheader_filename = "glib.h", type_id = "G_TYPE_POINTER", marshaller_type_name = "POINTER", get_value_function = "g_value_get_pointer", set_value_function = "g_value_set_pointer", default_value = "NULL")] public struct constpointer { } +[SimpleType] [CCode (cname = "gchar", cprefix = "g_ascii_", cheader_filename = "glib.h", type_id = "G_TYPE_CHAR", marshaller_type_name = "CHAR", get_value_function = "g_value_get_char", set_value_function = "g_value_set_char", default_value = "\'\\0\'")] [IntegerType (rank = 1)] public struct char { @@ -62,6 +66,7 @@ public struct char { public char toupper (); } +[SimpleType] [CCode (cname = "guchar", cheader_filename = "glib.h", type_id = "G_TYPE_UCHAR", marshaller_type_name = "UCHAR", get_value_function = "g_value_get_uchar", set_value_function = "g_value_set_uchar", default_value = "\'\\0\'")] [IntegerType (rank = 2)] public struct uchar { @@ -70,6 +75,7 @@ public struct uchar { public string! to_string (string! format = "%hhu"); } +[SimpleType] [CCode (cname = "gint", cheader_filename = "glib.h", type_id = "G_TYPE_INT", marshaller_type_name = "INT", get_value_function = "g_value_get_int", set_value_function = "g_value_set_int", default_value = "0")] [IntegerType (rank = 9)] public struct int { @@ -89,6 +95,7 @@ public struct int { public pointer to_pointer (); } +[SimpleType] [CCode (cname = "guint", cheader_filename = "glib.h", type_id = "G_TYPE_UINT", marshaller_type_name = "UINT", get_value_function = "g_value_get_uint", set_value_function = "g_value_set_uint", default_value = "0U")] [IntegerType (rank = 10)] public struct uint { @@ -108,6 +115,7 @@ public struct uint { public pointer to_pointer (); } +[SimpleType] [CCode (cname = "gshort", cheader_filename = "glib.h", default_value = "0")] [IntegerType (rank = 5)] public struct short { @@ -121,6 +129,7 @@ public struct short { public string! to_string (string! format = "%hi"); } +[SimpleType] [CCode (cname = "gushort", cheader_filename = "glib.h", default_value = "0U")] [IntegerType (rank = 6)] public struct ushort { @@ -134,6 +143,7 @@ public struct ushort { public string! to_string (string! format = "%hu"); } +[SimpleType] [CCode (cname = "glong", cheader_filename = "glib.h", type_id = "G_TYPE_LONG", marshaller_type_name = "LONG", get_value_function = "g_value_get_long", set_value_function = "g_value_set_long", default_value = "0L")] [IntegerType (rank = 14)] public struct long { @@ -147,6 +157,7 @@ public struct long { public string! to_string (string! format = "%li"); } +[SimpleType] [CCode (cname = "gulong", cheader_filename = "glib.h", type_id = "G_TYPE_ULONG", marshaller_type_name = "ULONG", get_value_function = "g_value_get_ulong", set_value_function = "g_value_set_ulong", default_value = "0UL")] [IntegerType (rank = 15)] public struct ulong { @@ -160,6 +171,7 @@ public struct ulong { public string! to_string (string! format = "%lu"); } +[SimpleType] [CCode (cname = "gint8", cheader_filename = "glib.h", type_id = "G_TYPE_CHAR", marshaller_type_name = "CHAR", get_value_function = "g_value_get_char", set_value_function = "g_value_set_char", default_value = "0")] [IntegerType (rank = 3)] public struct int8 { @@ -172,6 +184,7 @@ public struct int8 { public string! to_string (string! format = "%hhi"); } +[SimpleType] [CCode (cname = "guint8", cheader_filename = "glib.h", default_value = "0U")] [IntegerType (rank = 4)] public struct uint8 { @@ -184,6 +197,7 @@ public struct uint8 { public string! to_string (string! format = "%hhu"); } +[SimpleType] [CCode (cname = "gint16", cheader_filename = "glib.h", default_value = "0")] [IntegerType (rank = 7)] public struct int16 { @@ -196,6 +210,7 @@ public struct int16 { public string! to_string (string! format = "%hi"); } +[SimpleType] [CCode (cname = "guint16", cheader_filename = "glib.h", default_value = "0U")] [IntegerType (rank = 8)] public struct uint16 { @@ -208,6 +223,7 @@ public struct uint16 { public string! to_string (string! format = "%hu"); } +[SimpleType] [CCode (cname = "gint32", cheader_filename = "glib.h", default_value = "0")] [IntegerType (rank = 11)] public struct int32 { @@ -220,6 +236,7 @@ public struct int32 { public string! to_string (string! format = "%i"); } +[SimpleType] [CCode (cname = "guint32", cheader_filename = "glib.h", default_value = "0U")] [IntegerType (rank = 12)] public struct uint32 { @@ -233,6 +250,7 @@ public struct uint32 { public string! to_string (string! format = "%u"); } +[SimpleType] [CCode (cname = "gint64", cheader_filename = "glib.h", type_id = "G_TYPE_INT64", marshaller_type_name = "INT64", get_value_function = "g_value_get_int64", set_value_function = "g_value_set_int64", default_value = "0LL")] [IntegerType (rank = 16)] public struct int64 { @@ -246,6 +264,7 @@ public struct int64 { public string! to_string (string! format = "%lli"); } +[SimpleType] [CCode (cname = "guint64", cheader_filename = "glib.h", type_id = "G_TYPE_UINT64", marshaller_type_name = "UINT64", get_value_function = "g_value_get_uint64", set_value_function = "g_value_set_uint64", default_value = "0ULL")] [IntegerType (rank = 17)] public struct uint64 { @@ -259,6 +278,7 @@ public struct uint64 { public string! to_string (string! format = "%llu"); } +[SimpleType] [CCode (cname = "float", cheader_filename = "glib.h,float.h,math.h", type_id = "G_TYPE_FLOAT", marshaller_type_name = "FLOAT", get_value_function = "g_value_get_float", set_value_function = "g_value_set_float", default_value = "0.0F")] [FloatingType (rank = 1)] public struct float { @@ -302,6 +322,7 @@ public struct float { public string! to_string (string! format = "%g"); } +[SimpleType] [CCode (cname = "double", cheader_filename = "glib.h,float.h,math.h", type_id = "G_TYPE_DOUBLE", marshaller_type_name = "DOUBLE", get_value_function = "g_value_get_double", set_value_function = "g_value_set_double", default_value = "0.0")] [FloatingType (rank = 2)] public struct double { @@ -345,6 +366,7 @@ public struct double { public string! to_string (string! format = "%g"); } +[SimpleType] [CCode (cname = "gunichar", cprefix = "g_unichar_", cheader_filename = "glib.h", get_value_function = "g_value_get_int", set_value_function = "g_value_set_int", default_value = "0U")] [IntegerType (rank = 13)] public struct unichar { @@ -543,7 +565,7 @@ public class string { [CCode (cprefix = "G", lower_case_cprefix = "g_", cheader_filename = "glib.h")] namespace GLib { [CCode (type_id = "G_TYPE_GTYPE")] - public struct Type { + public struct Type : ulong { [CCode (cname = "G_TYPE_IS_OBJECT")] public bool is_object (); [CCode (cname = "G_TYPE_IS_ABSTRACT")] @@ -565,10 +587,10 @@ namespace GLib { [CCode (cname = "G_TYPE_IS_VALUE_TYPE")] public bool is_value_type (); - //public Type[] children (out uint n_children = null); + public Type[] children (); public uint depth (); public static Type from_name (string! name); - //public Type[] interfaces (out uint n_interfaces = null); + public Type[] interfaces (); public bool is_a (Type is_a_type); public weak string! name (); public Type parent (); diff --git a/vapi/gtk+-2.0.vala b/vapi/gtk+-2.0.vala index 81e7ae81a..56bd662e7 100644 --- a/vapi/gtk+-2.0.vala +++ b/vapi/gtk+-2.0.vala @@ -5933,9 +5933,7 @@ namespace Gtk { public int right; public int top; public int bottom; - [InstanceByReference] public Gtk.Border copy (); - [InstanceByReference] public void free (); public static GLib.Type get_type (); } @@ -5952,194 +5950,102 @@ namespace Gtk { public struct Requisition { public int width; public int height; - [InstanceByReference] public Gtk.Requisition copy (); - [InstanceByReference] public void free (); public static GLib.Type get_type (); } [CCode (cheader_filename = "gtk/gtk.h")] public struct TextIter { - [InstanceByReference] public bool backward_char (); - [InstanceByReference] public bool backward_chars (int count); - [InstanceByReference] public bool backward_cursor_position (); - [InstanceByReference] public bool backward_cursor_positions (int count); - [InstanceByReference] public bool backward_find_char (Gtk.TextCharPredicate pred, pointer user_data, out Gtk.TextIter limit); - [InstanceByReference] public bool backward_line (); - [InstanceByReference] public bool backward_lines (int count); - [InstanceByReference] public bool backward_search (string str, Gtk.TextSearchFlags flags, out Gtk.TextIter match_start, out Gtk.TextIter match_end, out Gtk.TextIter limit); - [InstanceByReference] public bool backward_sentence_start (); - [InstanceByReference] public bool backward_sentence_starts (int count); - [InstanceByReference] public bool backward_to_tag_toggle (Gtk.TextTag tag); - [InstanceByReference] public bool backward_visible_cursor_position (); - [InstanceByReference] public bool backward_visible_cursor_positions (int count); - [InstanceByReference] public bool backward_visible_line (); - [InstanceByReference] public bool backward_visible_lines (int count); - [InstanceByReference] public bool backward_visible_word_start (); - [InstanceByReference] public bool backward_visible_word_starts (int count); - [InstanceByReference] public bool backward_word_start (); - [InstanceByReference] public bool backward_word_starts (int count); - [InstanceByReference] public bool begins_tag (Gtk.TextTag tag); - [InstanceByReference] public bool can_insert (bool default_editability); - [InstanceByReference] public int compare (out Gtk.TextIter rhs); - [InstanceByReference] public Gtk.TextIter copy (); - [InstanceByReference] public bool editable (bool default_setting); - [InstanceByReference] public bool ends_line (); - [InstanceByReference] public bool ends_sentence (); - [InstanceByReference] public bool ends_tag (Gtk.TextTag tag); - [InstanceByReference] public bool ends_word (); - [InstanceByReference] public bool equal (out Gtk.TextIter rhs); - [InstanceByReference] public bool forward_char (); - [InstanceByReference] public bool forward_chars (int count); - [InstanceByReference] public bool forward_cursor_position (); - [InstanceByReference] public bool forward_cursor_positions (int count); - [InstanceByReference] public bool forward_find_char (Gtk.TextCharPredicate pred, pointer user_data, out Gtk.TextIter limit); - [InstanceByReference] public bool forward_line (); - [InstanceByReference] public bool forward_lines (int count); - [InstanceByReference] public bool forward_search (string str, Gtk.TextSearchFlags flags, out Gtk.TextIter match_start, out Gtk.TextIter match_end, out Gtk.TextIter limit); - [InstanceByReference] public bool forward_sentence_end (); - [InstanceByReference] public bool forward_sentence_ends (int count); - [InstanceByReference] public void forward_to_end (); - [InstanceByReference] public bool forward_to_line_end (); - [InstanceByReference] public bool forward_to_tag_toggle (Gtk.TextTag tag); - [InstanceByReference] public bool forward_visible_cursor_position (); - [InstanceByReference] public bool forward_visible_cursor_positions (int count); - [InstanceByReference] public bool forward_visible_line (); - [InstanceByReference] public bool forward_visible_lines (int count); - [InstanceByReference] public bool forward_visible_word_end (); - [InstanceByReference] public bool forward_visible_word_ends (int count); - [InstanceByReference] public bool forward_word_end (); - [InstanceByReference] public bool forward_word_ends (int count); - [InstanceByReference] public void free (); - [InstanceByReference] public bool get_attributes (Gtk.TextAttributes values); - [InstanceByReference] public weak Gtk.TextBuffer get_buffer (); - [InstanceByReference] public int get_bytes_in_line (); - [InstanceByReference] public unichar get_char (); - [InstanceByReference] public int get_chars_in_line (); - [InstanceByReference] public weak Gtk.TextChildAnchor get_child_anchor (); - [InstanceByReference] public weak Pango.Language get_language (); - [InstanceByReference] public int get_line (); - [InstanceByReference] public int get_line_index (); - [InstanceByReference] public int get_line_offset (); - [InstanceByReference] public weak GLib.SList get_marks (); - [InstanceByReference] public int get_offset (); - [InstanceByReference] public weak Gdk.Pixbuf get_pixbuf (); - [InstanceByReference] public weak string get_slice (out Gtk.TextIter end); - [InstanceByReference] public weak GLib.SList get_tags (); - [InstanceByReference] public weak string get_text (out Gtk.TextIter end); - [InstanceByReference] public weak GLib.SList get_toggled_tags (bool toggled_on); public static GLib.Type get_type (); - [InstanceByReference] public int get_visible_line_index (); - [InstanceByReference] public int get_visible_line_offset (); - [InstanceByReference] public weak string get_visible_slice (out Gtk.TextIter end); - [InstanceByReference] public weak string get_visible_text (out Gtk.TextIter end); - [InstanceByReference] public bool has_tag (Gtk.TextTag tag); - [InstanceByReference] public bool in_range (out Gtk.TextIter start, out Gtk.TextIter end); - [InstanceByReference] public bool inside_sentence (); - [InstanceByReference] public bool inside_word (); - [InstanceByReference] public bool is_cursor_position (); - [InstanceByReference] public bool is_end (); - [InstanceByReference] public bool is_start (); - [InstanceByReference] public void order (out Gtk.TextIter second); - [InstanceByReference] public void set_line (int line_number); - [InstanceByReference] public void set_line_index (int byte_on_line); - [InstanceByReference] public void set_line_offset (int char_on_line); - [InstanceByReference] public void set_offset (int char_offset); - [InstanceByReference] public void set_visible_line_index (int byte_on_line); - [InstanceByReference] public void set_visible_line_offset (int char_on_line); - [InstanceByReference] public bool starts_line (); - [InstanceByReference] public bool starts_sentence (); - [InstanceByReference] public bool starts_word (); - [InstanceByReference] public bool toggles_tag (Gtk.TextTag tag); } [CCode (cheader_filename = "gtk/gtk.h")] @@ -6158,9 +6064,7 @@ namespace Gtk { public pointer user_data; public pointer user_data2; public pointer user_data3; - [InstanceByReference] public Gtk.TreeIter copy (); - [InstanceByReference] public void free (); public static GLib.Type get_type (); } diff --git a/vapi/pango.vala b/vapi/pango.vala index 5f92c82ae..148d064be 100644 --- a/vapi/pango.vala +++ b/vapi/pango.vala @@ -720,14 +720,10 @@ namespace Pango { public ushort red; public ushort green; public ushort blue; - [InstanceByReference] public Pango.Color copy (); - [InstanceByReference] public void free (); public static GLib.Type get_type (); - [InstanceByReference] public bool parse (string spec); - [InstanceByReference] public weak string to_string (); } [CCode (cheader_filename = "pango/pango.h")] @@ -753,28 +749,17 @@ namespace Pango { public double yy; public double x0; public double y0; - [InstanceByReference] public void concat (out Pango.Matrix new_matrix); - [InstanceByReference] public Pango.Matrix copy (); - [InstanceByReference] public void free (); - [InstanceByReference] public double get_font_scale_factor (); public static GLib.Type get_type (); - [InstanceByReference] public void rotate (double degrees); - [InstanceByReference] public void scale (double scale_x, double scale_y); - [InstanceByReference] public void transform_distance (double dx, double dy); - [InstanceByReference] public void transform_pixel_rectangle (out Pango.Rectangle rect); - [InstanceByReference] public void transform_point (double x, double y); - [InstanceByReference] public void transform_rectangle (out Pango.Rectangle rect); - [InstanceByReference] public void translate (double tx, double ty); } [CCode (cheader_filename = "pango/pango.h")] diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala index cf8b967ab..438802820 100644 --- a/vapigen/valagidlparser.vala +++ b/vapigen/valagidlparser.vala @@ -1042,12 +1042,6 @@ public class Vala.GIdlParser : CodeVisitor { (param_node.name == "self" || param.type.@interface.has_suffix (current_data_type.get_cname ()))) { // instance method - - if (!current_data_type.is_reference_type () && - param.type.is_pointer) { - m.instance_by_reference = true; - } - continue; } else { // static method