Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark functions as static and const #764

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all 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/vcpkg/base/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace vcpkg
return lhs.data() >= rhs.data();
}

bool empty() { return m_data.empty(); }
bool empty() const { return m_data.empty(); }
void clear() { m_data.clear(); }

private:
Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/binarycaching.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace vcpkg
std::vector<std::string> headers_for_put;
std::vector<std::string> headers_for_get;

LocalizedString valid();
LocalizedString valid() const;
std::string instantiate_variables(const InstallPlanAction& action) const;
};

Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ namespace vcpkg
Cache<Path, TripletMapEntry> m_triplet_cache;
Cache<Path, std::string> m_toolchain_cache;

const TripletMapEntry& get_triplet_cache(const Filesystem& fs, const Path& p);
const TripletMapEntry& get_triplet_cache(const Filesystem& fs, const Path& p) const;

#if defined(_WIN32)
struct EnvMapEntry
Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace vcpkg
std::vector<std::string> overlay_triplets;

Json::Object serialize() const;
void validate_as_active();
void validate_as_active() const;

std::unique_ptr<RegistrySet> instantiate_registry_set(const VcpkgPaths& paths, const Path& config_dir) const;

Expand Down
18 changes: 9 additions & 9 deletions include/vcpkg/export.prefab.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ namespace vcpkg::Export::Prefab
struct NdkVersion
{
NdkVersion(int _major, int _minor, int _patch) : m_major{_major}, m_minor{_minor}, m_patch{_patch} { }
int major() { return this->m_major; }
int minor() { return this->m_minor; }
int patch() { return this->m_patch; }
std::string to_string();
void to_string(std::string& out);
int major() const { return this->m_major; }
int minor() const { return this->m_minor; }
int patch() const { return this->m_patch; }
std::string to_string() const;
void to_string(std::string& out) const;

friend bool operator==(const NdkVersion& lhs, const NdkVersion& rhs)
{
Expand All @@ -49,22 +49,22 @@ namespace vcpkg::Export::Prefab
int api;
int ndk;
std::string stl;
std::string to_string();
std::string to_string() const;
};

struct PlatformModuleMetadata
{
std::vector<std::string> export_libraries;
std::string library_name;
std::string to_json();
std::string to_json() const;
};

struct ModuleMetadata
{
std::vector<std::string> export_libraries;
std::string library_name;
PlatformModuleMetadata android;
std::string to_json();
std::string to_json() const;
};

struct PackageMetadata
Expand All @@ -73,7 +73,7 @@ namespace vcpkg::Export::Prefab
int schema;
std::vector<std::string> dependencies;
std::string version;
std::string to_json();
std::string to_json() const;
};

void do_export(const std::vector<ExportPlanAction>& export_plan,
Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/xunitwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace vcpkg
const std::string& abi_tag,
const std::vector<std::string>& features);

std::string build_xml(Triplet controlling_triplet);
std::string build_xml(Triplet controlling_triplet) const;

private:
std::map<std::string, std::vector<XunitTest>> m_tests;
Expand Down
4 changes: 2 additions & 2 deletions src/vcpkg-fuzz/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace

// returns {arg, ""} when there isn't an `=`
// skips preceding `-`s
std::pair<StringView, StringView> split_arg(StringView arg)
std::pair<StringView, StringView> split_arg(StringView arg) const
{
auto first = std::find_if(arg.begin(), arg.end(), [](char c) { return c != '-'; });
auto division = std::find(first, arg.end(), '=');
Expand All @@ -112,7 +112,7 @@ namespace
}
}

