Skip to content

Commit 3f3e8d9

Browse files
committed
recurse scan continue
1 parent 05e72d5 commit 3f3e8d9

File tree

10 files changed

+75
-52
lines changed

10 files changed

+75
-52
lines changed

src/error/error_code.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <set>
1010
#include <cassert>
1111
#include <format>
12+
#include <print>
1213

1314
namespace hk {
1415

@@ -59,6 +60,37 @@ struct error_code {
5960
{
6061
return has_value();
6162
}
63+
64+
[[nodiscard]] friend std::string to_string(error_code rhs)
65+
{
66+
return std::format("{}{:04}", rhs.kind, rhs.code);
67+
}
6268
};
6369

70+
71+
struct error_code_and_message_base {
72+
error_code code = {};
73+
74+
error_code_and_message_base(error_code code) : code(code)
75+
{
76+
auto [it, inserted] = all_error_codes.insert(code);
77+
if (not inserted) {
78+
std::println(stderr, "Error: found collision in error-list: {}", to_string(code));
79+
std::terminate();
80+
}
81+
}
82+
83+
inline static std::set<error_code> all_error_codes = {};
84+
};
85+
86+
template<fixed_string Fmt>
87+
struct error_code_and_message : public error_code_and_message_base {
88+
constexpr static decltype(Fmt) fmt = Fmt;
89+
90+
error_code_and_message() : error_code_and_message_base(error_code{fmt})
91+
{
92+
}
93+
};
94+
95+
6496
}

src/error/error_list.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "utility/fixed_string.hpp"
88
#include <vector>
99
#include <format>
10+
#include <concepts>
1011

