From 7e71a0aa478a93e6cf5b02f28a15ab82f08196d7 Mon Sep 17 00:00:00 2001 From: Ciaran McCreesh Date: Fri, 11 Mar 2011 14:03:31 +0000 Subject: Refactor --- paludis/repositories/e/Makefile.am | 4 +- paludis/repositories/e/apply_annotations.cc | 128 ---------------------------- paludis/repositories/e/apply_annotations.hh | 39 --------- paludis/repositories/e/dep_parser.cc | 67 +++++++++------ paludis/repositories/e/parse_annotations.cc | 126 +++++++++++++++++++++++++++ paludis/repositories/e/parse_annotations.hh | 39 +++++++++ 6 files changed, 207 insertions(+), 196 deletions(-) delete mode 100644 paludis/repositories/e/apply_annotations.cc delete mode 100644 paludis/repositories/e/apply_annotations.hh create mode 100644 paludis/repositories/e/parse_annotations.cc create mode 100644 paludis/repositories/e/parse_annotations.hh diff --git a/paludis/repositories/e/Makefile.am b/paludis/repositories/e/Makefile.am index 8feaeadf5..88d7c198f 100644 --- a/paludis/repositories/e/Makefile.am +++ b/paludis/repositories/e/Makefile.am @@ -22,7 +22,6 @@ endif noinst_HEADERS = \ a_finder.hh \ aa_visitor.hh \ - apply_annotations.hh \ can_skip_phase.hh \ check_fetched_files_visitor.hh \ check_userpriv.hh \ @@ -79,6 +78,7 @@ noinst_HEADERS = \ metadata_xml.hh \ myoption.hh \ myoptions_requirements_verifier.hh \ + parse_annotations.hh \ parse_dependency_label.hh \ parse_plain_text_label.hh \ parse_uri_label.hh \ @@ -102,7 +102,6 @@ noinst_HEADERS = \ libpaludiserepository_la_SOURCES = \ a_finder.cc \ aa_visitor.cc \ - apply_annotations.cc \ can_skip_phase.cc \ check_fetched_files_visitor.cc \ check_userpriv.cc \ @@ -154,6 +153,7 @@ libpaludiserepository_la_SOURCES = \ metadata_xml.cc \ myoption.cc \ myoptions_requirements_verifier.cc \ + parse_annotations.cc \ parse_dependency_label.cc \ parse_plain_text_label.cc \ parse_uri_label.cc \ diff --git a/paludis/repositories/e/apply_annotations.cc b/paludis/repositories/e/apply_annotations.cc deleted file mode 100644 index d8ba39007..000000000 --- a/paludis/repositories/e/apply_annotations.cc +++ /dev/null @@ -1,128 +0,0 @@ -/* vim: set sw=4 sts=4 et foldmethod=syntax : */ - -/* - * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace paludis; -using namespace paludis::erepository; - -void -paludis::erepository::apply_annotations( - const EAPI & eapi, - const std::shared_ptr & spec, - const std::shared_ptr > & m) -{ - auto annotations(std::make_shared()); - for (auto k(m->begin()), k_end(m->end()) ; - k != k_end ; ++k) - { - if (k->first.empty()) - continue; - - DepSpecAnnotationRole role(dsar_none); - - /* blocks */ - if (k->first == eapi.supported()->annotations()->blocker_resolution()) - { - if (k->second.empty()) - { - } - else if (k->second == eapi.supported()->annotations()->blocker_resolution_manual()) - role = dsar_blocker_manual; - else if (k->second == eapi.supported()->annotations()->blocker_resolution_uninstall_blocked_after()) - role = dsar_blocker_uninstall_blocked_after; - else if (k->second == eapi.supported()->annotations()->blocker_resolution_uninstall_blocked_before()) - role = dsar_blocker_uninstall_blocked_before; - else if (k->second == eapi.supported()->annotations()->blocker_resolution_upgrade_blocked_before()) - role = dsar_blocker_upgrade_blocked_before; - else - throw EDepParseError(k->second, "Unknown value '" + k->second + "' for annotation '" + k->first + "'"); - } - - /* myoptions number-selected */ - if (dsar_none == role) - { - if (k->first == eapi.supported()->annotations()->myoptions_number_selected()) - { - if (k->second.empty()) - { - } - else if (k->second == eapi.supported()->annotations()->myoptions_number_selected_at_least_one()) - role = dsar_myoptions_n_at_least_one; - else if (k->second == eapi.supported()->annotations()->myoptions_number_selected_at_most_one()) - role = dsar_myoptions_n_at_most_one; - else if (k->second == eapi.supported()->annotations()->myoptions_number_selected_exactly_one()) - role = dsar_myoptions_n_exactly_one; - else - throw EDepParseError(k->first, "Unknown value '" + k->second + "' for annotation '" + k->first + "'"); - } - } - - /* myoptions requires */ - if (dsar_none == role) - { - if (k->first == eapi.supported()->annotations()->myoptions_requires()) - role = dsar_myoptions_requires; - } - - /* suggestions */ - if (dsar_none == role) - { - if (k->first == eapi.supported()->annotations()->suggestions_group_name()) - role = dsar_suggestions_group_name; - } - - /* general */ - if (dsar_none == role) - { - if (k->first == eapi.supported()->annotations()->general_description()) - role = dsar_general_description; - else if (k->first == eapi.supported()->annotations()->general_url()) - role = dsar_general_url; - else if (k->first == eapi.supported()->annotations()->general_note()) - role = dsar_general_note; - else if (k->first == eapi.supported()->annotations()->general_lang()) - role = dsar_general_lang; - else if (k->first == eapi.supported()->ebuild_options()->bracket_merged_variables_annotation()) - role = dsar_general_defined_in; - } - - if (dsar_none == role) - Log::get_instance()->message("e.dep_parser.unknown_annotation", ll_qa, lc_context) - << "Unknown annotation '" << k->first << "' = '" << k->second << "'"; - - annotations->add(make_named_values( - n::key() = k->first, - n::kind() = dsak_literal, - n::role() = role, - n::value() = k->second)); - } - - spec->set_annotations(annotations); -} - diff --git a/paludis/repositories/e/apply_annotations.hh b/paludis/repositories/e/apply_annotations.hh deleted file mode 100644 index 5e512fe6e..000000000 --- a/paludis/repositories/e/apply_annotations.hh +++ /dev/null @@ -1,39 +0,0 @@ -/* vim: set sw=4 sts=4 et foldmethod=syntax : */ - -/* - * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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_APPLY_ANNOTATIONS_HH -#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_APPLY_ANNOTATIONS_HH 1 - -#include -#include -#include -#include - -namespace paludis -{ - namespace erepository - { - void apply_annotations( - const EAPI & eapi, - const std::shared_ptr & spec, - const std::shared_ptr > & m); - } -} - -#endif diff --git a/paludis/repositories/e/dep_parser.cc b/paludis/repositories/e/dep_parser.cc index c80963c40..b13f2b39c 100644 --- a/paludis/repositories/e/dep_parser.cc +++ b/paludis/repositories/e/dep_parser.cc @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -379,24 +379,16 @@ namespace block = b; } - void fix_block_annotations( - const std::shared_ptr & if_block_spec, + void add_block_annotations( + std::shared_ptr & annotations, const BlockFixOp & block_fix_op) { - if (! if_block_spec) - return; - DepSpecAnnotationRole current_role(dsar_none); - if (if_block_spec->maybe_annotations()) - current_role = find_blocker_role_in_annotations(if_block_spec->maybe_annotations()); + if (annotations) + current_role = find_blocker_role_in_annotations(annotations); if (dsar_none != current_role) return; - std::shared_ptr annotations(std::make_shared()); - if (if_block_spec->maybe_annotations()) - std::for_each(if_block_spec->maybe_annotations()->begin(), if_block_spec->maybe_annotations()->end(), - std::bind(&DepSpecAnnotations::add, annotations, std::placeholders::_1)); - switch (block_fix_op) { case bfo_explicit_strong: @@ -426,19 +418,40 @@ namespace )); break; } - - if_block_spec->set_annotations(annotations); } - void apply_annotations_then_fixup( + void apply_maybe_blocker_annotations( const EAPI & eapi, const std::shared_ptr & spec, const std::shared_ptr & if_block_spec, const BlockFixOp & block_fix_op, const std::shared_ptr > & m) { - apply_annotations(eapi, spec, m); - fix_block_annotations(if_block_spec, block_fix_op); + auto annotations(parse_annotations(eapi, m)); + if (if_block_spec) + add_block_annotations(annotations, block_fix_op); + spec->set_annotations(annotations); + } + + void apply_maybe_blocker_no_annotations( + const std::shared_ptr & if_block_spec, + const BlockFixOp & block_fix_op) + { + if (if_block_spec) + { + auto annotations(std::make_shared()); + add_block_annotations(annotations, block_fix_op); + if_block_spec->set_annotations(annotations); + } + } + + void apply_non_blocker_annotations( + const EAPI & eapi, + const std::shared_ptr & spec, + const std::shared_ptr > & m) + { + auto annotations(parse_annotations(eapi, m)); + spec->set_annotations(annotations); } } @@ -462,7 +475,7 @@ paludis::erepository::parse_depend(const std::string & s, const Environment * co ELikeDepParserCallbacks callbacks( make_named_values( n::on_all() = std::bind(&any_all_handler, std::ref(stack)), - n::on_annotations() = std::bind(&apply_annotations_then_fixup, std::cref(eapi), std::cref(thing_to_annotate), + n::on_annotations() = std::bind(&apply_maybe_blocker_annotations, std::cref(eapi), std::cref(thing_to_annotate), std::cref(thing_to_annotate_if_block), std::cref(block_fix_op), _1), n::on_any() = std::bind(&any_all_handler, std::ref(stack)), n::on_arrow() = std::bind(&arrows_not_allowed_handler, s, _1, _2), @@ -473,7 +486,7 @@ paludis::erepository::parse_depend(const std::string & s, const Environment * co ParseStackTypes::AnnotationsGoHere(std::bind( &set_thing_to_annotate_maybe_block, std::ref(thing_to_annotate), _1, std::ref(thing_to_annotate_if_block), _2)), _1, std::cref(eapi)), - n::on_no_annotations() = std::bind(&fix_block_annotations, std::cref(thing_to_annotate_if_block), std::cref(block_fix_op)), + n::on_no_annotations() = std::bind(&apply_maybe_blocker_no_annotations, std::cref(thing_to_annotate_if_block), std::cref(block_fix_op)), n::on_pop() = std::bind(&pop_handler, std::ref(stack), ParseStackTypes::AnnotationsGoHere(std::bind( &set_thing_to_annotate_maybe_block, std::ref(thing_to_annotate), _1, std::ref(thing_to_annotate_if_block), _2)), s), @@ -509,7 +522,7 @@ paludis::erepository::parse_provide(const std::string & s, const Environment * c ELikeDepParserCallbacks callbacks( make_named_values( n::on_all() = std::bind(&any_all_handler, std::ref(stack)), - n::on_annotations() = std::bind(&apply_annotations, std::cref(eapi), std::ref(thing_to_annotate), _1), + n::on_annotations() = std::bind(&apply_non_blocker_annotations, std::cref(eapi), std::ref(thing_to_annotate), _1), n::on_any() = std::bind(&any_not_allowed_handler, s), n::on_arrow() = std::bind(&arrows_not_allowed_handler, s, _1, _2), n::on_error() = std::bind(&error_handler, s, _1), @@ -550,7 +563,7 @@ paludis::erepository::parse_fetchable_uri(const std::string & s, const Environme ELikeDepParserCallbacks callbacks( make_named_values( n::on_all() = std::bind(&any_all_handler, std::ref(stack)), - n::on_annotations() = std::bind(&apply_annotations, std::cref(eapi), std::ref(thing_to_annotate), _1), + n::on_annotations() = std::bind(&apply_non_blocker_annotations, std::cref(eapi), std::ref(thing_to_annotate), _1), n::on_any() = std::bind(&any_not_allowed_handler, s), n::on_arrow() = std::bind(&arrow_handler, std::ref(stack), ParseStackTypes::AnnotationsGoHere(std::bind( @@ -595,7 +608,7 @@ paludis::erepository::parse_simple_uri(const std::string & s, const Environment ELikeDepParserCallbacks callbacks( make_named_values( n::on_all() = std::bind(&any_all_handler, std::ref(stack)), - n::on_annotations() = std::bind(&apply_annotations, std::cref(eapi), std::ref(thing_to_annotate), _1), + n::on_annotations() = std::bind(&apply_non_blocker_annotations, std::cref(eapi), std::ref(thing_to_annotate), _1), n::on_any() = std::bind(&any_not_allowed_handler, s), n::on_arrow() = std::bind(&arrows_not_allowed_handler, s, _1, _2), n::on_error() = std::bind(&error_handler, s, _1), @@ -636,7 +649,7 @@ paludis::erepository::parse_license(const std::string & s, const Environment * c ELikeDepParserCallbacks callbacks( make_named_values( n::on_all() = std::bind(&any_all_handler, std::ref(stack)), - n::on_annotations() = std::bind(&apply_annotations, std::cref(eapi), std::ref(thing_to_annotate), _1), + n::on_annotations() = std::bind(&apply_non_blocker_annotations, std::cref(eapi), std::ref(thing_to_annotate), _1), n::on_any() = std::bind(&any_all_handler, std::ref(stack)), n::on_arrow() = std::bind(&arrows_not_allowed_handler, s, _1, _2), n::on_error() = std::bind(&error_handler, s, _1), @@ -677,7 +690,7 @@ paludis::erepository::parse_plain_text(const std::string & s, const Environment ELikeDepParserCallbacks callbacks( make_named_values( n::on_all() = std::bind(&any_all_handler, std::ref(stack)), - n::on_annotations() = std::bind(&apply_annotations, std::cref(eapi), std::ref(thing_to_annotate), _1), + n::on_annotations() = std::bind(&apply_non_blocker_annotations, std::cref(eapi), std::ref(thing_to_annotate), _1), n::on_any() = std::bind(&any_not_allowed_handler, s), n::on_arrow() = std::bind(&arrows_not_allowed_handler, s, _1, _2), n::on_error() = std::bind(&error_handler, s, _1), @@ -718,7 +731,7 @@ paludis::erepository::parse_myoptions(const std::string & s, const Environment * ELikeDepParserCallbacks callbacks( make_named_values( n::on_all() = std::bind(&any_all_handler, std::ref(stack)), - n::on_annotations() = std::bind(&apply_annotations, std::cref(eapi), std::ref(thing_to_annotate), _1), + n::on_annotations() = std::bind(&apply_non_blocker_annotations, std::cref(eapi), std::ref(thing_to_annotate), _1), n::on_any() = std::bind(&any_not_allowed_handler, s), n::on_arrow() = std::bind(&arrows_not_allowed_handler, s, _1, _2), n::on_error() = std::bind(&error_handler, s, _1), @@ -761,7 +774,7 @@ paludis::erepository::parse_required_use(const std::string & s, const Environmen ELikeDepParserCallbacks callbacks( make_named_values( n::on_all() = std::bind(&any_all_handler, std::ref(stack)), - n::on_annotations() = std::bind(&apply_annotations, std::cref(eapi), std::ref(thing_to_annotate), _1), + n::on_annotations() = std::bind(&apply_non_blocker_annotations, std::cref(eapi), std::ref(thing_to_annotate), _1), n::on_any() = std::bind(&any_all_handler, std::ref(stack)), n::on_arrow() = std::bind(&arrows_not_allowed_handler, s, _1, _2), n::on_error() = std::bind(&error_handler, s, _1), diff --git a/paludis/repositories/e/parse_annotations.cc b/paludis/repositories/e/parse_annotations.cc new file mode 100644 index 000000000..a4ab6ba5c --- /dev/null +++ b/paludis/repositories/e/parse_annotations.cc @@ -0,0 +1,126 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace paludis; +using namespace paludis::erepository; + +const std::shared_ptr +paludis::erepository::parse_annotations( + const EAPI & eapi, + const std::shared_ptr > & m) +{ + auto annotations(std::make_shared()); + for (auto k(m->begin()), k_end(m->end()) ; + k != k_end ; ++k) + { + if (k->first.empty()) + continue; + + DepSpecAnnotationRole role(dsar_none); + + /* blocks */ + if (k->first == eapi.supported()->annotations()->blocker_resolution()) + { + if (k->second.empty()) + { + } + else if (k->second == eapi.supported()->annotations()->blocker_resolution_manual()) + role = dsar_blocker_manual; + else if (k->second == eapi.supported()->annotations()->blocker_resolution_uninstall_blocked_after()) + role = dsar_blocker_uninstall_blocked_after; + else if (k->second == eapi.supported()->annotations()->blocker_resolution_uninstall_blocked_before()) + role = dsar_blocker_uninstall_blocked_before; + else if (k->second == eapi.supported()->annotations()->blocker_resolution_upgrade_blocked_before()) + role = dsar_blocker_upgrade_blocked_before; + else + throw EDepParseError(k->second, "Unknown value '" + k->second + "' for annotation '" + k->first + "'"); + } + + /* myoptions number-selected */ + if (dsar_none == role) + { + if (k->first == eapi.supported()->annotations()->myoptions_number_selected()) + { + if (k->second.empty()) + { + } + else if (k->second == eapi.supported()->annotations()->myoptions_number_selected_at_least_one()) + role = dsar_myoptions_n_at_least_one; + else if (k->second == eapi.supported()->annotations()->myoptions_number_selected_at_most_one()) + role = dsar_myoptions_n_at_most_one; + else if (k->second == eapi.supported()->annotations()->myoptions_number_selected_exactly_one()) + role = dsar_myoptions_n_exactly_one; + else + throw EDepParseError(k->first, "Unknown value '" + k->second + "' for annotation '" + k->first + "'"); + } + } + + /* myoptions requires */ + if (dsar_none == role) + { + if (k->first == eapi.supported()->annotations()->myoptions_requires()) + role = dsar_myoptions_requires; + } + + /* suggestions */ + if (dsar_none == role) + { + if (k->first == eapi.supported()->annotations()->suggestions_group_name()) + role = dsar_suggestions_group_name; + } + + /* general */ + if (dsar_none == role) + { + if (k->first == eapi.supported()->annotations()->general_description()) + role = dsar_general_description; + else if (k->first == eapi.supported()->annotations()->general_url()) + role = dsar_general_url; + else if (k->first == eapi.supported()->annotations()->general_note()) + role = dsar_general_note; + else if (k->first == eapi.supported()->annotations()->general_lang()) + role = dsar_general_lang; + else if (k->first == eapi.supported()->ebuild_options()->bracket_merged_variables_annotation()) + role = dsar_general_defined_in; + } + + if (dsar_none == role) + Log::get_instance()->message("e.dep_parser.unknown_annotation", ll_qa, lc_context) + << "Unknown annotation '" << k->first << "' = '" << k->second << "'"; + + annotations->add(make_named_values( + n::key() = k->first, + n::kind() = dsak_literal, + n::role() = role, + n::value() = k->second)); + } + + return annotations; +} + diff --git a/paludis/repositories/e/parse_annotations.hh b/paludis/repositories/e/parse_annotations.hh new file mode 100644 index 000000000..52b8b11ed --- /dev/null +++ b/paludis/repositories/e/parse_annotations.hh @@ -0,0 +1,39 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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_PARSE_ANNOTATIONS_HH +#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_PARSE_ANNOTATIONS_HH 1 + +#include +#include +#include +#include + +namespace paludis +{ + namespace erepository + { + const std::shared_ptr + parse_annotations( + const EAPI & eapi, + const std::shared_ptr > & m); + } +} + +#endif -- cgit v1.2.3