add check to report an error on invalid method_header and method_body
authorRaffaele Sandrini <raffaele@sandrini.ch>
Sat, 28 Jul 2007 15:57:56 +0000 (15:57 +0000)
committerRaffaele Sandrini <rasa@src.gnome.org>
Sat, 28 Jul 2007 15:57:56 +0000 (15:57 +0000)
2007-07-28  Raffaele Sandrini  <raffaele@sandrini.ch>

* 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
vala/parser.y
vala/valamethod.vala

index 4c0e80b..4a347ef 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-07-28  Raffaele Sandrini  <raffaele@sandrini.ch>
+
+       * 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  <pvanhoof@gnome.org>
 
        * doc/building.txt: Added some documentation about how to build your
index 1799bb6..362fb43 100644 (file)
@@ -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
index 0c597dc..72bc1e7 100644 (file)
@@ -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;
                        }
                }
        }