[vala/wip/issue/370: 19/20] Improvements




commit 7b0d08f0d1e59ba76a858a7069cd5b43206f428c
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Sep 21 14:27:30 2021 +0200

    Improvements

 vala/valanamespace.vala | 53 -------------------------------------------------
 vala/valaparser.vala    | 36 ++++++++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 54 deletions(-)
---
diff --git a/vala/valanamespace.vala b/vala/valanamespace.vala
index 8dc8b9069..d62babb63 100644
--- a/vala/valanamespace.vala
+++ b/vala/valanamespace.vala
@@ -160,59 +160,6 @@ public class Vala.Namespace : Symbol {
                        cl.access = SymbolAccessibility.INTERNAL;
                }
 
-               if (cl.is_partial) {
-                       var old_cl = scope.lookup (cl.name) as Class;
-                       if (old_cl != null && old_cl.is_partial) {
-                               if (cl.access != old_cl.access) {
-                                       Report.error (cl.source_reference, "partial declarations of `%s' have 
conflicting accessiblity modifiers".printf (cl.name));
-                                       cl.error = true;
-                                       return;
-                               }
-                               if (cl.is_abstract != old_cl.is_abstract) {
-                                       Report.error (cl.source_reference, "partial declarations of `%s' have 
conflicting abstract modifiers".printf (cl.name));
-                                       cl.error = true;
-                                       return;
-                               }
-
-                               foreach (Class cls in cl.get_classes ()) {
-                                       old_cl.add_class (cls);
-                               }
-                               foreach (Struct st in cl.get_structs ()) {
-                                       old_cl.add_struct (st);
-                               }
-                               foreach (Delegate d in cl.get_delegates ()) {
-                                       old_cl.add_delegate (d);
-                               }
-                               foreach (Enum en in cl.get_enums ()) {
-                                       old_cl.add_enum (en);
-                               }
-                               foreach (Constant c in cl.get_constants ()) {
-                                       old_cl.add_constant (c);
-                               }
-                               foreach (Field f in cl.get_fields ()) {
-                                       old_cl.add_field (f);
-                               }
-                               foreach (Method m in cl.get_methods ()) {
-                                       if (m != cl.default_construction_method) {
-                                               old_cl.add_method (m);
-                                       }
-                               }
-                               foreach (Property prop in cl.get_properties ()) {
-                                       //FIXME old_cl.add_property (prop);
-                               }
-                               foreach (Signal sig in cl.get_signals ()) {
-                                       old_cl.add_signal (sig);
-                               }
-                               foreach (Attribute a in cl.attributes) {
-                                       if (old_cl.get_attribute (a.name) == null) {
-                                               old_cl.attributes.append(a);
-                                       }
-                               }
-
-                               return;
-                       }
-               }
-
                if (cl.owner == null) {
                        cl.source_reference.file.add_node (cl);
                }
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 0aa50e7d7..a0be9d394 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -2735,8 +2735,8 @@ public class Vala.Parser : CodeVisitor {
                        case TokenType.NAMESPACE:
                        case TokenType.NEW:
                        case TokenType.OVERRIDE:
-                       case TokenType.PRIVATE:
                        case TokenType.PARTIAL:
+                       case TokenType.PRIVATE:
                        case TokenType.PROTECTED:
                        case TokenType.PUBLIC:
                        case TokenType.SEALED:
@@ -2846,11 +2846,41 @@ public class Vala.Parser : CodeVisitor {
                        cl.is_sealed = true;
                }
                if (ModifierFlags.PARTIAL in flags) {
+                       if (!context.experimental) {
+                               Report.warning (cl.source_reference, "`partial' classes are experimental");
+                       }
                        cl.is_partial = true;
                }
                if (ModifierFlags.EXTERN in flags) {
                        cl.is_extern = true;
                }
+
+               var old_cl = parent.scope.lookup (cl.name) as Class;
+               if (old_cl != null && old_cl.is_partial) {
+                       if (cl.is_partial != old_cl.is_partial) {
+                               Report.error (cl.source_reference, "conflicting partial and not partial 
declarations of `%s'".printf (cl.name));
+                               cl.error = true;
+                       }
+                       if (cl.access != old_cl.access) {
+                               Report.error (cl.source_reference, "partial declarations of `%s' have 
conflicting accessiblity modifiers".printf (cl.name));
+                               cl.error = true;
+                       }
+                       if (cl.is_abstract != old_cl.is_abstract) {
+                               Report.error (cl.source_reference, "partial declarations of `%s' have 
conflicting abstract modifiers".printf (cl.name));
+                               cl.error = true;
+                       }
+                       if (cl.is_sealed != old_cl.is_sealed) {
+                               Report.error (cl.source_reference, "partial declarations of `%s' have 
conflicting sealed modifiers".printf (cl.name));
+                               cl.error = true;
+                       }
+                       if (cl.error) {
+                               Report.notice (old_cl.source_reference, "previous declaration of `%s' was 
here", old_cl.name);
+                               return;
+                       }
+
+                       cl = old_cl;
+               }
+
                set_attributes (cl, attrs);
                foreach (TypeParameter type_param in type_param_list) {
                        cl.add_type_parameter (type_param);
@@ -2861,6 +2891,10 @@ public class Vala.Parser : CodeVisitor {
 
                parse_declarations (cl);
 
+               if (old_cl != null && old_cl.is_partial) {
+                       return;
+               }
+
                // ensure there is always a default construction method
                if (scanner.source_file.file_type == SourceFileType.SOURCE
                    && cl.default_construction_method == null) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]