mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-26 07:46:21 +02:00
Merge pull request #6201 from edolstra/print-value
printValue(): Don't show repeated values
This commit is contained in:
commit
391f4fcabe
3 changed files with 25 additions and 24 deletions
|
@ -86,15 +86,10 @@ RootValue allocRootValue(Value * v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void printValue(std::ostream & str, std::set<const Value *> & active, const Value & v)
|
void printValue(std::ostream & str, std::set<const void *> & seen, const Value & v)
|
||||||
{
|
{
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
|
|
||||||
if (!active.insert(&v).second) {
|
|
||||||
str << "<CYCLE>";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (v.internalType) {
|
switch (v.internalType) {
|
||||||
case tInt:
|
case tInt:
|
||||||
str << v.integer;
|
str << v.integer;
|
||||||
|
@ -120,24 +115,32 @@ void printValue(std::ostream & str, std::set<const Value *> & active, const Valu
|
||||||
str << "null";
|
str << "null";
|
||||||
break;
|
break;
|
||||||
case tAttrs: {
|
case tAttrs: {
|
||||||
|
if (!v.attrs->empty() && !seen.insert(v.attrs).second)
|
||||||
|
str << "<REPEAT>";
|
||||||
|
else {
|
||||||
str << "{ ";
|
str << "{ ";
|
||||||
for (auto & i : v.attrs->lexicographicOrder()) {
|
for (auto & i : v.attrs->lexicographicOrder()) {
|
||||||
str << i->name << " = ";
|
str << i->name << " = ";
|
||||||
printValue(str, active, *i->value);
|
printValue(str, seen, *i->value);
|
||||||
str << "; ";
|
str << "; ";
|
||||||
}
|
}
|
||||||
str << "}";
|
str << "}";
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case tList1:
|
case tList1:
|
||||||
case tList2:
|
case tList2:
|
||||||
case tListN:
|
case tListN:
|
||||||
|
if (v.listSize() && !seen.insert(v.listElems()).second)
|
||||||
|
str << "<REPEAT>";
|
||||||
|
else {
|
||||||
str << "[ ";
|
str << "[ ";
|
||||||
for (auto v2 : v.listItems()) {
|
for (auto v2 : v.listItems()) {
|
||||||
printValue(str, active, *v2);
|
printValue(str, seen, *v2);
|
||||||
str << " ";
|
str << " ";
|
||||||
}
|
}
|
||||||
str << "]";
|
str << "]";
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case tThunk:
|
case tThunk:
|
||||||
case tApp:
|
case tApp:
|
||||||
|
@ -161,15 +164,13 @@ void printValue(std::ostream & str, std::set<const Value *> & active, const Valu
|
||||||
default:
|
default:
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
active.erase(&v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::ostream & operator << (std::ostream & str, const Value & v)
|
std::ostream & operator << (std::ostream & str, const Value & v)
|
||||||
{
|
{
|
||||||
std::set<const Value *> active;
|
std::set<const void *> seen;
|
||||||
printValue(str, active, v);
|
printValue(str, seen, v);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,8 +114,8 @@ struct Value
|
||||||
private:
|
private:
|
||||||
InternalType internalType;
|
InternalType internalType;
|
||||||
|
|
||||||
friend std::string showType(const Value & v);
|
friend std::string showType(const Value & v);
|
||||||
friend void printValue(std::ostream & str, std::set<const Value *> & active, const Value & v);
|
friend void printValue(std::ostream & str, std::set<const void *> & seen, const Value & v);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
@ -800,7 +800,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
|
||||||
else
|
else
|
||||||
printStringValue(str, i.first.c_str());
|
printStringValue(str, i.first.c_str());
|
||||||
str << " = ";
|
str << " = ";
|
||||||
if (seen.find(i.second) != seen.end())
|
if (seen.count(i.second))
|
||||||
str << "«repeated»";
|
str << "«repeated»";
|
||||||
else
|
else
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue