]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Add support for [Deprecated] attribute
authorEvan Nemerson <evan@coeus-group.com>
Sat, 15 May 2010 22:14:48 +0000 (15:14 -0700)
committerJürg Billeter <j@bitron.ch>
Tue, 15 Jun 2010 18:38:18 +0000 (20:38 +0200)
Fixes bug 614712.

17 files changed:
vala/valaclass.vala
vala/valacodewriter.vala
vala/valaconstant.vala
vala/valadelegate.vala
vala/valaenum.vala
vala/valaenumvalue.vala
vala/valaerrordomain.vala
vala/valafield.vala
vala/valainterface.vala
vala/valalambdaexpression.vala
vala/valamemberaccess.vala
vala/valamethod.vala
vala/valaobjectcreationexpression.vala
vala/valaproperty.vala
vala/valasignal.vala
vala/valastruct.vala
vala/valasymbol.vala

index eef5075b29ad0543bd669af47dd04524bb0897fb..54916c592ae12d4588ac3c62f216939688c9fe9a 100644 (file)
@@ -673,6 +673,8 @@ public class Vala.Class : ObjectTypeSymbol {
                                is_compact = true;
                        } else if (a.name == "Immutable") {
                                is_immutable = true;
+                       } else if (a.name == "Deprecated") {
+                               process_deprecated_attribute (a);
                        }
                }
        }
