summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe DUFRAIGNE <j.dufraigne@gmail.com>2016-10-30 03:57:07 +0000
committerJean-Philippe DUFRAIGNE <j.dufraigne@gmail.com>2016-10-31 14:15:27 +0000
commit2744b23a3e12b5938f7865e748639eb3be848e07 (patch)
treeaf7d6599c108046c280d85a386b1de92dd75ac83
parentebfa0839ede25ed807311033532bdaa8820b3f07 (diff)
Use iterators for comment children partial fix #166
-rwxr-xr-xsrc/clang.rs39
-rw-r--r--src/ir/annotations.rs4
2 files changed, 28 insertions, 15 deletions
diff --git a/src/clang.rs b/src/clang.rs
index 1bb219b0..a69bb5cf 100755
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -791,19 +791,12 @@ impl Comment {
}
}
- /// Get the number of children this comment node has.
- pub fn num_children(&self) -> c_uint {
- unsafe {
- clang_Comment_getNumChildren(self.x)
- }
- }
-
- /// Get this comment's `idx`th child comment
- pub fn get_child(&self, idx: c_uint) -> Option<Comment> {
- if idx >= self.num_children() {
- None
- } else {
- Some(Comment { x: unsafe { clang_Comment_getChild(self.x, idx) } })
+ /// Get this comment's children comment
+ pub fn get_children(&self) -> CommentChildrenIterator {
+ CommentChildrenIterator {
+ parent: self.x,
+ length: unsafe { clang_Comment_getNumChildren(self.x) },
+ index: 0
}
}
@@ -852,6 +845,26 @@ impl Comment {
}
}
+/// An iterator for a comment's children
+pub struct CommentChildrenIterator {
+ parent: CXComment,
+ length: c_uint,
+ index: c_uint
+}
+
+impl Iterator for CommentChildrenIterator {
+ type Item = Comment;
+ fn next(&mut self) -> Option<Comment> {
+ if self.index < self.length {
+ let idx = self.index;
+ self.index += 1;
+ Some( Comment { x: unsafe { clang_Comment_getChild(self.parent, idx) } } )
+ } else {
+ None
+ }
+ }
+}
+
/// A source file.
pub struct File {
x: CXFile
diff --git a/src/ir/annotations.rs b/src/ir/annotations.rs
index 9b141372..44c0190c 100644
--- a/src/ir/annotations.rs
+++ b/src/ir/annotations.rs
@@ -153,8 +153,8 @@ impl Annotations {
}
}
- for i in 0..comment.num_children() {
- self.parse(&comment.get_child(i).unwrap(), matched);
+ for child in comment.get_children() {
+ self.parse(&child, matched);
}
}
}