Fix comment matching for includes not on top of the file
See foonathan/standardese#83.
This commit is contained in:
parent
cb764832b7
commit
9df3b39e1e
4 changed files with 23 additions and 5 deletions
|
|
@ -489,7 +489,9 @@ std::unique_ptr<cpp_file> libclang_parser::do_parse(const cpp_entity_index& idx,
|
||||||
auto include =
|
auto include =
|
||||||
cpp_include_directive::build(std::move(include_iter->file), include_iter->kind,
|
cpp_include_directive::build(std::move(include_iter->file), include_iter->kind,
|
||||||
detail::get_cursor_name(cur).c_str());
|
detail::get_cursor_name(cur).c_str());
|
||||||
context.comments.match(*include, include_iter->line);
|
context.comments.match(*include, include_iter->line,
|
||||||
|
false); // must not skip comments,
|
||||||
|
// includes are not reported in order
|
||||||
builder.add_child(std::move(include));
|
builder.add_child(std::move(include));
|
||||||
|
|
||||||
++include_iter;
|
++include_iter;
|
||||||
|
|
|
||||||
|
|
@ -85,13 +85,17 @@ void detail::comment_context::match(cpp_entity& e, const CXCursor& cur) const
|
||||||
match(e, line);
|
match(e, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void detail::comment_context::match(cpp_entity& e, unsigned line) const
|
void detail::comment_context::match(cpp_entity& e, unsigned line, bool skip_comments) const
|
||||||
{
|
{
|
||||||
// find comment
|
// find comment
|
||||||
|
auto save = cur_;
|
||||||
while (cur_ != end_ && cur_->line + 1 < line)
|
while (cur_ != end_ && cur_->line + 1 < line)
|
||||||
++cur_;
|
++cur_;
|
||||||
if (cur_ != end_ && cur_->matches(e, line))
|
if (cur_ != end_ && cur_->matches(e, line))
|
||||||
e.set_comment(std::move(cur_++->comment));
|
e.set_comment(std::move(cur_++->comment));
|
||||||
|
|
||||||
|
if (!skip_comments)
|
||||||
|
cur_ = save;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ namespace cppast
|
||||||
// must be called for entities that want an associated comment
|
// must be called for entities that want an associated comment
|
||||||
// must be called *BEFORE* the children are added
|
// must be called *BEFORE* the children are added
|
||||||
void match(cpp_entity& e, const CXCursor& cur) const;
|
void match(cpp_entity& e, const CXCursor& cur) const;
|
||||||
void match(cpp_entity& e, unsigned line) const;
|
void match(cpp_entity& e, unsigned line, bool skip_comments = true) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable pp_doc_comment* cur_;
|
mutable pp_doc_comment* cur_;
|
||||||
|
|
|
||||||
|
|
@ -279,6 +279,10 @@ g(h)
|
||||||
i */
|
i */
|
||||||
using i = int;
|
using i = int;
|
||||||
|
|
||||||
|
/// cstddef
|
||||||
|
/// cstddef
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
/// j
|
/// j
|
||||||
/// j
|
/// j
|
||||||
template <typename T/**/>
|
template <typename T/**/>
|
||||||
|
|
@ -300,7 +304,15 @@ void j();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
auto add = 0u;
|
||||||
for (auto& comment : file->unmatched_comments())
|
for (auto& comment : file->unmatched_comments())
|
||||||
REQUIRE(comment.content == "u");
|
{
|
||||||
REQUIRE((file->unmatched_comments().size() == 3u));
|
if (comment.content == "cstddef\ncstddef")
|
||||||
|
// happens if include parsing is not supported
|
||||||
|
// error is still going to be detected because if it is supported, the entity will be matched above
|
||||||
|
add = 1u;
|
||||||
|
else
|
||||||
|
REQUIRE(comment.content == "u");
|
||||||
|
}
|
||||||
|
REQUIRE((file->unmatched_comments().size() == 3u + add));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue