Add semantic parent to forward declarable entities
This commit is contained in:
parent
cf7ea80768
commit
599f2bbff8
20 changed files with 260 additions and 109 deletions
|
|
@ -178,7 +178,8 @@ namespace cppast
|
|||
/// \effects Registers the class in the [cppast::cpp_entity_index](),
|
||||
/// using the given [cppast::cpp_entity_id]().
|
||||
/// \returns The finished class.
|
||||
std::unique_ptr<cpp_class> finish(const cpp_entity_index& idx, cpp_entity_id id);
|
||||
std::unique_ptr<cpp_class> finish(const cpp_entity_index& idx, cpp_entity_id id,
|
||||
type_safe::optional<cpp_entity_ref> semantic_parent);
|
||||
|
||||
/// \effects Marks the class as forward declaration.
|
||||
/// \returns The finished class.
|
||||
|
|
@ -187,7 +188,7 @@ namespace cppast
|
|||
|
||||
/// \effects Returns the finished class without registering it.
|
||||
/// \notes This is intended for templated classes only.
|
||||
std::unique_ptr<cpp_class> finish();
|
||||
std::unique_ptr<cpp_class> finish(type_safe::optional<cpp_entity_ref> semantic_parent);
|
||||
|
||||
/// \effects Returns the finish class without registering it and marks it as forward declaration.
|
||||
/// \notes This is intended for templated classes only.
|
||||
|
|
|
|||
|
|
@ -85,8 +85,11 @@ namespace cppast
|
|||
/// \effects Registers the enum in the [cppast::cpp_entity_index](),
|
||||
/// using the given [cppast::cpp_entity_id]().
|
||||
/// \returns The finished enum.
|
||||
std::unique_ptr<cpp_enum> finish(const cpp_entity_index& idx, cpp_entity_id id) noexcept
|
||||
std::unique_ptr<cpp_enum> finish(
|
||||
const cpp_entity_index& idx, cpp_entity_id id,
|
||||
type_safe::optional<cpp_entity_ref> semantic_parent) noexcept
|
||||
{
|
||||
enum_->set_semantic_parent(std::move(semantic_parent));
|
||||
idx.register_definition(std::move(id), type_safe::ref(*enum_));
|
||||
return std::move(enum_);
|
||||
}
|
||||
|
|
@ -96,7 +99,7 @@ namespace cppast
|
|||
std::unique_ptr<cpp_enum> finish_declaration(const cpp_entity_index& idx,
|
||||
cpp_entity_id definition_id) noexcept
|
||||
{
|
||||
enum_->set_definition(definition_id);
|
||||
enum_->mark_declaration(definition_id);
|
||||
idx.register_forward_declaration(std::move(definition_id), type_safe::ref(*enum_));
|
||||
return std::move(enum_);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,22 @@ namespace cppast
|
|||
return definition_;
|
||||
}
|
||||
|
||||
/// \returns A reference to the semantic parent of the entity.
|
||||
/// This applies only to out-of-line definitions
|
||||
/// and is the entity which owns the declaration.
|
||||
const type_safe::optional<cpp_entity_ref>& semantic_parent() const noexcept
|
||||
{
|
||||
return semantic_parent_;
|
||||
}
|
||||
|
||||
/// \returns The name of the semantic parent, if it has own,
|
||||
/// else the empty string.
|
||||
/// \notes This may include template parameters.
|
||||
std::string semantic_scope() const noexcept
|
||||
{
|
||||
return semantic_parent_.map(&cpp_entity_ref::name).value_or("");
|
||||
}
|
||||
|
||||
protected:
|
||||
/// \effects Marks the entity as definition.
|
||||
/// \notes If it is not a definition,
|
||||
|
|
@ -49,15 +65,22 @@ namespace cppast
|
|||
|
||||
~cpp_forward_declarable() noexcept = default;
|
||||
|
||||
/// \effects Sets the definition of the entity,
|
||||
/// \effects Sets the definition entity,
|
||||
/// marking it as a forward declaration.
|
||||
void set_definition(cpp_entity_id def) noexcept
|
||||
void mark_declaration(cpp_entity_id def) noexcept
|
||||
{
|
||||
definition_ = std::move(def);
|
||||
}
|
||||
|
||||
/// \effects Sets the semantic parent of the entity.
|
||||
void set_semantic_parent(type_safe::optional<cpp_entity_ref> semantic_parent) noexcept
|
||||
{
|
||||
semantic_parent_ = std::move(semantic_parent);
|
||||
}
|
||||
|
||||
private:
|
||||
type_safe::optional<cpp_entity_id> definition_;
|
||||
type_safe::optional<cpp_entity_ref> semantic_parent_;
|
||||
type_safe::optional<cpp_entity_id> definition_;
|
||||
};
|
||||
|
||||
/// \returns Whether or not the given entity is a definition.
|
||||
|
|
|
|||
|
|
@ -137,14 +137,16 @@ namespace cppast
|
|||
/// Else marks it as a declaration.
|
||||
/// \returns The finished function.
|
||||
std::unique_ptr<T> finish(const cpp_entity_index& idx, cpp_entity_id id,
|
||||
cpp_function_body_kind body_kind)
|
||||
cpp_function_body_kind body_kind,
|
||||
type_safe::optional<cpp_entity_ref> semantic_parent)
|
||||
{
|
||||
function->body_ = body_kind;
|
||||
function->set_semantic_parent(std::move(semantic_parent));
|
||||
if (cppast::is_definition(body_kind))
|
||||
idx.register_definition(std::move(id), type_safe::ref(*function));
|
||||
else
|
||||
{
|
||||
function->set_definition(id);
|
||||
function->mark_declaration(id);
|
||||
idx.register_forward_declaration(std::move(id), type_safe::ref(*function));
|
||||
}
|
||||
return std::move(function);
|
||||
|
|
@ -152,11 +154,13 @@ namespace cppast
|
|||
|
||||
/// \returns The finished function without registering it.
|
||||
/// \notes This is intended for templated functions only.
|
||||
std::unique_ptr<T> finish(cpp_entity_id id, cpp_function_body_kind body_kind)
|
||||
std::unique_ptr<T> finish(cpp_entity_id id, cpp_function_body_kind body_kind,
|
||||
type_safe::optional<cpp_entity_ref> semantic_parent)
|
||||
{
|
||||
if (!cppast::is_definition(body_kind))
|
||||
function->set_definition(id);
|
||||
function->body_ = body_kind;
|
||||
function->set_semantic_parent(std::move(semantic_parent));
|
||||
if (!cppast::is_definition(body_kind))
|
||||
function->mark_declaration(id);
|
||||
return std::move(function);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue