Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/cpp2util.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ class contract_group {
public:
using handler = void (*)(CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM);

constexpr contract_group (handler h = {}) : reporter(h) { }
constexpr contract_group (handler h) : reporter{h} { }
constexpr auto set_handler(handler h);
constexpr auto get_handler() const -> handler { return reporter; }
constexpr auto expects (bool b, CPP2_MESSAGE_PARAM msg = "" CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT)
Expand Down
60 changes: 48 additions & 12 deletions source/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -2982,7 +2982,7 @@ struct declaration_node
}


auto add_type_member( std::unique_ptr<statement_node> statement )
auto add_type_member( std::unique_ptr<statement_node>&& statement )
-> bool
{
if (
Expand Down Expand Up @@ -3014,6 +3014,23 @@ struct declaration_node
}


auto add_function_initializer( std::unique_ptr<statement_node>&& statement )
-> bool
{
if (
!is_function()
|| initializer
)
{
return false;
}

// Adopt it as our initializer statement
initializer = std::move( statement );
return true;
}


auto get_decl_if_type_scope_object_name_before_a_base_type( std::string_view s ) const
-> declaration_node const*
{
Expand Down Expand Up @@ -3383,6 +3400,20 @@ struct declaration_node
return false;
}

auto get_function_parameters()
-> std::vector<parameter_declaration_node const*>
{
if (!is_function()) {
return {};
}
// else
auto ret = std::vector<parameter_declaration_node const*>{};
for (auto& param : std::get<a_function>(type)->parameters->parameters) {
ret.push_back( param.get() );
}
return ret;
}

auto unnamed_return_type_to_string() const
-> std::string
{
Expand Down Expand Up @@ -5251,17 +5282,22 @@ class parser
tokens = &tokens_;
generated_tokens = &generated_tokens_;

// Parse one declaration - we succeed if the parse succeeded,
// and there were no new errors, and all tokens were consumed
auto errors_size = std::ssize(errors);
pos = 0;
if (auto d = statement();
d
&& std::ssize(errors) == errors_size
&& done()
)
{
return d;
try {
// Parse one declaration - we succeed if the parse succeeded,
// and there were no new errors, and all tokens were consumed
auto errors_size = std::ssize(errors);
pos = 0;
if (auto d = statement();
d
&& std::ssize(errors) == errors_size
&& done()
)
{
return d;
}
}
catch(std::runtime_error& e) {
error(e.what(), true, {}, true);
}

return {};
Expand Down
Loading