@@ -1115,6 +1117,7 @@ public class Vala.Class : ObjectTypeSymbol {
                                                        }
                                                        if (sym is Method) {
                                                                // method is used as interface implementation, so it is not unused
+                                                               sym.check_deprecated (source_reference);
                                                                sym.used = true;
                                                        } else {
                                                                error = true;
@@ -1134,6 +1137,7 @@ public class Vala.Class : ObjectTypeSymbol {
                                                        }
                                                        if (sym is Property) {
                                                                // property is used as interface implementation, so it is not unused
+                                                               sym.check_deprecated (source_reference);
                                                                sym.used = true;
                                                        } else {
                                                                error = true;
index a2bb0f9912694644643fec27ee3f190ada686c37..2fc5f8261df83c536bb894ccb6c29952ac857e65 100644 (file)
@@ -160,6 +160,30 @@ public class Vala.CodeWriter : CodeVisitor {
                return cheaders;
        }
 
+       private void emit_deprecated_attribute (Symbol symbol) {
+               if (symbol.deprecated) {
+                       write_indent ();
+                       write_string ("[Deprecated");
+                       var since = symbol.deprecated_since;
+                       var replacement = symbol.replacement;
+
+                       if (since != null || replacement != null) {
+                               write_string (" (");
+                               if (since != null) {
+                                       write_string ("since = \"%s\"".printf (since));
+                               }
+                               if (since != null && replacement != null) {
+                                       write_string (", ");
+                               }
+                               if (replacement != null) {
+                                       write_string ("replacement = \"%s\"".printf (since));
+                               }
+                               write_string (")");
+                       }
+                       write_string ("]");
+               }
+       }
+
        public override void visit_class (Class cl) {
                if (cl.external_package) {
                        return;
@@ -181,6 +205,8 @@ public class Vala.CodeWriter : CodeVisitor {
                        write_newline ();
                }
 
+               emit_deprecated_attribute (cl);
+
                write_indent ();
                
                write_string ("[CCode (");
@@ -330,6 +356,8 @@ public class Vala.CodeWriter : CodeVisitor {
                        write_newline ();
                }
 
+               emit_deprecated_attribute (st);
+
                write_indent ();
 
                write_string ("[CCode (");
@@ -411,6 +439,8 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               emit_deprecated_attribute (iface);
+
                write_indent ();
 
                write_string ("[CCode (cheader_filename = \"%s\"".printf (get_cheaders(iface)));
@@ -485,6 +515,8 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               emit_deprecated_attribute (en);
+
                write_indent ();
 
                write_string ("[CCode (cprefix = \"%s\", ".printf (en.get_cprefix ()));
@@ -554,6 +586,8 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               emit_deprecated_attribute (edomain);
+
                write_indent ();
 
                write_string ("[CCode (cprefix = \"%s\", cheader_filename = \"%s\")]".printf (edomain.get_cprefix (), get_cheaders(edomain)));
@@ -588,6 +622,8 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               emit_deprecated_attribute (c);
+
                bool custom_cname = (c.get_cname () != c.get_default_cname ());
                bool custom_cheaders = (c.parent_symbol is Namespace);
                if (custom_cname || custom_cheaders) {
@@ -630,6 +666,8 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               emit_deprecated_attribute (f);
+
                bool custom_cname = (f.get_cname () != f.get_default_cname ());
                bool custom_ctype = (f.get_ctype () != null);
                bool custom_cheaders = (f.parent_symbol is Namespace);
@@ -826,6 +864,8 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               emit_deprecated_attribute (cb);
+
                write_indent ();
 
                write_string ("[CCode (cheader_filename = \"%s\"".printf (get_cheaders(cb)));
@@ -897,6 +937,8 @@ public class Vala.CodeWriter : CodeVisitor {
                        write_string ("[ScanfFormat]");
                }
 
+               emit_deprecated_attribute (m);
+
                var ccode_params = new StringBuilder ();
                var separator = "";
 
@@ -1022,6 +1064,8 @@ public class Vala.CodeWriter : CodeVisitor {
                        return;
                }
 
+               emit_deprecated_attribute (prop);
+
                if (prop.no_accessor_method) {
                        write_indent ();
                        write_string ("[NoAccessorMethod]");
@@ -1089,6 +1133,8 @@ public class Vala.CodeWriter : CodeVisitor {
                        write_indent ();
                        write_string ("[HasEmitter]");
                }
+
+               emit_deprecated_attribute (sig);
                
                write_indent ();
                write_accessibility (sig);
index 6c0ee9e26ff4bd37571f86eb9ecf0e5d1984ce75..b9d29a2b98485c1346092cf566ecd8fa58594f33 100644 (file)
@@ -153,6 +153,8 @@ public class Vala.Constant : Member, Lockable {
                foreach (Attribute a in attributes) {
                        if (a.name == "CCode") {
                                process_ccode_attribute (a);
+                       } else if (a.name == "Deprecated") {
+                               process_deprecated_attribute (a);
                        }
                }
        }
index 09538e98a8e1d24b824e2d6db38a7add08400ec4..6952409953d96136650b414e09a7cf4b623b14bb 100644 (file)
@@ -276,6 +276,8 @@ public class Vala.Delegate : TypeSymbol {
                foreach (Attribute a in attributes) {
                        if (a.name == "CCode") {
                                process_ccode_attribute (a);
+                       } else if (a.name == "Deprecated") {
+                               process_deprecated_attribute (a);
                        }
                }
        }
index ef8a07792fd7d91aef18a2b0da5c9fbde7ae7b93..85bd3b4d1870c0db209ef83d7d2b60875679487e 100644 (file)
@@ -244,6 +244,8 @@ public class Vala.Enum : TypeSymbol {
                                process_ccode_attribute (a);
                        } else if (a.name == "Flags") {
                                is_flags = true;
+                       } else if (a.name == "Deprecated") {
+                               process_deprecated_attribute (a);
                        }
                }
        }
index eaade92c15af1f86175fbfb29cecb1dced517be0..47f11ee19792b54b76b98b2c204ad51e2d43ed3d 100644 (file)
@@ -102,6 +102,8 @@ public class Vala.EnumValue : Symbol {
                foreach (Attribute a in attributes) {
                        if (a.name == "CCode" && a.has_argument("cname")) {
                                cname = a.get_string ("cname");
+                       } else if (a.name == "Deprecated") {
+                               process_deprecated_attribute (a);
                        }
                }
        }
index dbc6b4567a4cebb71631f4726ea2c795bbeccdc1..24b807214712595dbecf3c2606e83bf2e21abf91 100644 (file)
@@ -189,6 +189,8 @@ public class Vala.ErrorDomain : TypeSymbol {
                foreach (Attribute a in attributes) {
                        if (a.name == "CCode") {
                                process_ccode_attribute (a);
+                       } else if (a.name == "Deprecated") {
+                               process_deprecated_attribute (a);
                        }
                }
        }
index b038c729f08ccf7c53b71db8053d0f77de62c09a..ed7e091bf34e462e346e9036cf05fbd3faafb456 100644 (file)
@@ -249,6 +249,8 @@ public class Vala.Field : Member, Lockable {
                foreach (Attribute a in attributes) {
                        if (a.name == "CCode") {
                                process_ccode_attribute (a);
+                       } else if (a.name == "Deprecated") {
+                               process_deprecated_attribute (a);
                        }
                }
        }
index e88d44fc667fdbc2d344f2465c65f4cb8eabfa28..02c63a8460e394287bfc4d5ca3786d82bd2d007b 100644 (file)
@@ -482,6 +482,8 @@ public class Vala.Interface : ObjectTypeSymbol {
                foreach (Attribute a in attributes) {
                        if (a.name == "CCode") {
                                process_ccode_attribute (a);
+                       } else if (a.name == "Deprecated") {
+                               process_deprecated_attribute (a);
                        }
                }
        }
index 25e54b0f6b380f54d33ecedcb1da25240ef86c45..4bc618ff130e01a34075ef462f8245be2b1f007e 100644 (file)
@@ -136,6 +136,7 @@ public class Vala.LambdaExpression : Expression {
                method = new Method (get_lambda_name (analyzer), cb.return_type, source_reference);
                // track usage for flow analyzer
                method.used = true;
+               method.check_deprecated (source_reference);
 
                if (!cb.has_target || !analyzer.is_in_instance_method ()) {
                        method.binding = MemberBinding.STATIC;
index c566995acc2198af9190554f08b4d5d74d50bad8..6d12220252ba247f1f6eccbeed83921a68486d57 100644 (file)
@@ -640,6 +640,7 @@ public class Vala.MemberAccess : Expression {
                }
 
                member.used = true;
+               member.check_deprecated (source_reference);
 
                if (access == SymbolAccessibility.PROTECTED) {
                        var target_type = (TypeSymbol) member.parent_symbol;
index 61a5aa1689daabc6e12d230f96d3cde1e770b4ff..60995c81e9880275170dcf7eba06fd45dfe94614 100644 (file)
@@ -498,6 +498,8 @@ public class Vala.Method : Member {
                        } else if (a.name == "NoArrayLength") {
                                Report.warning (source_reference, "NoArrayLength attribute is deprecated, use [CCode (array_length = false)] instead.");
                                no_array_length = true;
+                       } else if (a.name == "Deprecated") {
+                               process_deprecated_attribute (a);
                        }
                }
        }
index 2c8ad17b3a791486f093021f72f0570e18fd235e..ab726e79fafb7e49c335fdd6de617b01e502160b 100644 (file)
@@ -261,6 +261,7 @@ public class Vala.ObjectCreationExpression : Expression {
 
                                // track usage for flow analyzer
                                symbol_reference.used = true;
+                               symbol_reference.check_deprecated (source_reference);
                        }
 
                        if (symbol_reference != null && symbol_reference.access == SymbolAccessibility.PRIVATE) {
index ac15b8e854d3cf4c45bec428e88ac22c6bf67622..ea9d2e12314dd2ca2ac2acc09749ee0ef3fad593 100644 (file)
@@ -294,6 +294,8 @@ public class Vala.Property : Member, Lockable {
                                if (a.has_argument ("blurb")) {
                                        blurb = a.get_string ("blurb");
                                }
+                       } else if (a.name == "Deprecated") {
+                               process_deprecated_attribute (a);
                        }                       
                }
        }
index f4859d5cb53c46b9c523712aa3ccaf779bab9bae..89bca45c978d10a0c73b8788ce6ad216e6096d4e 100644 (file)
@@ -246,9 +246,10 @@ public class Vala.Signal : Member, Lockable {
                foreach (Attribute a in attributes) {
                        if (a.name == "HasEmitter") {
                                has_emitter = true;
-                       }
-                       if (a.name == "Signal") {
+                       } else if (a.name == "Signal") {
                                process_signal_attribute (a);
+                       } else if (a.name == "Deprecated") {
+                               process_deprecated_attribute (a);
                        }
                }
        }
index b7af767fc93636c045298dd240189b3412c42948..bcfa13e1862a68f0fd3bbcda66d1c369b7fed300 100644 (file)
@@ -497,6 +497,8 @@ public class Vala.Struct : TypeSymbol {
                                process_floating_type_attribute (a);
                        } else if (a.name == "Immutable") {
                                is_immutable = true;
+                       } else if (a.name == "Deprecated") {
+                               process_deprecated_attribute (a);
                        }
                }
        }
index 231eacea6706e5eebb88e27e11b814063e90ad71..8cb6e434861ab2a867b6f2221408f1770c39e73b 100644 (file)
@@ -67,6 +67,21 @@ public abstract class Vala.Symbol : CodeNode {
         */
        public bool active { get; set; default = true; }
 
+       /**
+        * Specifies whether this symbol has been deprecated.
+        */
+       public bool deprecated { get; set; default = false; }
+
+       /**
+        * Specifies what version this symbol has been deprecated since.
+        */
+       public string? deprecated_since { get; set; default = null; }
+
+       /**
+        * Specifies the replacement if this symbol has been deprecated.
+        */
+       public string? replacement { get; set; default = null; }
+
        /**
         * Specifies whether this symbol has been accessed.
         */
@@ -365,6 +380,39 @@ public abstract class Vala.Symbol : CodeNode {
 
                return isclass;
        }
+
+       /**
+        * Process a [Deprecated] attribute
+        */
+       public virtual void process_deprecated_attribute (Attribute attr) {
+               if (attr.name != "Deprecated") {
+                       return;
+               }
+
+               deprecated = true;
+
+               if (attr.has_argument ("since")) {
+                       deprecated_since = attr.get_string ("since");
+               }
+               if (attr.has_argument ("replacement")) {
+                       replacement = attr.get_string ("replacement");
+               }
+       }
+
+       /**
+        * Check to see if the symbol has been deprecated, and emit a warning
+        * if it has.
+        */
+       public bool check_deprecated (SourceReference? source_ref = null) {
+               if (deprecated) {
+                       if (!CodeContext.get ().deprecated) {
+                               Report.warning (source_ref, "%s %s%s".printf (get_full_name (), (deprecated_since == null) ? "is deprecated" : "has been deprecated since %s".printf (deprecated_since), (replacement == null) ? "" : ". Use %s".printf (replacement)));
+                       }
+                       return true;
+               } else {
+                       return false;
+               }
+       }
 }
 
 public enum Vala.SymbolAccessibility {