diff options
-rwxr-xr-x | src/clang.rs | 39 | ||||
-rw-r--r-- | src/ir/annotations.rs | 4 |
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); } } } |