Skip to content

Commit 816e3cc

Browse files
committed
libexpr: apply static analysis "quick fix" to splitted files
This PR contains no functioanl change, there are bunch of suggesstions by clang-tidy in the file and there are fixes available. Including: - 0 -> nullptr - use `auto` for iterator types - sort `#include`s - closing namespace comment - use `.empty()` instead of comparing it with empty object - use `auto` if it the type is apparently specified (e.g. `new Type`) - add const specifier or `&` to improve readability
1 parent b9f5324 commit 816e3cc

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed

src/libexpr/lexer/prologue.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static StringToken unescapeStr(SymbolTable & symbols, char * s, size_t length)
8484
return {result, size_t(t - result)};
8585
}
8686

87-
}
87+
} // namespace nix
8888

8989
#define YY_USER_INIT initLoc(yylloc)
9090
#define YY_USER_ACTION adjustLoc(yylloc, yytext, yyleng);

src/libexpr/parser/epilogue.inc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
#include <sys/types.h>
21
#include <sys/stat.h>
2+
#include <sys/types.h>
3+
34
#include <fcntl.h>
45
#include <unistd.h>
56

67
#include "parser-tab.hh"
7-
88
#include "lexer-tab.hh"
99

1010
#include "eval.hh"
11-
#include "filetransfer.hh"
1211
#include "fetchers.hh"
13-
#include "store-api.hh"
12+
#include "filetransfer.hh"
1413
#include "flake/flake.hh"
14+
#include "store-api.hh"
1515

1616
namespace nix {
1717

@@ -97,7 +97,7 @@ SourcePath EvalState::findFile(const std::string_view path)
9797

9898
SourcePath EvalState::findFile(const SearchPath & searchPath, const std::string_view path, const PosIdx pos)
9999
{
100-
for (auto & i : searchPath.elements) {
100+
for (const auto & i : searchPath.elements) {
101101
auto suffixOpt = i.prefix.suffixIfPotentialMatch(path);
102102

103103
if (!suffixOpt)
@@ -109,7 +109,7 @@ SourcePath EvalState::findFile(const SearchPath & searchPath, const std::string_
109109
continue;
110110
auto r = *rOpt;
111111

112-
Path res = suffix == "" ? r : concatStrings(r, "/", suffix);
112+
Path res = suffix.empty() ? r : concatStrings(r, "/", suffix);
113113
if (pathExists(res))
114114
return CanonPath(canonPath(res));
115115
}
@@ -125,12 +125,12 @@ SourcePath EvalState::findFile(const SearchPath & searchPath, const std::string_
125125
: "file '%s' was not found in the Nix search path (add it using $NIX_PATH or -I)",
126126
path),
127127
.errPos = positions[pos]}),
128-
0, 0);
128+
nullptr, nullptr);
129129
}
130130

131131
std::optional<std::string> EvalState::resolveSearchPathPath(const SearchPath::Path & value0)
132132
{
133-
auto & value = value0.s;
133+
const auto & value = value0.s;
134134
auto i = searchPathResolved.find(value);
135135
if (i != searchPathResolved.end())
136136
return i->second;
@@ -175,4 +175,4 @@ std::optional<std::string> EvalState::resolveSearchPathPath(const SearchPath::Pa
175175
return res;
176176
}
177177

178-
}
178+
} // namespace nix

src/libexpr/parser/prologue.inc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#include "parser-tab.hh"
32
#include "lexer-tab.hh"
43

@@ -32,37 +31,37 @@ static void addAttr(ExprAttrs * attrs, AttrPath && attrPath, Expr * e, const Pos
3231
// ===========================
3332
for (i = attrPath.begin(); i + 1 < attrPath.end(); i++) {
3433
if (i->symbol) {
35-
ExprAttrs::AttrDefs::iterator j = attrs->attrs.find(i->symbol);
34+
auto j = attrs->attrs.find(i->symbol);
3635
if (j != attrs->attrs.end()) {
3736
if (!j->second.inherited) {
38-
ExprAttrs * attrs2 = dynamic_cast<ExprAttrs *>(j->second.e);
37+
auto * attrs2 = dynamic_cast<ExprAttrs *>(j->second.e);
3938
if (!attrs2)
4039
dupAttr(state, attrPath, pos, j->second.pos);
4140
attrs = attrs2;
4241
} else
4342
dupAttr(state, attrPath, pos, j->second.pos);
4443
} else {
45-
ExprAttrs * nested = new ExprAttrs;
44+
auto * nested = new ExprAttrs;
4645
attrs->attrs[i->symbol] = ExprAttrs::AttrDef(nested, pos);
4746
attrs = nested;
4847
}
4948
} else {
50-
ExprAttrs * nested = new ExprAttrs;
49+
auto * nested = new ExprAttrs;
5150
attrs->dynamicAttrs.push_back(ExprAttrs::DynamicAttrDef(i->expr, nested, pos));
5251
attrs = nested;
5352
}
5453
}
5554
// Expr insertion.
5655
// ==========================
5756
if (i->symbol) {
58-
ExprAttrs::AttrDefs::iterator j = attrs->attrs.find(i->symbol);
57+
auto j = attrs->attrs.find(i->symbol);
5958
if (j != attrs->attrs.end()) {
6059
// This attr path is already defined. However, if both
6160
// e and the expr pointed by the attr path are two attribute sets,
6261
// we want to merge them.
6362
// Otherwise, throw an error.
64-
auto ae = dynamic_cast<ExprAttrs *>(e);
65-
auto jAttrs = dynamic_cast<ExprAttrs *>(j->second.e);
63+
auto * ae = dynamic_cast<ExprAttrs *>(e);
64+
auto * jAttrs = dynamic_cast<ExprAttrs *>(j->second.e);
6665
if (jAttrs && ae) {
6766
for (auto & ad : ae->attrs) {
6867
auto j2 = jAttrs->attrs.find(ad.first);
@@ -222,7 +221,7 @@ static inline PosIdx makeCurPos(const YYLTYPE & loc, ParseData * data)
222221

223222
#define CUR_POS makeCurPos(*yylocp, data)
224223

225-
}
224+
} // namespace nix
226225

227226
void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * error)
228227
{

src/libexpr/parser/requires.hh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
#include <variant>
66

7-
#include "util.hh"
8-
9-
#include "nixexpr.hh"
10-
#include "eval.hh"
117
#include "eval-settings.hh"
8+
#include "eval.hh"
129
#include "globals.hh"
10+
#include "nixexpr.hh"
11+
#include "util.hh"
1312

1413
namespace nix {
1514

@@ -29,7 +28,7 @@ struct ParserFormals
2928
bool ellipsis = false;
3029
};
3130

32-
}
31+
} // namespace nix
3332

3433
// using C a struct allows us to avoid having to define the special
3534
// members that using string_view here would implicitly delete.

0 commit comments

Comments
 (0)