Add support for consteval
This commit is contained in:
parent
ce218dfb8a
commit
1b03d106ab
6 changed files with 250 additions and 9 deletions
|
|
@ -465,7 +465,7 @@ bool write_variable_base(code_generator::output& output, const cpp_variable_base
|
|||
}
|
||||
|
||||
void write_storage_class(code_generator::output& output, cpp_storage_class_specifiers storage,
|
||||
bool is_constexpr)
|
||||
bool is_constexpr, bool is_consteval)
|
||||
{
|
||||
if (is_static(storage))
|
||||
output << keyword("static") << whitespace;
|
||||
|
|
@ -475,6 +475,8 @@ void write_storage_class(code_generator::output& output, cpp_storage_class_speci
|
|||
output << keyword("thread_local") << whitespace;
|
||||
if (is_constexpr)
|
||||
output << keyword("constexpr") << whitespace;
|
||||
else if (is_consteval)
|
||||
output << keyword("consteval") << whitespace;
|
||||
}
|
||||
|
||||
bool generate_variable(code_generator& generator, const cpp_variable& var,
|
||||
|
|
@ -483,7 +485,7 @@ bool generate_variable(code_generator& generator, const cpp_variable& var,
|
|||
code_generator::output output(type_safe::ref(generator), type_safe::ref(var), cur_access);
|
||||
if (output)
|
||||
{
|
||||
write_storage_class(output, var.storage_class(), var.is_constexpr());
|
||||
write_storage_class(output, var.storage_class(), var.is_constexpr(), false);
|
||||
|
||||
write_variable_base(output, var, var.name());
|
||||
output << punctuation(";") << newl;
|
||||
|
|
@ -602,7 +604,7 @@ bool generate_function(code_generator& generator, const cpp_function& func,
|
|||
{
|
||||
if (is_friended(func))
|
||||
output << keyword("friend") << whitespace;
|
||||
write_storage_class(output, func.storage_class(), func.is_constexpr());
|
||||
write_storage_class(output, func.storage_class(), func.is_constexpr(), func.is_consteval());
|
||||
|
||||
if (output.options() & code_generator::exclude_return)
|
||||
output.excluded(func) << whitespace;
|
||||
|
|
@ -705,6 +707,8 @@ bool generate_member_function(code_generator& generator, const cpp_member_functi
|
|||
output << keyword("friend") << whitespace;
|
||||
if (func.is_constexpr())
|
||||
output << keyword("constexpr") << whitespace;
|
||||
else if (func.is_consteval())
|
||||
output << keyword("consteval") << whitespace;
|
||||
else
|
||||
write_prefix_virtual(output, func.virtual_info());
|
||||
|
||||
|
|
@ -756,6 +760,8 @@ bool generate_conversion_op(code_generator& generator, const cpp_conversion_op&
|
|||
output << keyword("explicit") << whitespace;
|
||||
if (op.is_constexpr())
|
||||
output << keyword("constexpr") << whitespace;
|
||||
else if (op.is_consteval())
|
||||
output << keyword("consteval") << whitespace;
|
||||
else
|
||||
write_prefix_virtual(output, op.virtual_info());
|
||||
|
||||
|
|
@ -791,6 +797,8 @@ bool generate_constructor(code_generator& generator, const cpp_constructor& ctor
|
|||
output << keyword("explicit") << whitespace;
|
||||
if (ctor.is_constexpr())
|
||||
output << keyword("constexpr") << whitespace;
|
||||
if (ctor.is_consteval())
|
||||
output << keyword("consteval") << whitespace;
|
||||
|
||||
output << identifier(ctor.semantic_scope()) << identifier(ctor.name());
|
||||
write_function_parameters(output, ctor);
|
||||
|
|
|
|||
|
|
@ -220,6 +220,7 @@ struct prefix_info
|
|||
{
|
||||
cpp_attribute_list attributes;
|
||||
bool is_constexpr = false;
|
||||
bool is_consteval = false;
|
||||
bool is_virtual = false;
|
||||
bool is_explicit = false;
|
||||
bool is_friend = false;
|
||||
|
|
@ -284,7 +285,9 @@ prefix_info parse_prefix_info(detail::cxtoken_stream& stream, const char* name,
|
|||
|
||||
while (!stream.done() && !prefix_end(stream, name, is_ctor_dtor))
|
||||
{
|
||||
if (detail::skip_if(stream, "constexpr"))
|
||||
if (detail::skip_if(stream, "consteval"))
|
||||
result.is_consteval = true;
|
||||
else if (detail::skip_if(stream, "constexpr"))
|
||||
result.is_constexpr = true;
|
||||
else if (detail::skip_if(stream, "virtual"))
|
||||
result.is_virtual = true;
|
||||
|
|
@ -534,8 +537,13 @@ std::unique_ptr<cpp_entity> parse_cpp_function_impl(const detail::parse_context&
|
|||
builder.storage_class(cpp_storage_class_specifiers(
|
||||
detail::get_storage_class(cur)
|
||||
| (is_static ? cpp_storage_class_static : cpp_storage_class_none)));
|
||||
|
||||
DEBUG_ASSERT(!(prefix.is_constexpr && prefix.is_consteval), detail::parse_error_handler{}, cur,
|
||||
"function cannot be both constexpr and consteval");
|
||||
if (prefix.is_constexpr)
|
||||
builder.is_constexpr();
|
||||
else if (prefix.is_consteval)
|
||||
builder.is_consteval();
|
||||
|
||||
skip_parameters(stream);
|
||||
|
||||
|
|
@ -687,6 +695,8 @@ std::unique_ptr<cpp_entity> detail::parse_cpp_member_function(const detail::pars
|
|||
|
||||
if (prefix.is_constexpr)
|
||||
builder.is_constexpr();
|
||||
else if (prefix.is_consteval)
|
||||
builder.is_consteval();
|
||||
|
||||
skip_parameters(stream);
|
||||
return handle_suffix(context, cur, builder, stream, prefix.is_virtual,
|
||||
|
|
@ -751,6 +761,8 @@ std::unique_ptr<cpp_entity> detail::parse_cpp_conversion_op(const detail::parse_
|
|||
builder.is_explicit();
|
||||
else if (prefix.is_constexpr)
|
||||
builder.is_constexpr();
|
||||
else if (prefix.is_consteval)
|
||||
builder.is_consteval();
|
||||
|
||||
return handle_suffix(context, cur, builder, stream, prefix.is_virtual,
|
||||
parse_scope(cur, is_friend));
|
||||
|
|
@ -785,6 +797,8 @@ std::unique_ptr<cpp_entity> detail::parse_cpp_constructor(const detail::parse_co
|
|||
builder.is_constexpr();
|
||||
else if (prefix.is_explicit)
|
||||
builder.is_explicit();
|
||||
else if (prefix.is_consteval)
|
||||
builder.is_consteval();
|
||||
|
||||
skip_parameters(stream);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue