Skip to content

Commit

Permalink
chore: Use std::span for include paths in preprocessor
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Raggi <[email protected]>
  • Loading branch information
robertoraggi committed Nov 12, 2024
1 parent 0629fbe commit d70c04f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/parser/cxx/preprocessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <utf8/unchecked.h>

#include <algorithm>
#include <array>
#include <cassert>
#include <format>
#include <forward_list>
Expand Down Expand Up @@ -1019,8 +1020,9 @@ struct Preprocessor::Private {
Resolve(const Resolve &other) = delete;
auto operator=(const Resolve &other) -> Resolve & = delete;

Resolve(const Private *d, bool next)
: d(d), wantNextInlude(next), currentPaths{{d->currentPath_}} {}
Resolve(const Private *d, bool next) : d(d), wantNextInlude(next) {
currentPaths[0] = d->currentPath_.string();
}

using SearchPaths = std::vector<std::span<const std::string>>;

Expand All @@ -1041,24 +1043,24 @@ struct Preprocessor::Private {
return p;
}

if (wantNextInlude && !didFindCurrentPath) {
return firstMatch;
if (wantNextInlude && !didFindCurrentPath && firstMatch.has_value()) {
return firstMatch->string();
}

return std::nullopt;
}

[[nodiscard]] auto userHeaderSearchPaths() -> SearchPaths {
std::vector<std::span<const std::string>> paths;
paths.push_back(currentPaths);
paths.push_back(d->quoteIncludePaths_);
paths.push_back(d->systemIncludePaths_);
paths.push_back(std::span<const std::string>(currentPaths));
paths.push_back(std::span<const std::string>(d->quoteIncludePaths_));
paths.push_back(std::span<const std::string>(d->systemIncludePaths_));
return paths;
}

[[nodiscard]] auto systemHeaderSearchPaths() -> SearchPaths {
std::vector<std::span<const std::string>> paths;
paths.push_back(d->systemIncludePaths_);
paths.push_back(std::span<const std::string>(d->systemIncludePaths_));
return paths;
}

Expand Down

0 comments on commit d70c04f

Please sign in to comment.