[valadoc] libvaladoc: Add CTypeResolver
- From: Florian Brosch <flobrosch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [valadoc] libvaladoc: Add CTypeResolver
- Date: Thu, 2 Sep 2010 03:35:00 +0000 (UTC)
commit 7ab846b7351b0eccb1a26b0d7c3dd39e5c8c1e06
Author: Florian Brosch <flo brosch gmail com>
Date: Sat Aug 7 04:26:14 2010 +0200
libvaladoc: Add CTypeResolver
src/libvaladoc/Makefile.am | 1 +
src/libvaladoc/api/tree.vala | 11 ++
src/libvaladoc/importer/ctyperesolver.vala | 145 ++++++++++++++++++++++++++++
3 files changed, 157 insertions(+), 0 deletions(-)
---
diff --git a/src/libvaladoc/Makefile.am b/src/libvaladoc/Makefile.am
index 0633ae1..b769576 100644
--- a/src/libvaladoc/Makefile.am
+++ b/src/libvaladoc/Makefile.am
@@ -36,6 +36,7 @@ libvaladoc_la_VALASOURCES = \
documentation/wiki.vala \
documentation/wikiscanner.vala \
importer/documentationimporter.vala \
+ importer/ctyperesolver.vala \
api/array.vala \
api/class.vala \
api/constant.vala \
diff --git a/src/libvaladoc/api/tree.vala b/src/libvaladoc/api/tree.vala
index fe48ade..3a90dd5 100644
--- a/src/libvaladoc/api/tree.vala
+++ b/src/libvaladoc/api/tree.vala
@@ -20,6 +20,7 @@
* Florian Brosch <flo brosch gmail com>
*/
+using Valadoc.Importer;
using Gee;
@@ -33,12 +34,22 @@ public class Valadoc.Api.Tree {
private Vala.CodeContext context;
private ErrorReporter reporter;
private Package sourcefiles = null;
+ private CTypeResolver _cresolver = null;
public WikiPageTree? wikitree {
private set;
get;
}
+ public CTypeResolver cresolver {
+ get {
+ if (_cresolver == null) {
+ _cresolver = new CTypeResolver (this);
+ }
+ return _cresolver;
+ }
+ }
+
public Collection<Package> get_package_list () {
return this.packages.read_only_view;
}
diff --git a/src/libvaladoc/importer/ctyperesolver.vala b/src/libvaladoc/importer/ctyperesolver.vala
new file mode 100644
index 0000000..83af779
--- /dev/null
+++ b/src/libvaladoc/importer/ctyperesolver.vala
@@ -0,0 +1,145 @@
+/* ctyperesolver.vala
+ *
+ * Copyright (C) 2010 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.Api;
+using Gee;
+
+public class Valadoc.Importer.CTypeResolver : Visitor {
+ private Map<string, Api.Node> nodes = new HashMap<string, Api.Node> ();
+
+ public CTypeResolver (Api.Tree tree) {
+ tree.accept (this);
+ }
+
+ public Api.Node? resolve_symbol (string name) {
+ return nodes.get (name);
+ }
+
+ private void register_symbol (string? name, Api.Node node) {
+ if (name != null) {
+ nodes.set (name, node);
+ }
+ }
+
+ private string? get_parent_type_cname (Item item) {
+ string parent_cname = null;
+ if (item.parent is Class) {
+ parent_cname = ((Class) item.parent).get_cname ();
+ } else if (item.parent is Interface) {
+ parent_cname = ((Interface) item.parent).get_cname ();
+ } else if (item.parent is Struct) {
+ parent_cname = ((Struct) item.parent).get_cname ();
+ } else if (item.parent is ErrorDomain) {
+ parent_cname = ((ErrorDomain) item.parent).get_cname ();
+ } else if (item.parent is Api.Enum) {
+ parent_cname = ((Api.Enum) item.parent).get_cname ();
+ } else {
+ assert (true);
+ }
+ return parent_cname;
+ }
+
+ public override void visit_tree (Api.Tree item) {
+ item.accept_children (this);
+ }
+
+ public override void visit_package (Package item) {
+ item.accept_all_children (this);
+ }
+
+ public override void visit_namespace (Namespace item) {
+ item.accept_all_children (this);
+ }
+
+ public override void visit_interface (Interface item) {
+ register_symbol (item.get_cname (), item);
+ item.accept_all_children (this);
+ }
+
+ public override void visit_class (Class item) {
+ register_symbol (item.get_cname (), item);
+ item.accept_all_children (this);
+ }
+
+ public override void visit_struct (Struct item) {
+ register_symbol (item.get_cname (), item);
+ item.accept_all_children (this);
+ }
+
+ public override void visit_property (Property item) {
+ string parent_cname = get_parent_type_cname (item);
+ if (parent_cname != null) {
+ register_symbol (parent_cname+":"+item.get_cname (), item);
+ }
+ }
+
+ public override void visit_field (Field item) {
+ if (item is Namespace) {
+ register_symbol (item.get_cname (), item);
+ } else {
+ string parent_cname = get_parent_type_cname (item);
+ if (parent_cname != null) {
+ register_symbol (parent_cname+"."+item.get_cname (), item);
+ }
+ }
+ }
+
+ public override void visit_constant (Constant item) {
+ register_symbol (item.get_cname (), item);
+ }
+
+ public override void visit_delegate (Delegate item) {
+ register_symbol (item.get_cname (), item);
+ }
+
+ public override void visit_signal (Api.Signal item) {
+ string parent_cname = get_parent_type_cname (item);
+ if (parent_cname != null) {
+ register_symbol (parent_cname+"::"+item.get_cname (), item);
+ }
+ }
+
+ public override void visit_method (Method item) {
+ register_symbol (item.get_cname (), item);
+ }
+
+ public override void visit_error_domain (ErrorDomain item) {
+ register_symbol (item.get_cname (), item);
+ item.accept_all_children (this);
+ }
+
+ public override void visit_error_code (ErrorCode item) {
+ register_symbol (item.get_cname (), item);
+ }
+
+ public override void visit_enum (Api.Enum item) {
+ register_symbol (item.get_cname (), item);
+ item.accept_all_children (this);
+ }
+
+ public override void visit_enum_value (Api.EnumValue item) {
+ register_symbol (item.get_cname (), item);
+ }
+}
+
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]