diff options
author | Qyriad <qyriad@qyriad.me> | 2024-05-31 13:12:14 -0600 |
---|---|---|
committer | Qyriad <qyriad@qyriad.me> | 2024-06-17 15:13:18 +0000 |
commit | 19a93dd02508a7a7dddde633f76044911acb5668 (patch) | |
tree | 7e709eee522aac06ead32805664fd5213a6ef1d6 /src/libexpr/nixexpr.hh | |
parent | 010d93393e7dd978927f1c805c9b0c64e96b0ecc (diff) |
mini-refactor "lambda.name or anonymous lambda" logic
Change-Id: I08d39c4ad5b967de526c0d5c5e6299256c7967f3
Diffstat (limited to 'src/libexpr/nixexpr.hh')
-rw-r--r-- | src/libexpr/nixexpr.hh | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 64a9ddeec..d18c37dda 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -297,6 +297,31 @@ struct ExprLambda : Expr std::string showNamePos(const EvalState & state) const; inline bool hasFormals() const { return formals != nullptr; } PosIdx getPos() const override { return pos; } + + /** Returns the name of the lambda, + * or "anonymous lambda" if it doesn't have one. + */ + inline std::string getName(SymbolTable const & symbols) const + { + if (this->name) { + return symbols[this->name]; + } + + return "anonymous lambda"; + } + + /** Returns the name of the lambda in single quotes, + * or "anonymous lambda" if it doesn't have one. + */ + inline std::string getQuotedName(SymbolTable const & symbols) const + { + if (this->name) { + return concatStrings("'", symbols[this->name], "'"); + } + + return "anonymous lambda"; + } + COMMON_METHODS }; |