mirror of
https://github.com/NixOS/nix.git
synced 2025-11-19 16:59:35 +01:00
parser.y: remove pointless std::move()s
This commit is contained in:
parent
7a60f1429f
commit
5ffc9fd253
3 changed files with 19 additions and 18 deletions
|
|
@ -289,7 +289,7 @@ struct ExprSelect : Expr
|
||||||
std::pmr::polymorphic_allocator<char> & alloc,
|
std::pmr::polymorphic_allocator<char> & alloc,
|
||||||
const PosIdx & pos,
|
const PosIdx & pos,
|
||||||
Expr * e,
|
Expr * e,
|
||||||
std::span<const AttrName> attrPath,
|
const std::span<const AttrName> & attrPath,
|
||||||
Expr * def)
|
Expr * def)
|
||||||
: pos(pos)
|
: pos(pos)
|
||||||
, nAttrPath(attrPath.size())
|
, nAttrPath(attrPath.size())
|
||||||
|
|
@ -339,7 +339,7 @@ struct ExprOpHasAttr : Expr
|
||||||
Expr * e;
|
Expr * e;
|
||||||
std::span<AttrName> attrPath;
|
std::span<AttrName> attrPath;
|
||||||
|
|
||||||
ExprOpHasAttr(std::pmr::polymorphic_allocator<char> & alloc, Expr * e, std::vector<AttrName> attrPath)
|
ExprOpHasAttr(std::pmr::polymorphic_allocator<char> & alloc, Expr * e, const std::vector<AttrName> & attrPath)
|
||||||
: e(e)
|
: e(e)
|
||||||
, attrPath({alloc.allocate_object<AttrName>(attrPath.size()), attrPath.size()})
|
, attrPath({alloc.allocate_object<AttrName>(attrPath.size()), attrPath.size()})
|
||||||
{
|
{
|
||||||
|
|
@ -433,7 +433,7 @@ struct ExprList : Expr
|
||||||
{
|
{
|
||||||
std::span<Expr *> elems;
|
std::span<Expr *> elems;
|
||||||
|
|
||||||
ExprList(std::pmr::polymorphic_allocator<char> & alloc, std::vector<Expr *> exprs)
|
ExprList(std::pmr::polymorphic_allocator<char> & alloc, const std::vector<Expr *> & exprs)
|
||||||
: elems({alloc.allocate_object<Expr *>(exprs.size()), exprs.size()})
|
: elems({alloc.allocate_object<Expr *>(exprs.size()), exprs.size()})
|
||||||
{
|
{
|
||||||
std::ranges::copy(exprs, elems.begin());
|
std::ranges::copy(exprs, elems.begin());
|
||||||
|
|
@ -562,7 +562,7 @@ public:
|
||||||
const PosTable & positions,
|
const PosTable & positions,
|
||||||
std::pmr::polymorphic_allocator<char> & alloc,
|
std::pmr::polymorphic_allocator<char> & alloc,
|
||||||
PosIdx pos,
|
PosIdx pos,
|
||||||
FormalsBuilder formals,
|
const FormalsBuilder & formals,
|
||||||
Expr * body)
|
Expr * body)
|
||||||
: ExprLambda(positions, alloc, pos, Symbol(), formals, body) {};
|
: ExprLambda(positions, alloc, pos, Symbol(), formals, body) {};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,8 @@ struct ParserState
|
||||||
ExprAttrs * attrs, AttrPath && attrPath, const ParserLocation & loc, Expr * e, const ParserLocation & exprLoc);
|
ExprAttrs * attrs, AttrPath && attrPath, const ParserLocation & loc, Expr * e, const ParserLocation & exprLoc);
|
||||||
void addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def);
|
void addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def);
|
||||||
void validateFormals(FormalsBuilder & formals, PosIdx pos = noPos, Symbol arg = {});
|
void validateFormals(FormalsBuilder & formals, PosIdx pos = noPos, Symbol arg = {});
|
||||||
Expr * stripIndentation(const PosIdx pos, std::vector<std::pair<PosIdx, std::variant<Expr *, StringToken>>> && es);
|
Expr *
|
||||||
|
stripIndentation(const PosIdx pos, const std::vector<std::pair<PosIdx, std::variant<Expr *, StringToken>>> & es);
|
||||||
PosIdx at(const ParserLocation & loc);
|
PosIdx at(const ParserLocation & loc);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -238,8 +239,8 @@ inline void ParserState::validateFormals(FormalsBuilder & formals, PosIdx pos, S
|
||||||
{.msg = HintFmt("duplicate formal function argument '%1%'", symbols[arg]), .pos = positions[pos]});
|
{.msg = HintFmt("duplicate formal function argument '%1%'", symbols[arg]), .pos = positions[pos]});
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Expr *
|
inline Expr * ParserState::stripIndentation(
|
||||||
ParserState::stripIndentation(const PosIdx pos, std::vector<std::pair<PosIdx, std::variant<Expr *, StringToken>>> && es)
|
const PosIdx pos, const std::vector<std::pair<PosIdx, std::variant<Expr *, StringToken>>> & es)
|
||||||
{
|
{
|
||||||
if (es.empty())
|
if (es.empty())
|
||||||
return exprs.add<ExprString>(""_sds);
|
return exprs.add<ExprString>(""_sds);
|
||||||
|
|
@ -343,7 +344,7 @@ ParserState::stripIndentation(const PosIdx pos, std::vector<std::pair<PosIdx, st
|
||||||
auto * const result = (es2)[0].second;
|
auto * const result = (es2)[0].second;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return exprs.add<ExprConcatStrings>(exprs.alloc, pos, true, std::move(es2));
|
return exprs.add<ExprConcatStrings>(exprs.alloc, pos, true, es2);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline PosIdx LexerState::at(const ParserLocation & loc)
|
inline PosIdx LexerState::at(const ParserLocation & loc)
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,7 @@ expr_function
|
||||||
| formal_set ':' expr_function[body]
|
| formal_set ':' expr_function[body]
|
||||||
{
|
{
|
||||||
state->validateFormals($formal_set);
|
state->validateFormals($formal_set);
|
||||||
auto me = state->exprs.add<ExprLambda>(state->positions, state->exprs.alloc, CUR_POS, std::move($formal_set), $body);
|
auto me = state->exprs.add<ExprLambda>(state->positions, state->exprs.alloc, CUR_POS, $formal_set, $body);
|
||||||
$$ = me;
|
$$ = me;
|
||||||
SET_DOC_POS(me, @1);
|
SET_DOC_POS(me, @1);
|
||||||
}
|
}
|
||||||
|
|
@ -194,7 +194,7 @@ expr_function
|
||||||
{
|
{
|
||||||
auto arg = state->symbols.create($ID);
|
auto arg = state->symbols.create($ID);
|
||||||
state->validateFormals($formal_set, CUR_POS, arg);
|
state->validateFormals($formal_set, CUR_POS, arg);
|
||||||
auto me = state->exprs.add<ExprLambda>(state->positions, state->exprs.alloc, CUR_POS, arg, std::move($formal_set), $body);
|
auto me = state->exprs.add<ExprLambda>(state->positions, state->exprs.alloc, CUR_POS, arg, $formal_set, $body);
|
||||||
$$ = me;
|
$$ = me;
|
||||||
SET_DOC_POS(me, @1);
|
SET_DOC_POS(me, @1);
|
||||||
}
|
}
|
||||||
|
|
@ -202,7 +202,7 @@ expr_function
|
||||||
{
|
{
|
||||||
auto arg = state->symbols.create($ID);
|
auto arg = state->symbols.create($ID);
|
||||||
state->validateFormals($formal_set, CUR_POS, arg);
|
state->validateFormals($formal_set, CUR_POS, arg);
|
||||||
auto me = state->exprs.add<ExprLambda>(state->positions, state->exprs.alloc, CUR_POS, arg, std::move($formal_set), $body);
|
auto me = state->exprs.add<ExprLambda>(state->positions, state->exprs.alloc, CUR_POS, arg, $formal_set, $body);
|
||||||
$$ = me;
|
$$ = me;
|
||||||
SET_DOC_POS(me, @1);
|
SET_DOC_POS(me, @1);
|
||||||
}
|
}
|
||||||
|
|
@ -251,7 +251,7 @@ expr_op
|
||||||
| expr_op OR expr_op { $$ = state->exprs.add<ExprOpOr>(state->at(@2), $1, $3); }
|
| expr_op OR expr_op { $$ = state->exprs.add<ExprOpOr>(state->at(@2), $1, $3); }
|
||||||
| expr_op IMPL expr_op { $$ = state->exprs.add<ExprOpImpl>(state->at(@2), $1, $3); }
|
| expr_op IMPL expr_op { $$ = state->exprs.add<ExprOpImpl>(state->at(@2), $1, $3); }
|
||||||
| expr_op UPDATE expr_op { $$ = state->exprs.add<ExprOpUpdate>(state->at(@2), $1, $3); }
|
| expr_op UPDATE expr_op { $$ = state->exprs.add<ExprOpUpdate>(state->at(@2), $1, $3); }
|
||||||
| expr_op '?' attrpath { $$ = state->exprs.add<ExprOpHasAttr>(state->exprs.alloc, $1, std::move($3)); }
|
| expr_op '?' attrpath { $$ = state->exprs.add<ExprOpHasAttr>(state->exprs.alloc, $1, $3); }
|
||||||
| expr_op '+' expr_op
|
| expr_op '+' expr_op
|
||||||
{ $$ = state->exprs.add<ExprConcatStrings>(state->exprs.alloc, state->at(@2), false, {{state->at(@1), $1}, {state->at(@3), $3}}); }
|
{ $$ = state->exprs.add<ExprConcatStrings>(state->exprs.alloc, state->at(@2), false, {{state->at(@1), $1}, {state->at(@3), $3}}); }
|
||||||
| expr_op '-' expr_op { $$ = state->exprs.add<ExprCall>(state->at(@2), state->exprs.add<ExprVar>(state->s.sub), {$1, $3}); }
|
| expr_op '-' expr_op { $$ = state->exprs.add<ExprCall>(state->at(@2), state->exprs.add<ExprVar>(state->s.sub), {$1, $3}); }
|
||||||
|
|
@ -272,9 +272,9 @@ expr_app
|
||||||
|
|
||||||
expr_select
|
expr_select
|
||||||
: expr_simple '.' attrpath
|
: expr_simple '.' attrpath
|
||||||
{ $$ = state->exprs.add<ExprSelect>(state->exprs.alloc, CUR_POS, $1, std::move($3), nullptr); }
|
{ $$ = state->exprs.add<ExprSelect>(state->exprs.alloc, CUR_POS, $1, $3, nullptr); }
|
||||||
| expr_simple '.' attrpath OR_KW expr_select
|
| expr_simple '.' attrpath OR_KW expr_select
|
||||||
{ $$ = state->exprs.add<ExprSelect>(state->exprs.alloc, CUR_POS, $1, std::move($3), $5); $5->warnIfCursedOr(state->symbols, state->positions); }
|
{ $$ = state->exprs.add<ExprSelect>(state->exprs.alloc, CUR_POS, $1, $3, $5); $5->warnIfCursedOr(state->symbols, state->positions); }
|
||||||
| /* Backwards compatibility: because Nixpkgs has a function named ‘or’,
|
| /* Backwards compatibility: because Nixpkgs has a function named ‘or’,
|
||||||
allow stuff like ‘map or [...]’. This production is problematic (see
|
allow stuff like ‘map or [...]’. This production is problematic (see
|
||||||
https://github.com/NixOS/nix/issues/11118) and will be refactored in the
|
https://github.com/NixOS/nix/issues/11118) and will be refactored in the
|
||||||
|
|
@ -304,12 +304,12 @@ expr_simple
|
||||||
$2);
|
$2);
|
||||||
}
|
}
|
||||||
| IND_STRING_OPEN ind_string_parts IND_STRING_CLOSE {
|
| IND_STRING_OPEN ind_string_parts IND_STRING_CLOSE {
|
||||||
$$ = state->stripIndentation(CUR_POS, std::move($2));
|
$$ = state->stripIndentation(CUR_POS, $2);
|
||||||
}
|
}
|
||||||
| path_start PATH_END
|
| path_start PATH_END
|
||||||
| path_start string_parts_interpolated PATH_END {
|
| path_start string_parts_interpolated PATH_END {
|
||||||
$2.insert($2.begin(), {state->at(@1), $1});
|
$2.insert($2.begin(), {state->at(@1), $1});
|
||||||
$$ = state->exprs.add<ExprConcatStrings>(state->exprs.alloc, CUR_POS, false, std::move($2));
|
$$ = state->exprs.add<ExprConcatStrings>(state->exprs.alloc, CUR_POS, false, $2);
|
||||||
}
|
}
|
||||||
| SPATH {
|
| SPATH {
|
||||||
std::string_view path($1.p + 1, $1.l - 2);
|
std::string_view path($1.p + 1, $1.l - 2);
|
||||||
|
|
@ -338,12 +338,12 @@ expr_simple
|
||||||
{ $2->pos = CUR_POS; $$ = $2; }
|
{ $2->pos = CUR_POS; $$ = $2; }
|
||||||
| '{' '}'
|
| '{' '}'
|
||||||
{ $$ = state->exprs.add<ExprAttrs>(CUR_POS); }
|
{ $$ = state->exprs.add<ExprAttrs>(CUR_POS); }
|
||||||
| '[' list ']' { $$ = state->exprs.add<ExprList>(state->exprs.alloc, std::move($2)); }
|
| '[' list ']' { $$ = state->exprs.add<ExprList>(state->exprs.alloc, $2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
string_parts
|
string_parts
|
||||||
: STR { $$ = $1; }
|
: STR { $$ = $1; }
|
||||||
| string_parts_interpolated { $$ = state->exprs.add<ExprConcatStrings>(state->exprs.alloc, CUR_POS, true, std::move($1)); }
|
| string_parts_interpolated { $$ = state->exprs.add<ExprConcatStrings>(state->exprs.alloc, CUR_POS, true, $1); }
|
||||||
| { $$ = std::string_view(); }
|
| { $$ = std::string_view(); }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue