]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Support deprecating properties and their accessors
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 13 Oct 2016 07:39:47 +0000 (09:39 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 18 Oct 2016 09:07:29 +0000 (11:07 +0200)
Use G_PARAM_DEPRECATED for properties and in addition their accessor
methods will be marked as deprecated.

Guard internal accessors calls with G_GNUC_BEGIN/END_IGNORED_DEPRECATIONS
to silence unavoidable warnings.

Based on patch by Simon Werbeck <simon.werbeck@gmail.com>

https://bugzilla.gnome.org/show_bug.cgi?id=732449

ccode/Makefile.am
ccode/valaccodeggnucsection.vala [new file with mode: 0644]
codegen/valaccodebasemodule.vala
codegen/valagobjectmodule.vala
codegen/valagtypemodule.vala

index fd3186a871a25d251f44e875a92484bcda7dca71..0402f62695d4d3b12186533ab6240514509b8d4c 100644 (file)
@@ -40,6 +40,7 @@ libvalaccode_la_VALASOURCES = \
        valaccodefunction.vala \
        valaccodefunctioncall.vala \
        valaccodefunctiondeclarator.vala \
+       valaccodeggnucsection.vala \
        valaccodegotostatement.vala \
        valaccodeidentifier.vala \
        valaccodeifstatement.vala \
diff --git a/ccode/valaccodeggnucsection.vala b/ccode/valaccodeggnucsection.vala
new file mode 100644 (file)
index 0000000..deb969c
--- /dev/null
@@ -0,0 +1,64 @@
+/* valaccodeggnucsection.vala
+ *
+ * Copyright (C) 2016  Rico Tzschichholz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ *     Rico Tzschichholz <ricotz@ubuntu.com>
+ */
+
+using GLib;
+
+/**
+ * Represents a section that should be processed on condition.
+ */
+public class Vala.CCodeGGnucSection : CCodeFragment {
+       /**
+        * The expression
+        */
+       public GGnucSectionType section_type { get; set; }
+
+       public CCodeGGnucSection (GGnucSectionType t) {
+               section_type = t;
+       }
+
+       public override void write (CCodeWriter writer) {
+               writer.write_string ("G_GNUC_BEGIN_");
+               writer.write_string (section_type.to_string ());
+               foreach (CCodeNode node in get_children ()) {
+                       node.write_combined (writer);
+               }
+               writer.write_string ("G_GNUC_END_");
+               writer.write_string (section_type.to_string ());
+               writer.write_newline ();
+       }
+
+       public override void write_declaration (CCodeWriter writer) {
+       }
+}
+
+public enum Vala.GGnucSectionType {
+       IGNORE_DEPRECATIONS;
+
+       public unowned string to_string () {
+               switch (this) {
+                       case IGNORE_DEPRECATIONS:
+                               return "IGNORE_DEPRECATIONS";
+                       default:
+                               assert_not_reached ();
+               }
+       }
+}
index 2f983d0d2a113c4b048dbda611d47600a1ddcf11..60fd6bf6fea784380e17eddcd31bb2a47cc31402 100644 (file)
@@ -1526,6 +1526,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        }
                }
 
+               if (prop.version.deprecated) {
+                       function.modifiers |= CCodeModifiers.DEPRECATED;
+               }
+
                if (prop.is_private_symbol () || (!acc.readable && !acc.writable) || acc.access == SymbolAccessibility.PRIVATE) {
                        function.modifiers |= CCodeModifiers.STATIC;
                } else if (context.hide_internal && (prop.is_internal_symbol () || acc.access == SymbolAccessibility.INTERNAL)) {
index cc14136394f827d4eb24a79c5494f7917d0ce246..d4b8887083add8d0e2fa7c447652f73a61d12234 100644 (file)
@@ -166,6 +166,17 @@ public class Vala.GObjectModule : GTypeModule {
                return false;
        }
 
+       private void add_guarded_expression (Symbol sym, CCodeExpression expression) {
+               // prevent deprecation warnings
+               if (sym.version.deprecated) {
+                       var guard = new CCodeGGnucSection (GGnucSectionType.IGNORE_DEPRECATIONS);
+                       ccode.add_statement (guard);
+                       guard.append (new CCodeExpressionStatement (expression));
+               } else {
+                       ccode.add_expression (expression);
+               }
+       }
+
        private void add_get_property_function (Class cl) {
                var get_prop = new CCodeFunction ("_vala_%s_get_property".printf (get_ccode_lower_case_name (cl, null)), "void");
                get_prop.modifiers = CCodeModifiers.STATIC;
@@ -231,7 +242,7 @@ public class Vala.GObjectModule : GTypeModule {
                                csetcall.call = get_value_setter_function (prop.property_type);
                                csetcall.add_argument (new CCodeIdentifier ("value"));
                                csetcall.add_argument (boxed_addr);
-                               ccode.add_expression (csetcall);
+                               add_guarded_expression (prop, csetcall);
 
                                if (requires_destroy (prop.get_accessor.value_type)) {
                                        ccode.add_expression (destroy_value (new GLibValue (prop.get_accessor.value_type, new CCodeIdentifier ("boxed"), true)));
@@ -255,7 +266,7 @@ public class Vala.GObjectModule : GTypeModule {
                                }
                                csetcall.add_argument (new CCodeIdentifier ("value"));
                                csetcall.add_argument (ccall);
-                               ccode.add_expression (csetcall);
+                               add_guarded_expression (prop, csetcall);
                                if (array_type != null && array_type.element_type.data_type == string_type.data_type) {
                                        ccode.close ();
                                }
@@ -339,7 +350,7 @@ public class Vala.GObjectModule : GTypeModule {
                                var ccond = new CCodeConditionalExpression (cisnull, new CCodeConstant ("0"), cstrvlen);
 
                                ccall.add_argument (ccond);
-                               ccode.add_expression (ccall);
+                               add_guarded_expression (prop, ccall);
                                ccode.close ();
                        } else {
                                var cgetcall = new CCodeFunctionCall ();
@@ -350,7 +361,7 @@ public class Vala.GObjectModule : GTypeModule {
                                }
                                cgetcall.add_argument (new CCodeIdentifier ("value"));
                                ccall.add_argument (cgetcall);
-                               ccode.add_expression (ccall);
+                               add_guarded_expression (prop, ccall);
                        }
                        ccode.add_break ();
                }
index f46465fc5c2eb8006573f4e1acad2d83a67caf28..4bbfab6ac6d7cfad81cc675969d17198f6d7f160 100644 (file)
@@ -1893,6 +1893,9 @@ public class Vala.GTypeModule : GErrorModule {
                                }
                        }
                }
+               if (prop.version.deprecated) {
+                       pflags = "%s%s".printf (pflags, " | G_PARAM_DEPRECATED");
+               }
                cspec.add_argument (new CCodeConstant (pflags));
 
                return cspec;