]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girparser: Report unused metadata information
authorLuca Bruno <lucabru@src.gnome.org>
Sun, 29 Aug 2010 13:11:02 +0000 (15:11 +0200)
committerEvan Nemerson <evan@coeus-group.com>
Mon, 8 Nov 2010 09:43:19 +0000 (01:43 -0800)
vala/valagirparser.vala

index 2e19773723d7006c660a1323e2e2488cbcfb79cc..3089ad197a150ddb337dd468de73c4ddbf3d4959 100644 (file)
@@ -591,6 +591,8 @@ public class Vala.GirParser : CodeVisitor {
                next ();
                parse_repository ();
 
+               report_unused_metadata (metadata);
+
                reader = null;
                this.current_source_file = null;
        }
@@ -2353,6 +2355,34 @@ public class Vala.GirParser : CodeVisitor {
                return c;
        }
 
+       /* Reporting */
+       void report_unused_metadata (Metadata metadata) {
+               if (metadata == Metadata.empty) {
+                       return;
+               }
+
+               if (metadata.args.size == 0 && metadata.children.size == 0) {
+                       Report.warning (metadata.source_reference, "empty metadata");
+                       return;
+               }
+
+               foreach (var arg_type in metadata.args.get_keys ()) {
+                       var arg = metadata.args[arg_type];
+                       if (!arg.used) {
+                               // if metadata is used and argument is not, then it's a unexpected argument
+                               Report.warning (arg.source_reference, "argument never used");
+                       }
+               }
+
+               foreach (var child in metadata.children) {
+                       if (!child.used) {
+                               Report.warning (child.source_reference, "metadata never used");
+                       } else {
+                               report_unused_metadata (child);
+                       }
+               }
+       }
+
        /* Post-parsing */
 
        void resolve_gir_symbols () {