Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 550c36044c98d8c2bfbfc9f6cf3cb7b7737e312f Mon Sep 17 00:00:00 2001
- From: Florian Brosch <flo.brosch@gmail.com>
- Date: Tue, 29 Nov 2011 01:56:46 +0100
- Subject: [PATCH] Add support for gir-comments
- ---
- gee/Makefile.am | 1 +
- gee/hashmap.vala | 47 ++++++++++++++++++
- gee/map.vala | 9 +++
- gee/mapiterator.vala | 52 +++++++++++++++++++
- vala/Makefile.am | 1 +
- vala/valacomment.vala | 2 +-
- vala/valagircomment.vala | 50 +++++++++++++++++++
- vala/valagirparser.vala | 122 ++++++++++++++++++++++++++++++++++++++++++---
- 8 files changed, 274 insertions(+), 10 deletions(-)
- create mode 100644 gee/mapiterator.vala
- create mode 100644 vala/valagircomment.vala
- diff --git a/gee/Makefile.am b/gee/Makefile.am
- index ab31565..f9ac2fc 100644
- --- a/gee/Makefile.am
- +++ b/gee/Makefile.am
- @@ -17,6 +17,7 @@ libgee_la_VALASOURCES = \
- hashmap.vala \
- hashset.vala \
- iterable.vala \
- + mapiterator.vala \
- iterator.vala \
- list.vala \
- map.vala \
- diff --git a/gee/hashmap.vala b/gee/hashmap.vala
- index 5159fe3..1fb2ed3 100644
- --- a/gee/hashmap.vala
- +++ b/gee/hashmap.vala
- @@ -74,6 +74,10 @@ public class Vala.HashMap<K,V> : Map<K,V> {
- return new ValueCollection<K,V> (this);
- }
- + public override Vala.MapIterator<K,V> map_iterator () {
- + return new MapIterator<K,V> (this);
- + }
- +
- private Node<K,V>** lookup_node (K key) {
- uint hash_value = _key_hash_func (key);
- Node<K,V>** node = &_nodes[hash_value % _array_size];
- @@ -224,6 +228,49 @@ public class Vala.HashMap<K,V> : Map<K,V> {
- }
- }
- + private class MapIterator<K,V> : Vala.MapIterator<K, V> {
- + public HashMap<K,V> map {
- + set {
- + _map = value;
- + _stamp = _map._stamp;
- + }
- + }
- +
- + private HashMap<K,V> _map;
- + private int _index = -1;
- + private weak Node<K,V> _node;
- +
- + // concurrent modification protection
- + private int _stamp;
- +
- + public MapIterator (HashMap map) {
- + this.map = map;
- + }
- +
- + public override bool next () {
- + if (_node != null) {
- + _node = _node.next;
- + }
- + while (_node == null && _index + 1 < _map._array_size) {
- + _index++;
- + _node = _map._nodes[_index];
- + }
- + return (_node != null);
- + }
- +
- + public override K? get_key () {
- + assert (_stamp == _map._stamp);
- + assert (_node != null);
- + return _node.key;
- + }
- +
- + public override V? get_value () {
- + assert (_stamp == _map._stamp);
- + assert (_node != null);
- + return _node.value;
- + }
- + }
- +
- private class KeyIterator<K,V> : Iterator<K> {
- public HashMap<K,V> map {
- set {
- diff --git a/gee/map.vala b/gee/map.vala
- index e78f794..2c96a3d 100644
- --- a/gee/map.vala
- +++ b/gee/map.vala
- @@ -84,5 +84,14 @@ public abstract class Vala.Map<K,V> {
- * read-only collections.
- */
- public abstract void clear ();
- +
- + /**
- + * Returns a Iterator that can be used for simple iteration over a
- + * map.
- + *
- + * @return a Iterator that can be used for simple iteration over a
- + * map
- + */
- + public abstract MapIterator<K,V> map_iterator ();
- }
- diff --git a/gee/mapiterator.vala b/gee/mapiterator.vala
- new file mode 100644
- index 0000000..78243c2
- --- /dev/null
- +++ b/gee/mapiterator.vala
- @@ -0,0 +1,52 @@
- +/* mapiterator.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>
- + */
- +
- +
- +
- +/**
- + * An iterator over a map.
- + */
- +public abstract class Vala.MapIterator<K,V> {
- + /**
- + * Advances to the next element in the iteration.
- + *
- + * @return true if the iterator has a next element
- + */
- + public abstract bool next ();
- +
- + /**
- + * Returns the current key in the iteration.
- + *
- + * @return the current key in the iteration
- + */
- + public abstract K get_key ();
- +
- + /**
- + * Returns the current value in the iteration.
- + *
- + * @return the current value in the iteration
- + */
- + public abstract V get_value ();
- +}
- +
- +
- +
- diff --git a/vala/Makefile.am b/vala/Makefile.am
- index 936a2cb..999a63a 100644
- --- a/vala/Makefile.am
- +++ b/vala/Makefile.am
- @@ -40,6 +40,7 @@ libvalacore_la_VALASOURCES = \
- valacodevisitor.vala \
- valacodewriter.vala \
- valacomment.vala \
- + valagircomment.vala \
- valaconditionalexpression.vala \
- valaconstant.vala \
- valaconstructor.vala \
- diff --git a/vala/valacomment.vala b/vala/valacomment.vala
- index 181d8a1..0e48f89 100644
- --- a/vala/valacomment.vala
- +++ b/vala/valacomment.vala
- @@ -34,7 +34,7 @@ public class Vala.Comment {
- /**
- * The text describing the referenced source code.
- */
- - public virtual string content { set; get; }
- + public string content { set; get; }
- /**
- * References the location in the source file where this code node has
- diff --git a/vala/valagircomment.vala b/vala/valagircomment.vala
- new file mode 100644
- index 0000000..10c1a76
- --- /dev/null
- +++ b/vala/valagircomment.vala
- @@ -0,0 +1,50 @@
- +/* valagircomment.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 GLib;
- +
- +
- +/**
- + * A documentation comment used by valadoc
- + */
- +public class Vala.GirComment : Comment {
- + private HashMap<string, Comment> parameter_content = new HashMap<string, Comment> ();
- +
- + public MapIterator<string, Comment> parameter_iterator () {
- + return this.parameter_content.map_iterator ();
- + }
- +
- + public Comment? return_content { get; set; }
- +
- + public GirComment (string? comment, SourceReference _source_reference) {
- + base (comment ?? "", _source_reference);
- + }
- +
- + internal void add_content_for_parameter (string name, Comment comment) {
- + parameter_content.set (name, comment);
- + }
- +
- + public Comment? get_content_for_parameter (string name) {
- + return parameter_content.get (name);
- + }
- +}
- +
- diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
- index 21b63d7..1aca142 100644
- --- a/vala/valagirparser.vala
- +++ b/vala/valagirparser.vala
- @@ -489,6 +489,7 @@ public class Vala.GirParser : CodeVisitor {
- public ArrayList<Node> members = new ArrayList<Node> (); // guarantees fields order
- public HashMap<string, ArrayList<Node>> scope = new HashMap<string, ArrayList<Node>> (str_hash, str_equal);
- + public GirComment comment;
- public Symbol symbol;
- public bool new_symbol;
- public bool merged;
- @@ -1166,10 +1167,6 @@ public class Vala.GirParser : CodeVisitor {
- void next () {
- current_token = reader.read_token (out begin, out end);
- -
- - // Skip *all* <doc> tags
- - if (current_token == MarkupTokenType.START_ELEMENT && reader.name == "doc")
- - skip_element();
- }
- void start_element (string name) {
- @@ -1923,6 +1920,13 @@ public class Vala.GirParser : CodeVisitor {
- // not enough information, symbol will be created while processing the tree
- next ();
- +
- + if (current.comment == null) {
- + current.comment = parse_symbol_doc ();
- + } else {
- + parse_symbol_doc ();
- + }
- +
- bool no_array_length = false;
- current.base_type = element_get_type (parse_type (null, null, true), true, ref no_array_length);
- @@ -1949,6 +1953,44 @@ public class Vala.GirParser : CodeVisitor {
- }
- }
- + GirComment? parse_symbol_doc () {
- + if (reader.name != "doc") {
- + return null;
- + }
- +
- + start_element ("doc");
- + next ();
- +
- + GirComment? comment = null;
- +
- + if (current_token == MarkupTokenType.TEXT) {
- + comment = new GirComment (reader.content, current.source_reference);
- + next ();
- + }
- +
- + end_element ("doc");
- + return comment;
- + }
- +
- + Comment? parse_doc () {
- + if (reader.name != "doc") {
- + return null;
- + }
- +
- + start_element ("doc");
- + next ();
- +
- + Comment? comment = null;
- +
- + if (current_token == MarkupTokenType.TEXT) {
- + comment = new Comment (reader.content, current.source_reference);
- + next ();
- + }
- +
- + end_element ("doc");
- + return comment;
- + }
- +
- void parse_enumeration (string element_name = "enumeration", bool error_domain = false) {
- start_element (element_name);
- push_node (element_get_name (), true);
- @@ -1974,7 +2016,9 @@ public class Vala.GirParser : CodeVisitor {
- string common_prefix = null;
- next ();
- -
- +
- + sym.comment = parse_symbol_doc ();
- +
- while (current_token == MarkupTokenType.START_ELEMENT) {
- if (!push_metadata ()) {
- skip_element ();
- @@ -2024,6 +2068,8 @@ public class Vala.GirParser : CodeVisitor {
- current.symbol = ev;
- next ();
- + ev.comment = parse_symbol_doc ();
- +
- pop_node ();
- end_element ("member");
- }
- @@ -2042,16 +2088,21 @@ public class Vala.GirParser : CodeVisitor {
- current.symbol = ec;
- next ();
- + ec.comment = parse_symbol_doc ();
- +
- pop_node ();
- end_element ("member");
- }
- - DataType parse_return_value (out string? ctype = null, out int array_length_idx = null, out bool no_array_length = null, out bool array_null_terminated = null) {
- + DataType parse_return_value (out string? ctype = null, out int array_length_idx = null, out bool no_array_length = null, out bool array_null_terminated = null, out Comment? comment = null) {
- start_element ("return-value");
- string transfer = reader.get_attribute ("transfer-ownership");
- string allow_none = reader.get_attribute ("allow-none");
- next ();
- +
- + comment = parse_doc ();
- +
- var transfer_elements = transfer != "container";
- var type = parse_type (out ctype, out array_length_idx, transfer_elements, out no_array_length, out array_null_terminated);
- if (transfer == "full" || transfer == "container") {
- @@ -2065,7 +2116,7 @@ public class Vala.GirParser : CodeVisitor {
- return type;
- }
- - Parameter parse_parameter (out int array_length_idx = null, out int closure_idx = null, out int destroy_idx = null, out string? scope = null, string? default_name = null) {
- + Parameter parse_parameter (out int array_length_idx = null, out int closure_idx = null, out int destroy_idx = null, out string? scope = null, out Comment? comment, string? default_name = null) {
- Parameter param;
- array_length_idx = -1;
- @@ -2107,6 +2158,9 @@ public class Vala.GirParser : CodeVisitor {
- }
- next ();
- +
- + comment = parse_doc ();
- +
- if (reader.name == "varargs") {
- start_element ("varargs");
- next ();
- @@ -2349,6 +2403,9 @@ public class Vala.GirParser : CodeVisitor {
- bool first_field = true;
- next ();
- +
- + st.comment = parse_symbol_doc ();
- +
- while (current_token == MarkupTokenType.START_ELEMENT) {
- if (!push_metadata ()) {
- if (first_field && reader.name == "field") {
- @@ -2408,6 +2465,9 @@ public class Vala.GirParser : CodeVisitor {
- cl.external = true;
- next ();
- +
- + cl.comment = parse_symbol_doc ();
- +
- var first_field = true;
- while (current_token == MarkupTokenType.START_ELEMENT) {
- if (!push_metadata ()) {
- @@ -2486,6 +2546,9 @@ public class Vala.GirParser : CodeVisitor {
- next ();
- +
- + iface.comment = parse_symbol_doc ();
- +
- while (current_token == MarkupTokenType.START_ELEMENT) {
- if (!push_metadata ()) {
- skip_element ();
- @@ -2528,12 +2591,16 @@ public class Vala.GirParser : CodeVisitor {
- string allow_none = reader.get_attribute ("allow-none");
- next ();
- +
- + var comment = parse_symbol_doc ();
- +
- var type = parse_type ();
- bool no_array_length = true;
- type = element_get_type (type, true, ref no_array_length);
- var field = new Field (current.name, type, null, current.source_reference);
- field.access = SymbolAccessibility.PUBLIC;
- + field.comment = comment;
- if (type is ArrayType) {
- if (no_array_length) {
- field.set_attribute_bool ("CCode", "array_length", false);
- @@ -2554,11 +2621,15 @@ public class Vala.GirParser : CodeVisitor {
- push_node (element_get_name().replace ("-", "_"), false);
- next ();
- +
- + var comment = parse_symbol_doc ();
- +
- bool no_array_length;
- bool array_null_terminated;
- var type = parse_type (null, null, false, out no_array_length, out array_null_terminated);
- type = element_get_type (type, true, ref no_array_length);
- var prop = new Property (current.name, type, null, null, current.source_reference);
- + prop.comment = comment;
- prop.access = SymbolAccessibility.PUBLIC;
- prop.external = true;
- if (current.parent.symbol is Interface) {
- @@ -2612,13 +2683,23 @@ public class Vala.GirParser : CodeVisitor {
- string invoker = reader.get_attribute ("invoker");
- next ();
- +
- + var comment = parse_symbol_doc ();
- +
- DataType return_type;
- string return_ctype = null;
- int return_array_length_idx = -1;
- bool return_no_array_length = false;
- bool return_array_null_terminated = false;
- if (current_token == MarkupTokenType.START_ELEMENT && reader.name == "return-value") {
- - return_type = parse_return_value (out return_ctype, out return_array_length_idx, out return_no_array_length, out return_array_null_terminated);
- + Comment? return_comment;
- + return_type = parse_return_value (out return_ctype, out return_array_length_idx, out return_no_array_length, out return_array_null_terminated, out return_comment);
- + if (return_comment != null) {
- + if (comment == null) {
- + comment = new GirComment (null, current.source_reference);
- + }
- + comment.return_content = return_comment;
- + }
- } else {
- return_type = new VoidType ();
- }
- @@ -2652,6 +2733,7 @@ public class Vala.GirParser : CodeVisitor {
- }
- s.access = SymbolAccessibility.PUBLIC;
- + s.comment = comment;
- s.external = true;
- if (s is Method) {
- @@ -2739,8 +2821,9 @@ public class Vala.GirParser : CodeVisitor {
- int array_length_idx, closure_idx, destroy_idx;
- string scope;
- string default_param_name = null;
- + Comment? param_comment;
- default_param_name = "arg%d".printf (parameters.size);
- - var param = parse_parameter (out array_length_idx, out closure_idx, out destroy_idx, out scope, default_param_name);
- + var param = parse_parameter (out array_length_idx, out closure_idx, out destroy_idx, out scope, out param_comment, default_param_name);
- if (array_length_idx != -1) {
- current.array_length_parameters.add (array_length_idx);
- }
- @@ -2750,6 +2833,14 @@ public class Vala.GirParser : CodeVisitor {
- if (destroy_idx != -1) {
- current.destroy_parameters.add (destroy_idx);
- }
- + if (param_comment != null) {
- + if (comment == null) {
- + comment = new GirComment (null, s.source_reference);
- + s.comment = comment;
- + }
- +
- + comment.add_content_for_parameter ((param.ellipsis)? "..." : param.name, param_comment);
- + }
- var info = new ParameterInfo (param, array_length_idx, closure_idx, destroy_idx);
- @@ -2808,6 +2899,9 @@ public class Vala.GirParser : CodeVisitor {
- cl.external = true;
- next ();
- +
- + cl.comment = parse_symbol_doc ();
- +
- while (current_token == MarkupTokenType.START_ELEMENT) {
- if (!push_metadata ()) {
- skip_element ();
- @@ -2852,6 +2946,9 @@ public class Vala.GirParser : CodeVisitor {
- st.external = true;
- next ();
- +
- + st.comment = parse_symbol_doc ();
- +
- while (current_token == MarkupTokenType.START_ELEMENT) {
- if (!push_metadata ()) {
- skip_element ();
- @@ -2886,10 +2983,14 @@ public class Vala.GirParser : CodeVisitor {
- push_node (element_get_name (), false);
- next ();
- +
- + var comment = parse_symbol_doc ();
- +
- var type = parse_type ();
- var c = new Constant (current.name, type, null, current.source_reference);
- current.symbol = c;
- c.access = SymbolAccessibility.PUBLIC;
- + c.comment = comment;
- c.external = true;
- pop_node ();
- @@ -3016,6 +3117,7 @@ public class Vala.GirParser : CodeVisitor {
- // threat target="none" as a new struct
- st.base_type = base_type;
- }
- + st.comment = alias.comment;
- st.external = true;
- st.set_simple_type (simple_type);
- alias.symbol = st;
- @@ -3025,6 +3127,7 @@ public class Vala.GirParser : CodeVisitor {
- if (base_type != null) {
- cl.add_base_type (base_type);
- }
- + cl.comment = alias.comment;
- cl.external = true;
- alias.symbol = cl;
- }
- @@ -3295,6 +3398,7 @@ public class Vala.GirParser : CodeVisitor {
- finish_method_node.process (this);
- var finish_method = (Method) finish_method_node.symbol;
- if (finish_method is CreationMethod) {
- +// TODO
- method = new CreationMethod (((CreationMethod) finish_method).class_name, null, m.source_reference);
- method.access = m.access;
- method.binding = m.binding;
- --
- 1.7.7.4
Add Comment
Please, Sign In to add comment