[[noreturn]] void print_help_and_exit(bool invalid = false)
[[noreturn]] void print_help_and_exit(bool invalid = false) const
{
auto color = invalid ? Color::error : Color::none;

Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg-test/expected.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace
std::size_t moves = 0;
std::size_t move_assigns = 0;

void check_no_ops()
void check_no_ops() const
{
CHECK(copies == 0);
CHECK(copy_assigns == 0);
Expand Down
8 changes: 4 additions & 4 deletions src/vcpkg-test/hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ using vcpkg::StringView;

TEST_CASE ("SHA256: basic tests", "[hash][sha256]")
{
const auto algorithm = Hash::Algorithm::Sha256;
constexpr auto algorithm = Hash::Algorithm::Sha256;

CHECK_HASH_STRING("", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
CHECK_HASH_STRING(";", "41b805ea7ac014e23556e98bb374702a08344268f92489a02f0880849394a1e4");
Expand All @@ -72,11 +72,11 @@ TEST_CASE ("SHA256: basic tests", "[hash][sha256]")

TEST_CASE ("SHA256: NIST test cases (small)", "[hash][sha256]")
{
const auto algorithm = Hash::Algorithm::Sha256;
constexpr auto algorithm = Hash::Algorithm::Sha256;

CHECK_HASH(1, 0xbd, "68325720aabd7c82f30f554b313d0570c95accbb7dc4b5aae11204c08ffe732b");
{
const unsigned char data[] = {0xc9, 0x8c, 0x8e, 0x55};
constexpr unsigned char data[] = {0xc9, 0x8c, 0x8e, 0x55};
CHECK_HASH_OF(data, "7abc22c0ae5af26ce93dbb94433a0e0b2e119d014f8e7f65bd56c61ccccd9504");
}
CHECK_HASH(55, 0, "02779466cdec163811d078815c633f21901413081449002f24aa3e80f0b88ef7");
Expand All @@ -90,7 +90,7 @@ TEST_CASE ("SHA256: NIST test cases (small)", "[hash][sha256]")

TEST_CASE ("SHA512: NIST test cases (small)", "[hash][sha512]")
{
const auto algorithm = Hash::Algorithm::Sha512;
constexpr auto algorithm = Hash::Algorithm::Sha512;

CHECK_HASH_STRING("",
"cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f"
Expand Down
4 changes: 2 additions & 2 deletions src/vcpkg-test/optional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ TEST_CASE ("optional.map", "[optional]")

struct MoveTest
{
int operator()(int&&) { return 1; }
int operator()(const int&) { return -1; }
int operator()(int&&) const { return 1; }
int operator()(const int&) const { return -1; }
} move_test;

Optional<int> dst = std::move(five).map(move_test);
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/base/downloads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace vcpkg
return ret;
}

ExpectedS<int> query_status()
ExpectedS<int> query_status() const
{
DWORD dwStatusCode = 0;
DWORD dwSize = sizeof(dwStatusCode);
Expand Down
4 changes: 2 additions & 2 deletions src/vcpkg/base/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ namespace vcpkg::Json
JsonStyle style;
std::string& buffer;

void append_indent(int indent)
void append_indent(int indent) const
{
if (style.use_tabs())
{
Expand All @@ -1165,7 +1165,7 @@ namespace vcpkg::Json
}
};

void append_unicode_escape(char16_t code_unit)
void append_unicode_escape(char16_t code_unit) const
{
buffer.append("\\u");

Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/base/strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ vcpkg::ExpectedL<std::string> vcpkg::details::api_stable_format_impl(StringView
{
// Transforms similarly to std::format -- "{xyz}" -> f(xyz), "{{" -> "{", "}}" -> "}"

static const char s_brackets[] = "{}";
static constexpr char s_brackets[] = "{}";

std::string out;
auto prev = sv.begin();
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/binarycaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ namespace

namespace vcpkg
{
LocalizedString UrlTemplate::valid()
LocalizedString UrlTemplate::valid() const
{
std::vector<std::string> invalid_keys;
auto result = api_stable_format(url_template, [&](std::string&, StringView key) {
Expand Down
10 changes: 5 additions & 5 deletions src/vcpkg/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ namespace vcpkg
});
}

const EnvCache::TripletMapEntry& EnvCache::get_triplet_cache(const Filesystem& fs, const Path& p)
const EnvCache::TripletMapEntry& EnvCache::get_triplet_cache(const Filesystem& fs, const Path& p) const
{
return m_triplet_cache.get_lazy(p, [&]() -> TripletMapEntry {
return TripletMapEntry{Hash::get_file_hash(fs, p, Hash::Algorithm::Sha256).value_or_exit(VCPKG_LINE_INFO)};
Expand Down Expand Up @@ -657,17 +657,17 @@ namespace vcpkg
rc = cmd_execute_and_stream_lines(
command,
[&](StringView s) {
static const StringLiteral s_hash_marker = "#COMPILER_HASH#";
static constexpr StringLiteral s_hash_marker = "#COMPILER_HASH#";
if (Strings::starts_with(s, s_hash_marker))
{
compiler_info.hash = s.substr(s_hash_marker.size()).to_string();
}
static const StringLiteral s_version_marker = "#COMPILER_CXX_VERSION#";
static constexpr StringLiteral s_version_marker = "#COMPILER_CXX_VERSION#";
if (Strings::starts_with(s, s_version_marker))
{
compiler_info.version = s.substr(s_version_marker.size()).to_string();
}
static const StringLiteral s_id_marker = "#COMPILER_CXX_ID#";
static constexpr StringLiteral s_id_marker = "#COMPILER_CXX_ID#";
if (Strings::starts_with(s, s_id_marker))
{
compiler_info.id = s.substr(s_id_marker.size()).to_string();
Expand Down Expand Up @@ -1091,7 +1091,7 @@ namespace vcpkg
// If there is an unusually large number of files in the port then
// something suspicious is going on. Rather than hash all of them
// just mark the port as no-hash
const int max_port_file_count = 100;
constexpr int max_port_file_count = 100;

std::string portfile_cmake_contents;
std::vector<Path> files;
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace

namespace vcpkg::Commands::Version
{
const StringLiteral version = version_init;
constexpr StringLiteral version = version_init;
const CommandStructure COMMAND_STRUCTURE = {
create_example_string("version"),
0,
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ namespace vcpkg
return known_fields;
}

void Configuration::validate_as_active()
void Configuration::validate_as_active() const
{
if (!ce_metadata.is_empty())
{
Expand Down
7 changes: 4 additions & 3 deletions src/vcpkg/dependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ namespace vcpkg
.append_raw(m_scfl.error()));
}

Optional<const PlatformExpression::Expr&> get_applicable_supports_expression(const FeatureSpec& spec)
Optional<const PlatformExpression::Expr&> get_applicable_supports_expression(const FeatureSpec& spec) const
{
if (spec.feature() == "core")
{
Expand Down Expand Up @@ -292,7 +292,8 @@ namespace vcpkg

ActionPlan serialize(GraphRandomizer* randomizer) const;

void mark_for_reinstall(const PackageSpec& spec, std::vector<FeatureSpec>& out_reinstall_requirements);
void mark_for_reinstall(const PackageSpec& spec,
std::vector<FeatureSpec>& out_reinstall_requirements) const;
const CMakeVars::CMakeVarProvider& m_var_provider;

std::unique_ptr<ClusterGraph> m_graph;
Expand Down Expand Up @@ -720,7 +721,7 @@ namespace vcpkg
}

void PackageGraph::mark_for_reinstall(const PackageSpec& first_remove_spec,
std::vector<FeatureSpec>& out_reinstall_requirements)
std::vector<FeatureSpec>& out_reinstall_requirements) const
{
std::set<PackageSpec> removed;
std::vector<PackageSpec> to_remove{first_remove_spec};
Expand Down
12 changes: 6 additions & 6 deletions src/vcpkg/export.prefab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ namespace vcpkg::Export::Prefab
return paths;
}

std::string NdkVersion::to_string()
std::string NdkVersion::to_string() const
{
std::string ret;
this->to_string(ret);
return ret;
}
void NdkVersion::to_string(std::string& out)
void NdkVersion::to_string(std::string& out) const
{
out.append("NdkVersion{major=")
.append(std::to_string(major()))
Expand Down Expand Up @@ -90,7 +90,7 @@ namespace vcpkg::Export::Prefab
return copy;
}

std::string ABIMetadata::to_string()
std::string ABIMetadata::to_string() const
{
std::string TEMPLATE = R"({
"abi":"@ABI@",
Expand All @@ -105,7 +105,7 @@ namespace vcpkg::Export::Prefab
return json;
}

std::string PlatformModuleMetadata::to_json()
std::string PlatformModuleMetadata::to_json() const
{
std::string TEMPLATE = R"({
"export_libraries": @LIBRARIES@,
Expand All @@ -117,7 +117,7 @@ namespace vcpkg::Export::Prefab
return json;
}

std::string ModuleMetadata::to_json()
std::string ModuleMetadata::to_json() const
{
std::string TEMPLATE = R"({
"export_libraries": [@LIBRARIES@],
Expand All @@ -131,7 +131,7 @@ namespace vcpkg::Export::Prefab
return json;
}

std::string PackageMetadata::to_json()
std::string PackageMetadata::to_json() const
{
std::string deps = jsonify(dependencies);

Expand Down
8 changes: 4 additions & 4 deletions src/vcpkg/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ namespace vcpkg
// The VS2015 standard library requires comparison operators of T and U
// to also support comparison of T and T, and of U and U, due to debug checks.
#if _MSC_VER <= 1910
bool operator()(const std::string& lhs, const std::string& rhs) { return lhs < rhs; }
bool operator()(const file_pack& lhs, const file_pack& rhs) { return lhs.first < rhs.first; }
bool operator()(const std::string& lhs, const std::string& rhs) const { return lhs < rhs; }
bool operator()(const file_pack& lhs, const file_pack& rhs) const { return lhs.first < rhs.first; }
#endif
bool operator()(const std::string& lhs, const file_pack& rhs) { return lhs < rhs.first; }
bool operator()(const file_pack& lhs, const std::string& rhs) { return lhs.first < rhs; }
bool operator()(const std::string& lhs, const file_pack& rhs) const { return lhs < rhs.first; }
bool operator()(const file_pack& lhs, const std::string& rhs) const { return lhs.first < rhs; }
};

std::vector<file_pack> intersection;
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/registries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ namespace vcpkg
{
static constexpr struct
{
bool operator()(char ch) { return ('0' <= ch && ch <= '9') || ('a' <= ch && ch <= 'f'); }
bool operator()(char ch) const { return ('0' <= ch && ch <= '9') || ('a' <= ch && ch <= 'f'); }
} is_lcase_ascii_hex;

return sv.size() == 40 && std::all_of(sv.begin(), sv.end(), is_lcase_ascii_hex);
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/sourceparagraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ namespace vcpkg
const vcpkg::Json::Object& obj,
vcpkg::SourceParagraph& spgh,
vcpkg::Json::Reader& r,
std::unique_ptr<vcpkg::SourceControlFile>& control_file)
std::unique_ptr<vcpkg::SourceControlFile>& control_file) const
{
for (const auto& el : obj)
{
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/xunitwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void XunitWriter::add_test_results(const PackageSpec& spec,
features});
}

std::string XunitWriter::build_xml(Triplet controlling_triplet)
std::string XunitWriter::build_xml(Triplet controlling_triplet) const
{
XmlSerializer xml;
xml.emit_declaration();
Expand Down