[valadoc] docbook: improve implicit parameter handling
- From: Florian Brosch <flobrosch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [valadoc] docbook: improve implicit parameter handling
- Date: Tue, 2 Sep 2014 17:16:30 +0000 (UTC)
commit 221e57d0dc01fe95309987db0e1b5f8264b0c85a
Author: Florian Brosch <flo brosch gmail com>
Date: Thu Aug 21 01:01:17 2014 +0200
docbook: improve implicit parameter handling
.../documentation/gtkdoccommentparser.vala | 107 ++-----------------
.../documentation/gtkdocmarkdownparser.vala | 27 +++++-
src/libvaladoc/documentation/importerhelper.vala | 110 ++++++++++++++++++++
3 files changed, 145 insertions(+), 99 deletions(-)
---
diff --git a/src/libvaladoc/documentation/gtkdoccommentparser.vala
b/src/libvaladoc/documentation/gtkdoccommentparser.vala
index bb2d500..417590b 100644
--- a/src/libvaladoc/documentation/gtkdoccommentparser.vala
+++ b/src/libvaladoc/documentation/gtkdoccommentparser.vala
@@ -38,6 +38,7 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
private ErrorReporter reporter;
private Settings settings;
private Api.Tree tree;
+ private Api.Node? element;
private bool show_warnings;
private Api.SourceComment comment;
@@ -113,8 +114,6 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
}
}
- private Api.Node? element;
-
public Comment? parse (Api.Node element, Api.GirSourceComment gir_comment, GirMetaData gir_metadata) {
this.instance_param_name = gir_comment.instance_param_name;
this.current_metadata = gir_metadata;
@@ -1415,101 +1414,6 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
}
}
- private string[]? split_type_name (string id) {
- unichar c;
-
- for (unowned string pos = id; (c = pos.get_char ()) != '\0'; pos = pos.next_char ()) {
- switch (c) {
- case '-': // ->
- return {id.substring (0, (long) (((char*) pos) - ((char*) id))), "->",
(string) (((char*) pos) + 2)};
-
- case ':': // : or ::
- string sep = (pos.next_char ().get_char () == ':')? "::" : ":";
- return {id.substring (0, (long) (((char*) pos) - ((char*) id))), sep,
(string) (((char*) pos) + sep.length)};
-
- case '.':
- return {id.substring (0, (long) (((char*) pos) - ((char*) id))), ".",
(string) (((char*) pos) + 1)};
- }
- }
-
- return {id};
- }
-
- private string? resolve_parameter_ctype (string parameter_name, out string? param_name,
- out string?
param_array_name, out bool is_return_type_len)
- {
- string[]? parts = split_type_name (parameter_name);
- is_return_type_len = false;
- param_array_name = null;
-
- Api.FormalParameter? param = null; // type parameter or formal parameter
- foreach (Api.Node node in this.element.get_children_by_type (Api.NodeType.FORMAL_PARAMETER,
false)) {
- if (node.name == parts[0]) {
- param = node as Api.FormalParameter;
- break;
- }
-
- if (((Api.FormalParameter) node).implicit_array_length_cparameter_name == parts[0]) {
- param_array_name = ((Api.FormalParameter) node).name;
- break;
- }
- }
-
- if (this.element is Api.Callable
- && ((Api.Callable) this.element).implicit_array_length_cparameter_name == parts[0])
- {
- is_return_type_len = true;
- }
-
- if (parts.length == 1) {
- param_name = parameter_name;
- return null;
- }
-
-
- Api.Item? inner = null;
-
- if (param_array_name != null || is_return_type_len) {
- inner = tree.search_symbol_str (null, "int");
- } else if (param != null) {
- inner = param.parameter_type;
- }
-
- while (inner != null) {
- if (inner is Api.TypeReference) {
- inner = ((Api.TypeReference) inner).data_type;
- } else if (inner is Api.Pointer) {
- inner = ((Api.Pointer) inner).data_type;
- } else if (inner is Api.Array) {
- inner = ((Api.Array) inner).data_type;
- } else {
- break ;
- }
- }
-
-
- if (inner == null) {
- param_name = parameter_name;
- return null;
- }
-
- string? cname = null;
- if (inner is Api.ErrorDomain) {
- cname = ((Api.ErrorDomain) inner).get_cname ();
- } else if (inner is Api.Struct) {
- cname = ((Api.Struct) inner).get_cname ();
- } else if (inner is Api.Class) {
- cname = ((Api.Class) inner).get_cname ();
- } else if (inner is Api.Enum) {
- cname = ((Api.Enum) inner).get_cname ();
- } else {
- assert_not_reached ();
- }
-
- param_name = (owned) parts[0];
- return "c::" + cname + parts[1] + parts[2];
- }
-
private Run parse_inline_content () {
Run run = factory.create_run (Run.Style.NONE);
@@ -1600,7 +1504,14 @@ public class Valadoc.Gtkdoc.Parser : Object, ResourceLocator {
bool is_return_type_len;
string? param_name;
- string? cname = resolve_parameter_ctype (current.content, out
param_name, out param_array_name, out is_return_type_len);
+ string? cname = ImporterHelper.resolve_parameter_ctype (
+ this.tree,
+ this.element,
+ current.content,
+ out param_name,
+ out param_array_name,
+ out is_return_type_len);
+
Run current_run = factory.create_run (Run.Style.MONOSPACED);
run.content.add (current_run);
diff --git a/src/libvaladoc/documentation/gtkdocmarkdownparser.vala
b/src/libvaladoc/documentation/gtkdocmarkdownparser.vala
index 9614e6c..341dff0 100644
--- a/src/libvaladoc/documentation/gtkdocmarkdownparser.vala
+++ b/src/libvaladoc/documentation/gtkdocmarkdownparser.vala
@@ -86,8 +86,33 @@ public class Valadoc.Gtkdoc.MarkdownParser : Object, ResourceLocator {
_run = _factory.create_run (Run.Style.LANG_KEYWORD);
_run.content.add (_factory.create_text ("throws"));
} else {
+ string? param_name;
+ string? param_array_name;
+ bool is_return_type_len;
+
+ ImporterHelper.resolve_parameter_ctype (
+ this._tree,
+ this.element,
+ token.value,
+ out param_name,
+ out param_array_name,
+ out is_return_type_len);
+
_run = _factory.create_run (Run.Style.MONOSPACED);
- _run.content.add (_factory.create_text (token.value));
+
+ if (is_return_type_len) {
+ Run keyword_run = _factory.create_run
(Run.Style.LANG_KEYWORD);
+ keyword_run.content.add (_factory.create_text ("return"));
+ _run.content.add (keyword_run);
+
+ _run.content.add (_factory.create_text (".length"));
+ } else if (param_array_name != null) {
+ _run.content.add (_factory.create_text (param_array_name +
".length"));
+ } else {
+ _run.content.add (_factory.create_text (param_name));
+ }
+
+
}
push (_run);
diff --git a/src/libvaladoc/documentation/importerhelper.vala
b/src/libvaladoc/documentation/importerhelper.vala
index 36ed06d..3f75018 100644
--- a/src/libvaladoc/documentation/importerhelper.vala
+++ b/src/libvaladoc/documentation/importerhelper.vala
@@ -27,6 +27,111 @@ using Gee;
namespace Valadoc.ImporterHelper {
+ //
+ // resolve-parameter-ctype:
+ //
+
+ internal string? resolve_parameter_ctype (Api.Tree tree, Api.Node element, string parameter_name,
+ out string? param_name, out string? param_array_name, out bool is_return_type_len)
+ {
+ string[]? parts = split_type_name (parameter_name);
+ is_return_type_len = false;
+ param_array_name = null;
+
+ Api.FormalParameter? param = null; // type parameter or formal parameter
+ foreach (Api.Node node in element.get_children_by_type (Api.NodeType.FORMAL_PARAMETER,
false)) {
+ if (node.name == parts[0]) {
+ param = node as Api.FormalParameter;
+ break;
+ }
+
+ if (((Api.FormalParameter) node).implicit_array_length_cparameter_name == parts[0]) {
+ param_array_name = ((Api.FormalParameter) node).name;
+ break;
+ }
+ }
+
+ if (element is Api.Callable
+ && ((Api.Callable) element).implicit_array_length_cparameter_name == parts[0])
+ {
+ is_return_type_len = true;
+ }
+
+ if (parts.length == 1) {
+ param_name = parameter_name;
+ return null;
+ }
+
+
+ Api.Item? inner = null;
+
+ if (param_array_name != null || is_return_type_len) {
+ inner = tree.search_symbol_str (null, "int");
+ } else if (param != null) {
+ inner = param.parameter_type;
+ }
+
+ while (inner != null) {
+ if (inner is Api.TypeReference) {
+ inner = ((Api.TypeReference) inner).data_type;
+ } else if (inner is Api.Pointer) {
+ inner = ((Api.Pointer) inner).data_type;
+ } else if (inner is Api.Array) {
+ inner = ((Api.Array) inner).data_type;
+ } else {
+ break ;
+ }
+ }
+
+
+ if (inner == null) {
+ param_name = parameter_name;
+ return null;
+ }
+
+ string? cname = null;
+ if (inner is Api.ErrorDomain) {
+ cname = ((Api.ErrorDomain) inner).get_cname ();
+ } else if (inner is Api.Struct) {
+ cname = ((Api.Struct) inner).get_cname ();
+ } else if (inner is Api.Class) {
+ cname = ((Api.Class) inner).get_cname ();
+ } else if (inner is Api.Enum) {
+ cname = ((Api.Enum) inner).get_cname ();
+ } else {
+ assert_not_reached ();
+ }
+
+ param_name = (owned) parts[0];
+ return "c::" + cname + parts[1] + parts[2];
+ }
+
+
+ private string[]? split_type_name (string id) {
+ unichar c;
+
+ for (unowned string pos = id; (c = pos.get_char ()) != '\0'; pos = pos.next_char ()) {
+ switch (c) {
+ case '-': // ->
+ return {id.substring (0, (long) (((char*) pos) - ((char*) id))), "->",
(string) (((char*) pos) + 2)};
+
+ case ':': // : or ::
+ string sep = (pos.next_char ().get_char () == ':')? "::" : ":";
+ return {id.substring (0, (long) (((char*) pos) - ((char*) id))), sep,
(string) (((char*) pos) + sep.length)};
+
+ case '.':
+ return {id.substring (0, (long) (((char*) pos) - ((char*) id))), ".",
(string) (((char*) pos) + 1)};
+ }
+ }
+
+ return {id};
+ }
+
+
+
+ //
+ // extract-short-desc:
+ //
internal void extract_short_desc (Comment comment, ContentFactory factory) {
if (comment.content.size == 0) {
@@ -99,8 +204,13 @@ namespace Valadoc.ImporterHelper {
}
private inline Run? split_run (Run run, ContentFactory factory) {
+ if (run.style != Run.Style.NONE) {
+ return null;
+ }
+
Run? sec = null;
+
Iterator<Inline> iter = run.content.iterator ();
for (bool has_next = iter.next (); has_next; has_next = iter.next ()) {
Inline item = iter.get ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]