mirror of
https://github.com/NixOS/nix
synced 2025-06-30 07:33:16 +02:00
Introduce AbstractPos
This commit is contained in:
parent
a04ca0a522
commit
9e9170a92e
21 changed files with 158 additions and 182 deletions
|
@ -8,6 +8,64 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
struct SourcePathAdapter : AbstractPos
|
||||
{
|
||||
std::string file;
|
||||
|
||||
std::optional<std::string> getSource() const override
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void print(std::ostream & out) const override
|
||||
{
|
||||
out << fmt(ANSI_BLUE "at " ANSI_WARNING "%s:%s" ANSI_NORMAL ":", file, showErrPos());
|
||||
}
|
||||
};
|
||||
|
||||
struct StringPosAdapter : AbstractPos
|
||||
{
|
||||
void print(std::ostream & out) const override
|
||||
{
|
||||
out << fmt(ANSI_BLUE "at " ANSI_WARNING "«string»:%s" ANSI_NORMAL ":", showErrPos());
|
||||
}
|
||||
};
|
||||
|
||||
struct StdinPosAdapter : AbstractPos
|
||||
{
|
||||
void print(std::ostream & out) const override
|
||||
{
|
||||
out << fmt(ANSI_BLUE "at " ANSI_WARNING "«stdin»:%s" ANSI_NORMAL ":", showErrPos());
|
||||
}
|
||||
};
|
||||
|
||||
Pos::operator std::shared_ptr<AbstractPos>() const
|
||||
{
|
||||
if (!line) return nullptr;
|
||||
|
||||
switch (origin) {
|
||||
case foFile: {
|
||||
auto pos = std::make_shared<SourcePathAdapter>();
|
||||
pos->line = line;
|
||||
pos->column = column;
|
||||
pos->file = file;
|
||||
return pos;
|
||||
}
|
||||
case foStdin: {
|
||||
auto pos = std::make_shared<StdinPosAdapter>();
|
||||
pos->line = line;
|
||||
pos->column = column;
|
||||
return pos;
|
||||
}
|
||||
case foString:
|
||||
auto pos = std::make_shared<StringPosAdapter>();
|
||||
pos->line = line;
|
||||
pos->column = column;
|
||||
return pos;
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
|
||||
/* Displaying abstract syntax trees. */
|
||||
|
||||
static void showString(std::ostream & str, std::string_view s)
|
||||
|
@ -289,7 +347,6 @@ std::string showAttrPath(const SymbolTable & symbols, const AttrPath & attrPath)
|
|||
}
|
||||
|
||||
|
||||
|
||||
/* Computing levels/displacements for variables. */
|
||||
|
||||
void Expr::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue