From cc5f762b62509071450a6405fe63416c9e8e3cde Mon Sep 17 00:00:00 2001 From: Ciaran McCreesh Date: Thu, 23 May 2013 22:03:47 +0100 Subject: Convert to fancy new visitors --- paludis/resolver/get_sameness.cc | 44 ++++---------- paludis/resolver/reason.cc | 64 ++++++-------------- paludis/resolver/reason_utils.cc | 123 +++++++++------------------------------ 3 files changed, 57 insertions(+), 174 deletions(-) diff --git a/paludis/resolver/get_sameness.cc b/paludis/resolver/get_sameness.cc index e313901a1..29c8a2ab7 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(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 36cb23d30..c34904edf 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(*this); - } - - std::string visit(const LikeOtherDestinationTypeReason & r) const - { - return "to be like " + stringify(r.other_resolvent()) + " due to " + r.reason_for_other()->accept_returning(*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(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 & revisit) { + return "set " + stringify(r.set_name()) + " due to " + revisit(*r.reason_for_set()); + }, + [&] (const LikeOtherDestinationTypeReason & r, const Revisit & 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 4a075c176..54707e853 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(*this); - } - - bool visit(const SetReason & r) const - { - return r.reason_for_set()->accept_returning(*this); - } - }; - - struct FromIDVisitor - { - std::shared_ptr visit(const DependencyReason & r) const - { - return r.from_id(); - } - - std::shared_ptr visit(const DependentReason &) const - { - return nullptr; - } - - std::shared_ptr visit(const WasUsedByReason &) const - { - return nullptr; - } - - std::shared_ptr visit(const PresetReason &) const - { - return nullptr; - } - - std::shared_ptr visit(const ViaBinaryReason &) const - { - return nullptr; - } - - std::shared_ptr visit(const TargetReason &) const - { - return nullptr; - } - - std::shared_ptr visit(const LikeOtherDestinationTypeReason & r) const - { - return r.reason_for_other()->accept_returning >(*this); - } - - std::shared_ptr visit(const SetReason & r) const - { - return r.reason_for_set()->accept_returning >(*this); - } - }; -} - bool paludis::resolver::is_target(const std::shared_ptr & reason) { - IsTargetVisitor v; - return reason->accept_returning(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 & revisit) { + return revisit(*r.reason_for_other()); + }, + [&] (const SetReason & r, const Revisit & revisit) { + return revisit(*r.reason_for_set()); + } + ); } const std::shared_ptr paludis::resolver::maybe_from_package_id_from_reason(const std::shared_ptr & reason) { - FromIDVisitor v; - return reason->accept_returning >(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, Reason> & revisit) { + return revisit(*r.reason_for_other()); + }, + [&] (const SetReason & r, const Revisit, Reason> & revisit) { + return revisit(*r.reason_for_set()); + } + ); } -- cgit v1.2.3