Properly handle unnecessary semicolons

Now fixes #45.
This commit is contained in:
Jonathan Müller 2018-03-19 21:12:40 +01:00
commit 003207361a
3 changed files with 19 additions and 8 deletions

View file

@ -78,6 +78,9 @@ namespace
simple_tokenizer tokenizer(tu, inc > 0 ? clang_getRange(loc, loc_after) : simple_tokenizer tokenizer(tu, inc > 0 ? clang_getRange(loc, loc_after) :
clang_getRange(loc_after, loc)); clang_getRange(loc_after, loc));
if (tokenizer.size() == 0u)
return false;
detail::cxstring spelling(clang_getTokenSpelling(tu, tokenizer[0u])); detail::cxstring spelling(clang_getTokenSpelling(tu, tokenizer[0u]));
return spelling == token_str; return spelling == token_str;
} }

View file

@ -212,18 +212,15 @@ std::unique_ptr<cpp_entity> detail::parse_entity(const detail::parse_context& co
if (!clang_isAttribute(clang_getCursorKind(cur))) if (!clang_isAttribute(clang_getCursorKind(cur)))
{ {
auto msg = detail::format("unhandled cursor of kind '",
detail::get_cursor_kind_spelling(cur).c_str(), "'");
context.logger->log("libclang parser",
format_diagnostic(severity::warning, detail::make_location(cur),
"unhandled cursor of kind '",
detail::get_cursor_kind_spelling(cur).c_str(), "'"));
// build unexposed entity // build unexposed entity
auto name = detail::get_cursor_name(cur);
detail::cxtokenizer tokenizer(context.tu, context.file, cur); detail::cxtokenizer tokenizer(context.tu, context.file, cur);
detail::cxtoken_stream stream(tokenizer, cur); detail::cxtoken_stream stream(tokenizer, cur);
auto spelling = detail::to_string(stream, stream.end()); auto spelling = detail::to_string(stream, stream.end());
if (spelling.begin() + 1 == spelling.end() && spelling.front().spelling == ";")
// unnecessary semicolon
return nullptr;
auto name = detail::get_cursor_name(cur);
std::unique_ptr<cppast::cpp_entity> entity; std::unique_ptr<cppast::cpp_entity> entity;
if (name.empty()) if (name.empty())
@ -233,6 +230,14 @@ std::unique_ptr<cpp_entity> detail::parse_entity(const detail::parse_context& co
name.c_str(), std::move(spelling)); name.c_str(), std::move(spelling));
context.comments.match(*entity, cur); context.comments.match(*entity, cur);
auto msg = detail::format("unhandled cursor of kind '",
detail::get_cursor_kind_spelling(cur).c_str(), "'");
context.logger->log("libclang parser",
format_diagnostic(severity::warning, detail::make_location(cur),
"unhandled cursor of kind '",
detail::get_cursor_kind_spelling(cur).c_str(), "'"));
return entity; return entity;
} }
else else

View file

@ -37,6 +37,9 @@ namespace {}
/// namespace f{ /// namespace f{
/// } /// }
namespace e::f {} namespace e::f {}
// unnecessary semicolon at end of file
;
)"; )";
auto file = parse({}, "cpp_namespace.cpp", code); auto file = parse({}, "cpp_namespace.cpp", code);