aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-08-16 21:40:29 +0100
committerAvatar David Leverton <levertond@googlemail.com> 2008-08-16 21:43:32 +0100
commitb1d4ba7ddf41ae047eb2cb43f28bb48c58375021 (patch)
tree6d6a3a34c33179461b910661ca1146178c016001
parent6054ceaa64a6d5ec81f1558c0e90b77ae6907bb0 (diff)
downloadpaludis-b1d4ba7ddf41ae047eb2cb43f28bb48c58375021.tar.gz
paludis-b1d4ba7ddf41ae047eb2cb43f28bb48c58375021.tar.xz
Fix DepSpec pretty-printing with labels.
-rw-r--r--paludis/repositories/e/dep_spec_pretty_printer.cc88
-rw-r--r--paludis/repositories/e/e_repository_TEST.cc6
-rwxr-xr-xpaludis/repositories/e/ebuild_flat_metadata_cache_TEST_setup.sh2
-rw-r--r--paludis/repositories/e/vdb_repository_TEST.cc6
4 files changed, 91 insertions, 11 deletions
diff --git a/paludis/repositories/e/dep_spec_pretty_printer.cc b/paludis/repositories/e/dep_spec_pretty_printer.cc
index 2052ee2..232de62 100644
--- a/paludis/repositories/e/dep_spec_pretty_printer.cc
+++ b/paludis/repositories/e/dep_spec_pretty_printer.cc
@@ -57,6 +57,7 @@ namespace paludis
bool extra_label_indent;
bool use_newlines;
bool outer_block;
+ bool all_needs_parens;
bool need_space;
Implementation(
@@ -72,6 +73,7 @@ namespace paludis
extra_label_indent(false),
use_newlines(b),
outer_block(true),
+ all_needs_parens(false),
need_space(false)
{
}
@@ -99,12 +101,88 @@ paludis::erepository::operator<< (std::ostream & s, const DepSpecPrettyPrinter &
return s;
}
+namespace
+{
+ struct IsLabelVisitor :
+ ConstVisitor<GenericSpecTree>
+ {
+ bool result;
+
+ IsLabelVisitor() :
+ result(false)
+ {
+ }
+
+ void visit_leaf(const PlainTextDepSpec &)
+ {
+ }
+
+ void visit_leaf(const SimpleURIDepSpec &)
+ {
+ }
+
+ void visit_leaf(const FetchableURIDepSpec &)
+ {
+ }
+
+ void visit_leaf(const LicenseDepSpec &)
+ {
+ }
+
+ void visit_leaf(const PackageDepSpec &)
+ {
+ }
+
+ void visit_leaf(const BlockDepSpec &)
+ {
+ }
+
+ void visit_leaf(const URILabelsDepSpec &)
+ {
+ result = true;
+ }
+
+ void visit_leaf(const DependencyLabelsDepSpec &)
+ {
+ result = true;
+ }
+
+ void visit_leaf(const NamedSetDepSpec &)
+ {
+ }
+
+ void visit_sequence(const AllDepSpec &, GenericSpecTree::ConstSequenceIterator, GenericSpecTree::ConstSequenceIterator)
+ {
+ }
+
+ void visit_sequence(const AnyDepSpec &, GenericSpecTree::ConstSequenceIterator, GenericSpecTree::ConstSequenceIterator)
+ {
+ }
+
+ void visit_sequence(const ConditionalDepSpec &, GenericSpecTree::ConstSequenceIterator, GenericSpecTree::ConstSequenceIterator)
+ {
+ }
+ };
+
+ bool is_label(const ConstAcceptInterface<GenericSpecTree> & i)
+ {
+ IsLabelVisitor v;
+ i.accept(v);
+ return v.result;
+ }
+}
+
void
DepSpecPrettyPrinter::visit_sequence(const AllDepSpec &,
GenericSpecTree::ConstSequenceIterator cur,
GenericSpecTree::ConstSequenceIterator end)
{
- if (! _imp->outer_block)
+ bool need_parens(_imp->all_needs_parens ||
+ (! _imp->outer_block && end != std::find_if(cur, 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->formatter.indent(_imp->indent);
@@ -118,12 +196,12 @@ DepSpecPrettyPrinter::visit_sequence(const AllDepSpec &,
}
{
- Save<unsigned> old_indent(&_imp->indent, _imp->outer_block ? _imp->indent : _imp->indent + 1);
- Save<bool> extra_label_indent(&_imp->extra_label_indent, _imp->outer_block ? _imp->extra_label_indent : false);
+ 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(cur, end, accept_visitor(*this));
}
- if (! _imp->outer_block)
+ if (need_parens)
{
if (_imp->use_newlines)
_imp->s << _imp->formatter.indent(_imp->indent);
@@ -143,6 +221,7 @@ DepSpecPrettyPrinter::visit_sequence(const AnyDepSpec &,
GenericSpecTree::ConstSequenceIterator end)
{
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->formatter.indent(_imp->indent);
@@ -177,6 +256,7 @@ DepSpecPrettyPrinter::visit_sequence(const ConditionalDepSpec & a,
GenericSpecTree::ConstSequenceIterator end)
{
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->formatter.indent(_imp->indent);
diff --git a/paludis/repositories/e/e_repository_TEST.cc b/paludis/repositories/e/e_repository_TEST.cc
index a26cf96..e30290e 100644
--- a/paludis/repositories/e/e_repository_TEST.cc
+++ b/paludis/repositories/e/e_repository_TEST.cc
@@ -2139,17 +2139,17 @@ namespace test_cases
erepository::DepSpecPrettyPrinter pd(0, std::tr1::shared_ptr<const PackageID>(), ff, 0, false);
TEST_CHECK(id->build_dependencies_key());
id->build_dependencies_key()->value()->accept(pd);
- TEST_CHECK_STRINGIFY_EQUAL(pd, "cat/pkg1 build: cat/pkg2 build,run: cat/pkg3 suggested: cat/pkg4 post:");
+ TEST_CHECK_STRINGIFY_EQUAL(pd, "( cat/pkg1 build: cat/pkg2 build,run: cat/pkg3 suggested: cat/pkg4 post: )");
erepository::DepSpecPrettyPrinter pr(0, std::tr1::shared_ptr<const PackageID>(), ff, 0, false);
TEST_CHECK(id->run_dependencies_key());
id->run_dependencies_key()->value()->accept(pr);
- TEST_CHECK_STRINGIFY_EQUAL(pr, "cat/pkg1 build: build,run: cat/pkg3 suggested: cat/pkg4 post:");
+ TEST_CHECK_STRINGIFY_EQUAL(pr, "( cat/pkg1 build: build,run: cat/pkg3 suggested: cat/pkg4 post: )");
erepository::DepSpecPrettyPrinter pp(0, std::tr1::shared_ptr<const PackageID>(), ff, 0, false);
TEST_CHECK(id->post_dependencies_key());
id->post_dependencies_key()->value()->accept(pp);
- TEST_CHECK_STRINGIFY_EQUAL(pp, "build: build,run: suggested: post: cat/pkg5");
+ TEST_CHECK_STRINGIFY_EQUAL(pp, "( build: build,run: suggested: post: cat/pkg5 )");
}
} test_e_repository_dependencies_rewriter;
diff --git a/paludis/repositories/e/ebuild_flat_metadata_cache_TEST_setup.sh b/paludis/repositories/e/ebuild_flat_metadata_cache_TEST_setup.sh
index 39408c6..87a843d 100755
--- a/paludis/repositories/e/ebuild_flat_metadata_cache_TEST_setup.sh
+++ b/paludis/repositories/e/ebuild_flat_metadata_cache_TEST_setup.sh
@@ -1033,7 +1033,7 @@ END
cat <<END > cache/expected/cat/write-exlibs-1
_mtime_=60
_exlibs_=bar ebuild_flat_metadata_cache_TEST_dir/repo/cat/exlibs 180 foo ebuild_flat_metadata_cache_TEST_dir/repo/exlibs 180
-DEPENDENCIES=build: cat/foo bar? ( cat/bar ) cat/baz build: bar? ( ) cat/baz build: bar? ( )
+DEPENDENCIES=( build: cat/foo bar? ( cat/bar ) ) cat/baz ( build: bar? ( ) ) cat/baz ( build: bar? ( ) )
SLOT=0
HOMEPAGE=http://example.com/
LICENSE=GPL-2
diff --git a/paludis/repositories/e/vdb_repository_TEST.cc b/paludis/repositories/e/vdb_repository_TEST.cc
index a20b8fe..1e71c7c 100644
--- a/paludis/repositories/e/vdb_repository_TEST.cc
+++ b/paludis/repositories/e/vdb_repository_TEST.cc
@@ -269,17 +269,17 @@ namespace test_cases
erepository::DepSpecPrettyPrinter pd(0, std::tr1::shared_ptr<const PackageID>(), ff, 0, false);
TEST_CHECK(id->build_dependencies_key());
id->build_dependencies_key()->value()->accept(pd);
- TEST_CHECK_STRINGIFY_EQUAL(pd, "cat/pkg1 build: cat/pkg2 build,run: cat/pkg3 suggested: cat/pkg4 post:");
+ TEST_CHECK_STRINGIFY_EQUAL(pd, "( cat/pkg1 build: cat/pkg2 build,run: cat/pkg3 suggested: cat/pkg4 post: )");
erepository::DepSpecPrettyPrinter pr(0, std::tr1::shared_ptr<const PackageID>(), ff, 0, false);
TEST_CHECK(id->run_dependencies_key());
id->run_dependencies_key()->value()->accept(pr);
- TEST_CHECK_STRINGIFY_EQUAL(pr, "cat/pkg1 build: build,run: cat/pkg3 suggested: cat/pkg4 post:");
+ TEST_CHECK_STRINGIFY_EQUAL(pr, "( cat/pkg1 build: build,run: cat/pkg3 suggested: cat/pkg4 post: )");
erepository::DepSpecPrettyPrinter pp(0, std::tr1::shared_ptr<const PackageID>(), ff, 0, false);
TEST_CHECK(id->post_dependencies_key());
id->post_dependencies_key()->value()->accept(pp);
- TEST_CHECK_STRINGIFY_EQUAL(pp, "build: build,run: suggested: post: cat/pkg5");
+ TEST_CHECK_STRINGIFY_EQUAL(pp, "( build: build,run: suggested: post: cat/pkg5 )");
}
} test_vdb_repository_dependencies_rewriter;