Add ability to set semanitc parent of a cpp_variable

This commit is contained in:
Jonathan Müller 2022-12-07 12:47:42 +01:00
commit 12432de30d
2 changed files with 17 additions and 17 deletions

View file

@ -27,16 +27,16 @@ public:
static std::unique_ptr<cpp_variable> build(const cpp_entity_index& idx, cpp_entity_id id, static std::unique_ptr<cpp_variable> build(const cpp_entity_index& idx, cpp_entity_id id,
std::string name, std::unique_ptr<cpp_type> type, std::string name, std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_expression> def, std::unique_ptr<cpp_expression> def,
cpp_storage_class_specifiers spec, cpp_storage_class_specifiers spec, bool is_constexpr,
bool is_constexpr); type_safe::optional<cpp_entity_ref> semantic_parent
= {});
/// \returns A newly created variable that is a declaration. /// \returns A newly created variable that is a declaration.
/// A declaration will not be registered and it does not have the default value. /// A declaration will not be registered and it does not have the default value.
static std::unique_ptr<cpp_variable> build_declaration(cpp_entity_id definition_id, static std::unique_ptr<cpp_variable> build_declaration(
std::string name, cpp_entity_id definition_id, std::string name, std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_type> type, cpp_storage_class_specifiers spec, bool is_constexpr,
cpp_storage_class_specifiers spec, type_safe::optional<cpp_entity_ref> semantic_parent = {});
bool is_constexpr);
/// \returns The [cppast::cpp_storage_specifiers]() on that variable. /// \returns The [cppast::cpp_storage_specifiers]() on that variable.
cpp_storage_class_specifiers storage_class() const noexcept cpp_storage_class_specifiers storage_class() const noexcept

View file

@ -12,26 +12,26 @@ cpp_entity_kind cpp_variable::kind() noexcept
return cpp_entity_kind::variable_t; return cpp_entity_kind::variable_t;
} }
std::unique_ptr<cpp_variable> cpp_variable::build(const cpp_entity_index& idx, cpp_entity_id id, std::unique_ptr<cpp_variable> cpp_variable::build(
std::string name, std::unique_ptr<cpp_type> type, const cpp_entity_index& idx, cpp_entity_id id, std::string name, std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_expression> def, std::unique_ptr<cpp_expression> def, cpp_storage_class_specifiers spec, bool is_constexpr,
cpp_storage_class_specifiers spec, type_safe::optional<cpp_entity_ref> semantic_parent)
bool is_constexpr)
{ {
auto result = std::unique_ptr<cpp_variable>( auto result = std::unique_ptr<cpp_variable>(
new cpp_variable(std::move(name), std::move(type), std::move(def), spec, is_constexpr)); new cpp_variable(std::move(name), std::move(type), std::move(def), spec, is_constexpr));
result->set_semantic_parent(std::move(semantic_parent));
idx.register_definition(std::move(id), type_safe::cref(*result)); idx.register_definition(std::move(id), type_safe::cref(*result));
return result; return result;
} }
std::unique_ptr<cpp_variable> cpp_variable::build_declaration(cpp_entity_id definition_id, std::unique_ptr<cpp_variable> cpp_variable::build_declaration(
std::string name, cpp_entity_id definition_id, std::string name, std::unique_ptr<cpp_type> type,
std::unique_ptr<cpp_type> type, cpp_storage_class_specifiers spec, bool is_constexpr,
cpp_storage_class_specifiers spec, type_safe::optional<cpp_entity_ref> semantic_parent)
bool is_constexpr)
{ {
auto result = std::unique_ptr<cpp_variable>( auto result = std::unique_ptr<cpp_variable>(
new cpp_variable(std::move(name), std::move(type), nullptr, spec, is_constexpr)); new cpp_variable(std::move(name), std::move(type), nullptr, spec, is_constexpr));
result->set_semantic_parent(std::move(semantic_parent));
result->mark_declaration(definition_id); result->mark_declaration(definition_id);
return result; return result;
} }