Add support for consteval

This commit is contained in:
Minh Lu 2021-02-16 15:45:30 -08:00 committed by Jonathan Müller
commit 1b03d106ab
6 changed files with 250 additions and 9 deletions

View file

@ -226,6 +226,12 @@ public:
{
function->constexpr_ = true;
}
/// \effects Marks the function as `consteval`.
void is_consteval()
{
function->consteval_ = true;
}
};
/// \returns A reference to the return [cppast::cpp_type]().
@ -248,17 +254,24 @@ public:
return constexpr_;
}
/// \returns Whether the function is marked `consteval`.
bool is_consteval() const noexcept
{
return consteval_;
}
private:
cpp_entity_kind do_get_entity_kind() const noexcept override;
cpp_function(std::string name, std::unique_ptr<cpp_type> ret)
: cpp_function_base(std::move(name)), return_type_(std::move(ret)),
storage_(cpp_storage_class_auto), constexpr_(false)
storage_(cpp_storage_class_auto), constexpr_(false), consteval_(false)
{}
std::unique_ptr<cpp_type> return_type_;
cpp_storage_class_specifiers storage_;
bool constexpr_;
bool consteval_;
};
} // namespace cppast

View file

@ -100,6 +100,12 @@ public:
return constexpr_;
}
/// \returns Whether or not the member function is `consteval`.
bool is_consteval() const noexcept
{
return consteval_;
}
protected:
/// Builder class for member functions.
template <typename T>
@ -132,6 +138,12 @@ protected:
static_cast<cpp_member_function_base&>(*this->function).constexpr_ = true;
}
/// \effects Marks the function as `consteval`.
void is_consteval() noexcept
{
static_cast<cpp_member_function_base&>(*this->function).consteval_ = true;
}
protected:
basic_member_builder() noexcept = default;
};
@ -139,7 +151,7 @@ protected:
/// \effects Sets name and return type, as well as the rest to defaults.
cpp_member_function_base(std::string name, std::unique_ptr<cpp_type> return_type)
: cpp_function_base(std::move(name)), return_type_(std::move(return_type)), cv_(cpp_cv_none),
ref_(cpp_ref_none), constexpr_(false)
ref_(cpp_ref_none), constexpr_(false), consteval_(false)
{}
protected:
@ -151,6 +163,7 @@ private:
cpp_cv cv_;
cpp_reference ref_;
bool constexpr_;
bool consteval_;
};
/// A [cppast::cpp_entity]() modelling a member function.
@ -239,6 +252,12 @@ public:
{
function->constexpr_ = true;
}
/// \effects Marks the constructor `consteval`.
void is_consteval() noexcept
{
function->consteval_ = true;
}
};
/// \returns Whether or not the constructor is `explicit`.
@ -253,15 +272,22 @@ public:
return constexpr_;
}
/// \returns Whether or not the constructor is `consteval`.
bool is_consteval() const noexcept
{
return consteval_;
}
private:
cpp_constructor(std::string name)
: cpp_function_base(std::move(name)), explicit_(false), constexpr_(false)
: cpp_function_base(std::move(name)), explicit_(false), constexpr_(false), consteval_(false)
{}
cpp_entity_kind do_get_entity_kind() const noexcept override;
bool explicit_;
bool constexpr_;
bool consteval_;
friend basic_builder<cpp_constructor>;
};