]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Let the parser have set namespace members as static
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 24 Nov 2019 21:42:18 +0000 (22:42 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 24 Nov 2019 21:42:18 +0000 (22:42 +0100)
... and move error reporting for invalid members into check()

vala/valagenieparser.vala
vala/valagirparser.vala
vala/valanamespace.vala
vala/valaparser.vala
vapigen/valagidlparser.vala

index 05c300723e89694757fcf70c30be5480687281e1..668c404285febfd353cb5af7807684c7f98d4abc 100644 (file)
@@ -2587,13 +2587,13 @@ public class Vala.Genie.Parser : CodeVisitor {
                } else if (sym is Delegate) {
                        ns.add_delegate ((Delegate) sym);
                } else if (sym is Method) {
-                       var method = (Method) sym;
+                       unowned Method method = (Method) sym;
                        if (method.binding == MemberBinding.INSTANCE) {
                                method.binding = MemberBinding.STATIC;
                        }
                        ns.add_method (method);
                } else if (sym is Field) {
-                       var field = (Field) sym;
+                       unowned Field field = (Field) sym;
                        if (field.binding == MemberBinding.INSTANCE) {
                                field.binding = MemberBinding.STATIC;
                        }
index 3f2025093f67abff2d47e1b1e92c156338c5d0b8..17b41b1e556e37edb8cfdcfa6431bb7d8d361f5a 100644 (file)
@@ -1522,11 +1522,19 @@ public class Vala.GirParser : CodeVisitor {
                        } else if (sym is ErrorDomain) {
                                ns.add_error_domain ((ErrorDomain) sym);
                        } else if (sym is Field) {
-                               ns.add_field ((Field) sym);
+                               unowned Field field = (Field) sym;
+                               if (field.binding == MemberBinding.INSTANCE) {
+                                       field.binding = MemberBinding.STATIC;
+                               }
+                               ns.add_field (field);
                        } else if (sym is Interface) {
                                ns.add_interface ((Interface) sym);
                        } else if (sym is Method) {
-                               ns.add_method ((Method) sym);
+                               unowned Method method = (Method) sym;
+                               if (method.binding == MemberBinding.INSTANCE) {
+                                       method.binding = MemberBinding.STATIC;
+                               }
+                               ns.add_method (method);
                        } else if (sym is Struct) {
                                ns.add_struct ((Struct) sym);
                        }
index a413f07f61330ddedbfffb00d552c3e9213178d6..56a905bb43ae7b80f9762fc78d822c808a2097e1 100644 (file)
@@ -380,26 +380,11 @@ public class Vala.Namespace : Symbol {
         * @param f a field
         */
        public override void add_field (Field f) {
-               if (f.binding == MemberBinding.INSTANCE) {
-                       // default to static member binding
-                       f.binding = MemberBinding.STATIC;
-               }
-
                // namespaces do not support private memebers
                if (f.access == SymbolAccessibility.PRIVATE) {
                        f.access = SymbolAccessibility.INTERNAL;
                }
 
-               if (f.binding == MemberBinding.INSTANCE) {
-                       Report.error (f.source_reference, "instance members are not allowed outside of data types");
-                       f.error = true;
-                       return;
-               } else if (f.binding == MemberBinding.CLASS) {
-                       Report.error (f.source_reference, "class members are not allowed outside of classes");
-                       f.error = true;
-                       return;
-               }
-
                if (f.owner == null) {
                        f.source_reference.file.add_node (f);
                }
@@ -414,30 +399,11 @@ public class Vala.Namespace : Symbol {
         * @param m a method
         */
        public override void add_method (Method m) {
-               if (m.binding == MemberBinding.INSTANCE) {
-                       // default to static member binding
-                       m.binding = MemberBinding.STATIC;
-               }
-
                // namespaces do not support private memebers
                if (m.access == SymbolAccessibility.PRIVATE) {
                        m.access = SymbolAccessibility.INTERNAL;
                }
 
-               if (m is CreationMethod) {
-                       Report.error (m.source_reference, "construction methods may only be declared within classes and structs");
-                       m.error = true;
-                       return;
-               }
-               if (m.binding == MemberBinding.INSTANCE) {
-                       Report.error (m.source_reference, "instance members are not allowed outside of data types");
-                       m.error = true;
-                       return;
-               } else if (m.binding == MemberBinding.CLASS) {
-                       Report.error (m.source_reference, "class members are not allowed outside of classes");
-                       m.error = true;
-                       return;
-               }
                if (!(m.return_type is VoidType) && m.get_postconditions ().size > 0) {
                        m.result_var = new LocalVariable (m.return_type.copy (), "result", null, source_reference);
                        m.result_var.is_result = true;
@@ -517,6 +483,35 @@ public class Vala.Namespace : Symbol {
                        source_reference.file.gir_version = a.get_string ("gir_version");
                }
 
+               foreach (Field f in fields) {
+                       if (f.binding == MemberBinding.INSTANCE) {
+                               Report.error (f.source_reference, "instance fields are not allowed outside of data types");
+                               f.error = true;
+                               error = true;
+                       } else if (f.binding == MemberBinding.CLASS) {
+                               Report.error (f.source_reference, "class fields are not allowed outside of classes");
+                               f.error = true;
+                               error = true;
+                       }
+               }
+
+               foreach (Method m in methods) {
+                       if (m is CreationMethod) {
+                               Report.error (m.source_reference, "construction methods may only be declared within classes and structs");
+                               m.error = true;
+                               error = true;
+                       }
+                       if (m.binding == MemberBinding.INSTANCE) {
+                               Report.error (m.source_reference, "instance methods are not allowed outside of data types");
+                               m.error = true;
+                               error = true;
+                       } else if (m.binding == MemberBinding.CLASS) {
+                               Report.error (m.source_reference, "class methods are not allowed outside of classes");
+                               m.error = true;
+                               error = true;
+                       }
+               }
+
                foreach (Namespace ns in namespaces) {
                        ns.check (context);
                }
index e6c667bca621c4ea2fc609f201dc6e1586e2a250..45a420955e168dae989c733bb9816538fc219b40 100644 (file)
@@ -2683,6 +2683,9 @@ public class Vala.Parser : CodeVisitor {
                        f.binding = MemberBinding.STATIC;
                } else if (ModifierFlags.CLASS in flags) {
                        f.binding = MemberBinding.CLASS;
+               } else if (parent is Namespace) {
+                       // default to static member binding in namespace
+                       f.binding = MemberBinding.STATIC;
                }
 
                if (!parent.external_package && parent is Struct
@@ -2748,6 +2751,9 @@ public class Vala.Parser : CodeVisitor {
                        method.binding = MemberBinding.STATIC;
                } else if (ModifierFlags.CLASS in flags) {
                        method.binding = MemberBinding.CLASS;
+               } else if (parent is Namespace) {
+                       // default to static member binding in namespace
+                       method.binding = MemberBinding.STATIC;
                }
                if (ModifierFlags.ASYNC in flags) {
                        method.coroutine = true;
index 82f4b12cc53d9e6f42cae303f767d181a9d82823..d4c70d8a21529936ccedc876585875f5918503eb 100644 (file)
@@ -384,11 +384,19 @@ public class Vala.GIdlParser : CodeVisitor {
                        } else if (sym is ErrorDomain) {
                                ns.add_error_domain ((ErrorDomain) sym);
                        } else if (sym is Field) {
-                               ns.add_field ((Field) sym);
+                               unowned Field field = (Field) sym;
+                               if (field.binding == MemberBinding.INSTANCE) {
+                                       field.binding = MemberBinding.STATIC;
+                               }
+                               ns.add_field (field);
                        } else if (sym is Interface) {
                                ns.add_interface ((Interface) sym);
                        } else if (sym is Method) {
-                               ns.add_method ((Method) sym);
+                               unowned Method method = (Method) sym;
+                               if (method.binding == MemberBinding.INSTANCE) {
+                                       method.binding = MemberBinding.STATIC;
+                               }
+                               ns.add_method (method);
                        } else if (sym is Namespace) {
                                ns.add_namespace ((Namespace) sym);
                        } else if (sym is Struct) {