aboutsummaryrefslogtreecommitdiff
path: root/paludis/repositories/e
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-12-30 22:48:34 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-01-01 03:57:53 +0000
commit3dd53676acf85d7b3d9758f2def081d20c00b3b9 (patch)
tree7214265998b38ce234a4198a4c2b9533aeea5f4d /paludis/repositories/e
parentcdaf7c2138035625d99ee5be127f427943b66e09 (diff)
downloadpaludis-3dd53676acf85d7b3d9758f2def081d20c00b3b9.tar.gz
paludis-3dd53676acf85d7b3d9758f2def081d20c00b3b9.tar.xz
Better pretty printing mechanism
Diffstat (limited to 'paludis/repositories/e')
-rw-r--r--paludis/repositories/e/Makefile.am2
-rw-r--r--paludis/repositories/e/e_key.cc95
-rw-r--r--paludis/repositories/e/e_key.hh40
-rw-r--r--paludis/repositories/e/info_metadata_key.cc11
-rw-r--r--paludis/repositories/e/info_metadata_key.hh4
-rw-r--r--paludis/repositories/e/spec_tree_pretty_printer.cc545
-rw-r--r--paludis/repositories/e/spec_tree_pretty_printer.hh72
7 files changed, 769 insertions, 0 deletions
diff --git a/paludis/repositories/e/Makefile.am b/paludis/repositories/e/Makefile.am
index 46235845e..b9f2e6ef0 100644
--- a/paludis/repositories/e/Makefile.am
+++ b/paludis/repositories/e/Makefile.am
@@ -83,6 +83,7 @@ noinst_HEADERS = \
profile_file.hh \
required_use_verifier.hh \
source_uri_finder.hh \
+ spec_tree_pretty_printer.hh \
traditional_layout.hh \
traditional_profile.hh \
use_desc.hh \
@@ -153,6 +154,7 @@ libpaludiserepository_la_SOURCES = \
registration.cc \
required_use_verifier.cc \
source_uri_finder.cc \
+ spec_tree_pretty_printer.cc \
traditional_layout.cc \
traditional_profile.cc \
use_desc.cc \
diff --git a/paludis/repositories/e/e_key.cc b/paludis/repositories/e/e_key.cc
index 61bef825b..3a7bd52ce 100644
--- a/paludis/repositories/e/e_key.cc
+++ b/paludis/repositories/e/e_key.cc
@@ -25,6 +25,7 @@
#include <paludis/repositories/e/vdb_contents_tokeniser.hh>
#include <paludis/repositories/e/e_repository.hh>
#include <paludis/repositories/e/myoption.hh>
+#include <paludis/repositories/e/spec_tree_pretty_printer.hh>
#include <paludis/util/pretty_print.hh>
#include <paludis/util/pimp-impl.hh>
@@ -51,6 +52,7 @@
#include <paludis/stringify_formatter-impl.hh>
#include <paludis/dep_spec_flattener.hh>
#include <paludis/literal_metadata_key.hh>
+#include <paludis/call_pretty_printer.hh>
#include <algorithm>
#include <functional>
@@ -167,6 +169,16 @@ EDependenciesKey::initial_labels() const
return _imp->labels;
}
+const std::string
+EDependenciesKey::pretty_print_value(
+ const PrettyPrinter & pretty_printer,
+ const PrettyPrintOptions & options) const
+{
+ SpecTreePrettyPrinter p(pretty_printer, options);
+ value()->top()->accept(p);
+ return stringify(p);
+}
+
std::string
EDependenciesKey::pretty_print(const DependencySpecTree::ItemFormatter & f) const
{
@@ -254,6 +266,16 @@ ELicenseKey::value() const
return _imp->value;
}
+const std::string
+ELicenseKey::pretty_print_value(
+ const PrettyPrinter & pretty_printer,
+ const PrettyPrintOptions & options) const
+{
+ SpecTreePrettyPrinter p(pretty_printer, options);
+ value()->top()->accept(p);
+ return stringify(p);
+}
+
std::string
ELicenseKey::pretty_print(const LicenseSpecTree::ItemFormatter & f) const
{
@@ -342,6 +364,16 @@ EFetchableURIKey::value() const
return _imp->value;
}
+const std::string
+EFetchableURIKey::pretty_print_value(
+ const PrettyPrinter & pretty_printer,
+ const PrettyPrintOptions & options) const
+{
+ SpecTreePrettyPrinter p(pretty_printer, options);
+ value()->top()->accept(p);
+ return stringify(p);
+}
+
std::string
EFetchableURIKey::pretty_print(const FetchableURISpecTree::ItemFormatter & f) const
{
@@ -467,6 +499,16 @@ ESimpleURIKey::value() const
return _imp->value;
}
+const std::string
+ESimpleURIKey::pretty_print_value(
+ const PrettyPrinter & pretty_printer,
+ const PrettyPrintOptions & options) const
+{
+ SpecTreePrettyPrinter p(pretty_printer, options);
+ value()->top()->accept(p);
+ return stringify(p);
+}
+
std::string
ESimpleURIKey::pretty_print(const SimpleURISpecTree::ItemFormatter & f) const
{
@@ -554,6 +596,16 @@ EPlainTextSpecKey::value() const
return _imp->value;
}
+const std::string
+EPlainTextSpecKey::pretty_print_value(
+ const PrettyPrinter & pretty_printer,
+ const PrettyPrintOptions & options) const
+{
+ SpecTreePrettyPrinter p(pretty_printer, options);
+ value()->top()->accept(p);
+ return stringify(p);
+}
+
std::string
EPlainTextSpecKey::pretty_print(const PlainTextSpecTree::ItemFormatter & f) const
{
@@ -642,6 +694,16 @@ EMyOptionsKey::value() const
return _imp->value;
}
+const std::string
+EMyOptionsKey::pretty_print_value(
+ const PrettyPrinter & pretty_printer,
+ const PrettyPrintOptions & options) const
+{
+ SpecTreePrettyPrinter p(pretty_printer, options);
+ value()->top()->accept(p);
+ return stringify(p);
+}
+
std::string
EMyOptionsKey::pretty_print(const PlainTextSpecTree::ItemFormatter & f) const
{
@@ -730,6 +792,16 @@ ERequiredUseKey::value() const
return _imp->value;
}
+const std::string
+ERequiredUseKey::pretty_print_value(
+ const PrettyPrinter & pretty_printer,
+ const PrettyPrintOptions & options) const
+{
+ SpecTreePrettyPrinter p(pretty_printer, options);
+ value()->top()->accept(p);
+ return stringify(p);
+}
+
std::string
ERequiredUseKey::pretty_print(const RequiredUseSpecTree::ItemFormatter & f) const
{
@@ -817,6 +889,16 @@ EProvideKey::value() const
return _imp->value;
}
+const std::string
+EProvideKey::pretty_print_value(
+ const PrettyPrinter & pretty_printer,
+ const PrettyPrintOptions & options) const
+{
+ SpecTreePrettyPrinter p(pretty_printer, options);
+ value()->top()->accept(p);
+ return stringify(p);
+}
+
std::string
EProvideKey::pretty_print(const ProvideSpecTree::ItemFormatter & f) const
{
@@ -904,6 +986,12 @@ EKeywordsKey::value() const
return _imp->value;
}
+const std::string
+EKeywordsKey::pretty_print_value(const PrettyPrinter & p, const PrettyPrintOptions &) const
+{
+ return join(value()->begin(), value()->end(), " ", CallPrettyPrinter(p));
+}
+
std::string
EKeywordsKey::pretty_print_flat(const Formatter<KeywordName> & f) const
{
@@ -1026,6 +1114,13 @@ EStringSetKey::pretty_print_flat(const Formatter<std::string> & f) const
return join(value()->begin(), value()->end(), " ", std::bind(&format_string, _1, f));
}
+const std::string
+EStringSetKey::pretty_print_value(
+ const PrettyPrinter & p, const PrettyPrintOptions &) const
+{
+ return join(value()->begin(), value()->end(), " ", CallPrettyPrinter(p));
+}
+
namespace paludis
{
template <>
diff --git a/paludis/repositories/e/e_key.hh b/paludis/repositories/e/e_key.hh
index 62f344dee..6589da8ff 100644
--- a/paludis/repositories/e/e_key.hh
+++ b/paludis/repositories/e/e_key.hh
@@ -85,6 +85,10 @@ namespace paludis
virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual const std::string pretty_print_value(
+ const PrettyPrinter &,
+ const PrettyPrintOptions &) const PALUDIS_ATTRIBUTE((warn_unused_result));
};
class EFetchableURIKey :
@@ -114,6 +118,10 @@ namespace paludis
virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual const std::string pretty_print_value(
+ const PrettyPrinter &,
+ const PrettyPrintOptions &) const PALUDIS_ATTRIBUTE((warn_unused_result));
};
class ESimpleURIKey :
@@ -138,6 +146,10 @@ namespace paludis
virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual const std::string pretty_print_value(
+ const PrettyPrinter &,
+ const PrettyPrintOptions &) const PALUDIS_ATTRIBUTE((warn_unused_result));
};
class EPlainTextSpecKey :
@@ -163,6 +175,10 @@ namespace paludis
virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual const std::string pretty_print_value(
+ const PrettyPrinter &,
+ const PrettyPrintOptions &) const PALUDIS_ATTRIBUTE((warn_unused_result));
};
class EMyOptionsKey :
@@ -187,6 +203,10 @@ namespace paludis
virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual const std::string pretty_print_value(
+ const PrettyPrinter &,
+ const PrettyPrintOptions &) const PALUDIS_ATTRIBUTE((warn_unused_result));
};
class ERequiredUseKey :
@@ -211,6 +231,10 @@ namespace paludis
virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual const std::string pretty_print_value(
+ const PrettyPrinter &,
+ const PrettyPrintOptions &) const PALUDIS_ATTRIBUTE((warn_unused_result));
};
class EProvideKey :
@@ -235,6 +259,10 @@ namespace paludis
virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual const std::string pretty_print_value(
+ const PrettyPrinter &,
+ const PrettyPrintOptions &) const PALUDIS_ATTRIBUTE((warn_unused_result));
};
class ELicenseKey :
@@ -261,6 +289,10 @@ namespace paludis
virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual const std::string pretty_print_value(
+ const PrettyPrinter &,
+ const PrettyPrintOptions &) const PALUDIS_ATTRIBUTE((warn_unused_result));
};
class EKeywordsKey :
@@ -283,6 +315,10 @@ namespace paludis
virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual const std::string pretty_print_value(
+ const PrettyPrinter &,
+ const PrettyPrintOptions &) const PALUDIS_ATTRIBUTE((warn_unused_result));
};
class EStringSetKey :
@@ -303,6 +339,10 @@ namespace paludis
virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual const std::string pretty_print_value(
+ const PrettyPrinter &,
+ const PrettyPrintOptions &) const PALUDIS_ATTRIBUTE((warn_unused_result));
};
class EContentsKey :
diff --git a/paludis/repositories/e/info_metadata_key.cc b/paludis/repositories/e/info_metadata_key.cc
index 1e78bc554..11744495a 100644
--- a/paludis/repositories/e/info_metadata_key.cc
+++ b/paludis/repositories/e/info_metadata_key.cc
@@ -42,6 +42,8 @@
#include <paludis/environment.hh>
#include <paludis/package_id.hh>
#include <paludis/formatter.hh>
+#include <paludis/pretty_printer.hh>
+#include <paludis/call_pretty_printer.hh>
#include <map>
#include <algorithm>
@@ -225,6 +227,15 @@ InfoVarsMetadataKey::pretty_print_flat(const Formatter<std::string> & f) const
}
const std::string
+InfoVarsMetadataKey::pretty_print_value(
+ const PrettyPrinter & pretty_printer,
+ const PrettyPrintOptions &) const
+{
+ using namespace std::placeholders;
+ return join(value()->begin(), value()->end(), " ", CallPrettyPrinter(pretty_printer));
+}
+
+const std::string
InfoPkgsMetadataKey::raw_name() const
{
return "info_pkgs";
diff --git a/paludis/repositories/e/info_metadata_key.hh b/paludis/repositories/e/info_metadata_key.hh
index e4db7518b..ea3dc9fe1 100644
--- a/paludis/repositories/e/info_metadata_key.hh
+++ b/paludis/repositories/e/info_metadata_key.hh
@@ -50,6 +50,10 @@ namespace paludis
virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual const std::string pretty_print_value(
+ const PrettyPrinter &,
+ const PrettyPrintOptions &) const PALUDIS_ATTRIBUTE((warn_unused_result));
};
}
diff --git a/paludis/repositories/e/spec_tree_pretty_printer.cc b/paludis/repositories/e/spec_tree_pretty_printer.cc
new file mode 100644
index 000000000..363d5e01f
--- /dev/null
+++ b/paludis/repositories/e/spec_tree_pretty_printer.cc
@@ -0,0 +1,545 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2010 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis/repositories/e/spec_tree_pretty_printer.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/save.hh>
+#include <paludis/util/accept_visitor.hh>
+#include <paludis/util/pimp-impl.hh>
+#include <paludis/pretty_printer.hh>
+#include <paludis/dep_spec_annotations.hh>
+#include <algorithm>
+#include <sstream>
+
+using namespace paludis;
+using namespace paludis::erepository;
+
+namespace paludis
+{
+ template<>
+ struct Imp<SpecTreePrettyPrinter>
+ {
+ std::stringstream s;
+ const PrettyPrinter & pretty_printer;
+ const PrettyPrintOptions options;
+
+ unsigned indent;
+ bool extra_label_indent;
+ bool use_newlines;
+ bool outer_block;
+ bool all_needs_parens;
+ bool need_space;
+
+ Imp(const PrettyPrinter & p, const PrettyPrintOptions & o) :
+ pretty_printer(p),
+ options(o),
+ indent(0),
+ extra_label_indent(false),
+ use_newlines(options[ppo_multiline_allowed]),
+ outer_block(true),
+ all_needs_parens(false),
+ need_space(false)
+ {
+ }
+ };
+}
+
+SpecTreePrettyPrinter::SpecTreePrettyPrinter(
+ const PrettyPrinter & p,
+ const PrettyPrintOptions & o) :
+ Pimp<SpecTreePrettyPrinter>(p, o)
+{
+}
+
+SpecTreePrettyPrinter::~SpecTreePrettyPrinter() = default;
+
+std::ostream &
+paludis::erepository::operator<< (std::ostream & s, const SpecTreePrettyPrinter & p)
+{
+ s << p._imp->s.str();
+ return s;
+}
+
+namespace
+{
+ struct IsLabelVisitor
+ {
+ bool result;
+
+ IsLabelVisitor() :
+ result(false)
+ {
+ }
+
+ void visit(const GenericSpecTree::NodeType<PlainTextDepSpec>::Type &)
+ {
+ }
+
+ void visit(const GenericSpecTree::NodeType<SimpleURIDepSpec>::Type &)
+ {
+ }
+
+ void visit(const GenericSpecTree::NodeType<FetchableURIDepSpec>::Type &)
+ {
+ }
+
+ void visit(const GenericSpecTree::NodeType<LicenseDepSpec>::Type &)
+ {
+ }
+
+ void visit(const GenericSpecTree::NodeType<PackageDepSpec>::Type &)
+ {
+ }
+
+ void visit(const GenericSpecTree::NodeType<BlockDepSpec>::Type &)
+ {
+ }
+
+ void visit(const GenericSpecTree::NodeType<PlainTextLabelDepSpec>::Type &)
+ {
+ result = true;
+ }
+
+ void visit(const GenericSpecTree::NodeType<URILabelsDepSpec>::Type &)
+ {
+ result = true;
+ }
+
+ void visit(const GenericSpecTree::NodeType<DependenciesLabelsDepSpec>::Type &)
+ {
+ result = true;
+ }
+
+ void visit(const GenericSpecTree::NodeType<NamedSetDepSpec>::Type &)
+ {
+ }
+
+ void visit(const GenericSpecTree::NodeType<AllDepSpec>::Type &)
+ {
+ }
+
+ void visit(const GenericSpecTree::NodeType<ExactlyOneDepSpec>::Type &)
+ {
+ }
+
+ void visit(const GenericSpecTree::NodeType<AnyDepSpec>::Type &)
+ {
+ }
+
+ void visit(const GenericSpecTree::NodeType<ConditionalDepSpec>::Type &)
+ {
+ }
+ };
+
+ bool is_label(const GenericSpecTree::BasicNode & i)
+ {
+ IsLabelVisitor v;
+ i.accept(v);
+ return v.result;
+ }
+}
+
+void
+SpecTreePrettyPrinter::visit(const GenericSpecTree::NodeType<AllDepSpec>::Type & node)
+{
+ bool need_parens(_imp->all_needs_parens || node.spec()->maybe_annotations() ||
+ (! _imp->outer_block && indirect_iterator(node.end()) != std::find_if(indirect_iterator(node.begin()),
+ indirect_iterator(node.end()),
+ is_label)));
+ Save<bool> old_outer(&_imp->outer_block, false);
+ Save<bool> old_needs_parens(&_imp->all_needs_parens, false);
+
+ if (need_parens)
+ {
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+ _imp->s << "(";
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+ }
+
+ {
+ Save<unsigned> old_indent(&_imp->indent, need_parens ? _imp->indent +1 : _imp->indent);
+ Save<bool> extra_label_indent(&_imp->extra_label_indent, need_parens ? false : _imp->extra_label_indent);
+ std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(*this));
+ }
+
+ if (need_parens)
+ {
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+ _imp->s << ")";
+
+ do_annotations(*node.spec());
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+ }
+}
+
+void
+SpecTreePrettyPrinter::visit(const GenericSpecTree::NodeType<AnyDepSpec>::Type & node)
+{
+ Save<bool> old_outer(&_imp->outer_block, false);
+ Save<bool> old_needs_parens(&_imp->all_needs_parens, true);
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+ _imp->s << "|| (";
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+
+ {
+ Save<unsigned> old_indent(&_imp->indent, _imp->indent + 1);
+ Save<bool> extra_label_indent(&_imp->extra_label_indent, false);
+ std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(*this));
+ }
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+ _imp->s << ")";
+
+ do_annotations(*node.spec());
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+}
+
+void
+SpecTreePrettyPrinter::visit(const GenericSpecTree::NodeType<ExactlyOneDepSpec>::Type & node)
+{
+ Save<bool> old_outer(&_imp->outer_block, false);
+ Save<bool> old_needs_parens(&_imp->all_needs_parens, true);
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+ _imp->s << "^^ (";
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+
+ {
+ Save<unsigned> old_indent(&_imp->indent, _imp->indent + 1);
+ Save<bool> extra_label_indent(&_imp->extra_label_indent, false);
+ std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(*this));
+ }
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+ _imp->s << ")";
+
+ do_annotations(*node.spec());
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+}
+
+void
+SpecTreePrettyPrinter::visit(const GenericSpecTree::NodeType<ConditionalDepSpec>::Type & node)
+{
+ Save<bool> old_outer(&_imp->outer_block, false);
+ Save<bool> old_needs_parens(&_imp->all_needs_parens, false);
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+
+ _imp->s << _imp->pretty_printer.prettify(*node.spec()) << " (";
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+
+ {
+ Save<unsigned> old_indent(&_imp->indent, _imp->indent + 1);
+ Save<bool> extra_label_indent(&_imp->extra_label_indent, false);
+ std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(*this));
+ }
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+ _imp->s << ")";
+
+ do_annotations(*node.spec());
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+}
+
+void
+SpecTreePrettyPrinter::visit(const GenericSpecTree::NodeType<PackageDepSpec>::Type & node)
+{
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+
+ _imp->s << _imp->pretty_printer.prettify(*node.spec());
+
+ do_annotations(*node.spec());
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+}
+
+void
+SpecTreePrettyPrinter::visit(const GenericSpecTree::NodeType<PlainTextDepSpec>::Type & node)
+{
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+
+ _imp->s << _imp->pretty_printer.prettify(*node.spec());
+
+ do_annotations(*node.spec());
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+}
+
+void
+SpecTreePrettyPrinter::visit(const GenericSpecTree::NodeType<NamedSetDepSpec>::Type & node)
+{
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+
+ _imp->s << _imp->pretty_printer.prettify(*node.spec());
+
+ do_annotations(*node.spec());
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+}
+
+void
+SpecTreePrettyPrinter::visit(const GenericSpecTree::NodeType<LicenseDepSpec>::Type & node)
+{
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+
+ _imp->s << _imp->pretty_printer.prettify(*node.spec());
+
+ do_annotations(*node.spec());
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+}
+
+void
+SpecTreePrettyPrinter::visit(const GenericSpecTree::NodeType<FetchableURIDepSpec>::Type & node)
+{
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+
+ _imp->s << _imp->pretty_printer.prettify(*node.spec());
+
+ do_annotations(*node.spec());
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+}
+
+void
+SpecTreePrettyPrinter::visit(const GenericSpecTree::NodeType<SimpleURIDepSpec>::Type & node)
+{
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+
+ _imp->s << _imp->pretty_printer.prettify(*node.spec());
+
+ do_annotations(*node.spec());
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+}
+
+void
+SpecTreePrettyPrinter::visit(const GenericSpecTree::NodeType<BlockDepSpec>::Type & node)
+{
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+
+ _imp->s << _imp->pretty_printer.prettify(*node.spec());
+
+ do_annotations(*node.spec());
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+}
+
+void
+SpecTreePrettyPrinter::visit(const GenericSpecTree::NodeType<URILabelsDepSpec>::Type & node)
+{
+ if (_imp->extra_label_indent)
+ {
+ _imp->extra_label_indent = false;
+ _imp->indent -= 1;
+ }
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+
+ _imp->s << _imp->pretty_printer.prettify(*node.spec());
+
+ do_annotations(*node.spec());
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+
+ if (! _imp->extra_label_indent)
+ {
+ _imp->extra_label_indent = true;
+ _imp->indent += 1;
+ }
+}
+
+void
+SpecTreePrettyPrinter::visit(const GenericSpecTree::NodeType<PlainTextLabelDepSpec>::Type & node)
+{
+ if (_imp->extra_label_indent)
+ {
+ _imp->extra_label_indent = false;
+ _imp->indent -= 1;
+ }
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+
+ _imp->s << _imp->pretty_printer.prettify(*node.spec());
+
+ do_annotations(*node.spec());
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+
+ if (! _imp->extra_label_indent)
+ {
+ _imp->extra_label_indent = true;
+ _imp->indent += 1;
+ }
+}
+
+void
+SpecTreePrettyPrinter::visit(const GenericSpecTree::NodeType<DependenciesLabelsDepSpec>::Type & node)
+{
+ if (_imp->extra_label_indent)
+ {
+ _imp->extra_label_indent = false;
+ _imp->indent -= 1;
+ }
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.indentify(_imp->indent);
+ else if (_imp->need_space)
+ _imp->s << " ";
+
+ _imp->s << _imp->pretty_printer.prettify(*node.spec());
+
+ do_annotations(*node.spec());
+
+ if (_imp->use_newlines)
+ _imp->s << _imp->pretty_printer.newline();
+ else
+ _imp->need_space = true;
+
+ if (!_imp->extra_label_indent)
+ {
+ _imp->extra_label_indent = true;
+ _imp->indent += 1;
+ }
+}
+
+void
+SpecTreePrettyPrinter::do_annotations(const DepSpec & p)
+{
+ if (p.maybe_annotations() && (p.maybe_annotations()->begin() != p.maybe_annotations()->end()))
+ {
+ _imp->s << " [[ ";
+
+ for (auto m(p.maybe_annotations()->begin()), m_end(p.maybe_annotations()->end()) ;
+ m != m_end ; ++m)
+ {
+ _imp->s << m->key() << " = [" << (m->value().empty() ? " " : " " + m->value() + " ") << "] ";
+ }
+ _imp->s << "]]";
+ }
+}
+
diff --git a/paludis/repositories/e/spec_tree_pretty_printer.hh b/paludis/repositories/e/spec_tree_pretty_printer.hh
new file mode 100644
index 000000000..a44ecfc1f
--- /dev/null
+++ b/paludis/repositories/e/spec_tree_pretty_printer.hh
@@ -0,0 +1,72 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2010 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_SPEC_TREE_PRETTY_PRINTER_HH
+#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_SPEC_TREE_PRETTY_PRINTER_HH 1
+
+#include <paludis/util/attributes.hh>
+#include <paludis/dep_spec.hh>
+#include <paludis/spec_tree.hh>
+#include <paludis/metadata_key-fwd.hh>
+#include <paludis/environment-fwd.hh>
+#include <paludis/package_id-fwd.hh>
+#include <paludis/pretty_print_options-fwd.hh>
+#include <paludis/pretty_printer-fwd.hh>
+
+namespace paludis
+{
+ namespace erepository
+ {
+ class PALUDIS_VISIBLE SpecTreePrettyPrinter :
+ private Pimp<SpecTreePrettyPrinter>
+ {
+ friend std::ostream & operator<< (std::ostream &, const SpecTreePrettyPrinter &);
+
+ private:
+ void do_annotations(const DepSpec &);
+
+ public:
+ SpecTreePrettyPrinter(
+ const PrettyPrinter &,
+ const PrettyPrintOptions &
+ );
+
+ ~SpecTreePrettyPrinter();
+
+ void visit(const GenericSpecTree::NodeType<AllDepSpec>::Type & node);
+ void visit(const GenericSpecTree::NodeType<AnyDepSpec>::Type & node);
+ void visit(const GenericSpecTree::NodeType<ExactlyOneDepSpec>::Type & node);
+ void visit(const GenericSpecTree::NodeType<ConditionalDepSpec>::Type & node);
+ void visit(const GenericSpecTree::NodeType<PackageDepSpec>::Type & node);
+ void visit(const GenericSpecTree::NodeType<BlockDepSpec>::Type & node);
+ void visit(const GenericSpecTree::NodeType<DependenciesLabelsDepSpec>::Type & node);
+ void visit(const GenericSpecTree::NodeType<NamedSetDepSpec>::Type & node);
+ void visit(const GenericSpecTree::NodeType<SimpleURIDepSpec>::Type & node);
+ void visit(const GenericSpecTree::NodeType<FetchableURIDepSpec>::Type & node);
+ void visit(const GenericSpecTree::NodeType<URILabelsDepSpec>::Type & node);
+ void visit(const GenericSpecTree::NodeType<PlainTextDepSpec>::Type & node);
+ void visit(const GenericSpecTree::NodeType<PlainTextLabelDepSpec>::Type & node);
+ void visit(const GenericSpecTree::NodeType<LicenseDepSpec>::Type & node);
+ };
+
+ std::ostream & operator<< (std::ostream & s, const SpecTreePrettyPrinter & p) PALUDIS_VISIBLE;
+ }
+}
+
+#endif