1112
namespace hk {
1213

@@ -22,12 +23,12 @@ class error_list : public std::vector<error_item> {
2223
* @param args The arguments to format the error message.
2324
* @return A unexpected error containing the error code.
2425
*/
25-
template<typename ErrorType, typename... Args>
26-
std::unexpected<error_code> add(file_location first, file_location last, Args&&... args)
26+
template<std::derived_from<error_code_and_message_base> Message, typename... Args>
27+
std::unexpected<error_code> add(file_location first, file_location last, Message msg, Args&&... args)
2728
{
28-
auto e = error_item{first, last, ErrorType::code, ErrorType::fmt, std::forward<Args>(args)...};
29+
auto e = error_item{first, last, msg.code, Message::fmt, std::forward<Args>(args)...};
2930
this->push_back(std::move(e));
30-
return std::unexpected{ErrorType::code};
31+
return std::unexpected{msg.code};
3132
}
3233

3334
/** Add an error to the list.
@@ -36,12 +37,12 @@ class error_list : public std::vector<error_item> {
3637
* @param args The arguments to format the error message.
3738
* @return A unexpected error containing the error code.
3839
*/
39-
template<typename ErrorType, typename... Args>
40-
std::unexpected<error_code> add(Args&&... args)
40+
template<std::derived_from<error_code_and_message_base> Message, typename... Args>
41+
std::unexpected<error_code> add(Message msg, Args&&... args)
4142
{
42-
auto e = error_item{ErrorType::code, ErrorType::fmt, std::forward<Args>(args)...};
43+
auto e = error_item{msg.code, Message::fmt, std::forward<Args>(args)...};
4344
this->push_back(std::move(e));
44-
return std::unexpected{ErrorType::code};
45+
return std::unexpected{msg.code};
4546
}
4647

4748
private:

src/error/error_location.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ class error_location {
3535
* @param args The arguments to format the error message.
3636
* @return A unexpected error containing the error code.
3737
*/
38-
template<typename ErrorType, typename... Args>
39-
std::unexpected<error_code> add(Args&&... args)
38+
template<std::derived_from<error_code_and_message_base> Message, typename... Args>
39+
std::unexpected<error_code> add(Message msg, Args&&... args)
4040
{
4141
assert(_errors_ptr != nullptr);
4242

43-
auto e = error_item{_first, _last, ErrorType::code, ErrorType::fmt, std::forward<Args>(args)...};
43+
auto e = error_item{_first, _last, msg.code, Message::fmt, std::forward<Args>(args)...};
4444
_errors_ptr->push_back(std::move(e));
45-
return std::unexpected{ErrorType::code};
45+
return std::unexpected{msg.code};
4646
}
4747

4848
private:

src/error/errors.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11

22
#pragma once
33

4-
#include "make_error.hpp"
4+
#include "error_code.hpp"
55

6-
namespace hk::error {
7-
8-
#define E(name, fmt) struct name : public make_error<fmt> {}
6+
#define E(name, fmt) inline error_code_and_message<fmt> name = {};
97

8+
namespace hk::error {
109
E(missing_module_declaration_name, "E0001: Module declaration requires fqname.");
1110
E(missing_module_application_declaration_exe, "E0002: Module application declaration requires an executable name.");
1211
E(missing_module_library_declaration_bin, "E0003: Module library declaration requires a binary name.");
@@ -21,9 +20,10 @@ E(missing_import_mod_declaration_as_name, "E0011: Expected a name after 'as' key
2120
E(missing_import_mod_declaration_name, "E0012: Expected fully qualified name after 'import' keyword in a import-declaration.");
2221
E(missing_import_declaration_semicolon, "E0013: Expected ';' after a import-declaration.");
2322
E(missing_fqname_identifier_after_dot, "E0014: Expected identifier after '.' in fully qualified name.");
23+
E(could_not_clone_repository, "E0015: Could not clone repository '{}' rev '{}': {}.");
24+
}
2425

25-
E(could_not_clone_repository, "W0001: Could not clone repository '{}' rev '{}': {}.");
26+
namespace hk::warning {
27+
}
2628

2729
#undef E
28-
29-
}

src/error/make_error.hpp

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/parser/parse_fqname.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace hk {
2323

2424
++it;
2525
if (*it != token::identifier) {
26-
return e.add<error::missing_fqname_identifier_after_dot>(first, it->last);
26+
return e.add(first, it->last, error::missing_fqname_identifier_after_dot);
2727
}
2828

2929
r += it->text;

src/parser/parse_import_declaration.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ namespace hk {
2323
url = it->text;
2424
++it;
2525
} else {
26-
return e.add<error::missing_import_git_declaration_url>(first, it->last);
26+
return e.add(first, it->last, error::missing_import_git_declaration_url);
2727
}
2828

2929
auto rev = std::string{};
3030
if (*it == token::string_literal) {
3131
rev = it->text;
3232
++it;
3333
} else {
34-
return e.add<error::missing_import_git_declaration_branch>(first, it->last);
34+
return e.add(first, it->last, error::missing_import_git_declaration_branch);
3535
}
3636

3737
auto repository = repository_url{repository_type::git, std::move(url), std::move(rev)};
@@ -45,7 +45,7 @@ namespace hk {
4545
url = it->text;
4646
++it;
4747
} else {
48-
return e.add<error::missing_import_zip_declaration_path>(first, it->last);
48+
return e.add(first, it->last, error::missing_import_zip_declaration_path);
4949
}
5050

5151
auto repository = repository_url{repository_type::zip, it->text};
@@ -59,7 +59,7 @@ namespace hk {
5959
path = it->text;
6060
++it;
6161
} else {
62-
return e.add<error::missing_import_lib_declaration_path>(first, it->last);
62+
return e.add(first, it->last, error::missing_import_lib_declaration_path);
6363
}
6464

6565
r = std::make_unique<ast::import_library_declaration_node>(first, it->last, path);
@@ -75,7 +75,7 @@ namespace hk {
7575
as = std::move(as).value();
7676

7777
} else {
78-
return e.add<error::missing_import_mod_declaration_as_name>(first, it->last);
78+
return e.add(first, it->last, error::missing_import_mod_declaration_as_name);
7979
}
8080
}
8181

@@ -85,15 +85,15 @@ namespace hk {
8585
return std::unexpected{name.error()};
8686

8787
} else {
88-
return e.add<error::missing_import_mod_declaration_name>(first, it->last);
88+
return e.add(first, it->last, error::missing_import_mod_declaration_name);
8989
}
9090

9191
if (*it == ';') {
9292
++it;
9393
return r;
9494
}
9595

96-
return e.add<error::missing_import_declaration_semicolon>(first, it->last);
96+
return e.add(first, it->last, error::missing_import_declaration_semicolon);
9797
}
9898

9999
} // namespace hk

src/parser/parse_module_declaration.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace hk {
2121
} else if (node.error()) {
2222
return std::unexpected{node.error()};
2323
} else {
24-
return e.add<error::missing_module_declaration_name>(first, it->last);
24+
return e.add(first, it->last, error::missing_module_declaration_name);
2525
}
2626

2727
// Optional module specialization.
@@ -32,7 +32,7 @@ namespace hk {
3232
r->output_filename = it->text;
3333
++it;
3434
} else {
35-
return e.add<error::missing_module_application_declaration_exe>(first, it->last);
35+
return e.add(first, it->last, error::missing_module_application_declaration_exe);
3636
}
3737

3838
} else if (*it == "library") {
@@ -42,7 +42,7 @@ namespace hk {
4242
r->output_filename = it->text;
4343
++it;
4444
} else {
45-
return e.add<error::missing_module_library_declaration_bin>(first, it->last);
45+
return e.add(first, it->last, error::missing_module_library_declaration_bin);
4646
}
4747

4848
} else if (*it == "package") {
@@ -52,7 +52,7 @@ namespace hk {
5252
r->version = it->version_value();
5353
++it;
5454
} else {
55-
return e.add<error::missing_module_package_declaration_version>(first, it->last);
55+
return e.add(first, it->last, error::missing_module_package_declaration_version);
5656
}
5757

5858
} else {
@@ -66,15 +66,15 @@ namespace hk {
6666

6767
} else if (*it == "if") {
6868
++it;
69-
return e.add<error::unimplemented_module_declaration_if>(first, it->last);
69+
return e.add(first, it->last, error::unimplemented_module_declaration_if);
7070
}
7171

7272
if (*it == ';') {
7373
++it;
7474
return r;
7575
}
7676

77-
return e.add<error::missing_module_declaration_semicolon>(first, it->last);
77+
return e.add(first, it->last, error::missing_module_declaration_semicolon);
7878
}
7979

8080
} // namespace hk

