Throw exception on multiple parse error
This commit is contained in:
parent
23888ca9c4
commit
204961b7b1
5 changed files with 42 additions and 5 deletions
|
|
@ -62,11 +62,18 @@ namespace cppast
|
|||
class cpp_entity_index
|
||||
{
|
||||
public:
|
||||
/// Exception thrown on duplicate entity definition.
|
||||
class duplicate_definition_error : public std::logic_error
|
||||
{
|
||||
public:
|
||||
duplicate_definition_error();
|
||||
};
|
||||
|
||||
/// \effects Registers a new [cppast::cpp_entity]() which is a definition.
|
||||
/// It will override any previously registered declarations of the same entity.
|
||||
/// \requires If the entity has been registered before, it must be as declaration,
|
||||
/// and the entity must live as long as the index lives.
|
||||
/// \requires The entity must not be a namespace.
|
||||
/// \throws duplicate_defintion_error if the entity has been registered as definition before.
|
||||
/// \requires The entity must live as long as the index lives,
|
||||
/// and it must not be a namespace.
|
||||
/// \notes This operation is thread safe.
|
||||
void register_definition(cpp_entity_id id,
|
||||
type_safe::object_ref<const cpp_entity> entity) const;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@
|
|||
|
||||
using namespace cppast;
|
||||
|
||||
cpp_entity_index::duplicate_definition_error::duplicate_definition_error()
|
||||
: std::logic_error("duplicate registration of entity definition")
|
||||
{
|
||||
}
|
||||
|
||||
void cpp_entity_index::register_definition(cpp_entity_id id,
|
||||
type_safe::object_ref<const cpp_entity> entity) const
|
||||
{
|
||||
|
|
@ -21,8 +26,8 @@ void cpp_entity_index::register_definition(cpp_entity_id
|
|||
{
|
||||
// already in map, override declaration
|
||||
auto& value = result.first->second;
|
||||
DEBUG_ASSERT(!value.is_definition, detail::precondition_error_handler{},
|
||||
"duplicate entity registration");
|
||||
if (value.is_definition)
|
||||
throw duplicate_definition_error();
|
||||
value.is_definition = true;
|
||||
value.entity = entity;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,6 +96,11 @@ std::unique_ptr<cpp_entity> detail::parse_cpp_enum(const detail::parse_context&
|
|||
{
|
||||
context.logger->log("libclang parser", ex.get_diagnostic());
|
||||
}
|
||||
catch (std::logic_error& ex)
|
||||
{
|
||||
context.logger->log("libclang parser",
|
||||
diagnostic{ex.what(), make_location(child), severity::error});
|
||||
}
|
||||
});
|
||||
if (clang_isCursorDefinition(cur))
|
||||
return builder.finish(*context.idx, get_entity_id(cur), std::move(semantic_parent));
|
||||
|
|
|
|||
|
|
@ -48,6 +48,12 @@ namespace
|
|||
{
|
||||
context.logger->log("libclang parser", ex.get_diagnostic());
|
||||
}
|
||||
catch (std::logic_error& ex)
|
||||
{
|
||||
context.logger->log("libclang parser",
|
||||
diagnostic{ex.what(), detail::make_location(child),
|
||||
severity::error});
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
|
|
@ -66,6 +72,14 @@ namespace
|
|||
{
|
||||
context.logger->log("libclang parser", ex.get_diagnostic());
|
||||
}
|
||||
catch (std::logic_error& ex)
|
||||
{
|
||||
context.logger->log("libclang parser",
|
||||
diagnostic{ex.what(),
|
||||
detail::make_location(
|
||||
clang_Cursor_getArgument(cur, unsigned(i))),
|
||||
severity::error});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -233,6 +233,12 @@ catch (parse_error& ex)
|
|||
context.logger->log("libclang parser", ex.get_diagnostic());
|
||||
return nullptr;
|
||||
}
|
||||
catch (std::logic_error& ex)
|
||||
{
|
||||
context.logger->log("libclang parser",
|
||||
diagnostic{ex.what(), detail::make_location(cur), severity::error});
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<cpp_entity> detail::parse_cpp_static_assert(const detail::parse_context& context,
|
||||
const CXCursor& cur)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue