[breaking] Move error_logged() from logger to parser

This commit is contained in:
Jonathan Müller 2017-06-27 10:58:24 +02:00
commit 44708fff76
9 changed files with 47 additions and 20 deletions

View file

@ -94,10 +94,12 @@ std::unique_ptr<cpp_entity> detail::parse_cpp_enum(const detail::parse_context&
}
catch (parse_error& ex)
{
context.error = true;
context.logger->log("libclang parser", ex.get_diagnostic());
}
catch (std::logic_error& ex)
{
context.error = true;
context.logger->log("libclang parser",
diagnostic{ex.what(), make_location(child), severity::error});
}

View file

@ -46,10 +46,12 @@ namespace
}
catch (detail::parse_error& ex)
{
context.error = true;
context.logger->log("libclang parser", ex.get_diagnostic());
}
catch (std::logic_error& ex)
{
context.error = true;
context.logger->log("libclang parser",
diagnostic{ex.what(), detail::make_location(child),
severity::error});

View file

@ -400,8 +400,12 @@ std::unique_ptr<cpp_file> libclang_parser::do_parse(const cpp_entity_index& idx,
auto include_iter = preprocessed.includes.begin();
// convert entity hierarchies
detail::parse_context context{tu.get(), file, type_safe::ref(logger()), type_safe::ref(idx),
detail::comment_context(preprocessed.comments)};
detail::parse_context context{tu.get(),
file,
type_safe::ref(logger()),
type_safe::ref(idx),
detail::comment_context(preprocessed.comments),
false};
detail::visit_tu(tu, path.c_str(), [&](const CXCursor& cur) {
if (clang_getCursorKind(cur) == CXCursor_InclusionDirective)
{
@ -439,10 +443,14 @@ std::unique_ptr<cpp_file> libclang_parser::do_parse(const cpp_entity_index& idx,
builder.add_unmatched_comment(std::move(c.comment));
}
if (context.error)
set_error();
return builder.finish(idx);
}
catch (detail::parse_error& ex)
{
logger().log("libclang parser", ex.get_diagnostic());
set_error();
return nullptr;
}

View file

@ -230,11 +230,13 @@ std::unique_ptr<cpp_entity> detail::parse_entity(const detail::parse_context& co
}
catch (parse_error& ex)
{
context.error = true;
context.logger->log("libclang parser", ex.get_diagnostic());
return nullptr;
}
catch (std::logic_error& ex)
{
context.error = true;
context.logger->log("libclang parser",
diagnostic{ex.what(), detail::make_location(cur), severity::error});
return nullptr;

View file

@ -62,6 +62,7 @@ namespace cppast
type_safe::object_ref<const diagnostic_logger> logger;
type_safe::object_ref<const cpp_entity_index> idx;
comment_context comments;
mutable bool error;
};
// parse default value of variable, function parameter...

View file

@ -13,9 +13,7 @@ using namespace cppast;
bool diagnostic_logger::log(const char* source, const diagnostic& d) const
{
if (d.severity == severity::error || d.severity == severity::critical)
error_ = true;
else if (!verbose_ && d.severity == severity::debug)
if (!verbose_ && d.severity == severity::debug)
return false;
return do_log(source, d);
}