[vala/staging: 7/22] libvaladoc: Drop AttributeArgument
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 7/22] libvaladoc: Drop AttributeArgument
- Date: Sun, 25 Nov 2018 13:08:41 +0000 (UTC)
commit 9d827dd744d425bd7a39df7fa19def6c3a4398ea
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Sep 17 12:23:52 2018 +0200
libvaladoc: Drop AttributeArgument
libvaladoc/Makefile.am | 1 -
libvaladoc/api/attribute.vala | 75 +++++++---------
libvaladoc/api/attributeargument.vala | 132 ----------------------------
libvaladoc/api/symbol.vala | 18 ++--
libvaladoc/html/basicdoclet.vala | 19 ++--
valadoc/doclets/gtkdoc/generator.vala | 16 ++--
valadoc/tests/drivers/generic-api-test.vala | 27 +++---
valadoc/treebuilder.vala | 66 +-------------
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/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);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]