diff options
author | 2011-04-04 13:36:57 +0100 | |
---|---|---|
committer | 2011-04-04 13:36:57 +0100 | |
commit | 4cd184dd41cc756de430499a36972a6824b68f90 (patch) | |
tree | cb135ef5b502b97167cad2c5915fd85f74f8021e | |
parent | e1469fa5c597017a79ce62706f579aca35fd3c40 (diff) | |
download | paludis-4cd184dd41cc756de430499a36972a6824b68f90.tar.gz paludis-4cd184dd41cc756de430499a36972a6824b68f90.tar.xz |
Move around KeyConstraint logic
-rw-r--r-- | paludis/elike_package_dep_spec.cc | 2 | ||||
-rw-r--r-- | paludis/package_dep_spec_constraint.cc | 198 | ||||
-rw-r--r-- | paludis/package_dep_spec_constraint.hh | 9 | ||||
-rw-r--r-- | paludis/package_dep_spec_constraint.se | 10 | ||||
-rw-r--r-- | paludis/partially_made_package_dep_spec.cc | 21 | ||||
-rw-r--r-- | paludis/partially_made_package_dep_spec.hh | 2 | ||||
-rw-r--r-- | paludis/user_dep_spec.cc | 35 | ||||
-rw-r--r-- | paludis/user_dep_spec.hh | 2 | ||||
-rw-r--r-- | paludis/user_dep_spec_TEST.cc | 15 | ||||
-rw-r--r-- | python/dep_spec.cc | 2 |
10 files changed, 183 insertions, 113 deletions
diff --git a/paludis/elike_package_dep_spec.cc b/paludis/elike_package_dep_spec.cc index 35d47f57e..b3b186e9f 100644 --- a/paludis/elike_package_dep_spec.cc +++ b/paludis/elike_package_dep_spec.cc @@ -139,7 +139,7 @@ paludis::elike_remove_trailing_square_bracket_if_exists(std::string & s, Partial } auto k(parse_user_key_constraint(flag.substr(1))); - result.key_constraint(std::get<0>(k), std::get<1>(k), std::get<2>(k)); + result.key_constraint(std::get<0>(k), std::get<1>(k), std::get<2>(k), std::get<3>(k)); } break; diff --git a/paludis/package_dep_spec_constraint.cc b/paludis/package_dep_spec_constraint.cc index f147316d9..dcdb7ad98 100644 --- a/paludis/package_dep_spec_constraint.cc +++ b/paludis/package_dep_spec_constraint.cc @@ -298,7 +298,8 @@ template class Pool<AnySlotConstraint>; template class Singleton<Pool<AnySlotConstraint> >; template const std::shared_ptr<const AnySlotConstraint> Pool<AnySlotConstraint>::create(const bool &) const; -KeyConstraint::KeyConstraint(const std::string & k, const KeyConstraintOperation o, const std::string & p) : +KeyConstraint::KeyConstraint(const KeyConstraintKeyType t, const std::string & k, const KeyConstraintOperation o, const std::string & p) : + _key_type(t), _key(k), _operation(o), _pattern(p) @@ -307,6 +308,12 @@ KeyConstraint::KeyConstraint(const std::string & k, const KeyConstraintOperation KeyConstraint::~KeyConstraint() = default; +KeyConstraintKeyType +KeyConstraint::key_type() const +{ + return _key_type; +} + const std::string KeyConstraint::key() const { @@ -810,76 +817,90 @@ KeyConstraint::matches( { const MetadataKey * k(0); - auto repo(env->fetch_repository(id->repository_name())); - if (0 == key().compare(0, 3, "::$")) - { - if (key() == "::$format") - k = repo->format_key().get(); - else if (key() == "::$location") - k = repo->location_key().get(); - else if (key() == "::$installed_root") - k = repo->installed_root_key().get(); - else if (key() == "::$accept_keywords") - k = repo->accept_keywords_key().get(); - else if (key() == "::$sync_host") - k = repo->sync_host_key().get(); - } - else if (0 == key().compare(0, 1, "$")) - { - if (key() == "$behaviours") - k = id->behaviours_key().get(); - else if (key() == "$build_dependencies") - k = id->build_dependencies_key().get(); - else if (key() == "$choices") - k = id->choices_key().get(); - else if (key() == "$contained_in") - k = id->contained_in_key().get(); - else if (key() == "$contains") - k = id->contains_key().get(); - else if (key() == "$contents") - k = id->contents_key().get(); - else if (key() == "$dependencies") - k = id->dependencies_key().get(); - else if (key() == "$fetches") - k = id->fetches_key().get(); - else if (key() == "$from_repositories") - k = id->from_repositories_key().get(); - else if (key() == "$fs_location") - k = id->fs_location_key().get(); - else if (key() == "$homepage") - k = id->homepage_key().get(); - else if (key() == "$installed_time") - k = id->installed_time_key().get(); - else if (key() == "$keywords") - k = id->keywords_key().get(); - else if (key() == "$long_description") - k = id->long_description_key().get(); - else if (key() == "$post_dependencies") - k = id->post_dependencies_key().get(); - else if (key() == "$provide") - k = id->provide_key().get(); - else if (key() == "$run_dependencies") - k = id->run_dependencies_key().get(); - else if (key() == "$short_description") - k = id->short_description_key().get(); - else if (key() == "$slot") - k = id->slot_key().get(); - else if (key() == "$suggested_dependencies") - k = id->suggested_dependencies_key().get(); - else if (key() == "$virtual_for") - k = id->virtual_for_key().get(); - } - else if (0 == key().compare(0, 2, "::")) - { - Repository::MetadataConstIterator m(repo->find_metadata(key().substr(2))); - if (m != repo->end_metadata()) - k = m->get(); - } - else + switch (key_type()) { - PackageID::MetadataConstIterator m(id->find_metadata(key())); - if (m != id->end_metadata()) - k = m->get(); + case kckt_repo_role: + { + auto repo(env->fetch_repository(id->repository_name())); + if (key() == "format") + k = repo->format_key().get(); + else if (key() == "location") + k = repo->location_key().get(); + else if (key() == "installed_root") + k = repo->installed_root_key().get(); + else if (key() == "accept_keywords") + k = repo->accept_keywords_key().get(); + else if (key() == "sync_host") + k = repo->sync_host_key().get(); + } + break; + + case kckt_id_role: + { + if (key() == "behaviours") + k = id->behaviours_key().get(); + else if (key() == "build_dependencies") + k = id->build_dependencies_key().get(); + else if (key() == "choices") + k = id->choices_key().get(); + else if (key() == "contained_in") + k = id->contained_in_key().get(); + else if (key() == "contains") + k = id->contains_key().get(); + else if (key() == "contents") + k = id->contents_key().get(); + else if (key() == "dependencies") + k = id->dependencies_key().get(); + else if (key() == "fetches") + k = id->fetches_key().get(); + else if (key() == "from_repositories") + k = id->from_repositories_key().get(); + else if (key() == "fs_location") + k = id->fs_location_key().get(); + else if (key() == "homepage") + k = id->homepage_key().get(); + else if (key() == "installed_time") + k = id->installed_time_key().get(); + else if (key() == "keywords") + k = id->keywords_key().get(); + else if (key() == "long_description") + k = id->long_description_key().get(); + else if (key() == "post_dependencies") + k = id->post_dependencies_key().get(); + else if (key() == "provide") + k = id->provide_key().get(); + else if (key() == "run_dependencies") + k = id->run_dependencies_key().get(); + else if (key() == "short_description") + k = id->short_description_key().get(); + else if (key() == "slot") + k = id->slot_key().get(); + else if (key() == "suggested_dependencies") + k = id->suggested_dependencies_key().get(); + else if (key() == "virtual_for") + k = id->virtual_for_key().get(); + } + break; + + case kckt_repo: + { + auto repo(env->fetch_repository(id->repository_name())); + Repository::MetadataConstIterator m(repo->find_metadata(key())); + if (m != repo->end_metadata()) + k = m->get(); + } + break; + + case kckt_id: + { + PackageID::MetadataConstIterator m(id->find_metadata(key())); + if (m != id->end_metadata()) + k = m->get(); + } + break; + + case last_kckt: + break; } if (! k) @@ -894,9 +915,44 @@ KeyConstraint::matches( } } +const std::string +KeyConstraint::as_raw_string() const +{ + std::stringstream s; + s << "[."; + + switch (key_type()) + { + case kckt_id: break; + case kckt_id_role: s << "$"; break; + case kckt_repo: s << "::"; break; + case kckt_repo_role: s << "::$"; break; + case last_kckt: + break; + } + + s << key(); + + switch (operation()) + { + case kco_equals: s << "=" << pattern(); break; + case kco_less_than: s << "<" << pattern(); break; + case kco_greater_than: s << ">" << pattern(); break; + case kco_question: s << "?"; break; + + case last_kco: + throw InternalError(PALUDIS_HERE, "Bad KeyConstraintOperation"); + } + + s << "]"; + + return s.str(); +} + template class Pool<KeyConstraint>; template class Singleton<Pool<KeyConstraint> >; -template const std::shared_ptr<const KeyConstraint> Pool<KeyConstraint>::create(const std::string &, const KeyConstraintOperation &, const std::string &) const; +template const std::shared_ptr<const KeyConstraint> Pool<KeyConstraint>::create( + const KeyConstraintKeyType &, const std::string &, const KeyConstraintOperation &, const std::string &) const; template class Sequence<std::shared_ptr<const KeyConstraint> >; template class WrappedForwardIterator<Sequence<std::shared_ptr<const KeyConstraint> >::ConstIteratorTag, const std::shared_ptr<const KeyConstraint> >; diff --git a/paludis/package_dep_spec_constraint.hh b/paludis/package_dep_spec_constraint.hh index 34519c799..244352f86 100644 --- a/paludis/package_dep_spec_constraint.hh +++ b/paludis/package_dep_spec_constraint.hh @@ -282,17 +282,19 @@ namespace paludis friend class Pool<KeyConstraint>; private: + KeyConstraintKeyType _key_type; std::string _key; KeyConstraintOperation _operation; std::string _pattern; - KeyConstraint(const std::string &, const KeyConstraintOperation, const std::string &); + KeyConstraint(const KeyConstraintKeyType, const std::string &, const KeyConstraintOperation, const std::string &); KeyConstraint(const KeyConstraint &) = delete; public: ~KeyConstraint(); + KeyConstraintKeyType key_type() const PALUDIS_ATTRIBUTE((warn_unused_result)); const std::string key() const PALUDIS_ATTRIBUTE((warn_unused_result)); KeyConstraintOperation operation() const PALUDIS_ATTRIBUTE((warn_unused_result)); const std::string pattern() const PALUDIS_ATTRIBUTE((warn_unused_result)); @@ -300,6 +302,11 @@ namespace paludis bool matches( const Environment * const env, const std::shared_ptr<const PackageID> & id) const PALUDIS_ATTRIBUTE((warn_unused_result)); + + /** + * Return a raw string representation of ourself. + */ + const std::string as_raw_string() const PALUDIS_ATTRIBUTE((warn_unused_result)); }; class PALUDIS_VISIBLE ChoiceConstraint : diff --git a/paludis/package_dep_spec_constraint.se b/paludis/package_dep_spec_constraint.se index 8a9369691..3322a9ef5 100644 --- a/paludis/package_dep_spec_constraint.se +++ b/paludis/package_dep_spec_constraint.se @@ -11,6 +11,16 @@ make_enum_KeyConstraintOperation() key kco_question "A question constraint" } +make_enum_KeyConstraintKeyType() +{ + prefix kckt + + key kckt_id "A regular [.key] constraint" + key kckt_id_role "A role [.\$key] constraint" + key kckt_repo "A [.::repo] constraint" + key kckt_repo_role "A [.::\$repo] constraint" +} + make_enum_VersionConstraintCombiner() { prefix vcc diff --git a/paludis/partially_made_package_dep_spec.cc b/paludis/partially_made_package_dep_spec.cc index 7fad45450..2dc71ff5a 100644 --- a/paludis/partially_made_package_dep_spec.cc +++ b/paludis/partially_made_package_dep_spec.cc @@ -300,22 +300,7 @@ namespace if (all_key_constraints()) for (auto u(all_key_constraints()->begin()), u_end(all_key_constraints()->end()) ; u != u_end ; ++u) - { - s << "[" << (*u)->key(); - - switch ((*u)->operation()) - { - case kco_equals: s << "=" << (*u)->pattern(); break; - case kco_less_than: s << "<" << (*u)->pattern(); break; - case kco_greater_than: s << ">" << (*u)->pattern(); break; - case kco_question: s << "?"; break; - - case last_kco: - throw InternalError(PALUDIS_HERE, "Bad KeyConstraintOperation"); - } - - s << "]"; - } + s << (*u)->as_raw_string(); return s.str(); } @@ -614,11 +599,11 @@ PartiallyMadePackageDepSpec::clear_version() } PartiallyMadePackageDepSpec & -PartiallyMadePackageDepSpec::key_constraint(const std::string & k, const KeyConstraintOperation o, const std::string & p) +PartiallyMadePackageDepSpec::key_constraint(const KeyConstraintKeyType t, const std::string & k, const KeyConstraintOperation o, const std::string & p) { if (! _imp->data->all_keys) _imp->data->all_keys = std::make_shared<KeyConstraintSequence>(); - _imp->data->all_keys->push_back(KeyConstraintPool::get_instance()->create(k, o, p)); + _imp->data->all_keys->push_back(KeyConstraintPool::get_instance()->create(t, k, o, p)); return *this; } diff --git a/paludis/partially_made_package_dep_spec.hh b/paludis/partially_made_package_dep_spec.hh index 01dbb56ae..850cd943d 100644 --- a/paludis/partially_made_package_dep_spec.hh +++ b/paludis/partially_made_package_dep_spec.hh @@ -209,7 +209,7 @@ namespace paludis * Add a key constraint, return ourself. */ PartiallyMadePackageDepSpec & key_constraint( - const std::string & key, const KeyConstraintOperation, const std::string & pattern); + const KeyConstraintKeyType, const std::string & key, const KeyConstraintOperation, const std::string & pattern); /** * Clear choice constraints, return ourself. diff --git a/paludis/user_dep_spec.cc b/paludis/user_dep_spec.cc index d6122e573..e4ee764b4 100644 --- a/paludis/user_dep_spec.cc +++ b/paludis/user_dep_spec.cc @@ -160,7 +160,7 @@ namespace case '.': { auto k(parse_user_key_constraint(flag.substr(1))); - result.key_constraint(std::get<0>(k), std::get<1>(k), std::get<2>(k)); + result.key_constraint(std::get<0>(k), std::get<1>(k), std::get<2>(k), std::get<3>(k)); } break; @@ -323,23 +323,28 @@ paludis::user_version_spec_options() vso_ignore_case, vso_letters_anywhere, vso_dotted_suffixes }; } -std::tuple<std::string, KeyConstraintOperation, std::string> +std::tuple<KeyConstraintKeyType, std::string, KeyConstraintOperation, std::string> paludis::parse_user_key_constraint(const std::string & s) { std::string::size_type p(s.find_first_of("=<>?")); if (std::string::npos == p) throw PackageDepSpecError("[." + s + "] contains no operator"); + std::string key, value; + KeyConstraintOperation op(last_kco); + if (s.at(p) == '?') { if (s.length() - 1 != p) throw PackageDepSpecError("[." + s + "] uses a key with operator '?'"); else - return std::make_tuple(s.substr(0, p), kco_question, ""); + { + key = s.substr(0, p); + op = kco_question; + } } else { - KeyConstraintOperation op(last_kco); switch (s.at(p)) { case '=': op = kco_equals; break; @@ -348,7 +353,27 @@ paludis::parse_user_key_constraint(const std::string & s) default: throw PackageDepSpecError("[." + s + "] unknown operator"); } - return std::make_tuple(s.substr(0, p), op, s.substr(p + 1)); + key = s.substr(0, p); + value = s.substr(p + 1); + } + + KeyConstraintKeyType type(kckt_id); + if (0 == key.compare(0, 3, "::$", 0, 3)) + { + type = kckt_repo_role; + key.erase(0, 3); } + else if (0 == key.compare(0, 2, "::2", 0, 2)) + { + type = kckt_repo; + key.erase(0, 2); + } + else if (0 == key.compare(0, 1, "$", 0, 1)) + { + type = kckt_id_role; + key.erase(0, 1); + } + + return std::make_tuple(type, key, op, value); } diff --git a/paludis/user_dep_spec.hh b/paludis/user_dep_spec.hh index 0398c5ef9..b96479ace 100644 --- a/paludis/user_dep_spec.hh +++ b/paludis/user_dep_spec.hh @@ -61,7 +61,7 @@ namespace paludis * \ingroup g_dep_spec * \since 0.61 */ - std::tuple<std::string, KeyConstraintOperation, std::string> parse_user_key_constraint( + std::tuple<KeyConstraintKeyType, std::string, KeyConstraintOperation, std::string> parse_user_key_constraint( const std::string &) PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result)); } diff --git a/paludis/user_dep_spec_TEST.cc b/paludis/user_dep_spec_TEST.cc index f3d1b787f..d4ed5199a 100644 --- a/paludis/user_dep_spec_TEST.cc +++ b/paludis/user_dep_spec_TEST.cc @@ -53,20 +53,7 @@ namespace std::string stringify_key_constraint(const KeyConstraint & k) { - std::string result(k.key()); - - switch (k.operation()) - { - case kco_question: result.append("?"); break; - case kco_equals: result.append("="); break; - case kco_less_than: result.append("<"); break; - case kco_greater_than: result.append(">"); break; - case last_kco: - break; - } - - result.append(k.pattern()); - return "[." + result + "]"; + return k.as_raw_string(); } std::string stringify_choice_constraint(const ChoiceConstraint & k) diff --git a/python/dep_spec.cc b/python/dep_spec.cc index 6f8c0ec8e..8d30f1e36 100644 --- a/python/dep_spec.cc +++ b/python/dep_spec.cc @@ -305,7 +305,7 @@ PythonPackageDepSpec::operator PackageDepSpec() const { for (auto i(all_key_constraints()->begin()), i_end(all_key_constraints()->end()) ; i != i_end ; ++i) - p.key_constraint((*i)->key(), (*i)->operation(), (*i)->pattern()); + p.key_constraint((*i)->key_type(), (*i)->key(), (*i)->operation(), (*i)->pattern()); } return p.to_package_dep_spec(); |