From d331d3a0b5c497a46e2636f308234be66566c04c Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 20 May 2020 04:33:07 +0100 Subject: refactor(3p/nix): Apply clang-tidy's modernize-* fixes This applies the modernization fixes listed here: https://clang.llvm.org/extra/clang-tidy/checks/list.html The 'modernize-use-trailing-return-type' fix was excluded due to my personal preference (more specifically, I think the 'auto' keyword is misleading in that position). --- third_party/nix/src/libexpr/attr-path.cc | 2 +- third_party/nix/src/libexpr/eval.cc | 25 +++++++++++++------------ third_party/nix/src/libexpr/get-drvs.cc | 17 +++++++++-------- third_party/nix/src/libexpr/get-drvs.hh | 2 +- third_party/nix/src/libexpr/json-to-value.cc | 4 ++-- third_party/nix/src/libexpr/names.cc | 5 +++-- third_party/nix/src/libexpr/nixexpr.cc | 2 +- third_party/nix/src/libexpr/primops.cc | 12 ++++++------ 8 files changed, 36 insertions(+), 33 deletions(-) (limited to 'third_party/nix/src/libexpr') diff --git a/third_party/nix/src/libexpr/attr-path.cc b/third_party/nix/src/libexpr/attr-path.cc index 3d4e9c1e1096..485c240e3a4a 100644 --- a/third_party/nix/src/libexpr/attr-path.cc +++ b/third_party/nix/src/libexpr/attr-path.cc @@ -15,7 +15,7 @@ static Strings parseAttrPath(const string& s) { cur.clear(); } else if (*i == '"') { ++i; - while (1) { + while (true) { if (i == s.end()) { throw Error(format("missing closing quote in selection path '%1%'") % s); diff --git a/third_party/nix/src/libexpr/eval.cc b/third_party/nix/src/libexpr/eval.cc index c5329daf5faf..44f55dd68786 100644 --- a/third_party/nix/src/libexpr/eval.cc +++ b/third_party/nix/src/libexpr/eval.cc @@ -328,7 +328,7 @@ EvalState::EvalState(const Strings& _searchPath, ref store) repair(NoRepair), store(store), baseEnv(allocEnv(128)), - staticBaseEnv(false, 0) { + staticBaseEnv(false, nullptr) { countCalls = getEnv("NIX_COUNT_CALLS", "0") != "0"; assert(gcInitialised); @@ -378,7 +378,7 @@ EvalState::EvalState(const Strings& _searchPath, ref store) createBaseEnv(); } -EvalState::~EvalState() {} +EvalState::~EvalState() = default; Path EvalState::checkSourcePath(const Path& path_) { if (!allowedPaths) { @@ -575,7 +575,7 @@ Value& mkString(Value& v, const string& s, const PathSet& context) { for (auto& i : context) { v.string.context[n++] = dupString(i.c_str()); } - v.string.context[n] = 0; + v.string.context[n] = nullptr; } return v; } @@ -591,10 +591,10 @@ inline Value* EvalState::lookupVar(Env* env, const ExprVar& var, bool noEval) { return env->values[var.displ]; } - while (1) { + while (true) { if (env->type == Env::HasWithExpr) { if (noEval) { - return 0; + return nullptr; } Value* v = allocValue(); evalAttrs(*env->up, (Expr*)env->values[0], *v); @@ -656,7 +656,8 @@ void EvalState::mkList(Value& v, size_t size) { } else { v.type = tListN; v.bigList.size = size; - v.bigList.elems = size ? (Value**)allocBytes(size * sizeof(Value*)) : 0; + v.bigList.elems = + size ? (Value**)allocBytes(size * sizeof(Value*)) : nullptr; } nrListElems += size; } @@ -822,7 +823,7 @@ void ExprAttrs::eval(EvalState& state, Env& env, Value& v) { env2.up = &env; dynamicEnv = &env2; - AttrDefs::iterator overrides = attrs.find(state.sOverrides); + auto overrides = attrs.find(state.sOverrides); bool hasOverrides = overrides != attrs.end(); /* The recursive attributes are evaluated in the new @@ -858,7 +859,7 @@ void ExprAttrs::eval(EvalState& state, Env& env, Value& v) { newBnds->push_back(i); } for (auto& i : *vOverrides->attrs) { - AttrDefs::iterator j = attrs.find(i.name); + auto j = attrs.find(i.name); if (j != attrs.end()) { (*newBnds)[j->second.displ] = i; env2.values[j->second.displ] = i.value; @@ -955,7 +956,7 @@ unsigned long nrLookups = 0; void ExprSelect::eval(EvalState& state, Env& env, Value& v) { Value vTmp; - Pos* pos2 = 0; + Pos* pos2 = nullptr; Value* vAttrs = &vTmp; e->eval(state, env, vTmp); @@ -985,7 +986,7 @@ void ExprSelect::eval(EvalState& state, Env& env, Value& v) { } } - state.forceValue(*vAttrs, (pos2 != NULL ? *pos2 : this->pos)); + state.forceValue(*vAttrs, (pos2 != nullptr ? *pos2 : this->pos)); } catch (Error& e) { if (pos2 && pos2->file != state.sDerivationNix) { @@ -1334,7 +1335,7 @@ void EvalState::concatLists(Value& v, size_t nrLists, Value** lists, const Pos& pos) { nrListConcats++; - Value* nonEmpty = 0; + Value* nonEmpty = nullptr; size_t len = 0; for (size_t n = 0; n < nrLists; ++n) { forceList(*lists[n], pos); @@ -1796,7 +1797,7 @@ void EvalState::printStats() { #if HAVE_BOEHMGC GC_word heapSize, totalBytes; - GC_get_heap_usage_safe(&heapSize, 0, 0, 0, &totalBytes); + GC_get_heap_usage_safe(&heapSize, nullptr, nullptr, nullptr, &totalBytes); #endif if (showStats) { auto outPath = getEnv("NIX_SHOW_STATS_PATH", "-"); diff --git a/third_party/nix/src/libexpr/get-drvs.cc b/third_party/nix/src/libexpr/get-drvs.cc index c62e05d4541c..aa73c01fd1f2 100644 --- a/third_party/nix/src/libexpr/get-drvs.cc +++ b/third_party/nix/src/libexpr/get-drvs.cc @@ -2,6 +2,7 @@ #include #include +#include #include @@ -11,12 +12,12 @@ namespace nix { -DrvInfo::DrvInfo(EvalState& state, const string& attrPath, Bindings* attrs) - : state(&state), attrs(attrs), attrPath(attrPath) {} +DrvInfo::DrvInfo(EvalState& state, string attrPath, Bindings* attrs) + : state(&state), attrs(attrs), attrPath(std::move(attrPath)) {} DrvInfo::DrvInfo(EvalState& state, ref store, const std::string& drvPathWithOutputs) - : state(&state), attrs(nullptr), attrPath("") { + : state(&state), attrPath("") { auto spec = parseDrvPathWithOutputs(drvPathWithOutputs); drvPath = spec.first; @@ -158,11 +159,11 @@ Bindings* DrvInfo::getMeta() { return meta; } if (!attrs) { - return 0; + return nullptr; } Bindings::iterator a = attrs->find(state->sMeta); if (a == attrs->end()) { - return 0; + return nullptr; } state->forceAttrs(*a->value, *a->pos); meta = a->value->attrs; @@ -208,11 +209,11 @@ bool DrvInfo::checkMeta(Value& v) { Value* DrvInfo::queryMeta(const string& name) { if (!getMeta()) { - return 0; + return nullptr; } Bindings::iterator a = meta->find(state->symbols.create(name)); if (a == meta->end() || !checkMeta(*a->value)) { - return 0; + return nullptr; } return a->value; } @@ -303,7 +304,7 @@ void DrvInfo::setMeta(const string& name, Value* v) { } /* Cache for already considered attrsets. */ -typedef set Done; +using Done = set; /* Evaluate value `v'. If it evaluates to a set of type `derivation', then put information about it in `drvs' (unless it's already in `done'). diff --git a/third_party/nix/src/libexpr/get-drvs.hh b/third_party/nix/src/libexpr/get-drvs.hh index deb0a6d647a9..ef6ecd253e6a 100644 --- a/third_party/nix/src/libexpr/get-drvs.hh +++ b/third_party/nix/src/libexpr/get-drvs.hh @@ -33,7 +33,7 @@ struct DrvInfo { string attrPath; /* path towards the derivation */ DrvInfo(EvalState& state) : state(&state){}; - DrvInfo(EvalState& state, const string& attrPath, Bindings* attrs); + DrvInfo(EvalState& state, string attrPath, Bindings* attrs); DrvInfo(EvalState& state, ref store, const std::string& drvPathWithOutputs); diff --git a/third_party/nix/src/libexpr/json-to-value.cc b/third_party/nix/src/libexpr/json-to-value.cc index 70628636e16b..122bd2ad3147 100644 --- a/third_party/nix/src/libexpr/json-to-value.cc +++ b/third_party/nix/src/libexpr/json-to-value.cc @@ -66,7 +66,7 @@ static void parseJSON(EvalState& state, const char*& s, Value& v) { ValueVector values; values.reserve(128); skipWhitespace(s); - while (1) { + while (true) { if (values.empty() && *s == ']') { break; } @@ -92,7 +92,7 @@ static void parseJSON(EvalState& state, const char*& s, Value& v) { else if (*s == '{') { s++; ValueMap attrs; - while (1) { + while (true) { skipWhitespace(s); if (attrs.empty() && *s == '}') { break; diff --git a/third_party/nix/src/libexpr/names.cc b/third_party/nix/src/libexpr/names.cc index 184f30999e6b..ecad90c960af 100644 --- a/third_party/nix/src/libexpr/names.cc +++ b/third_party/nix/src/libexpr/names.cc @@ -1,5 +1,7 @@ #include "names.hh" +#include + #include "util.hh" namespace nix { @@ -26,8 +28,7 @@ DrvName::DrvName(const string& s) : hits(0) { bool DrvName::matches(DrvName& n) { if (name != "*") { if (!regex) { - regex = std::unique_ptr( - new std::regex(name, std::regex::extended)); + regex = std::make_unique(name, std::regex::extended); } if (!std::regex_match(n.name, *regex)) { return false; diff --git a/third_party/nix/src/libexpr/nixexpr.cc b/third_party/nix/src/libexpr/nixexpr.cc index dc2c2b75e3bc..55b9d545778c 100644 --- a/third_party/nix/src/libexpr/nixexpr.cc +++ b/third_party/nix/src/libexpr/nixexpr.cc @@ -239,7 +239,7 @@ void ExprVar::bindVars(const StaticEnv& env) { withLevel = level; } } else { - StaticEnv::Vars::const_iterator i = curEnv->vars.find(name); + auto i = curEnv->vars.find(name); if (i != curEnv->vars.end()) { fromWith = false; this->level = level; diff --git a/third_party/nix/src/libexpr/primops.cc b/third_party/nix/src/libexpr/primops.cc index 6835f03c8b7f..d576d4b61905 100644 --- a/third_party/nix/src/libexpr/primops.cc +++ b/third_party/nix/src/libexpr/primops.cc @@ -62,7 +62,7 @@ void EvalState::realiseContext(const PathSet& context) { paths. */ if (allowedPaths) { auto drv = store->derivationFromPath(decoded.first); - DerivationOutputs::iterator i = drv.outputs.find(decoded.second); + auto i = drv.outputs.find(decoded.second); if (i == drv.outputs.end()) { throw Error("derivation '%s' does not have an output named '%s'", decoded.first, decoded.second); @@ -160,7 +160,7 @@ static void prim_scopedImport(EvalState& state, const Pos& pos, Value** args, /* Want reasonable symbol names, so extern C */ /* !!! Should we pass the Pos or the file name too? */ -extern "C" typedef void (*ValueInitializer)(EvalState& state, Value& v); +extern "C" using ValueInitializer = void(*)(EvalState&, Value&); /* Load a ValueInitializer from a DSO and return whatever it initializes */ void prim_importNative(EvalState& state, const Pos& pos, Value** args, @@ -186,7 +186,7 @@ void prim_importNative(EvalState& state, const Pos& pos, Value** args, } dlerror(); - ValueInitializer func = (ValueInitializer)dlsym(handle, sym.c_str()); + auto func = (ValueInitializer)dlsym(handle, sym.c_str()); if (!func) { char* message = dlerror(); if (message) { @@ -2090,7 +2090,7 @@ static void prim_replaceStrings(EvalState& state, const Pos& pos, Value** args, for (unsigned int n = 0; n < args[1]->listSize(); ++n) { PathSet ctx; auto s = state.forceString(*args[1]->listElems()[n], ctx, pos); - to.push_back(std::make_pair(std::move(s), std::move(ctx))); + to.emplace_back(std::move(s), std::move(ctx)); } PathSet context; @@ -2253,7 +2253,7 @@ RegisterPrimOp::RegisterPrimOp(std::string name, size_t arity, PrimOpFun fun) { } void EvalState::createBaseEnv() { - baseEnv.up = 0; + baseEnv.up = nullptr; /* Add global constants such as `true' to the base environment. */ Value v; @@ -2281,7 +2281,7 @@ void EvalState::createBaseEnv() { }; if (!evalSettings.pureEval) { - mkInt(v, time(0)); + mkInt(v, time(nullptr)); addConstant("__currentTime", v); } -- cgit 1.4.1