From 42bfd9537e9b28e10f6ca7730186af3b072fa7e1 Mon Sep 17 00:00:00 2001 From: Juerg Billeter Date: Thu, 22 Nov 2007 15:25:54 +0000 Subject: [PATCH] report error for missing return types in methods 2007-11-22 Juerg Billeter * vala/parser.y, vala/valacodecontext.vala, vala/valacreationmethod.vala, vala/valasemanticanalyzer.vala, vapigen/valagidlparser.vala: report error for missing return types in methods * vapi/glib-2.0.vapi: fix revealed typo svn path=/trunk/; revision=696 --- ChangeLog | 9 +++++++++ vala/parser.y | 4 ++-- vala/valacodecontext.vala | 4 ++-- vala/valacreationmethod.vala | 9 +++++++-- vala/valasemanticanalyzer.vala | 7 +++++++ vapi/glib-2.0.vapi | 2 +- vapigen/valagidlparser.vala | 2 +- 7 files changed, 29 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 20020b1..2ba281e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2007-11-22 Jürg Billeter + * vala/parser.y, vala/valacodecontext.vala, + vala/valacreationmethod.vala, vala/valasemanticanalyzer.vala, + vapigen/valagidlparser.vala: report error for missing return types in + methods + + * vapi/glib-2.0.vapi: fix revealed typo + +2007-11-22 Jürg Billeter + * gobject-introspection/clexer.l, gobject-introspection/cparser.y, gobject-introspection/gen-introspect.c: improve error reporting and ignore get_type functions with parameters diff --git a/vala/parser.y b/vala/parser.y index 6003b4f..e164545 100644 --- a/vala/parser.y +++ b/vala/parser.y @@ -2561,7 +2561,7 @@ class_declaration ValaMethod *m; ValaBlock *block; src = vala_code_node_get_source_reference (VALA_CODE_NODE (cl)); - m = VALA_METHOD (vala_code_context_create_creation_method (context, NULL, src)); + m = VALA_METHOD (vala_code_context_create_creation_method (context, vala_symbol_get_name (VALA_SYMBOL (cl)), NULL, src)); vala_method_set_instance (m, FALSE); vala_symbol_set_access (VALA_SYMBOL (m), VALA_SYMBOL_ACCESSIBILITY_PUBLIC); block = vala_code_context_create_block (context, src); @@ -2957,7 +2957,7 @@ method_header GList *l; ValaSourceReference *src = src_com(@5, $1); - $$ = VALA_METHOD (vala_code_context_create_creation_method (context, $6, src)); + $$ = VALA_METHOD (vala_code_context_create_creation_method (context, $5, $6, src)); g_free ($5); g_free ($6); g_object_unref (src); diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index 89a3efb..b015d12 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -417,8 +417,8 @@ public class Vala.CodeContext : Object { return node; } - public CreationMethod! create_creation_method (string name, SourceReference source_reference = null) { - var node = new CreationMethod (name, source_reference); + public CreationMethod! create_creation_method (string type_name, string name, SourceReference source_reference = null) { + var node = new CreationMethod (type_name, name, source_reference); node.code_binding = codegen.create_creation_method_binding (node); return node; } diff --git a/vala/valacreationmethod.vala b/vala/valacreationmethod.vala index 8cf91a0..818ad69 100644 --- a/vala/valacreationmethod.vala +++ b/vala/valacreationmethod.vala @@ -28,10 +28,15 @@ using GLib; */ public class Vala.CreationMethod : Method { /** + * Specifies the name of the type this creation method belongs to. + */ + public string type_name { get; set; } + + /** * Specifies the number of parameters this creation method sets. */ public int n_construction_params { get; set; } - + /** * Creates a new method. * @@ -39,7 +44,7 @@ public class Vala.CreationMethod : Method { * @param source_reference reference to source code * @return newly created method */ - public CreationMethod (construct string name, construct SourceReference source_reference = null) { + public CreationMethod (construct string type_name, construct string name, construct SourceReference source_reference = null) { } public override void accept (CodeVisitor! visitor) { diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index b4f5ba2..5c9bed5 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -440,6 +440,13 @@ public class Vala.SemanticAnalyzer : CodeVisitor { public override void visit_creation_method (CreationMethod! m) { m.return_type = new TypeReference (); + if (m.type_name != null && m.type_name != current_symbol.name) { + // type_name is null for constructors generated by GIdlParser + Report.error (m.source_reference, "missing return type in method `%s.%s´".printf (current_symbol.get_full_name (), m.type_name)); + m.error = true; + return; + } + if (current_symbol is Class) { m.return_type.data_type = (DataType) m.parent_symbol; m.return_type.transfers_ownership = true; diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi index 9a8411a..81e73e7 100644 --- a/vapi/glib-2.0.vapi +++ b/vapi/glib-2.0.vapi @@ -1361,7 +1361,7 @@ namespace GLib { public struct IConv { [CCode (cname = "g_iconv_open")] - public Iconv (string to_codeset, string from_codeset); + public IConv (string to_codeset, string from_codeset); [CCode (cname = "g_iconv")] public uint iconv (out string inbuf, out uint inbytes_left, out string outbuf, out uint outbytes_left); public int close (); diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala index dff94e6..2d21bf6 100644 --- a/vapigen/valagidlparser.vala +++ b/vapigen/valagidlparser.vala @@ -998,7 +998,7 @@ public class Vala.GIdlParser : CodeVisitor { Method m; if (!is_interface && (f.is_constructor || node.name.has_prefix ("new"))) { - m = new CreationMethod (node.name, current_source_reference); + m = new CreationMethod (null, node.name, current_source_reference); if (m.name == "new") { m.name = null; } else if (m.name.has_prefix ("new_")) { -- 2.7.4