summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2018-09-17 12:23:52 +0200
committerRico Tzschichholz <ricotz@ubuntu.com>2018-11-25 11:03:58 +0100
commit9d827dd744d425bd7a39df7fa19def6c3a4398ea (patch)
tree8a1ba4fd7b293d03558c6356d13a939968229fef
parent77c480431bc87350b592a5c1c836be6e9bb9e63c (diff)
downloadvala-9d827dd744d425bd7a39df7fa19def6c3a4398ea.tar.gz
libvaladoc: Drop AttributeArgument
-rw-r--r--libvaladoc/Makefile.am1
-rw-r--r--libvaladoc/api/attribute.vala75
-rw-r--r--libvaladoc/api/attributeargument.vala132
-rw-r--r--libvaladoc/api/symbol.vala18
-rw-r--r--libvaladoc/html/basicdoclet.vala19
-rw-r--r--valadoc/doclets/gtkdoc/generator.vala16
-rw-r--r--valadoc/tests/drivers/generic-api-test.vala27
-rw-r--r--valadoc/treebuilder.vala66
8 files changed, 73 insertions, 281 deletions
diff --git a/libvaladoc/Makefile.am b/libvaladoc/Makefile.am
index 29386d473..413d12dd1 100644
--- a/libvaladoc/Makefile.am
+++ b/libvaladoc/Makefile.am
@@ -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 \
diff --git a/libvaladoc/api/attribute.vala b/libvaladoc/api/attribute.vala
index b80a1b52c..befdfe95d 100644
--- a/libvaladoc/api/attribute.vala
+++ b/libvaladoc/api/attribute.vala
@@ -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
index 374b3d6fc..000000000
--- a/libvaladoc/api/attributeargument.vala
+++ /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 ();
- }
-}
diff --git a/libvaladoc/api/symbol.vala b/libvaladoc/api/symbol.vala
index 7acc29bc5..22466981e 100644
--- a/libvaladoc/api/symbol.vala
+++ b/libvaladoc/api/symbol.vala
@@ -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;
}
diff --git a/libvaladoc/html/basicdoclet.vala b/libvaladoc/html/basicdoclet.vala
index 192e488cd..acd94cf5f 100644
--- a/libvaladoc/html/basicdoclet.vala
+++ b/libvaladoc/html/basicdoclet.vala
@@ -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) {
diff --git a/valadoc/doclets/gtkdoc/generator.vala b/valadoc/doclets/gtkdoc/generator.vala
index 6e389d7b7..5be0b746f 100644
--- a/valadoc/doclets/gtkdoc/generator.vala
+++ b/valadoc/doclets/gtkdoc/generator.vala
@@ -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 ("\"")) {
diff --git a/valadoc/tests/drivers/generic-api-test.vala b/valadoc/tests/drivers/generic-api-test.vala
index 789b0e009..24ef6954f 100644
--- a/valadoc/tests/drivers/generic-api-test.vala
+++ b/valadoc/tests/drivers/generic-api-test.vala
@@ -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;
diff --git a/valadoc/treebuilder.vala b/valadoc/treebuilder.vala
index 40cffb474..b81d01613 100644
--- a/valadoc/treebuilder.vala
+++ b/valadoc/treebuilder.vala
@@ -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);
}
}