From 8fb29e4a4e43ce0e55b1090396b2133e9a044199 Mon Sep 17 00:00:00 2001 From: Raffaele Sandrini Date: Sat, 28 Jul 2007 15:57:56 +0000 Subject: [PATCH] add check to report an error on invalid method_header and method_body 2007-07-28 Raffaele Sandrini * vala/parser.y: add check to report an error on invalid method_header and method_body presence combinations * vala/valamethod.vala: add `is_imported' property svn path=/trunk/; revision=411 --- ChangeLog | 6 ++++++ vala/parser.y | 25 ++++++++++++++++++++++++- vala/valamethod.vala | 8 ++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4c0e80b..4a347ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-07-28 Raffaele Sandrini + + * vala/parser.y: add check to report an error on invalid method_header + and method_body presence combinations + * vala/valamethod.vala: add `is_imported' property + 2007-07-28 Philip Van Hoof * doc/building.txt: Added some documentation about how to build your diff --git a/vala/parser.y b/vala/parser.y index 1799bb6..362fb43 100644 --- a/vala/parser.y +++ b/vala/parser.y @@ -2506,10 +2506,33 @@ variable_initializer method_declaration : method_header method_body { - $$ = $1; + ValaCodeNode *n = (ValaCodeNode*)$1; + ValaAttribute *a = vala_code_node_get_attribute (n, "Import"); + gboolean imported; + if (a != NULL) { + imported = TRUE; + g_object_unref (a); + } else { + imported = FALSE; + } + $$ = $1; vala_method_set_body ($$, $2); + if ($2 != NULL) { g_object_unref ($2); + /* method must not be imported, abstract or from a VAPI file */ + if (imported || vala_method_get_is_abstract ($1) || vala_source_file_get_pkg (current_source_file)) { + ValaSourceReference *sr = vala_code_node_get_source_reference (n); + vala_report_error (sr, "unexpected method body found"); + g_object_unref (sr); + } + } else { + /* only imported, abstract and VAPI methods are allowed to have no body */ + if (!imported && !vala_method_get_is_abstract ($1) && !vala_source_file_get_pkg (current_source_file)) { + ValaSourceReference *sr = vala_code_node_get_source_reference (n); + vala_report_error (sr, "expected method body got `;'"); + g_object_unref (sr); + } } } | error method_body diff --git a/vala/valamethod.vala b/vala/valamethod.vala index 0c597dc..72bc1e7 100644 --- a/vala/valamethod.vala +++ b/vala/valamethod.vala @@ -128,6 +128,12 @@ public class Vala.Method : Member, Invokable { } /** + * Specifies whether this is an imported method i.e. the Import + * attribute ist set for this method. + */ + public bool is_imported { get; set; } + + /** * Specifies whether this method expects printf-style format arguments. */ public bool printf_format { get; set; } @@ -279,6 +285,8 @@ public class Vala.Method : Member, Invokable { no_array_length = true; } else if (a.name == "PrintfFormat") { printf_format = true; + } else if (a.name == "Import") { + is_imported = true; } } } -- 2.7.4