1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-10 04:26:01 +01:00

Apply clang-format universally.

* It is tough to contribute to a project that doesn't use a formatter,
* It is extra hard to contribute to a project which has configured the formatter, but ignores it for some files
* Code formatting makes it harder to hide obscure / weird bugs by accident or on purpose,

Let's rip the bandaid off?

Note that PRs currently in flight should be able to be merged relatively easily by applying `clang-format` to their tip prior to merge.

Co-authored-by: Graham Christensen <graham@grahamc.com>
This commit is contained in:
Sergei Zimmerman 2025-07-18 22:25:33 +03:00
parent 9b8b5d8560
commit 95d9c13716
No known key found for this signature in database
585 changed files with 23297 additions and 23164 deletions

View file

@ -12,8 +12,10 @@ namespace nix {
// for more information, refer to
// https://github.com/nlohmann/json/blob/master/include/nlohmann/detail/input/json_sax.hpp
class JSONSax : nlohmann::json_sax<json> {
class JSONState {
class JSONSax : nlohmann::json_sax<json>
{
class JSONState
{
protected:
std::unique_ptr<JSONState> parent;
RootValue v;
@ -22,22 +24,36 @@ class JSONSax : nlohmann::json_sax<json> {
{
throw std::logic_error("tried to close toplevel json parser state");
}
explicit JSONState(std::unique_ptr<JSONState> && p) : parent(std::move(p)) {}
explicit JSONState(Value * v) : v(allocRootValue(v)) {}
explicit JSONState(std::unique_ptr<JSONState> && p)
: parent(std::move(p))
{
}
explicit JSONState(Value * v)
: v(allocRootValue(v))
{
}
JSONState(JSONState & p) = delete;
Value & value(EvalState & state)
{
if (!v)
v = allocRootValue(state.allocValue());
return **v;
}
virtual ~JSONState() {}
virtual void add() {}
};
class JSONObjectState : public JSONState {
class JSONObjectState : public JSONState
{
using JSONState::JSONState;
ValueMap attrs;
std::unique_ptr<JSONState> resolve(EvalState & state) override
{
auto attrs2 = state.buildBindings(attrs.size());
@ -46,7 +62,11 @@ class JSONSax : nlohmann::json_sax<json> {
parent->value(state).mkAttrs(attrs2);
return std::move(parent);
}
void add() override { v = nullptr; }
void add() override
{
v = nullptr;
}
public:
void key(string_t & name, EvalState & state)
{
@ -55,8 +75,10 @@ class JSONSax : nlohmann::json_sax<json> {
}
};
class JSONListState : public JSONState {
class JSONListState : public JSONState
{
ValueVector values;
std::unique_ptr<JSONState> resolve(EvalState & state) override
{
auto list = state.buildList(values.size());
@ -65,12 +87,15 @@ class JSONSax : nlohmann::json_sax<json> {
parent->value(state).mkList(list);
return std::move(parent);
}
void add() override {
void add() override
{
values.push_back(*v);
v = nullptr;
}
public:
JSONListState(std::unique_ptr<JSONState> && p, std::size_t reserve) : JSONState(std::move(p))
JSONListState(std::unique_ptr<JSONState> && p, std::size_t reserve)
: JSONState(std::move(p))
{
values.reserve(reserve);
}
@ -80,7 +105,9 @@ class JSONSax : nlohmann::json_sax<json> {
std::unique_ptr<JSONState> rs;
public:
JSONSax(EvalState & state, Value & v) : state(state), rs(new JSONState(&v)) {};
JSONSax(EvalState & state, Value & v)
: state(state)
, rs(new JSONState(&v)) {};
bool null() override
{
@ -130,7 +157,7 @@ public:
}
#if NLOHMANN_JSON_VERSION_MAJOR >= 3 && NLOHMANN_JSON_VERSION_MINOR >= 8
bool binary(binary_t&) override
bool binary(binary_t &) override
{
// This function ought to be unreachable
assert(false);
@ -146,27 +173,30 @@ public:
bool key(string_t & name) override
{
dynamic_cast<JSONObjectState*>(rs.get())->key(name, state);
dynamic_cast<JSONObjectState *>(rs.get())->key(name, state);
return true;
}
bool end_object() override {
bool end_object() override
{
rs = rs->resolve(state);
rs->add();
return true;
}
bool end_array() override {
bool end_array() override
{
return end_object();
}
bool start_array(size_t len) override {
rs = std::make_unique<JSONListState>(std::move(rs),
len != std::numeric_limits<size_t>::max() ? len : 128);
bool start_array(size_t len) override
{
rs = std::make_unique<JSONListState>(std::move(rs), len != std::numeric_limits<size_t>::max() ? len : 128);
return true;
}
bool parse_error(std::size_t, const std::string&, const nlohmann::detail::exception& ex) override {
bool parse_error(std::size_t, const std::string &, const nlohmann::detail::exception & ex) override
{
throw JSONParseError("%s", ex.what());
}
};
@ -179,4 +209,4 @@ void parseJSON(EvalState & state, const std::string_view & s_, Value & v)
throw JSONParseError("Invalid JSON Value");
}
}
} // namespace nix