]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
libvaladoc: Drop AttributeArgument
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 17 Sep 2018 10:23:52 +0000 (12:23 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 25 Nov 2018 10:03:58 +0000 (11:03 +0100)
libvaladoc/Makefile.am
libvaladoc/api/attribute.vala
libvaladoc/api/attributeargument.vala [deleted file]
libvaladoc/api/symbol.vala
libvaladoc/html/basicdoclet.vala
valadoc/doclets/gtkdoc/generator.vala
valadoc/tests/drivers/generic-api-test.vala
valadoc/treebuilder.vala

index 29386d473b5b3858ec51b7b8dba1029230fafbe5..413d12dd175914ed9d48fe248cc3fff31ddfdb16 100644 (file)
@@ -55,7 +55,6 @@ libvaladoc_la_VALASOURCES = \
        importer/internalidregistrar.vala \
        api/sourcecomment.vala \
        api/girsourcecomment.vala \
-       api/attributeargument.vala \
        api/attribute.vala \
        api/array.vala \
        api/callable.vala \
index b80a1b52c90959c858757361295718dee0c18ec3..befdfe95d568c9a8977587528fd67bb805a1c5b3 100644 (file)
@@ -24,7 +24,6 @@
 using Valadoc.Content;
 
 public class Valadoc.Api.Attribute : Item {
-       private Vala.ArrayList<AttributeArgument> args = new Vala.ArrayList<AttributeArgument> ();
        private SourceFile file;
 
        public string name {
@@ -40,42 +39,6 @@ public class Valadoc.Api.Attribute : Item {
                this.file = file;
        }
 
-       public AttributeArgument? get_argument (string name) {
-               if (args != null) {
-                       foreach (AttributeArgument arg in args) {
-                               if (arg.name == name) {
-                                       return arg;
-                               }
-                       }
-               }
-
-               return null;
-       }
-
-       public AttributeArgument add_boolean (string name, bool value, Vala.Attribute data) {
-               AttributeArgument arg = new AttributeArgument.boolean (this, file, name, value, data);
-               args.add (arg);
-               return arg;
-       }
-
-       public AttributeArgument add_integer (string name, int value, Vala.Attribute data) {
-               AttributeArgument arg = new AttributeArgument.integer (this, file, name, value, data);
-               args.add (arg);
-               return arg;
-       }
-
-       public AttributeArgument add_double (string name, double value, Vala.Attribute data) {
-               AttributeArgument arg = new AttributeArgument.double (this, file, name, value, data);
-               args.add (arg);
-               return arg;
-       }
-
-       public AttributeArgument add_string (string name, string value, Vala.Attribute data) {
-               AttributeArgument arg = new AttributeArgument.string (this, file, name, value, data);
-               args.add (arg);
-               return arg;
-       }
-
        public SourceFile get_source_file () {
                return file;
        }
@@ -83,23 +46,45 @@ public class Valadoc.Api.Attribute : Item {
        protected override Inline build_signature () {
                SignatureBuilder builder = new SignatureBuilder ();
 
+               unowned Vala.Attribute attr = (Vala.Attribute) data;
+
+               var keys = new GLib.Sequence<string> ();
+               foreach (var key in attr.args.get_keys ()) {
+                       if (key == "cheader_filename") {
+                               continue;
+                       }
+                       keys.insert_sorted (key, (CompareDataFunc<string>) strcmp);
+               }
+
+               if (attr.name == "CCode" && keys.get_length () == 0) {
+                       // only cheader_filename on namespace
+                       return builder.get ();
+               }
+
                builder.append_attribute ("[");
-               builder.append_type_name (name);
+               builder.append_type_name (attr.name);
 
-               if (args.size > 0) {
+               if (keys.get_length () > 0) {
                        builder.append_attribute ("(");
-                       bool first = true;
 
-                       foreach (AttributeArgument arg in args) {
-                               if (first == false) {
+                       unowned string separator = "";
+                       var arg_iter = keys.get_begin_iter ();
+                       while (!arg_iter.is_end ()) {
+                               unowned string arg_name = arg_iter.get ();
+                               arg_iter = arg_iter.next ();
+                               if (separator != "") {
                                        builder.append_attribute (", ");
                                }
-                               builder.append_content (arg.signature);
-                               first = false;
+                               if (arg_name != "cheader_filename") {
+                                       builder.append_attribute (arg_name);
+                                       builder.append_attribute ("=");
+                                       builder.append_literal (attr.args.get (arg_name));
+                               }
+                               separator = ", ";
                        }
+
                        builder.append_attribute (")");
                }
-
                builder.append_attribute ("]");
 
                return builder.get ();
diff --git a/libvaladoc/api/attributeargument.vala b/libvaladoc/api/attributeargument.vala
deleted file mode 100644 (file)
index 374b3d6..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/* attributeargument.vala
- *
- * Copyright (C) 2011 Florian Brosch
- *
- * 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:
- *     Florian Brosch <flo.brosch@gmail.com>
- */
-
-
-using Valadoc.Content;
-
-public class Valadoc.Api.AttributeArgument : Item {
-       public enum Type {
-               BOOLEAN,
-               INTEGER,
-               DOUBLE,
-               STRING
-       }
-
-       private SourceFile file;
-
-       public string name {
-               private set;
-               get;
-       }
-
-       public AttributeArgument.Type argument_type {
-               private set;
-               get;
-       }
-
-       public string value {
-               private set;
-               get;
-       }
-
-       public AttributeArgument.boolean (Attribute parent, SourceFile file, string name, bool value, Vala.Attribute data) {
-               this (parent, file, name, Type.BOOLEAN, value.to_string (), data);
-       }
-
-       public AttributeArgument.integer (Attribute parent, SourceFile file, string name, int value, Vala.Attribute data) {
-               this (parent, file, name, Type.INTEGER, value.to_string (), data);
-       }
-
-       public AttributeArgument.double (Attribute parent, SourceFile file, string name, double value, Vala.Attribute data) {
-               this (parent, file, name, Type.DOUBLE, value.to_string (), data);
-       }
-
-       public AttributeArgument.string (Attribute parent, SourceFile file, string name, string value, Vala.Attribute data) {
-               this (parent, file, name, Type.STRING, value, data);
-       }
-
-       private AttributeArgument (Attribute parent, SourceFile file, string name, Type type, string value, Vala.Attribute data) {
-               base (data);
-
-               this.argument_type = type;
-               this.parent = parent;
-               this.value = value;
-               this.file = file;
-               this.name = name;
-       }
-
-       public SourceFile get_source_file () {
-               return file;
-       }
-
-       public bool get_value_as_boolean () {
-               assert (argument_type == Type.BOOLEAN);
-
-               bool tmp;
-
-               if (bool.try_parse (value, out tmp)) {
-                       return tmp;
-               }
-
-               assert_not_reached ();
-       }
-
-       public int get_value_as_integer () {
-               assert (argument_type == Type.INTEGER);
-
-               double tmp;
-
-               if (global::double.try_parse (value, out tmp) && tmp >= int.MIN && tmp <= int.MAX) {
-                       return (int) tmp;
-               }
-
-               assert_not_reached ();
-       }
-
-       public double get_value_as_double () {
-               assert (argument_type == Type.DOUBLE);
-
-               double tmp;
-
-               if (global::double.try_parse (value, out tmp)) {
-                       return tmp;
-               }
-
-               assert_not_reached ();
-       }
-
-       public string get_value_as_string () {
-               assert (argument_type == Type.STRING);
-
-               return value;
-       }
-
-       protected override Inline build_signature () {
-               SignatureBuilder builder = new SignatureBuilder ();
-
-               builder.append_attribute (name);
-               builder.append_attribute ("=");
-               builder.append_literal (value);
-
-               return builder.get ();
-       }
-}
index 7acc29bc55c2af15b8db273ccce0ee2d5027ec06..22466981e773773f4f9b045d819f14953871ea47 100644 (file)
@@ -49,21 +49,19 @@ public abstract class Valadoc.Api.Symbol : Node {
                        attributes = new Vala.ArrayList<Attribute> ();
                }
 
+               Vala.Attribute attr = (Vala.Attribute) att.data;
+
                // register deprecated symbols:
                if (att.name == "Version") {
-                       AttributeArgument? deprecated = att.get_argument ("deprecated");
-                       AttributeArgument? version = att.get_argument ("deprecated_since");
-                       if ((deprecated != null && deprecated.get_value_as_boolean ()) || version != null) {
-                               string? version_str = (version != null) ? version.get_value_as_string () : null;
-
-                               package.register_deprecated_symbol (this, version_str);
+                       var deprecated = attr.get_bool ("deprecated");
+                       var version = attr.get_string ("deprecated_since");
+                       if (deprecated || version != null) {
+                               package.register_deprecated_symbol (this, version);
                                is_deprecated = true;
                        }
                } else if (att.name == "Deprecated") {
-                       AttributeArgument? version = att.get_argument ("version");
-                       string? version_str = (version != null) ? version.get_value_as_string () : null;
-
-                       package.register_deprecated_symbol (this, version_str);
+                       var version = attr.get_string ("version");
+                       package.register_deprecated_symbol (this, version);
                        is_deprecated = true;
                }
 
index 192e488cd7434b1af4cdb9324a8a22e7a58aa873..acd94cf5f87afcce92030ad14d3033f45d8baaca 100644 (file)
@@ -473,14 +473,14 @@ public abstract class Valadoc.Html.BasicDoclet : Api.Visitor, Doclet {
                        Symbol symbol = (Symbol) element;
                        Attribute? version;
                        Attribute? deprecated;
-                       AttributeArgument? replacement;
-                       AttributeArgument? since;
+                       string? replacement;
+                       string? since;
                        if ((version = symbol.get_attribute ("Version")) != null) {
-                               replacement = version.get_argument ("replacement");
-                               since = version.get_argument ("deprecated_since");
+                               replacement = ((Vala.Attribute) version.data).get_string ("replacement");
+                               since = ((Vala.Attribute) version.data).get_string ("deprecated_since");
                        } else if ((deprecated = symbol.get_attribute ("Deprecated")) != null) {
-                               replacement = deprecated.get_argument ("replacement");
-                               since = deprecated.get_argument ("version");
+                               replacement = ((Vala.Attribute) deprecated.data).get_string ("replacement");
+                               since = ((Vala.Attribute) deprecated.data).get_string ("version");
                        } else {
                                assert_not_reached ();
                        }
@@ -492,19 +492,18 @@ public abstract class Valadoc.Html.BasicDoclet : Api.Visitor, Doclet {
                        writer.text (" %s is deprecated".printf (element.name));
 
                        if (since != null) {
-                               writer.text (" since %s".printf (since.get_value_as_string ()));
+                               writer.text (" since %s".printf (since));
                        }
 
                        writer.text (".");
 
                        if (replacement != null) {
-                               string replacement_name = replacement.get_value_as_string ();
                                Api.Node? replacement_node = tree.search_symbol_str (pos,
-                                       replacement_name.substring (1, replacement_name.length - 2));
+                                       replacement.substring (1, replacement.length - 2));
 
                                writer.text (" Use ");
                                if (replacement_node == null) {
-                                       writer.text (replacement_name);
+                                       writer.text (replacement);
                                } else {
                                        string? link = get_link (replacement_node, pos);
                                        if (link != null) {
index 6e389d7b797cb77422d4dd24bde41f60a81dc146..5be0b746f95f26f9398ce23a9d191ec69c6e5ea6 100644 (file)
@@ -1339,21 +1339,21 @@ It is important that your <link linkend="GValue"><type>GValue</type></link> hold
                if (sym.is_deprecated) {
                        Attribute? version;
                        Attribute? deprecated;
-                       AttributeArgument? deprecated_since;
-                       AttributeArgument? replacement;
+                       string? deprecated_since;
+                       string? replacement;
                        if ((version = sym.get_attribute ("Version")) != null) {
-                               deprecated_since = version.get_argument ("deprecated_since");
-                               replacement = version.get_argument ("replacement");
+                               deprecated_since = ((Vala.Attribute) version.data).get_string ("deprecated_since");
+                               replacement = ((Vala.Attribute) version.data).get_string ("replacement");
                        } else if ((deprecated = sym.get_attribute ("Deprecated")) != null) {
-                               deprecated_since = deprecated.get_argument ("since");
-                               replacement = deprecated.get_argument ("replacement");
+                               deprecated_since = ((Vala.Attribute) deprecated.data).get_string ("since");
+                               replacement = ((Vala.Attribute) deprecated.data).get_string ("replacement");
                        } else {
                                assert_not_reached ();
                        }
 
                        string? since = null;
                        if (deprecated_since != null) {
-                               since = deprecated_since.value;
+                               since = deprecated_since;
 
                                // Strip surrounding quotation marks.
                                if (since.has_prefix ("\"")) {
@@ -1368,7 +1368,7 @@ It is important that your <link linkend="GValue"><type>GValue</type></link> hold
                        Api.Node? replacement_symbol = null;
 
                        if (replacement != null) {
-                               replacement_symbol_name = replacement.value;
+                               replacement_symbol_name = replacement;
 
                                // Strip surrounding quotation marks.
                                if (replacement_symbol_name.has_prefix ("\"")) {
index 789b0e0095166c37926e38b5f24e9566733e01f2..24ef6954fc04087ac0d4e12033673e58268acd98 100644 (file)
@@ -2579,6 +2579,11 @@ public static void version_test (Api.Namespace ns, Api.Package pkg) {
                Api.TypeReference? ret = m.return_type;
                assert (ret != null);
 
+               Api.Attribute? dattr = m.get_attribute ("Deprecated");
+               Api.Attribute? vattr = m.get_attribute ("Version");
+               Vala.Attribute? attr_deprecated = (dattr != null ? dattr.data as Vala.Attribute : null);
+               Vala.Attribute? attr_version = (vattr != null ? vattr.data as Vala.Attribute : null);
+
                switch (m.name) {
                case "test_function_1":
                        assert (m.get_attribute ("Deprecated") != null);
@@ -2588,8 +2593,8 @@ public static void version_test (Api.Namespace ns, Api.Package pkg) {
                        break;
 
                case "test_function_2":
-                       assert (m.get_attribute ("Deprecated").get_argument ("since").get_value_as_string () == "\"1.0\"");
-                       assert (m.get_attribute ("Deprecated").get_argument ("replacement").get_value_as_string () == "\"test_function_4\"");
+                       assert (attr_deprecated.get_string ("since") == "1.0");
+                       assert (attr_deprecated.get_string ("replacement") == "test_function_4");
                        assert (m.is_deprecated == true);
 
                        func2 = true;
@@ -2602,45 +2607,45 @@ public static void version_test (Api.Namespace ns, Api.Package pkg) {
                        break;
 
                case "test_function_4":
-                       assert (m.get_attribute ("Version").get_argument ("since").get_value_as_string () == "\"2.0\"");
+                       assert (attr_version.get_string ("since") == "2.0");
                        assert (m.is_deprecated == false);
 
                        func4 = true;
                        break;
 
                case "test_function_5":
-                       assert (m.get_attribute ("Version").get_argument ("deprecated").get_value_as_boolean () == true);
+                       assert (attr_version.get_bool ("deprecated") == true);
                        assert (m.is_deprecated == true);
 
                        func5 = true;
                        break;
 
                case "test_function_6":
-                       assert (m.get_attribute ("Version").get_argument ("deprecated").get_value_as_boolean () == true);
-                       assert (m.get_attribute ("Version").get_argument ("deprecated_since").get_value_as_string () == "\"2.0\"");
-                       assert (m.get_attribute ("Version").get_argument ("replacement").get_value_as_string () == "\"test_function_4\"");
-                       assert (m.get_attribute ("Version").get_argument ("since").get_value_as_string () == "\"1.0\"");
+                       assert (attr_version.get_bool ("deprecated") == true);
+                       assert (attr_version.get_string ("deprecated_since") == "2.0");
+                       assert (attr_version.get_string ("replacement") == "test_function_4");
+                       assert (attr_version.get_string ("since") == "1.0");
                        assert (m.is_deprecated == true);
 
                        func6 = true;
                        break;
 
                case "test_function_7":
-                       assert (m.get_attribute ("Version").get_argument ("deprecated_since").get_value_as_string () == "\"2.0\"");
+                       assert (attr_version.get_string ("deprecated_since") == "2.0");
                        assert (m.is_deprecated == true);
 
                        func7 = true;
                        break;
 
                case "test_function_8":
-                       assert (m.get_attribute ("Version").get_argument ("deprecated").get_value_as_boolean () == false);
+                       assert (attr_version.get_bool ("deprecated") == false);
                        assert (m.is_deprecated == false);
 
                        func8 = true;
                        break;
 
                case "test_function_9":
-                       //assert (m.get_attribute ("Version").get_argument ("experimental").get_value_as_boolean () == true);
+                       //assert (attr_version.get_bool ("experimental") == true);
 
                        func9 = true;
                        break;
index 40cffb474508741aabd8e9ef4fce0a729c54bd2a..b81d01613ff06960b8ad34c16c5a788632b26cb1 100644 (file)
@@ -213,71 +213,9 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
        //
 
        private void process_attributes (Api.Symbol parent, GLib.List<Vala.Attribute> lst) {
-               // attributes without arguments:
-               string[] attributes = {
-                               "ReturnsModifiedPointer",
-                               "DestroysInstance",
-                               "GenericAccessors",
-                               "NoAccessorMethod",
-                               "SingleInstance",
-                               "NoArrayLength",
-                               "Experimental",
-                               "Diagnostics",
-                               "PrintfFormat",
-                               "PointerType",
-                               "ScanfFormat",
-                               "ThreadLocal",
-                               "SimpleType",
-                               "HasEmitter",
-                               "ModuleInit",
-                               "NoWrapper",
-                               "Immutable",
-                               "ErrorBase",
-                               "NoReturn",
-                               "NoThrow",
-                               "Compact",
-                               "Assert",
-                               "Flags"
-                       };
-
-               string? tmp = "";
-
                foreach (Vala.Attribute att in lst) {
-                       if (att.name == "CCode" && (tmp = att.args.get ("has_target")) != null && tmp == "false") {
-                               Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
-                               new_attribute.add_boolean ("has_target", false, att);
-                               parent.add_attribute (new_attribute);
-                       } else if (att.name == "Version") {
-                               Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
-                               if ((tmp = att.args.get ("deprecated")) != null) {
-                                       new_attribute.add_boolean ("deprecated", bool.parse (tmp), att);
-                               }
-                               if ((tmp = att.args.get ("since")) != null) {
-                                       new_attribute.add_string ("since", tmp, att);
-                               }
-                               if ((tmp = att.args.get ("deprecated_since")) != null) {
-                                       new_attribute.add_string ("deprecated_since", tmp, att);
-                                       if (att.args.get ("deprecated") == null) {
-                                               new_attribute.add_boolean ("deprecated", true, att);
-                                       }
-                               }
-                               if ((tmp = att.args.get ("replacement")) != null) {
-                                       new_attribute.add_string ("replacement", tmp, att);
-                               }
-                               parent.add_attribute (new_attribute);
-                       } else if (att.name == "Deprecated") {
-                               Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
-                               if ((tmp = att.args.get ("since")) != null) {
-                                       new_attribute.add_string ("since", tmp, att);
-                               }
-                               if ((tmp = att.args.get ("replacement")) != null) {
-                                       new_attribute.add_string ("replacement", tmp, att);
-                               }
-                               parent.add_attribute (new_attribute);
-                       } else if (att.name in attributes) {
-                               Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
-                               parent.add_attribute (new_attribute);
-                       }
+                       Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
+                       parent.add_attribute (new_attribute);
                }
        }