src/repository/repository.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void repository::scan_prologues(repository_flags flags)
7171
untouch(true);
7272
}
7373

74-
void repository::recursive_scan_prologues(repository_flags flags)
74+
error_code repository::recursive_scan_prologues(repository_flags flags)
7575
{
7676
auto todo = std::map<repository_url, error_location>{};
7777
auto done = std::map<repository_url, error_location>{};
@@ -94,14 +94,20 @@ void repository::recursive_scan_prologues(repository_flags flags)
9494
auto &child_repo = get_child_repository(it->first);
9595
if (not child_repo.repository) {
9696
if (auto r = git_checkout_or_clone(it->first, child_repo_path, flags); r != git_error::ok) {
97-
it->second.add<error::could_not_clone_repository>(it->first.url(), it->first.rev(), r);
97+
return xxxxxxxxxxxxxxx needs destination directory in message it->second.add(error::could_not_clone_repository, it->first.url(), it->first.rev(), r).error();
9898
}
9999

100100
child_repo.repository = std::make_unique<repository>(child_repo_path);
101+
child_repo.repository->scan_prologues(flags);
102+
for (auto item : child_repo.repository->remote_repositories()) {
103+
todo.insert(std::move(item));
104+
}
101105
}
102106
}
103107

104108
// Remove internal repositories not in done.
109+
110+
return error_code{};
105111
}
106112

107113
void repository::untouch(bool remove)

src/repository/repository.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class repository {
2727
*
2828
* @param force Force scanning even on files that were already parsed.
2929
*/
30-
void recursive_scan_prologues(repository_flags flags);
30+
error_code recursive_scan_prologues(repository_flags flags);
3131

3232
[[nodiscard]] generator<std::pair<repository_url, error_location>> remote_repositories() const;
3333

0 commit comments

Comments
 (0)