add experimental support for class declarations in multiple source files
authorJürg Billeter <j@bitron.ch>
Mon, 30 Apr 2007 14:18:27 +0000 (14:18 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Mon, 30 Apr 2007 14:18:27 +0000 (14:18 +0000)
2007-04-30  Jürg Billeter  <j@bitron.ch>

* vala/parser.y, vala/valasymbolbuilder.vala, vala/valaclass.vala,
  vala/valanamespace.vala: add experimental support for class
  declarations in multiple source files

svn path=/trunk/; revision=295

vala/ChangeLog
vala/vala/parser.y
vala/vala/valaclass.vala
vala/vala/valanamespace.vala
vala/vala/valasymbolbuilder.vala

index 534d2e3..309dc21 100644 (file)
@@ -1,5 +1,11 @@
 2007-04-30  Jürg Billeter  <j@bitron.ch>
 
+       * vala/parser.y, vala/valasymbolbuilder.vala, vala/valaclass.vala,
+         vala/valanamespace.vala: add experimental support for class
+         declarations in multiple source files
+
+2007-04-30  Jürg Billeter  <j@bitron.ch>
+
        * vala/valasemanticanalyzer.vala: check whether specified collection is
          iterable in foreach statements, fixes bug 434514
 
index 06e69a3..b429754 100644 (file)
@@ -2401,7 +2401,7 @@ class_member_declaration
          {
                /* skip declarations with errors */
                if ($1 != NULL) {
-                       vala_class_add_property (current_class, $1);
+                       vala_class_add_property (current_class, $1, FALSE);
                        g_object_unref ($1);
                }
          }
index a5b846f..3f111eb 100644 (file)
@@ -188,10 +188,10 @@ public class Vala.Class : DataType {
         *
         * @param prop a property
         */
-       public void add_property (Property! prop) {
+       public void add_property (Property! prop, bool no_field = false) {
                properties.append (prop);
                
-               if (prop.set_accessor != null && prop.set_accessor.body == null &&
+               if (!no_field && prop.set_accessor != null && prop.set_accessor.body == null &&
                    source_reference != null && !source_reference.file.pkg) {
                        /* automatic property accessor body generation */
                        var field_type = prop.type_reference.copy ();
@@ -395,3 +395,4 @@ public class Vala.Class : DataType {
                return -1;
        }
 }
+
index 76fc7e3..3b63cba 100644 (file)
@@ -1,6 +1,6 @@
 /* valanamespace.vala
  *
- * Copyright (C) 2006  Jürg Billeter
+ * Copyright (C) 2006-2007  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -67,7 +67,17 @@ public class Vala.Namespace : CodeNode {
                classes.append (cl);
                cl.@namespace = this;
        }
-       
+
+       /**
+        * Removes the specified class from this namespace.
+        *
+        * @param cl a class
+        */
+       public void remove_class (Class! cl) {
+               cl.@namespace = null;
+               classes.remove (cl);
+       }
+
        /**
         * Adds the specified interface to this namespace.
         *
index 33548a1..0bceb41 100644 (file)
@@ -85,11 +85,46 @@ public class Vala.SymbolBuilder : CodeVisitor {
        }
 
        public override void visit_begin_class (Class! cl) {
-               if (add_symbol (cl.name, cl) == null) {
-                       return;
+               var class_symbol = current_symbol.lookup (cl.name);
+               if (class_symbol == null || !(class_symbol.node is Class)) {
+                       class_symbol = add_symbol (cl.name, cl);
+               } else {
+                       /* merge this class declaration with existing class symbol */
+                       var main_class = (Class) class_symbol.node;
+                       foreach (TypeReference base_type in cl.get_base_types ()) {
+                               main_class.add_base_type (base_type);
+                       }
+                       foreach (Field f in cl.get_fields ()) {
+                               main_class.add_field (f);
+                       }
+                       foreach (Method m in cl.get_methods ()) {
+                               main_class.add_method (m);
+                       }
+                       foreach (Property prop in cl.get_properties ()) {
+                               main_class.add_property (prop, true);
+                       }
+                       foreach (Signal sig in cl.get_signals ()) {
+                               main_class.add_signal (sig);
+                       }
+                       if (cl.constructor != null) {
+                               if (main_class.constructor != null) {
+                                       cl.error = true;
+                                       Report.error (cl.constructor.source_reference, "`%s' already contains a constructor".printf (current_symbol.get_full_name ()));
+                                       return;
+                               }
+                               main_class.constructor = cl.constructor;
+                       }
+                       if (cl.destructor != null) {
+                               if (main_class.destructor != null) {
+                                       cl.error = true;
+                                       Report.error (cl.destructor.source_reference, "`%s' already contains a destructor".printf (current_symbol.get_full_name ()));
+                                       return;
+                               }
+                               main_class.destructor = cl.destructor;
+                       }
                }
-               
-               current_symbol = cl.symbol;
+
+               current_symbol = class_symbol;
        }
        
        public override void visit_end_class (Class! cl) {
@@ -99,6 +134,11 @@ public class Vala.SymbolBuilder : CodeVisitor {
                }
                
                current_symbol = current_symbol.parent_symbol;
+
+               if (cl.symbol == null) {
+                       /* remove merged class */
+                       cl.@namespace.remove_class (cl);
+               }
        }
        
        public override void visit_begin_struct (Struct! st) {
@@ -386,3 +426,4 @@ public class Vala.SymbolBuilder : CodeVisitor {
                add_symbol (p.name, p);
        }
 }
+