mirror of
https://github.com/NixOS/nix.git
synced 2025-11-15 06:52:43 +01:00
libexpr: use std::span rather than const std::vector &
This commit is contained in:
parent
2d728f0c56
commit
90ba96a3d6
2 changed files with 32 additions and 9 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,
|
||||||
const std::span<const AttrName> & attrPath,
|
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, const std::vector<AttrName> & attrPath)
|
ExprOpHasAttr(std::pmr::polymorphic_allocator<char> & alloc, Expr * e, std::span<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, const std::vector<Expr *> & exprs)
|
ExprList(std::pmr::polymorphic_allocator<char> & alloc, std::span<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());
|
||||||
|
|
@ -753,7 +753,19 @@ struct ExprConcatStrings : Expr
|
||||||
std::pmr::polymorphic_allocator<char> & alloc,
|
std::pmr::polymorphic_allocator<char> & alloc,
|
||||||
const PosIdx & pos,
|
const PosIdx & pos,
|
||||||
bool forceString,
|
bool forceString,
|
||||||
const std::vector<std::pair<PosIdx, Expr *>> & es)
|
std::span<std::pair<PosIdx, Expr *>> es)
|
||||||
|
: pos(pos)
|
||||||
|
, forceString(forceString)
|
||||||
|
, es({alloc.allocate_object<std::pair<PosIdx, Expr *>>(es.size()), es.size()})
|
||||||
|
{
|
||||||
|
std::ranges::copy(es, this->es.begin());
|
||||||
|
};
|
||||||
|
|
||||||
|
ExprConcatStrings(
|
||||||
|
std::pmr::polymorphic_allocator<char> & alloc,
|
||||||
|
const PosIdx & pos,
|
||||||
|
bool forceString,
|
||||||
|
std::initializer_list<std::pair<PosIdx, Expr *>> es)
|
||||||
: pos(pos)
|
: pos(pos)
|
||||||
, forceString(forceString)
|
, forceString(forceString)
|
||||||
, es({alloc.allocate_object<std::pair<PosIdx, Expr *>>(es.size()), es.size()})
|
, es({alloc.allocate_object<std::pair<PosIdx, Expr *>>(es.size()), es.size()})
|
||||||
|
|
@ -833,7 +845,19 @@ public:
|
||||||
add(std::pmr::polymorphic_allocator<char> & alloc,
|
add(std::pmr::polymorphic_allocator<char> & alloc,
|
||||||
const PosIdx & pos,
|
const PosIdx & pos,
|
||||||
bool forceString,
|
bool forceString,
|
||||||
const std::vector<std::pair<PosIdx, Expr *>> & es)
|
std::span<std::pair<PosIdx, Expr *>> es)
|
||||||
|
requires(std::same_as<C, ExprConcatStrings>)
|
||||||
|
{
|
||||||
|
return alloc.new_object<C>(alloc, pos, forceString, es);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
[[gnu::always_inline]]
|
||||||
|
C *
|
||||||
|
add(std::pmr::polymorphic_allocator<char> & alloc,
|
||||||
|
const PosIdx & pos,
|
||||||
|
bool forceString,
|
||||||
|
std::initializer_list<std::pair<PosIdx, Expr *>> es)
|
||||||
requires(std::same_as<C, ExprConcatStrings>)
|
requires(std::same_as<C, ExprConcatStrings>)
|
||||||
{
|
{
|
||||||
return alloc.new_object<C>(alloc, pos, forceString, es);
|
return alloc.new_object<C>(alloc, pos, forceString, es);
|
||||||
|
|
|
||||||
|
|
@ -96,8 +96,7 @@ 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 *
|
Expr * stripIndentation(const PosIdx pos, std::span<std::pair<PosIdx, std::variant<Expr *, StringToken>>> es);
|
||||||
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);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -239,8 +238,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 * ParserState::stripIndentation(
|
inline Expr *
|
||||||
const PosIdx pos, const std::vector<std::pair<PosIdx, std::variant<Expr *, StringToken>>> & es)
|
ParserState::stripIndentation(const PosIdx pos, std::span<std::pair<PosIdx, std::variant<Expr *, StringToken>>> es)
|
||||||
{
|
{
|
||||||
if (es.empty())
|
if (es.empty())
|
||||||
return exprs.add<ExprString>(""_sds);
|
return exprs.add<ExprString>(""_sds);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue