aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2013-05-23 22:03:47 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2013-05-23 22:03:47 +0100
commitcc5f762b62509071450a6405fe63416c9e8e3cde (patch)
treec03b720bd3a6bfa8b5ca993d28c09371310b53a6
parent8629539830b1521995e798a0404a701e99a6c110 (diff)
downloadpaludis-cc5f762b62509071450a6405fe63416c9e8e3cde.tar.gz
paludis-cc5f762b62509071450a6405fe63416c9e8e3cde.tar.xz
Convert to fancy new visitors
-rw-r--r--paludis/resolver/get_sameness.cc44
-rw-r--r--paludis/resolver/reason.cc64
-rw-r--r--paludis/resolver/reason_utils.cc123
3 files changed, 57 insertions, 174 deletions
diff --git a/paludis/resolver/get_sameness.cc b/paludis/resolver/get_sameness.cc
index e313901..29c8a2a 100644
--- a/paludis/resolver/get_sameness.cc
+++ b/paludis/resolver/get_sameness.cc
@@ -40,38 +40,6 @@ using namespace paludis::resolver;
namespace
{
- /* since the EAPI5 syntax for rewritten := deps in the VDB doesn't
- allow us to tell whether the dep was originally a := kind or
- a :slot= kind, normalise them all to the same thing to avoid
- spurious differences */
- struct SloppySlotStringifier
- {
- /* this is probably covered by the generic case that just
- does a stringify, but a package format could theoretically
- define a different representation, so assume the standard
- form here for compatibility with the other two that we're
- assuming */
- std::string visit(const SlotAnyAtAllLockedRequirement &) const
- {
- return ":=";
- }
-
- std::string visit(const SlotAnyPartialLockedRequirement &) const
- {
- return ":=";
- }
-
- std::string visit(const SlotUnknownRewrittenRequirement &) const
- {
- return ":=";
- }
-
- std::string visit(const SlotRequirement & r) const
- {
- return stringify(r);
- }
- };
-
struct ComparingPrettyPrinter :
UnformattedPrettyPrinter
{
@@ -102,9 +70,17 @@ namespace
if (s.slot_requirement_ptr())
{
+ /* since the EAPI5 syntax for rewritten := deps in the VDB
+ * doesn't allow us to tell whether the dep was originally a :=
+ * kind or a :slot= kind, normalise them all to the same thing
+ * to avoid spurious differences */
auto r(s.slot_requirement_ptr()->maybe_original_requirement_if_rewritten());
- tokens.insert("slot_requirement:" + (r ? r : s.slot_requirement_ptr())
- ->accept_returning<std::string>(SloppySlotStringifier()));
+ tokens.insert("slot_requirement:" + (r ? r : s.slot_requirement_ptr())->make_accept_returning(
+ [&] (const SlotAnyAtAllLockedRequirement &) { return std::string{ ":=" }; },
+ [&] (const SlotAnyPartialLockedRequirement &) { return std::string{ ":=" }; },
+ [&] (const SlotUnknownRewrittenRequirement &) { return std::string{ ":=" }; },
+ [&] (const SlotRequirement & q) { return stringify(q); }
+ ));
}
if (s.in_repository_ptr())
diff --git a/paludis/resolver/reason.cc b/paludis/resolver/reason.cc
index 36cb23d..c34904e 100644
--- a/paludis/resolver/reason.cc
+++ b/paludis/resolver/reason.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2009, 2010, 2011 Ciaran McCreesh
+ * Copyright (c) 2009, 2010, 2011, 2013 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
@@ -495,56 +495,28 @@ namespace
{
return stringify(r.resolvent());
}
-
- struct ReasonStringifier
- {
- std::string visit(const TargetReason &) const
- {
- return "target";
- }
-
- std::string visit(const DependencyReason & r) const
- {
- return "dependency from " + stringify(*r.from_id());
- }
-
- std::string visit(const DependentReason & r) const
- {
- return "dependent upon " + stringify(*r.dependent_upon().package_id());
- }
-
- std::string visit(const WasUsedByReason & r) const
- {
- return "was used by " + join(r.ids_and_resolvents_being_removed()->begin(), r.ids_and_resolvents_being_removed()->end(),
- ", ", stringify_change_by_resolvent);
- }
-
- std::string visit(const PresetReason &) const
- {
- return "preset";
- }
-
- std::string visit(const SetReason & r) const
- {
- return "set " + stringify(r.set_name()) + " due to " + r.reason_for_set()->accept_returning<std::string>(*this);
- }
-
- std::string visit(const LikeOtherDestinationTypeReason & r) const
- {
- return "to be like " + stringify(r.other_resolvent()) + " due to " + r.reason_for_other()->accept_returning<std::string>(*this);
- }
-
- std::string visit(const ViaBinaryReason & r) const
- {
- return "via binary for " + stringify(r.other_resolvent());
- }
- };
}
std::ostream &
paludis::operator<< (std::ostream & s, const Reason & d)
{
- s << d.accept_returning<std::string>(ReasonStringifier());
+ s << d.make_accept_returning(
+ [&] (const TargetReason &) { return std::string{ "target" }; },
+ [&] (const DependencyReason & r) { return "dependency from " + stringify(*r.from_id()); },
+ [&] (const DependentReason & r) { return "dependent upon " + stringify(*r.dependent_upon().package_id()); },
+ [&] (const ViaBinaryReason & r) { return "via binary for " + stringify(r.other_resolvent()); },
+ [&] (const PresetReason &) { return "preset"; },
+ [&] (const WasUsedByReason & r) {
+ return "was used by " + join(r.ids_and_resolvents_being_removed()->begin(), r.ids_and_resolvents_being_removed()->end(),
+ ", ", stringify_change_by_resolvent);
+ },
+ [&] (const SetReason & r, const Revisit<std::string, Reason> & revisit) {
+ return "set " + stringify(r.set_name()) + " due to " + revisit(*r.reason_for_set());
+ },
+ [&] (const LikeOtherDestinationTypeReason & r, const Revisit<std::string, Reason> & revisit) {
+ return "to be like " + stringify(r.other_resolvent()) + " due to " + revisit(*r.reason_for_other());
+ }
+ );
return s;
}
diff --git a/paludis/resolver/reason_utils.cc b/paludis/resolver/reason_utils.cc
index 4a075c1..54707e8 100644
--- a/paludis/resolver/reason_utils.cc
+++ b/paludis/resolver/reason_utils.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2010, 2011 Ciaran McCreesh
+ * Copyright (c) 2010, 2011, 2013 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
@@ -23,106 +23,41 @@
using namespace paludis;
using namespace paludis::resolver;
-namespace
-{
- struct IsTargetVisitor
- {
- bool visit(const DependencyReason &) const
- {
- return false;
- }
-
- bool visit(const DependentReason &) const
- {
- return false;
- }
-
- bool visit(const WasUsedByReason &) const
- {
- return false;
- }
-
- bool visit(const PresetReason &) const
- {
- return false;
- }
-
- bool visit(const ViaBinaryReason &) const
- {
- return false;
- }
-
- bool visit(const TargetReason &) const
- {
- return true;
- }
-
- bool visit(const LikeOtherDestinationTypeReason & r) const
- {
- return r.reason_for_other()->accept_returning<bool>(*this);
- }
-
- bool visit(const SetReason & r) const
- {
- return r.reason_for_set()->accept_returning<bool>(*this);
- }
- };
-
- struct FromIDVisitor
- {
- std::shared_ptr<const PackageID> visit(const DependencyReason & r) const
- {
- return r.from_id();
- }
-
- std::shared_ptr<const PackageID> visit(const DependentReason &) const
- {
- return nullptr;
- }
-
- std::shared_ptr<const PackageID> visit(const WasUsedByReason &) const
- {
- return nullptr;
- }
-
- std::shared_ptr<const PackageID> visit(const PresetReason &) const
- {
- return nullptr;
- }
-
- std::shared_ptr<const PackageID> visit(const ViaBinaryReason &) const
- {
- return nullptr;
- }
-
- std::shared_ptr<const PackageID> visit(const TargetReason &) const
- {
- return nullptr;
- }
-
- std::shared_ptr<const PackageID> visit(const LikeOtherDestinationTypeReason & r) const
- {
- return r.reason_for_other()->accept_returning<std::shared_ptr<const PackageID> >(*this);
- }
-
- std::shared_ptr<const PackageID> visit(const SetReason & r) const
- {
- return r.reason_for_set()->accept_returning<std::shared_ptr<const PackageID> >(*this);
- }
- };
-}
-
bool
paludis::resolver::is_target(const std::shared_ptr<const Reason> & reason)
{
- IsTargetVisitor v;
- return reason->accept_returning<bool>(v);
+ return reason->make_accept_returning(
+ [&] (const DependencyReason &) { return false; },
+ [&] (const DependentReason &) { return false; },
+ [&] (const WasUsedByReason &) { return false; },
+ [&] (const PresetReason &) { return false; },
+ [&] (const ViaBinaryReason &) { return false; },
+ [&] (const TargetReason &) { return true; },
+ [&] (const LikeOtherDestinationTypeReason & r, const Revisit<bool, Reason> & revisit) {
+ return revisit(*r.reason_for_other());
+ },
+ [&] (const SetReason & r, const Revisit<bool, Reason> & revisit) {
+ return revisit(*r.reason_for_set());
+ }
+ );
}
const std::shared_ptr<const PackageID>
paludis::resolver::maybe_from_package_id_from_reason(const std::shared_ptr<const Reason> & reason)
{
- FromIDVisitor v;
- return reason->accept_returning<std::shared_ptr<const PackageID> >(v);
+ return reason->make_accept_returning(
+ [&] (const DependencyReason & r) { return r.from_id(); },
+ [&] (const DependentReason &) { return nullptr; },
+ [&] (const WasUsedByReason &) { return nullptr; },
+ [&] (const PresetReason &) { return nullptr; },
+ [&] (const ViaBinaryReason &) { return nullptr; },
+ [&] (const TargetReason &) { return nullptr; },
+ [&] (const LikeOtherDestinationTypeReason & r, const Revisit<std::shared_ptr<const PackageID>, Reason> & revisit) {
+ return revisit(*r.reason_for_other());
+ },
+ [&] (const SetReason & r, const Revisit<std::shared_ptr<const PackageID>, Reason> & revisit) {
+ return revisit(*r.reason_for_set());
+ }
+ );
}