diff options
author | Vincent Ambo <tazjin@google.com> | 2020-05-24T21·29+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2020-05-24T21·29+0100 |
commit | 838f86b0fd880b26539664140f04e5d16669dad8 (patch) | |
tree | c8fee2f0c136fbe5bb0735604e2f04d5b02698ba /third_party/nix/src/libexpr | |
parent | f30b2e610d9e612504a9f6460e0cc83413b80aeb (diff) |
style(3p/nix): Remove 'using std::*' from types.hh r/840
It is considered bad form to use things from includes in headers, as these directives propagate to everywhere else and can make it confusing. types.hh (which is includes almost literally everywhere) had some of these directives, which this commit removes.
Diffstat (limited to 'third_party/nix/src/libexpr')
-rw-r--r-- | third_party/nix/src/libexpr/attr-path.cc | 2 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/common-eval-args.cc | 6 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/eval.cc | 41 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/eval.hh | 12 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/get-drvs.cc | 14 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/get-drvs.hh | 6 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/names.cc | 12 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/names.hh | 6 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/nixexpr.cc | 13 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/nixexpr.hh | 43 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/parser.y | 39 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/primops.cc | 29 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/primops/context.cc | 10 |
13 files changed, 123 insertions, 110 deletions
diff --git a/third_party/nix/src/libexpr/attr-path.cc b/third_party/nix/src/libexpr/attr-path.cc index 1815b5e510d3..628b58c1b1e3 100644 --- a/third_party/nix/src/libexpr/attr-path.cc +++ b/third_party/nix/src/libexpr/attr-path.cc @@ -8,7 +8,7 @@ namespace nix { static Strings parseAttrPath(const std::string& s) { Strings res; std::string cur; - string::const_iterator i = s.begin(); + std::string::const_iterator i = s.begin(); while (i != s.end()) { if (*i == '.') { res.push_back(cur); diff --git a/third_party/nix/src/libexpr/common-eval-args.cc b/third_party/nix/src/libexpr/common-eval-args.cc index 2059d5374195..19271f2cc582 100644 --- a/third_party/nix/src/libexpr/common-eval-args.cc +++ b/third_party/nix/src/libexpr/common-eval-args.cc @@ -37,10 +37,10 @@ Bindings* MixEvalArgs::getAutoArgs(EvalState& state) { for (auto& i : autoArgs) { Value* v = state.allocValue(); if (i.second[0] == 'E') { - state.mkThunk_( - *v, state.parseExprFromString(string(i.second, 1), absPath("."))); + state.mkThunk_(*v, state.parseExprFromString(std::string(i.second, 1), + absPath("."))); } else { - mkString(*v, string(i.second, 1)); + mkString(*v, std::string(i.second, 1)); } res->push_back(Attr(state.symbols.Create(i.first), v)); } diff --git a/third_party/nix/src/libexpr/eval.cc b/third_party/nix/src/libexpr/eval.cc index 60d3cd012df8..d93f39bba4fe 100644 --- a/third_party/nix/src/libexpr/eval.cc +++ b/third_party/nix/src/libexpr/eval.cc @@ -136,7 +136,7 @@ const Value* getPrimOp(const Value& v) { return primOp; } -string showType(const Value& v) { +std::string showType(const Value& v) { switch (v.type) { case tInt: return "an integer"; @@ -163,10 +163,10 @@ string showType(const Value& v) { case tBlackhole: return "a black hole"; case tPrimOp: - return fmt("the built-in function '%s'", string(v.primOp->name)); + return fmt("the built-in function '%s'", std::string(v.primOp->name)); case tPrimOpApp: return fmt("the partially applied built-in function '%s'", - string(getPrimOp(v)->primOp->name)); + std::string(getPrimOp(v)->primOp->name)); case tExternal: return v.external->showType(); case tFloat: @@ -456,7 +456,8 @@ Value* EvalState::addConstant(const std::string& name, Value& v) { *v2 = v; staticBaseEnv.vars[symbols.Create(name)] = baseEnvDispl; baseEnv.values[baseEnvDispl++] = v2; - std::string name2 = string(name, 0, 2) == "__" ? string(name, 2) : name; + std::string name2 = + std::string(name, 0, 2) == "__" ? std::string(name, 2) : name; baseEnv.values[0]->attrs->push_back(Attr(symbols.Create(name2), v2)); return v2; } @@ -469,7 +470,8 @@ Value* EvalState::addPrimOp(const std::string& name, size_t arity, return addConstant(name, v); } Value* v = allocValue(); - std::string name2 = string(name, 0, 2) == "__" ? string(name, 2) : name; + std::string name2 = + std::string(name, 0, 2) == "__" ? std::string(name, 2) : name; Symbol sym = symbols.Create(name2); v->type = tPrimOp; v->primOp = new PrimOp(primOp, arity, sym); @@ -1423,7 +1425,7 @@ void EvalState::forceFunction(Value& v, const Pos& pos) { } } -string EvalState::forceString(Value& v, const Pos& pos) { +std::string EvalState::forceString(Value& v, const Pos& pos) { forceValue(v, pos); if (v.type != tString) { if (pos) { @@ -1433,7 +1435,7 @@ string EvalState::forceString(Value& v, const Pos& pos) { throwTypeError("value is %1% while a string was expected", v); } } - return string(v.string.s); + return std::string(v.string.s); } void copyContext(const Value& v, PathSet& context) { @@ -1444,13 +1446,13 @@ void copyContext(const Value& v, PathSet& context) { } } -string EvalState::forceString(Value& v, PathSet& context, const Pos& pos) { +std::string EvalState::forceString(Value& v, PathSet& context, const Pos& pos) { std::string s = forceString(v, pos); copyContext(v, context); return s; } -string EvalState::forceStringNoCtx(Value& v, const Pos& pos) { +std::string EvalState::forceStringNoCtx(Value& v, const Pos& pos) { std::string s = forceString(v, pos); if (v.string.context != nullptr) { if (pos) { @@ -1483,10 +1485,10 @@ bool EvalState::isDerivation(Value& v) { return strcmp(i->second.value->string.s, "derivation") == 0; } -std::optional<string> EvalState::tryAttrsToString(const Pos& pos, Value& v, - PathSet& context, - bool coerceMore, - bool copyToStore) { +std::optional<std::string> EvalState::tryAttrsToString(const Pos& pos, Value& v, + PathSet& context, + bool coerceMore, + bool copyToStore) { auto i = v.attrs->find(sToString); if (i != v.attrs->end()) { Value v1; @@ -1497,8 +1499,9 @@ std::optional<string> EvalState::tryAttrsToString(const Pos& pos, Value& v, return {}; } -string EvalState::coerceToString(const Pos& pos, Value& v, PathSet& context, - bool coerceMore, bool copyToStore) { +std::string EvalState::coerceToString(const Pos& pos, Value& v, + PathSet& context, bool coerceMore, + bool copyToStore) { forceValue(v); std::string s; @@ -1569,7 +1572,7 @@ string EvalState::coerceToString(const Pos& pos, Value& v, PathSet& context, throwTypeError("cannot coerce %1% to a string, at %2%", v, pos); } -string EvalState::copyPathToStore(PathSet& context, const Path& path) { +std::string EvalState::copyPathToStore(PathSet& context, const Path& path) { if (nix::isDerivation(path)) { throwEvalError("file names are not allowed to end in '%1%'", drvExtension); } @@ -1931,9 +1934,9 @@ size_t valueSize(Value& v) { return doValue(v); } -string ExternalValueBase::coerceToString(const Pos& pos, PathSet& context, - bool copyMore, - bool copyToStore) const { +std::string ExternalValueBase::coerceToString(const Pos& pos, PathSet& context, + bool copyMore, + bool copyToStore) const { throw TypeError(format("cannot coerce %1% to a string, at %2%") % showType() % pos); } diff --git a/third_party/nix/src/libexpr/eval.hh b/third_party/nix/src/libexpr/eval.hh index 531294c93ca2..f13e8553d14b 100644 --- a/third_party/nix/src/libexpr/eval.hh +++ b/third_party/nix/src/libexpr/eval.hh @@ -180,10 +180,10 @@ class EvalState { set with attribute `type = "derivation"'). */ bool isDerivation(Value& v); - std::optional<string> tryAttrsToString(const Pos& pos, Value& v, - PathSet& context, - bool coerceMore = false, - bool copyToStore = true); + std::optional<std::string> tryAttrsToString(const Pos& pos, Value& v, + PathSet& context, + bool coerceMore = false, + bool copyToStore = true); /* String coercion. Converts strings, paths and derivations to a string. If `coerceMore' is set, also converts nulls, integers, @@ -295,11 +295,11 @@ class EvalState { }; /* Return a string representing the type of the value `v'. */ -string showType(const Value& v); +std::string showType(const Value& v); /* Decode a context string ‘!<name>!<path>’ into a pair <path, name>. */ -std::pair<string, string> decodeContext(const std::string& s); +std::pair<std::string, std::string> decodeContext(const std::string& s); /* If `path' refers to a directory, then append "/default.nix". */ Path resolveExprPath(Path path); diff --git a/third_party/nix/src/libexpr/get-drvs.cc b/third_party/nix/src/libexpr/get-drvs.cc index 6d4ad33be063..bc40ec3fef6c 100644 --- a/third_party/nix/src/libexpr/get-drvs.cc +++ b/third_party/nix/src/libexpr/get-drvs.cc @@ -44,7 +44,7 @@ DrvInfo::DrvInfo(EvalState& state, const ref<Store>& store, outPath = i->second.path; } -string DrvInfo::queryName() const { +std::string DrvInfo::queryName() const { if (name.empty() && (attrs != nullptr)) { auto i = attrs->find(state->sName); if (i == attrs->end()) { @@ -55,7 +55,7 @@ string DrvInfo::queryName() const { return name; } -string DrvInfo::querySystem() const { +std::string DrvInfo::querySystem() const { if (system.empty() && (attrs != nullptr)) { auto i = attrs->find(state->sSystem); system = i == attrs->end() @@ -65,7 +65,7 @@ string DrvInfo::querySystem() const { return system; } -string DrvInfo::queryDrvPath() const { +std::string DrvInfo::queryDrvPath() const { if (drvPath.empty() && (attrs != nullptr)) { Bindings::iterator i = attrs->find(state->sDrvPath); PathSet context; @@ -76,7 +76,7 @@ string DrvInfo::queryDrvPath() const { return drvPath; } -string DrvInfo::queryOutPath() const { +std::string DrvInfo::queryOutPath() const { if (outPath.empty() && (attrs != nullptr)) { Bindings::iterator i = attrs->find(state->sOutPath); PathSet context; @@ -149,7 +149,7 @@ DrvInfo::Outputs DrvInfo::queryOutputs(bool onlyOutputsToInstall) { return result; } -string DrvInfo::queryOutputName() const { +std::string DrvInfo::queryOutputName() const { if (outputName.empty() && (attrs != nullptr)) { Bindings::iterator i = attrs->find(state->sOutputName); outputName = @@ -223,7 +223,7 @@ Value* DrvInfo::queryMeta(const std::string& name) { return a->second.value; } -string DrvInfo::queryMetaString(const std::string& name) { +std::string DrvInfo::queryMetaString(const std::string& name) { Value* v = queryMeta(name); if ((v == nullptr) || v->type != tString) { return ""; @@ -308,7 +308,7 @@ void DrvInfo::setMeta(const std::string& name, Value* v) { } /* Cache for already considered attrsets. */ -using Done = set<Bindings*>; +using Done = std::set<Bindings*>; /* 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 3da23194616e..a0840ee9b280 100644 --- a/third_party/nix/src/libexpr/get-drvs.hh +++ b/third_party/nix/src/libexpr/get-drvs.hh @@ -9,7 +9,7 @@ namespace nix { struct DrvInfo { public: - typedef std::map<string, Path> Outputs; + typedef std::map<std::string, Path> Outputs; private: EvalState* state; @@ -68,9 +68,9 @@ struct DrvInfo { }; #if HAVE_BOEHMGC -typedef list<DrvInfo, traceable_allocator<DrvInfo> > DrvInfos; +typedef std::list<DrvInfo, traceable_allocator<DrvInfo> > DrvInfos; #else -typedef list<DrvInfo> DrvInfos; +typedef std::list<DrvInfo> DrvInfos; #endif /* If value `v' denotes a derivation, return a DrvInfo object diff --git a/third_party/nix/src/libexpr/names.cc b/third_party/nix/src/libexpr/names.cc index ac8150532f25..20c326776cb7 100644 --- a/third_party/nix/src/libexpr/names.cc +++ b/third_party/nix/src/libexpr/names.cc @@ -18,8 +18,8 @@ DrvName::DrvName(const std::string& s) : hits(0) { for (unsigned int i = 0; i < s.size(); ++i) { /* !!! isalpha/isdigit are affected by the locale. */ if (s[i] == '-' && i + 1 < s.size() && (isalpha(s[i + 1]) == 0)) { - name = string(s, 0, i); - version = string(s, i + 1); + name = std::string(s, 0, i); + version = std::string(s, i + 1); break; } } @@ -37,8 +37,8 @@ bool DrvName::matches(DrvName& n) { return !(!version.empty() && version != n.version); } -string nextComponent(string::const_iterator& p, - const string::const_iterator end) { +std::string nextComponent(std::string::const_iterator& p, + const std::string::const_iterator end) { /* Skip any dots and dashes (component separators). */ while (p != end && (*p == '.' || *p == '-')) { ++p; @@ -91,8 +91,8 @@ static bool componentsLT(const std::string& c1, const std::string& c2) { } int compareVersions(const std::string& v1, const std::string& v2) { - string::const_iterator p1 = v1.begin(); - string::const_iterator p2 = v2.begin(); + std::string::const_iterator p1 = v1.begin(); + std::string::const_iterator p2 = v2.begin(); while (p1 != v1.end() || p2 != v2.end()) { std::string c1 = nextComponent(p1, v1.end()); diff --git a/third_party/nix/src/libexpr/names.hh b/third_party/nix/src/libexpr/names.hh index e2ddb5cb993e..521740152ca2 100644 --- a/third_party/nix/src/libexpr/names.hh +++ b/third_party/nix/src/libexpr/names.hh @@ -21,10 +21,10 @@ struct DrvName { std::unique_ptr<std::regex> regex; }; -typedef list<DrvName> DrvNames; +typedef std::list<DrvName> DrvNames; -string nextComponent(string::const_iterator& p, - const string::const_iterator end); +std::string nextComponent(std::string::const_iterator& p, + const std::string::const_iterator end); int compareVersions(const std::string& v1, const std::string& v2); DrvNames drvNamesFromArgs(const Strings& opArgs); diff --git a/third_party/nix/src/libexpr/nixexpr.cc b/third_party/nix/src/libexpr/nixexpr.cc index 3d454d266ff0..ef4a75ed8d5b 100644 --- a/third_party/nix/src/libexpr/nixexpr.cc +++ b/third_party/nix/src/libexpr/nixexpr.cc @@ -16,7 +16,7 @@ std::ostream& operator<<(std::ostream& str, const Expr& e) { static void showString(std::ostream& str, const std::string& s) { str << '"'; - for (auto c : (string)s) { + for (auto c : (std::string)s) { if (c == '"' || c == '\\' || c == '$') { str << "\\" << c; } else if (c == '\n') { @@ -188,14 +188,14 @@ std::ostream& operator<<(std::ostream& str, const Pos& pos) { if (!pos) { str << "undefined position"; } else { - str << (format(ANSI_BOLD "%1%" ANSI_NORMAL ":%2%:%3%") % (string)pos.file % - pos.line % pos.column) + str << (format(ANSI_BOLD "%1%" ANSI_NORMAL ":%2%:%3%") % + (std::string)pos.file % pos.line % pos.column) .str(); } return str; } -string showAttrPath(const AttrPath& attrPath) { +std::string showAttrPath(const AttrPath& attrPath) { std::ostringstream out; bool first = true; for (auto& i : attrPath) { @@ -407,9 +407,10 @@ void ExprLambda::setName(Symbol& name) { body->setName(name); } -string ExprLambda::showNamePos() const { +std::string ExprLambda::showNamePos() const { return (format("%1% at %2%") % - (name.set() ? "'" + (string)name + "'" : "anonymous function") % pos) + (name.set() ? "'" + (std::string)name + "'" : "anonymous function") % + pos) .str(); } diff --git a/third_party/nix/src/libexpr/nixexpr.hh b/third_party/nix/src/libexpr/nixexpr.hh index 3ac651c94548..8817fbc9ddb8 100644 --- a/third_party/nix/src/libexpr/nixexpr.hh +++ b/third_party/nix/src/libexpr/nixexpr.hh @@ -8,15 +8,18 @@ namespace nix { -MakeError(EvalError, Error) MakeError(ParseError, Error) - MakeError(AssertionError, EvalError) MakeError(ThrownError, AssertionError) - MakeError(Abort, EvalError) MakeError(TypeError, EvalError) - MakeError(UndefinedVarError, Error) - MakeError(RestrictedPathError, Error) - - /* Position objects. */ - - struct Pos { +MakeError(EvalError, Error); +MakeError(ParseError, Error); +MakeError(AssertionError, EvalError); +MakeError(ThrownError, AssertionError); +MakeError(Abort, EvalError); +MakeError(TypeError, EvalError); +MakeError(UndefinedVarError, Error); +MakeError(RestrictedPathError, Error); + +/* Position objects. */ + +struct Pos { Symbol file; unsigned int line, column; Pos() : line(0), column(0){}; @@ -30,7 +33,7 @@ MakeError(EvalError, Error) MakeError(ParseError, Error) if (!p2.line) { return false; } - int d = ((string)file).compare((string)p2.file); + int d = ((std::string)file).compare((std::string)p2.file); if (d < 0) { return true; } @@ -66,7 +69,7 @@ struct AttrName { typedef std::vector<AttrName> AttrPath; -string showAttrPath(const AttrPath& attrPath); +std::string showAttrPath(const AttrPath& attrPath); /* Abstract syntax of Nix expressions. */ @@ -297,16 +300,20 @@ struct ExprOpNot : Expr { void eval(EvalState& state, Env& env, Value& v); \ }; -MakeBinOp(ExprApp, "") MakeBinOp(ExprOpEq, "==") MakeBinOp(ExprOpNEq, "!=") - MakeBinOp(ExprOpAnd, "&&") MakeBinOp(ExprOpOr, "||") - MakeBinOp(ExprOpImpl, "->") MakeBinOp(ExprOpUpdate, "//") - MakeBinOp(ExprOpConcatLists, "++") +MakeBinOp(ExprApp, ""); +MakeBinOp(ExprOpEq, "=="); +MakeBinOp(ExprOpNEq, "!="); +MakeBinOp(ExprOpAnd, "&&"); +MakeBinOp(ExprOpOr, "||"); +MakeBinOp(ExprOpImpl, "->"); +MakeBinOp(ExprOpUpdate, "//"); +MakeBinOp(ExprOpConcatLists, "++"); - struct ExprConcatStrings : Expr { +struct ExprConcatStrings : Expr { Pos pos; bool forceString; - vector<Expr*>* es; - ExprConcatStrings(const Pos& pos, bool forceString, vector<Expr*>* es) + std::vector<Expr*>* es; + ExprConcatStrings(const Pos& pos, bool forceString, std::vector<Expr*>* es) : pos(pos), forceString(forceString), es(es){}; COMMON_METHODS }; diff --git a/third_party/nix/src/libexpr/parser.y b/third_party/nix/src/libexpr/parser.y index bd62a7fd0f52..9ba053ee7b12 100644 --- a/third_party/nix/src/libexpr/parser.y +++ b/third_party/nix/src/libexpr/parser.y @@ -146,7 +146,7 @@ static void addFormal(const Pos & pos, Formals * formals, const Formal & formal) } -static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, vector<Expr *> & es) +static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, std::vector<Expr *> & es) { if (es.empty()) { return new ExprString(symbols.Create("")); } @@ -186,11 +186,11 @@ static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, vector<Ex } /* Strip spaces from each line. */ - vector<Expr *> * es2 = new vector<Expr *>; + std::vector<Expr *> * es2 = new std::vector<Expr *>; atStartOfLine = true; size_t curDropped = 0; size_t n = es.size(); - for (vector<Expr *>::iterator i = es.begin(); i != es.end(); ++i, --n) { + for (std::vector<Expr *>::iterator i = es.begin(); i != es.end(); ++i, --n) { ExprIndStr * e = dynamic_cast<ExprIndStr *>(*i); if (!e) { atStartOfLine = false; @@ -223,9 +223,10 @@ static Expr * stripIndentation(const Pos & pos, SymbolTable & symbols, vector<Ex /* Remove the last line if it is empty and consists only of spaces. */ if (n == 1) { - string::size_type p = s2.find_last_of('\n'); - if (p != string::npos && s2.find_first_not_of(' ', p + 1) == string::npos) - s2 = string(s2, 0, p + 1); + std::string::size_type p = s2.find_last_of('\n'); + if (p != std::string::npos && s2.find_first_not_of(' ', p + 1) == std::string::npos) { + s2 = std::string(s2, 0, p + 1); + } } es2->push_back(new ExprString(symbols.Create(s2))); @@ -354,7 +355,7 @@ expr_op | expr_op UPDATE expr_op { $$ = new ExprOpUpdate(CUR_POS, $1, $3); } | expr_op '?' attrpath { $$ = new ExprOpHasAttr($1, *$3); } | expr_op '+' expr_op - { $$ = new ExprConcatStrings(CUR_POS, false, new vector<Expr *>({$1, $3})); } + { $$ = new ExprConcatStrings(CUR_POS, false, new std::vector<Expr *>({$1, $3})); } | expr_op '-' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.Create("__sub")), $1), $3); } | expr_op '*' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.Create("__mul")), $1), $3); } | expr_op '/' expr_op { $$ = new ExprApp(CUR_POS, new ExprApp(new ExprVar(data->symbols.Create("__div")), $1), $3); } @@ -394,7 +395,7 @@ expr_simple $$ = stripIndentation(CUR_POS, data->symbols, *$2); } | PATH { $$ = new ExprPath(absPath($1, data->basePath)); } - | HPATH { $$ = new ExprPath(getHome() + string{$1 + 1}); } + | HPATH { $$ = new ExprPath(getHome() + std::string{$1 + 1}); } | SPATH { std::string path($1 + 1, strlen($1) - 2); $$ = new ExprApp(CUR_POS, @@ -424,9 +425,9 @@ string_parts string_parts_interpolated : string_parts_interpolated STR { $$ = $1; $1->push_back($2); } | string_parts_interpolated DOLLAR_CURLY expr '}' { $$ = $1; $1->push_back($3); } - | DOLLAR_CURLY expr '}' { $$ = new vector<Expr *>; $$->push_back($2); } + | DOLLAR_CURLY expr '}' { $$ = new std::vector<Expr *>; $$->push_back($2); } | STR DOLLAR_CURLY expr '}' { - $$ = new vector<Expr *>; + $$ = new std::vector<Expr *>; $$->push_back($1); $$->push_back($3); } @@ -435,7 +436,7 @@ string_parts_interpolated ind_string_parts : ind_string_parts IND_STR { $$ = $1; $1->push_back($2); } | ind_string_parts DOLLAR_CURLY expr '}' { $$ = $1; $1->push_back($3); } - | { $$ = new vector<Expr *>; } + | { $$ = new std::vector<Expr *>; } ; binds @@ -487,9 +488,9 @@ attrpath } else $$->push_back(AttrName($3)); } - | attr { $$ = new vector<AttrName>; $$->push_back(AttrName(data->symbols.Create($1))); } + | attr { $$ = new std::vector<AttrName>; $$->push_back(AttrName(data->symbols.Create($1))); } | string_attr - { $$ = new vector<AttrName>; + { $$ = new std::vector<AttrName>; ExprString *str = dynamic_cast<ExprString *>($1); if (str) { $$->push_back(AttrName(str->s)); @@ -603,7 +604,7 @@ Expr * EvalState::parseExprFromFile(const Path & path, StaticEnv & staticEnv) Expr * EvalState::parseExprFromString(const std::string & s, const Path & basePath, StaticEnv & staticEnv) { - return parse(s.c_str(), "(string)", basePath, staticEnv); + return parse(s.c_str(), "(std::string)", basePath, staticEnv); } @@ -625,11 +626,11 @@ void EvalState::addToSearchPath(const std::string & s) size_t pos = s.find('='); std::string prefix; Path path; - if (pos == string::npos) { + if (pos == std::string::npos) { path = s; } else { - prefix = string(s, 0, pos); - path = string(s, pos + 1); + prefix = std::string(s, 0, pos); + path = std::string(s, pos + 1); } searchPath.emplace_back(prefix, path); @@ -653,7 +654,7 @@ Path EvalState::findFile(SearchPath & searchPath, const std::string & path, cons if (path.compare(0, s, i.first) != 0 || (path.size() > s && path[s] != '/')) continue; - suffix = path.size() == s ? "" : "/" + string(path, s); + suffix = path.size() == s ? "" : "/" + std::string(path, s); } auto r = resolveSearchPathElem(i); if (!r.first) { continue; } @@ -662,7 +663,7 @@ Path EvalState::findFile(SearchPath & searchPath, const std::string & path, cons } format f = format( "file '%1%' was not found in the Nix search path (add it using $NIX_PATH or -I)" - + string(pos ? ", at %2%" : "")); + + std::string(pos ? ", at %2%" : "")); f.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); throw ThrownError(f % path % pos); } diff --git a/third_party/nix/src/libexpr/primops.cc b/third_party/nix/src/libexpr/primops.cc index 5a9f1fe72076..fa0057041713 100644 --- a/third_party/nix/src/libexpr/primops.cc +++ b/third_party/nix/src/libexpr/primops.cc @@ -32,13 +32,14 @@ namespace nix { /* Decode a context string ‘!<name>!<path>’ into a pair <path, name>. */ -std::pair<string, string> decodeContext(const std::string& s) { +std::pair<std::string, std::string> decodeContext(const std::string& s) { if (s.at(0) == '!') { size_t index = s.find('!', 1); - return std::pair<string, string>(string(s, index + 1), - string(s, 1, index - 1)); + return std::pair<std::string, std::string>(std::string(s, index + 1), + std::string(s, 1, index - 1)); } - return std::pair<string, string>(s.at(0) == '/' ? s : string(s, 1), ""); + return std::pair<std::string, std::string>( + s.at(0) == '/' ? s : std::string(s, 1), ""); } InvalidPathError::InvalidPathError(const Path& path) @@ -48,7 +49,7 @@ void EvalState::realiseContext(const PathSet& context) { PathSet drvs; for (auto& i : context) { - std::pair<string, string> decoded = decodeContext(i); + std::pair<std::string, std::string> decoded = decodeContext(i); Path ctx = decoded.first; assert(store->isStorePath(ctx)); if (!store->isValidPath(ctx)) { @@ -382,9 +383,9 @@ struct CompareValues { }; #if HAVE_BOEHMGC -typedef list<Value*, gc_allocator<Value*>> ValueList; +typedef std::list<Value*, gc_allocator<Value*>> ValueList; #else -typedef list<Value*> ValueList; +typedef std::list<Value*> ValueList; #endif static void prim_genericClosure(EvalState& state, const Pos& pos, Value** args, @@ -418,7 +419,7 @@ static void prim_genericClosure(EvalState& state, const Pos& pos, Value** args, ValueList res; // `doneKeys' doesn't need to be a GC root, because its values are // reachable from res. - set<Value*, CompareValues> doneKeys; + std::set<Value*, CompareValues> doneKeys; while (!workSet.empty()) { Value* e = *(workSet.begin()); workSet.pop_front(); @@ -743,7 +744,7 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos, if (path.at(0) == '=') { /* !!! This doesn't work if readOnlyMode is set. */ PathSet refs; - state.store->computeFSClosure(string(path, 1), refs); + state.store->computeFSClosure(std::string(path, 1), refs); for (auto& j : refs) { drv.inputSrcs.insert(j); if (isDerivation(j)) { @@ -754,7 +755,7 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos, /* Handle derivation outputs of the form ‘!<name>!<path>’. */ else if (path.at(0) == '!') { - std::pair<string, string> ctx = decodeContext(path); + std::pair<std::string, std::string> ctx = decodeContext(path); drv.inputDrvs[ctx.first].insert(ctx.second); } @@ -965,7 +966,7 @@ static void prim_readFile(EvalState& state, const Pos& pos, Value** args, } std::string s = readFile(state.checkSourcePath(state.toRealPath(path, context))); - if (s.find((char)0) != string::npos) { + if (s.find((char)0) != std::string::npos) { throw Error(format("the contents of the file '%1%' cannot be represented " "as a Nix string") % path); @@ -1899,7 +1900,7 @@ static void prim_substring(EvalState& state, const Pos& pos, Value** args, pos); } - mkString(v, (unsigned int)start >= s.size() ? "" : string(s, start, len), + mkString(v, (unsigned int)start >= s.size() ? "" : std::string(s, start, len), context); } @@ -2066,13 +2067,13 @@ static void prim_replaceStrings(EvalState& state, const Pos& pos, Value** args, pos); } - vector<string> from; + std::vector<std::string> from; from.reserve(args[0]->listSize()); for (unsigned int n = 0; n < args[0]->listSize(); ++n) { from.push_back(state.forceString(*args[0]->listElems()[n], pos)); } - vector<std::pair<string, PathSet>> to; + std::vector<std::pair<std::string, PathSet>> to; to.reserve(args[1]->listSize()); for (unsigned int n = 0; n < args[1]->listSize(); ++n) { PathSet ctx; diff --git a/third_party/nix/src/libexpr/primops/context.cc b/third_party/nix/src/libexpr/primops/context.cc index 2ae8ba8aa99e..481a2910bf84 100644 --- a/third_party/nix/src/libexpr/primops/context.cc +++ b/third_party/nix/src/libexpr/primops/context.cc @@ -36,7 +36,7 @@ static void prim_unsafeDiscardOutputDependency(EvalState& state, const Pos& pos, PathSet context2; for (auto& p : context) { - context2.insert(p.at(0) == '=' ? string(p, 1) : p); + context2.insert(p.at(0) == '=' ? std::string(p, 1) : p); } mkString(v, s, context2); @@ -79,10 +79,10 @@ static void prim_getContext(EvalState& state, const Pos& pos, Value** args, std::string output; const Path* path = &p; if (p.at(0) == '=') { - drv = string(p, 1); + drv = std::string(p, 1); path = &drv; } else if (p.at(0) == '!') { - std::pair<string, string> ctx = decodeContext(p); + std::pair<std::string, std::string> ctx = decodeContext(p); drv = ctx.first; output = ctx.second; path = &drv; @@ -170,7 +170,7 @@ static void prim_appendContext(EvalState& state, const Pos& pos, Value** args, "derivation, to a string, at %s", i->name, i->pos); } - context.insert("=" + string(i->name)); + context.insert("=" + std::string(i->name)); } } @@ -186,7 +186,7 @@ static void prim_appendContext(EvalState& state, const Pos& pos, Value** args, for (unsigned int n = 0; n < iter->second.value->listSize(); ++n) { auto name = state.forceStringNoCtx(*iter->second.value->listElems()[n], *iter->second.pos); - context.insert("!" + name + "!" + string(i->name)); + context.insert("!" + name + "!" + std::string(i->name)); } } } |