aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-09-02 00:05:33 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2008-09-02 00:05:33 +0100
commit0d4d0d8eee72dcd29c6d1ffc3239079f9e3b4a41 (patch)
treef55a386a576061415f889c91b3c4b0977b9b2b61
parent1291fcfec43931bf02f53030fff79f276ff748a0 (diff)
downloadpaludis-0d4d0d8eee72dcd29c6d1ffc3239079f9e3b4a41.tar.gz
paludis-0d4d0d8eee72dcd29c6d1ffc3239079f9e3b4a41.tar.xz
Carry annotations around with e specs
-rw-r--r--paludis/dep_spec.cc111
-rw-r--r--paludis/dep_spec.hh52
-rw-r--r--paludis/repositories/e/dep_parser.cc267
-rw-r--r--paludis/repositories/e/dep_parser_TEST.cc25
-rw-r--r--paludis/repositories/e/dep_spec_pretty_printer.cc51
-rw-r--r--paludis/repositories/e/dep_spec_pretty_printer.hh3
6 files changed, 431 insertions, 78 deletions
diff --git a/paludis/dep_spec.cc b/paludis/dep_spec.cc
index b6b557f..0929d33 100644
--- a/paludis/dep_spec.cc
+++ b/paludis/dep_spec.cc
@@ -36,6 +36,7 @@
#include <paludis/util/options.hh>
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/visitor-impl.hh>
+#include <paludis/metadata_key.hh>
#include <tr1/functional>
#include <algorithm>
#include <list>
@@ -43,14 +44,57 @@
using namespace paludis;
-DepSpec::DepSpec()
+namespace paludis
+{
+ template <>
+ struct Implementation<DepSpec>
+ {
+ std::tr1::shared_ptr<const MetadataSectionKey> annotations_key;
+
+ Implementation()
+ {
+ }
+
+ Implementation(const std::tr1::shared_ptr<const MetadataSectionKey> & k) :
+ annotations_key(k)
+ {
+ }
+ };
+}
+
+DepSpec::DepSpec() :
+ PrivateImplementationPattern<DepSpec>(new Implementation<DepSpec>),
+ _imp(PrivateImplementationPattern<DepSpec>::_imp)
{
}
+DepSpec::DepSpec(const std::tr1::shared_ptr<const MetadataSectionKey> & k) :
+ PrivateImplementationPattern<DepSpec>(new Implementation<DepSpec>(k)),
+ _imp(PrivateImplementationPattern<DepSpec>::_imp)
+{
+ if (_imp->annotations_key)
+ add_metadata_key(_imp->annotations_key);
+}
+
DepSpec::~DepSpec()
{
}
+const std::tr1::shared_ptr<const MetadataSectionKey>
+DepSpec::annotations_key() const
+{
+ return _imp->annotations_key;
+}
+
+void
+DepSpec::set_annotations_key(const std::tr1::shared_ptr<const MetadataSectionKey> & k)
+{
+ clear_metadata_keys();
+ _imp->annotations_key = k;
+ if (_imp->annotations_key)
+ add_metadata_key(_imp->annotations_key);
+}
+
const ConditionalDepSpec *
DepSpec::as_conditional_dep_spec() const
{
@@ -73,10 +117,21 @@ AnyDepSpec::clone() const
return std::tr1::shared_ptr<AnyDepSpec>(new AnyDepSpec());
}
+void
+AnyDepSpec::need_keys_added() const
+{
+}
+
+
AllDepSpec::AllDepSpec()
{
}
+void
+AllDepSpec::need_keys_added() const
+{
+}
+
std::tr1::shared_ptr<DepSpec>
AllDepSpec::clone() const
{
@@ -120,7 +175,6 @@ ConditionalDepSpec::ConditionalDepSpec(const ConditionalDepSpec & other) :
Cloneable<DepSpec>(),
DepSpec(),
PrivateImplementationPattern<ConditionalDepSpec>(new Implementation<ConditionalDepSpec>(other._imp->data)),
- MetadataKeyHolder(),
CloneUsingThis<DepSpec, ConditionalDepSpec>(other),
_imp(PrivateImplementationPattern<ConditionalDepSpec>::_imp)
{
@@ -209,6 +263,11 @@ NamedSetDepSpec::clone() const
return std::tr1::shared_ptr<NamedSetDepSpec>(new NamedSetDepSpec(_name));
}
+void
+NamedSetDepSpec::need_keys_added() const
+{
+}
+
const PackageDepSpec *
PackageDepSpec::as_package_dep_spec() const
{
@@ -321,6 +380,12 @@ PlainTextDepSpec::clone() const
return std::tr1::shared_ptr<DepSpec>(new PlainTextDepSpec(text()));
}
+void
+PlainTextDepSpec::need_keys_added() const
+{
+}
+
+
LicenseDepSpec::LicenseDepSpec(const std::string & s) :
StringDepSpec(s)
{
@@ -332,6 +397,12 @@ LicenseDepSpec::clone() const
return std::tr1::shared_ptr<DepSpec>(new LicenseDepSpec(text()));
}
+void
+LicenseDepSpec::need_keys_added() const
+{
+}
+
+
SimpleURIDepSpec::SimpleURIDepSpec(const std::string & s) :
StringDepSpec(s)
{
@@ -343,6 +414,11 @@ SimpleURIDepSpec::clone() const
return std::tr1::shared_ptr<DepSpec>(new SimpleURIDepSpec(text()));
}
+void
+SimpleURIDepSpec::need_keys_added() const
+{
+}
+
std::tr1::shared_ptr<const PackageDepSpec>
BlockDepSpec::blocked_spec() const
{
@@ -355,11 +431,22 @@ BlockDepSpec::clone() const
return std::tr1::shared_ptr<DepSpec>(new BlockDepSpec(std::tr1::static_pointer_cast<PackageDepSpec>(_spec->clone())));
}
+void
+BlockDepSpec::need_keys_added() const
+{
+}
+
FetchableURIDepSpec::FetchableURIDepSpec(const std::string & s) :
StringDepSpec(s)
{
}
+void
+FetchableURIDepSpec::need_keys_added() const
+{
+}
+
+
std::string
FetchableURIDepSpec::original_url() const
{
@@ -415,7 +502,8 @@ namespace paludis
template <typename T_>
LabelsDepSpec<T_>::LabelsDepSpec() :
- PrivateImplementationPattern<LabelsDepSpec<T_> >(new Implementation<LabelsDepSpec<T_> >)
+ PrivateImplementationPattern<LabelsDepSpec<T_> >(new Implementation<LabelsDepSpec<T_> >),
+ _imp(PrivateImplementationPattern<LabelsDepSpec<T_> >::_imp)
{
}
@@ -455,6 +543,12 @@ LabelsDepSpec<T_>::add_label(const std::tr1::shared_ptr<const typename T_::Basic
_imp->items.push_back(item);
}
+template <typename T_>
+void
+LabelsDepSpec<T_>::need_keys_added() const
+{
+}
+
PackageDepSpecData::~PackageDepSpecData()
{
}
@@ -478,7 +572,8 @@ namespace paludis
PackageDepSpec::PackageDepSpec(const std::tr1::shared_ptr<const PackageDepSpecData> & d) :
Cloneable<DepSpec>(),
StringDepSpec(d->as_string()),
- PrivateImplementationPattern<PackageDepSpec>(new Implementation<PackageDepSpec>(d, std::tr1::shared_ptr<const DepTag>()))
+ PrivateImplementationPattern<PackageDepSpec>(new Implementation<PackageDepSpec>(d, std::tr1::shared_ptr<const DepTag>())),
+ _imp(PrivateImplementationPattern<PackageDepSpec>::_imp)
{
}
@@ -490,7 +585,8 @@ PackageDepSpec::PackageDepSpec(const PackageDepSpec & d) :
Cloneable<DepSpec>(d),
StringDepSpec(d._imp->data->as_string()),
PrivateImplementationPattern<PackageDepSpec>(new Implementation<PackageDepSpec>(d._imp->data, d._imp->tag)),
- CloneUsingThis<DepSpec, PackageDepSpec>(d)
+ CloneUsingThis<DepSpec, PackageDepSpec>(d),
+ _imp(PrivateImplementationPattern<PackageDepSpec>::_imp)
{
}
@@ -606,6 +702,11 @@ PackageDepSpec::data() const
return _imp->data;
}
+void
+PackageDepSpec::need_keys_added() const
+{
+}
+
AdditionalPackageDepSpecRequirement::~AdditionalPackageDepSpecRequirement()
{
}
diff --git a/paludis/dep_spec.hh b/paludis/dep_spec.hh
index 60d43a2..d1a6665 100644
--- a/paludis/dep_spec.hh
+++ b/paludis/dep_spec.hh
@@ -64,10 +64,16 @@ namespace paludis
*/
class PALUDIS_VISIBLE DepSpec :
private InstantiationPolicy<DepSpec, instantiation_method::NonCopyableTag>,
+ private PrivateImplementationPattern<DepSpec>,
+ public MetadataKeyHolder,
public virtual Cloneable<DepSpec>
{
+ private:
+ PrivateImplementationPattern<DepSpec>::ImpPtr & _imp;
+
protected:
DepSpec();
+ DepSpec(const std::tr1::shared_ptr<const MetadataSectionKey> &);
public:
///\name Basic operations
@@ -94,6 +100,17 @@ namespace paludis
virtual const PackageDepSpec * as_package_dep_spec() const
PALUDIS_ATTRIBUTE((warn_unused_result));
+ /**
+ * The annotations_key, if non-zero, contains any annotations.
+ */
+ const std::tr1::shared_ptr<const MetadataSectionKey> annotations_key() const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ /**
+ * Change the annotations key.
+ */
+ void set_annotations_key(const std::tr1::shared_ptr<const MetadataSectionKey> &);
+
///\}
};
@@ -106,6 +123,9 @@ namespace paludis
class PALUDIS_VISIBLE AnyDepSpec :
public DepSpec
{
+ protected:
+ virtual void need_keys_added() const;
+
public:
///\name Basic operations
///\{
@@ -127,6 +147,9 @@ namespace paludis
class PALUDIS_VISIBLE AllDepSpec :
public DepSpec
{
+ protected:
+ virtual void need_keys_added() const;
+
public:
///\name Basic operations
///\{
@@ -149,7 +172,6 @@ namespace paludis
class PALUDIS_VISIBLE ConditionalDepSpec :
public DepSpec,
private PrivateImplementationPattern<ConditionalDepSpec>,
- public MetadataKeyHolder,
public CloneUsingThis<DepSpec, ConditionalDepSpec>
{
friend std::ostream & operator<< (std::ostream &, const ConditionalDepSpec &);
@@ -399,6 +421,11 @@ namespace paludis
const PackageDepSpec & operator= (const PackageDepSpec &);
std::string _as_string() const;
+ PrivateImplementationPattern<PackageDepSpec>::ImpPtr & _imp;
+
+ protected:
+ virtual void need_keys_added() const;
+
public:
///\name Basic operations
///\{
@@ -565,6 +592,9 @@ namespace paludis
class PALUDIS_VISIBLE PlainTextDepSpec :
public StringDepSpec
{
+ protected:
+ virtual void need_keys_added() const;
+
public:
///\name Basic operations
///\{
@@ -588,6 +618,9 @@ namespace paludis
private:
const SetName _name;
+ protected:
+ virtual void need_keys_added() const;
+
public:
///\name Basic operations
///\{
@@ -612,6 +645,9 @@ namespace paludis
class PALUDIS_VISIBLE LicenseDepSpec :
public StringDepSpec
{
+ protected:
+ virtual void need_keys_added() const;
+
public:
///\name Basic operations
///\{
@@ -637,6 +673,9 @@ namespace paludis
class PALUDIS_VISIBLE FetchableURIDepSpec :
public StringDepSpec
{
+ protected:
+ virtual void need_keys_added() const;
+
public:
///\name Basic operations
///\{
@@ -678,6 +717,9 @@ namespace paludis
class PALUDIS_VISIBLE SimpleURIDepSpec :
public StringDepSpec
{
+ protected:
+ virtual void need_keys_added() const;
+
public:
///\name Basic operations
///\{
@@ -722,6 +764,9 @@ namespace paludis
private:
std::tr1::shared_ptr<const PackageDepSpec> _spec;
+ protected:
+ virtual void need_keys_added() const;
+
public:
///\name Basic operations
///\{
@@ -754,7 +799,10 @@ namespace paludis
private PrivateImplementationPattern<LabelsDepSpec<SpecTree_> >
{
private:
- using PrivateImplementationPattern<LabelsDepSpec<SpecTree_> >::_imp;
+ typename PrivateImplementationPattern<LabelsDepSpec>::ImpPtr & _imp;
+
+ protected:
+ virtual void need_keys_added() const;
public:
///\name Basic operations
diff --git a/paludis/repositories/e/dep_parser.cc b/paludis/repositories/e/dep_parser.cc
index 2ae82c4..6554eb6 100644
--- a/paludis/repositories/e/dep_parser.cc
+++ b/paludis/repositories/e/dep_parser.cc
@@ -25,6 +25,8 @@
#include <paludis/util/visitor-impl.hh>
#include <paludis/util/tokeniser.hh>
#include <paludis/util/make_named_values.hh>
+#include <paludis/util/map.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/elike_dep_parser.hh>
#include <paludis/elike_conditional_dep_spec.hh>
#include <paludis/elike_package_dep_spec.hh>
@@ -32,6 +34,8 @@
#include <paludis/environment.hh>
#include <paludis/repository.hh>
#include <paludis/package_id.hh>
+#include <paludis/metadata_key.hh>
+#include <paludis/literal_metadata_key.hh>
#include <list>
#include <set>
#include <ostream>
@@ -52,6 +56,7 @@ namespace paludis
{
struct add_handler;
struct item;
+ struct spec;
}
}
@@ -66,59 +71,95 @@ namespace
{
NamedValue<n::add_handler, AddHandler> add_handler;
NamedValue<n::item, const std::tr1::shared_ptr<const typename T_::ConstItem> > item;
+ NamedValue<n::spec, std::tr1::shared_ptr<DepSpec> > spec;
};
typedef std::list<Item> Stack;
+ typedef std::tr1::function<void (const std::tr1::shared_ptr<DepSpec> &)> AnnotationsGoHere;
};
template <typename T_>
- void package_dep_spec_string_handler(const typename ParseStackTypes<T_>::Stack & h, const std::string & s,
- const EAPI & eapi, const std::tr1::shared_ptr<const PackageID> & id)
+ void package_dep_spec_string_handler(
+ const typename ParseStackTypes<T_>::Stack & h,
+ const typename ParseStackTypes<T_>::AnnotationsGoHere & annotations_go_here,
+ const std::string & s,
+ const EAPI & eapi,
+ const std::tr1::shared_ptr<const PackageID> & id)
{
- PackageDepSpec p(parse_elike_package_dep_spec(s, eapi.supported()->package_dep_spec_parse_options(), id));
- (*h.begin()).add_handler()(make_shared_ptr(new TreeLeaf<T_, PackageDepSpec>(make_shared_ptr(new PackageDepSpec(p)))));
+ std::tr1::shared_ptr<PackageDepSpec> spec(new PackageDepSpec(
+ parse_elike_package_dep_spec(s, eapi.supported()->package_dep_spec_parse_options(), id)));
+ (*h.begin()).add_handler()(make_shared_ptr(new TreeLeaf<T_, PackageDepSpec>(spec)));
+ annotations_go_here(spec);
}
template <typename T_>
- void package_or_block_dep_spec_string_handler(const typename ParseStackTypes<T_>::Stack & h, const std::string & s,
- const EAPI & eapi, const std::tr1::shared_ptr<const PackageID> & id)
+ void package_or_block_dep_spec_string_handler(
+ const typename ParseStackTypes<T_>::Stack & h,
+ const typename ParseStackTypes<T_>::AnnotationsGoHere & annotations_go_here,
+ const std::string & s,
+ const EAPI & eapi,
+ const std::tr1::shared_ptr<const PackageID> & id)
{
if ((! s.empty()) && ('!' == s.at(0)))
{
- std::tr1::shared_ptr<BlockDepSpec> b(new BlockDepSpec(
+ std::tr1::shared_ptr<BlockDepSpec> spec(new BlockDepSpec(
make_shared_ptr(new PackageDepSpec(parse_elike_package_dep_spec(s.substr(1),
eapi.supported()->package_dep_spec_parse_options(), id)))));
- (*h.begin()).add_handler()(make_shared_ptr(new TreeLeaf<T_, BlockDepSpec>(b)));
+ (*h.begin()).add_handler()(make_shared_ptr(new TreeLeaf<T_, BlockDepSpec>(spec)));
+ annotations_go_here(spec);
}
else
- package_dep_spec_string_handler<T_>(h, s, eapi, id);
+ package_dep_spec_string_handler<T_>(h, annotations_go_here, s, eapi, id);
}
template <typename T_>
- void license_handler(const typename ParseStackTypes<T_>::Stack & h, const std::string & s)
+ void license_handler(
+ const typename ParseStackTypes<T_>::Stack & h,
+ const typename ParseStackTypes<T_>::AnnotationsGoHere & annotations_go_here,
+ const std::string & s)
{
- (*h.begin()).add_handler()(make_shared_ptr(new TreeLeaf<T_, LicenseDepSpec>(make_shared_ptr(new LicenseDepSpec(s)))));
+ std::tr1::shared_ptr<LicenseDepSpec> spec(new LicenseDepSpec(s));
+ (*h.begin()).add_handler()(make_shared_ptr(new TreeLeaf<T_, LicenseDepSpec>(spec)));
+ annotations_go_here(spec);
}
template <typename T_>
- void plain_text_handler(const typename ParseStackTypes<T_>::Stack & h, const std::string & s)
+ void plain_text_handler(
+ const typename ParseStackTypes<T_>::Stack & h,
+ const typename ParseStackTypes<T_>::AnnotationsGoHere & annotations_go_here,
+ const std::string & s)
{
- (*h.begin()).add_handler()(make_shared_ptr(new TreeLeaf<T_, PlainTextDepSpec>(make_shared_ptr(new PlainTextDepSpec(s)))));
+ std::tr1::shared_ptr<PlainTextDepSpec> spec(new PlainTextDepSpec(s));
+ (*h.begin()).add_handler()(make_shared_ptr(new TreeLeaf<T_, PlainTextDepSpec>(spec)));
+ annotations_go_here(spec);
}
template <typename T_>
- void simple_uri_handler(const typename ParseStackTypes<T_>::Stack & h, const std::string & s)
+ void simple_uri_handler(
+ const typename ParseStackTypes<T_>::Stack & h,
+ const typename ParseStackTypes<T_>::AnnotationsGoHere & annotations_go_here,
+ const std::string & s)
{
- (*h.begin()).add_handler()(make_shared_ptr(new TreeLeaf<T_, SimpleURIDepSpec>(make_shared_ptr(new SimpleURIDepSpec(s)))));
+ std::tr1::shared_ptr<SimpleURIDepSpec> spec(new SimpleURIDepSpec(s));
+ (*h.begin()).add_handler()(make_shared_ptr(new TreeLeaf<T_, SimpleURIDepSpec>(spec)));
+ annotations_go_here(spec);
}
template <typename T_>
- void arrow_handler(const typename ParseStackTypes<T_>::Stack & h, const std::string & s, const std::string & f, const std::string & t,
+ void arrow_handler(
+ const typename ParseStackTypes<T_>::Stack & h,
+ const typename ParseStackTypes<T_>::AnnotationsGoHere & annotations_go_here,
+ const std::string & s,
+ const std::string & f,
+ const std::string & t,
const EAPI & eapi)
{
if (t.empty() || eapi.supported()->dependency_spec_tree_parse_options()[dstpo_uri_supports_arrow])
- (*h.begin()).add_handler()(make_shared_ptr(new TreeLeaf<T_, FetchableURIDepSpec>(make_shared_ptr(
- new FetchableURIDepSpec(t.empty() ? f : f + " -> " + t)))));
+ {
+ std::tr1::shared_ptr<FetchableURIDepSpec> spec(new FetchableURIDepSpec(t.empty() ? f : f + " -> " + t));
+ (*h.begin()).add_handler()(make_shared_ptr(new TreeLeaf<T_, FetchableURIDepSpec>(spec)));
+ annotations_go_here(spec);
+ }
else
throw EDepParseError(s, "arrows in this EAPI");
}
@@ -152,59 +193,75 @@ namespace
}
template <typename T_>
- void dependency_label_handler(const typename ParseStackTypes<T_>::Stack & h, const std::string & s,
+ void dependency_label_handler(
+ const typename ParseStackTypes<T_>::Stack & h,
+ const typename ParseStackTypes<T_>::AnnotationsGoHere & annotations_go_here,
+ const std::string & s,
const EAPI & eapi)
{
- (*h.begin()).add_handler()(make_shared_ptr(new TreeLeaf<T_, DependencyLabelsDepSpec>(
- parse_dependency_label(s, eapi))));
+ std::tr1::shared_ptr<DependencyLabelsDepSpec> spec(parse_dependency_label(s, eapi));
+ (*h.begin()).add_handler()(make_shared_ptr(new TreeLeaf<T_, DependencyLabelsDepSpec>(spec)));
+ annotations_go_here(spec);
}
template <typename T_>
- void fetchable_label_handler(const typename ParseStackTypes<T_>::Stack & h, const std::string & s,
+ void fetchable_label_handler(
+ const typename ParseStackTypes<T_>::Stack & h,
+ const typename ParseStackTypes<T_>::AnnotationsGoHere & annotations_go_here,
+ const std::string & s,
const EAPI & eapi)
{
- (*h.begin()).add_handler()(make_shared_ptr(new TreeLeaf<T_, URILabelsDepSpec>(
- parse_uri_label(s, eapi))));
+ std::tr1::shared_ptr<URILabelsDepSpec> spec(parse_uri_label(s, eapi));
+ (*h.begin()).add_handler()(make_shared_ptr(new TreeLeaf<T_, URILabelsDepSpec>(spec)));
+ annotations_go_here(spec);
}
template <typename T_, typename A_>
void any_all_handler(typename ParseStackTypes<T_>::Stack & stack)
{
using namespace std::tr1::placeholders;
- std::tr1::shared_ptr<ConstTreeSequence<T_, A_> > item(
- new ConstTreeSequence<T_, A_>(make_shared_ptr(new A_)));
+ std::tr1::shared_ptr<A_> spec(new A_);
+ std::tr1::shared_ptr<ConstTreeSequence<T_, A_> > item(new ConstTreeSequence<T_, A_>(spec));
(*stack.begin()).add_handler()(item);
stack.push_front(make_named_values<typename ParseStackTypes<T_>::Item>(
value_for<n::add_handler>(std::tr1::bind(&ConstTreeSequence<T_, A_>::add, item.get(), _1)),
- value_for<n::item>(item)
+ value_for<n::item>(item),
+ value_for<n::spec>(spec)
));
}
template <typename T_>
- void use_handler(typename ParseStackTypes<T_>::Stack & stack, const std::string & u,
- const Environment * const env, const std::tr1::shared_ptr<const PackageID> & id)
+ void use_handler(
+ typename ParseStackTypes<T_>::Stack & stack,
+ const std::string & u,
+ const Environment * const env,
+ const std::tr1::shared_ptr<const PackageID> & id)
{
using namespace std::tr1::placeholders;
- std::tr1::shared_ptr<ConstTreeSequence<T_, ConditionalDepSpec> > item(
- new ConstTreeSequence<T_, ConditionalDepSpec>(make_shared_ptr(new ConditionalDepSpec(
- parse_elike_conditional_dep_spec(u, env, id)))));
+ std::tr1::shared_ptr<ConditionalDepSpec> spec(new ConditionalDepSpec(parse_elike_conditional_dep_spec(u, env, id)));
+ std::tr1::shared_ptr<ConstTreeSequence<T_, ConditionalDepSpec> > item(new ConstTreeSequence<T_, ConditionalDepSpec>(spec));
(*stack.begin()).add_handler()(item);
stack.push_front(make_named_values<typename ParseStackTypes<T_>::Item>(
value_for<n::add_handler>(std::tr1::bind(&ConstTreeSequence<T_, ConditionalDepSpec>::add, item.get(), _1)),
- value_for<n::item>(item)
+ value_for<n::item>(item),
+ value_for<n::spec>(spec)
));
}
template <typename T_>
- void pop_handler(typename ParseStackTypes<T_>::Stack & stack, const std::string & s)
+ void pop_handler(
+ typename ParseStackTypes<T_>::Stack & stack,
+ const typename ParseStackTypes<T_>::AnnotationsGoHere & annotations_go_here,
+ const std::string & s)
{
+ annotations_go_here(stack.begin()->spec());
stack.pop_front();
if (stack.empty())
throw EDepParseError(s, "Too many ')'s");
}
template <typename T_>
- void should_be_empty_handler(typename ParseStackTypes<T_>::Stack & stack, const std::string & s)
+ void should_be_empty_handler(const typename ParseStackTypes<T_>::Stack & stack, const std::string & s)
{
if (1 != stack.size())
throw EDepParseError(s, "Nesting error");
@@ -220,8 +277,31 @@ namespace
{
}
- void discard_annotations(const std::tr1::shared_ptr<const Map<std::string, std::string> > &)
+ struct AnnotationsKey :
+ MetadataSectionKey
+ {
+ AnnotationsKey(const std::tr1::shared_ptr<const Map<std::string, std::string> > & m) :
+ MetadataSectionKey("Annotations", "Annotations", mkt_normal)
+ {
+ for (Map<std::string, std::string>::ConstIterator k(m->begin()), k_end(m->end()) ;
+ k != k_end ; ++k)
+ add_metadata_key(make_shared_ptr(new LiteralMetadataValueKey<std::string>(k->first, k->first, mkt_normal, k->second)));
+ }
+
+ void need_keys_added() const
+ {
+ }
+ };
+
+ void set_annotations(std::tr1::shared_ptr<DepSpec> & spec, const std::tr1::shared_ptr<const Map<std::string, std::string> > & m)
+ {
+ std::tr1::shared_ptr<AnnotationsKey> key(new AnnotationsKey(m));
+ spec->set_annotations_key(key);
+ }
+
+ void set_thing_to_annotate(std::tr1::shared_ptr<DepSpec> & spec, const std::tr1::shared_ptr<DepSpec> & s)
{
+ spec = s;
}
}
@@ -232,24 +312,33 @@ paludis::erepository::parse_depend(const std::string & s,
using namespace std::tr1::placeholders;
ParseStackTypes<DependencySpecTree>::Stack stack;
+ std::tr1::shared_ptr<AllDepSpec> spec(new AllDepSpec);
+ std::tr1::shared_ptr<DepSpec> thing_to_annotate(spec);
std::tr1::shared_ptr<ConstTreeSequence<DependencySpecTree, AllDepSpec> > top(
- new ConstTreeSequence<DependencySpecTree, AllDepSpec>(make_shared_ptr(new AllDepSpec)));
+ new ConstTreeSequence<DependencySpecTree, AllDepSpec>(spec));
stack.push_front(make_named_values<ParseStackTypes<DependencySpecTree>::Item>(
value_for<n::add_handler>(std::tr1::bind(&ConstTreeSequence<DependencySpecTree, AllDepSpec>::add, top.get(), _1)),
- value_for<n::item>(top)
+ value_for<n::item>(top),
+ value_for<n::spec>(spec)
));
ELikeDepParserCallbacks callbacks(
make_named_values<ELikeDepParserCallbacks>(
value_for<n::on_all>(std::tr1::bind(&any_all_handler<DependencySpecTree, AllDepSpec>, std::tr1::ref(stack))),
- value_for<n::on_annotations>(&discard_annotations),
+ value_for<n::on_annotations>(std::tr1::bind(&set_annotations, std::tr1::ref(thing_to_annotate), _1)),
value_for<n::on_any>(std::tr1::bind(&any_all_handler<DependencySpecTree, AnyDepSpec>, std::tr1::ref(stack))),
value_for<n::on_arrow>(std::tr1::bind(&arrows_not_allowed_handler, s, _1, _2)),
value_for<n::on_error>(std::tr1::bind(&error_handler, s, _1)),
- value_for<n::on_label>(std::tr1::bind(&dependency_label_handler<DependencySpecTree>, std::tr1::ref(stack), _1, eapi)),
- value_for<n::on_pop>(std::tr1::bind(&pop_handler<DependencySpecTree>, std::tr1::ref(stack), s)),
+ value_for<n::on_label>(std::tr1::bind(&dependency_label_handler<DependencySpecTree>, std::tr1::ref(stack),
+ ParseStackTypes<DependencySpecTree>::AnnotationsGoHere(std::tr1::bind(
+ &set_thing_to_annotate, std::tr1::ref(thing_to_annotate), _1)), _1, eapi)),
+ value_for<n::on_pop>(std::tr1::bind(&pop_handler<DependencySpecTree>, std::tr1::ref(stack),
+ ParseStackTypes<DependencySpecTree>::AnnotationsGoHere(std::tr1::bind(
+ &set_thing_to_annotate, std::tr1::ref(thing_to_annotate), _1)), s)),
value_for<n::on_should_be_empty>(std::tr1::bind(&should_be_empty_handler<DependencySpecTree>, std::tr1::ref(stack), s)),
- value_for<n::on_string>(std::tr1::bind(&package_or_block_dep_spec_string_handler<DependencySpecTree>, std::tr1::ref(stack), _1, eapi, id)),
+ value_for<n::on_string>(std::tr1::bind(&package_or_block_dep_spec_string_handler<DependencySpecTree>, std::tr1::ref(stack),
+ ParseStackTypes<DependencySpecTree>::AnnotationsGoHere(std::tr1::bind(
+ &set_thing_to_annotate, std::tr1::ref(thing_to_annotate), _1)), _1, eapi, id)),
value_for<n::on_use>(std::tr1::bind(&use_handler<DependencySpecTree>, std::tr1::ref(stack), _1, env, id)),
value_for<n::on_use_under_any>(std::tr1::bind(&use_under_any_handler, s, eapi))
));
@@ -266,24 +355,31 @@ paludis::erepository::parse_provide(const std::string & s,
using namespace std::tr1::placeholders;
ParseStackTypes<ProvideSpecTree>::Stack stack;
+ std::tr1::shared_ptr<AllDepSpec> spec(new AllDepSpec);
+ std::tr1::shared_ptr<DepSpec> thing_to_annotate(spec);
std::tr1::shared_ptr<ConstTreeSequence<ProvideSpecTree, AllDepSpec> > top(
- new ConstTreeSequence<ProvideSpecTree, AllDepSpec>(make_shared_ptr(new AllDepSpec)));
+ new ConstTreeSequence<ProvideSpecTree, AllDepSpec>(spec));
stack.push_front(make_named_values<ParseStackTypes<ProvideSpecTree>::Item>(
value_for<n::add_handler>(std::tr1::bind(&ConstTreeSequence<ProvideSpecTree, AllDepSpec>::add, top.get(), _1)),
- value_for<n::item>(top)
+ value_for<n::item>(top),
+ value_for<n::spec>(spec)
));
ELikeDepParserCallbacks callbacks(
make_named_values<ELikeDepParserCallbacks>(
value_for<n::on_all>(std::tr1::bind(&any_all_handler<ProvideSpecTree, AllDepSpec>, std::tr1::ref(stack))),
- value_for<n::on_annotations>(&discard_annotations),
+ value_for<n::on_annotations>(std::tr1::bind(&set_annotations, std::tr1::ref(thing_to_annotate), _1)),
value_for<n::on_any>(std::tr1::bind(&any_not_allowed_handler, s)),
value_for<n::on_arrow>(std::tr1::bind(&arrows_not_allowed_handler, s, _1, _2)),
value_for<n::on_error>(std::tr1::bind(&error_handler, s, _1)),
value_for<n::on_label>(std::tr1::bind(&labels_not_allowed_handler, s, _1)),
- value_for<n::on_pop>(std::tr1::bind(&pop_handler<ProvideSpecTree>, std::tr1::ref(stack), s)),
+ value_for<n::on_pop>(std::tr1::bind(&pop_handler<ProvideSpecTree>, std::tr1::ref(stack),
+ ParseStackTypes<ProvideSpecTree>::AnnotationsGoHere(std::tr1::bind(
+ &set_thing_to_annotate, std::tr1::ref(thing_to_annotate), _1)), s)),
value_for<n::on_should_be_empty>(std::tr1::bind(&should_be_empty_handler<ProvideSpecTree>, std::tr1::ref(stack), s)),
- value_for<n::on_string>(std::tr1::bind(&package_dep_spec_string_handler<ProvideSpecTree>, std::tr1::ref(stack), _1, eapi, id)),
+ value_for<n::on_string>(std::tr1::bind(&package_dep_spec_string_handler<ProvideSpecTree>, std::tr1::ref(stack),
+ ParseStackTypes<DependencySpecTree>::AnnotationsGoHere(std::tr1::bind(
+ &set_thing_to_annotate, std::tr1::ref(thing_to_annotate), _1)), _1, eapi, id)),
value_for<n::on_use>(std::tr1::bind(&use_handler<ProvideSpecTree>, std::tr1::ref(stack), _1, env, id)),
value_for<n::on_use_under_any>(std::tr1::bind(&use_under_any_handler, s, eapi))
));
@@ -300,24 +396,35 @@ paludis::erepository::parse_fetchable_uri(const std::string & s,
using namespace std::tr1::placeholders;
ParseStackTypes<FetchableURISpecTree>::Stack stack;
+ std::tr1::shared_ptr<AllDepSpec> spec(new AllDepSpec);
+ std::tr1::shared_ptr<DepSpec> thing_to_annotate(spec);
std::tr1::shared_ptr<ConstTreeSequence<FetchableURISpecTree, AllDepSpec> > top(
- new ConstTreeSequence<FetchableURISpecTree, AllDepSpec>(make_shared_ptr(new AllDepSpec)));
+ new ConstTreeSequence<FetchableURISpecTree, AllDepSpec>(spec));
stack.push_front(make_named_values<ParseStackTypes<FetchableURISpecTree>::Item>(
value_for<n::add_handler>(std::tr1::bind(&ConstTreeSequence<FetchableURISpecTree, AllDepSpec>::add, top.get(), _1)),
- value_for<n::item>(top)
+ value_for<n::item>(top),
+ value_for<n::spec>(spec)
));
ELikeDepParserCallbacks callbacks(
make_named_values<ELikeDepParserCallbacks>(
value_for<n::on_all>(std::tr1::bind(&any_all_handler<FetchableURISpecTree, AllDepSpec>, std::tr1::ref(stack))),
- value_for<n::on_annotations>(&discard_annotations),
+ value_for<n::on_annotations>(std::tr1::bind(&set_annotations, std::tr1::ref(thing_to_annotate), _1)),
value_for<n::on_any>(std::tr1::bind(&any_not_allowed_handler, s)),
- value_for<n::on_arrow>(std::tr1::bind(&arrow_handler<FetchableURISpecTree>, std::tr1::ref(stack), s, _1, _2, eapi)),
+ value_for<n::on_arrow>(std::tr1::bind(&arrow_handler<FetchableURISpecTree>, std::tr1::ref(stack),
+ ParseStackTypes<FetchableURISpecTree>::AnnotationsGoHere(std::tr1::bind(
+ &set_thing_to_annotate, std::tr1::ref(thing_to_annotate), _1)), s, _1, _2, eapi)),
value_for<n::on_error>(std::tr1::bind(&error_handler, s, _1)),
- value_for<n::on_label>(std::tr1::bind(&fetchable_label_handler<FetchableURISpecTree>, std::tr1::ref(stack), _1, eapi)),
- value_for<n::on_pop>(std::tr1::bind(&pop_handler<FetchableURISpecTree>, std::tr1::ref(stack), s)),
+ value_for<n::on_label>(std::tr1::bind(&fetchable_label_handler<FetchableURISpecTree>, std::tr1::ref(stack),
+ ParseStackTypes<FetchableURISpecTree>::AnnotationsGoHere(std::tr1::bind(
+ &set_thing_to_annotate, std::tr1::ref(thing_to_annotate), _1)), _1, eapi)),
+ value_for<n::on_pop>(std::tr1::bind(&pop_handler<FetchableURISpecTree>, std::tr1::ref(stack),
+ ParseStackTypes<FetchableURISpecTree>::AnnotationsGoHere(std::tr1::bind(
+ &set_thing_to_annotate, std::tr1::ref(thing_to_annotate), _1)), s)),
value_for<n::on_should_be_empty>(std::tr1::bind(&should_be_empty_handler<FetchableURISpecTree>, std::tr1::ref(stack), s)),
- value_for<n::on_string>(std::tr1::bind(&arrow_handler<FetchableURISpecTree>, std::tr1::ref(stack), s, _1, "", eapi)),
+ value_for<n::on_string>(std::tr1::bind(&arrow_handler<FetchableURISpecTree>, std::tr1::ref(stack),
+ ParseStackTypes<FetchableURISpecTree>::AnnotationsGoHere(std::tr1::bind(
+ &set_thing_to_annotate, std::tr1::ref(thing_to_annotate), _1)), s, _1, "", eapi)),
value_for<n::on_use>(std::tr1::bind(&use_handler<FetchableURISpecTree>, std::tr1::ref(stack), _1, env, id)),
value_for<n::on_use_under_any>(std::tr1::bind(&use_under_any_handler, s, eapi))
));
@@ -334,24 +441,31 @@ paludis::erepository::parse_simple_uri(const std::string & s,
using namespace std::tr1::placeholders;
ParseStackTypes<SimpleURISpecTree>::Stack stack;
+ std::tr1::shared_ptr<AllDepSpec> spec(new AllDepSpec);
+ std::tr1::shared_ptr<DepSpec> thing_to_annotate(spec);
std::tr1::shared_ptr<ConstTreeSequence<SimpleURISpecTree, AllDepSpec> > top(
- new ConstTreeSequence<SimpleURISpecTree, AllDepSpec>(make_shared_ptr(new AllDepSpec)));
+ new ConstTreeSequence<SimpleURISpecTree, AllDepSpec>(spec));
stack.push_front(make_named_values<ParseStackTypes<SimpleURISpecTree>::Item>(
value_for<n::add_handler>(std::tr1::bind(&ConstTreeSequence<SimpleURISpecTree, AllDepSpec>::add, top.get(), _1)),
- value_for<n::item>(top)
+ value_for<n::item>(top),
+ value_for<n::spec>(spec)
));
ELikeDepParserCallbacks callbacks(
make_named_values<ELikeDepParserCallbacks>(
value_for<n::on_all>(std::tr1::bind(&any_all_handler<SimpleURISpecTree, AllDepSpec>, std::tr1::ref(stack))),
- value_for<n::on_annotations>(&discard_annotations),
+ value_for<n::on_annotations>(std::tr1::bind(&set_annotations, std::tr1::ref(thing_to_annotate), _1)),
value_for<n::on_any>(std::tr1::bind(&any_not_allowed_handler, s)),
value_for<n::on_arrow>(std::tr1::bind(&arrows_not_allowed_handler, s, _1, _2)),
value_for<n::on_error>(std::tr1::bind(&error_handler, s, _1)),
value_for<n::on_label>(std::tr1::bind(&labels_not_allowed_handler, s, _1)),
- value_for<n::on_pop>(std::tr1::bind(&pop_handler<SimpleURISpecTree>, std::tr1::ref(stack), s)),
+ value_for<n::on_pop>(std::tr1::bind(&pop_handler<SimpleURISpecTree>, std::tr1::ref(stack),
+ ParseStackTypes<DependencySpecTree>::AnnotationsGoHere(std::tr1::bind(
+ &set_thing_to_annotate, std::tr1::ref(thing_to_annotate), _1)), s)),
value_for<n::on_should_be_empty>(std::tr1::bind(&should_be_empty_handler<SimpleURISpecTree>, std::tr1::ref(stack), s)),
- value_for<n::on_string>(std::tr1::bind(&simple_uri_handler<SimpleURISpecTree>, std::tr1::ref(stack), _1)),
+ value_for<n::on_string>(std::tr1::bind(&simple_uri_handler<SimpleURISpecTree>, std::tr1::ref(stack),
+ ParseStackTypes<SimpleURISpecTree>::AnnotationsGoHere(std::tr1::bind(
+ &set_thing_to_annotate, std::tr1::ref(thing_to_annotate), _1)), _1)),
value_for<n::on_use>(std::tr1::bind(&use_handler<SimpleURISpecTree>, std::tr1::ref(stack), _1, env, id)),
value_for<n::on_use_under_any>(&do_nothing)
));
@@ -368,24 +482,31 @@ paludis::erepository::parse_license(const std::string & s,
using namespace std::tr1::placeholders;
ParseStackTypes<LicenseSpecTree>::Stack stack;
+ std::tr1::shared_ptr<AllDepSpec> spec(new AllDepSpec);
+ std::tr1::shared_ptr<DepSpec> thing_to_annotate(spec);
std::tr1::shared_ptr<ConstTreeSequence<LicenseSpecTree, AllDepSpec> > top(
- new ConstTreeSequence<LicenseSpecTree, AllDepSpec>(make_shared_ptr(new AllDepSpec)));
+ new ConstTreeSequence<LicenseSpecTree, AllDepSpec>(spec));
stack.push_front(make_named_values<ParseStackTypes<LicenseSpecTree>::Item>(
value_for<n::add_handler>(std::tr1::bind(&ConstTreeSequence<LicenseSpecTree, AllDepSpec>::add, top.get(), _1)),
- value_for<n::item>(top)
+ value_for<n::item>(top),
+ value_for<n::spec>(spec)
));
ELikeDepParserCallbacks callbacks(
make_named_values<ELikeDepParserCallbacks>(
value_for<n::on_all>(std::tr1::bind(&any_all_handler<LicenseSpecTree, AllDepSpec>, std::tr1::ref(stack))),
- value_for<n::on_annotations>(&discard_annotations),
+ value_for<n::on_annotations>(std::tr1::bind(&set_annotations, std::tr1::ref(thing_to_annotate), _1)),
value_for<n::on_any>(std::tr1::bind(&any_all_handler<LicenseSpecTree, AnyDepSpec>, std::tr1::ref(stack))),
value_for<n::on_arrow>(std::tr1::bind(&arrows_not_allowed_handler, s, _1, _2)),
value_for<n::on_error>(std::tr1::bind(&error_handler, s, _1)),
value_for<n::on_label>(std::tr1::bind(&labels_not_allowed_handler, s, _1)),
- value_for<n::on_pop>(std::tr1::bind(&pop_handler<LicenseSpecTree>, std::tr1::ref(stack), s)),
+ value_for<n::on_pop>(std::tr1::bind(&pop_handler<LicenseSpecTree>, std::tr1::ref(stack),
+ ParseStackTypes<DependencySpecTree>::AnnotationsGoHere(std::tr1::bind(
+ &set_thing_to_annotate, std::tr1::ref(thing_to_annotate), _1)), s)),
value_for<n::on_should_be_empty>(std::tr1::bind(&should_be_empty_handler<LicenseSpecTree>, std::tr1::ref(stack), s)),
- value_for<n::on_string>(std::tr1::bind(&license_handler<LicenseSpecTree>, std::tr1::ref(stack), _1)),
+ value_for<n::on_string>(std::tr1::bind(&license_handler<LicenseSpecTree>, std::tr1::ref(stack),
+ ParseStackTypes<LicenseSpecTree>::AnnotationsGoHere(std::tr1::bind(
+ &set_thing_to_annotate, std::tr1::ref(thing_to_annotate), _1)), _1)),
value_for<n::on_use>(std::tr1::bind(&use_handler<LicenseSpecTree>, std::tr1::ref(stack), _1, env, id)),
value_for<n::on_use_under_any>(std::tr1::bind(&use_under_any_handler, s, eapi))
));
@@ -402,24 +523,31 @@ paludis::erepository::parse_plain_text(const std::string & s,
using namespace std::tr1::placeholders;
ParseStackTypes<PlainTextSpecTree>::Stack stack;
+ std::tr1::shared_ptr<AllDepSpec> spec(new AllDepSpec);
+ std::tr1::shared_ptr<DepSpec> thing_to_annotate(spec);
std::tr1::shared_ptr<ConstTreeSequence<PlainTextSpecTree, AllDepSpec> > top(
- new ConstTreeSequence<PlainTextSpecTree, AllDepSpec>(make_shared_ptr(new AllDepSpec)));
+ new ConstTreeSequence<PlainTextSpecTree, AllDepSpec>(spec));
stack.push_front(make_named_values<ParseStackTypes<PlainTextSpecTree>::Item>(
value_for<n::add_handler>(std::tr1::bind(&ConstTreeSequence<PlainTextSpecTree, AllDepSpec>::add, top.get(), _1)),
- value_for<n::item>(top)
+ value_for<n::item>(top),
+ value_for<n::spec>(spec)
));
ELikeDepParserCallbacks callbacks(
make_named_values<ELikeDepParserCallbacks>(
value_for<n::on_all>(std::tr1::bind(&any_all_handler<PlainTextSpecTree, AllDepSpec>, std::tr1::ref(stack))),
- value_for<n::on_annotations>(&discard_annotations),
+ value_for<n::on_annotations>(std::tr1::bind(&set_annotations, std::tr1::ref(thing_to_annotate), _1)),
value_for<n::on_any>(std::tr1::bind(&any_not_allowed_handler, s)),
value_for<n::on_arrow>(std::tr1::bind(&arrows_not_allowed_handler, s, _1, _2)),
value_for<n::on_error>(std::tr1::bind(&error_handler, s, _1)),
value_for<n::on_label>(std::tr1::bind(&labels_not_allowed_handler, s, _1)),
- value_for<n::on_pop>(std::tr1::bind(&pop_handler<PlainTextSpecTree>, std::tr1::ref(stack), s)),
+ value_for<n::on_pop>(std::tr1::bind(&pop_handler<PlainTextSpecTree>, std::tr1::ref(stack),
+ ParseStackTypes<PlainTextSpecTree>::AnnotationsGoHere(std::tr1::bind(
+ &set_thing_to_annotate, std::tr1::ref(thing_to_annotate), _1)), s)),
value_for<n::on_should_be_empty>(std::tr1::bind(&should_be_empty_handler<PlainTextSpecTree>, std::tr1::ref(stack), s)),
- value_for<n::on_string>(std::tr1::bind(&plain_text_handler<PlainTextSpecTree>, std::tr1::ref(stack), _1)),
+ value_for<n::on_string>(std::tr1::bind(&plain_text_handler<PlainTextSpecTree>, std::tr1::ref(stack),
+ ParseStackTypes<PlainTextSpecTree>::AnnotationsGoHere(std::tr1::bind(
+ &set_thing_to_annotate, std::tr1::ref(thing_to_annotate), _1)), _1)),
value_for<n::on_use>(std::tr1::bind(&use_handler<PlainTextSpecTree>, std::tr1::ref(stack), _1, env, id)),
value_for<n::on_use_under_any>(&do_nothing)
));
@@ -515,3 +643,4 @@ paludis::erepository::parse_dependency_label(const std::string & s, const EAPI &
return l;
}
+
diff --git a/paludis/repositories/e/dep_parser_TEST.cc b/paludis/repositories/e/dep_parser_TEST.cc
index 5ff3560..6c7f168 100644
--- a/paludis/repositories/e/dep_parser_TEST.cc
+++ b/paludis/repositories/e/dep_parser_TEST.cc
@@ -431,5 +431,30 @@ namespace test_cases
&env, id, *EAPIData::get_instance()->eapi_from_string("kdebuild-1"))->accept(d), EDepParseError);
}
} test_dep_spec_parser_kdebuild_uri_labels;
+
+ struct AnnotationsTest : TestCase
+ {
+ AnnotationsTest() : TestCase("annotations") { }
+
+ void run()
+ {
+ TestEnvironment env;
+ std::tr1::shared_ptr<FakeRepository> repo(new FakeRepository(&env, RepositoryName("repo")));
+ env.package_database()->add_repository(1, repo);
+ std::tr1::shared_ptr<const PackageID> id(repo->add_version("cat", "pkg", "1"));
+
+ StringifyFormatter ff;
+ DepSpecPrettyPrinter d(0, std::tr1::shared_ptr<const PackageID>(), ff, 0, false);
+ parse_depend("cat/first [[ foo = bar bar = baz ]] cat/second cat/third [[ moo = oink ]]",
+ &env, id, *EAPIData::get_instance()->eapi_from_string("paludis-1"))->accept(d);
+ TEST_CHECK_EQUAL(stringify(d), "cat/first [[ bar = [ baz ] foo = [ bar ] ]] cat/second cat/third [[ moo = [ oink ] ]]");
+
+ DepSpecPrettyPrinter e(0, std::tr1::shared_ptr<const PackageID>(), ff, 0, false);
+ parse_depend("bar? ( foo? ( cat/first [[ for = first ]] ) [[ for = foo ]] baz? ( ) [[ for = baz ]] ) [[ for = bar ]]",
+ &env, id, *EAPIData::get_instance()->eapi_from_string("paludis-1"))->accept(e);
+ TEST_CHECK_EQUAL(stringify(e), "bar? ( foo? ( cat/first [[ for = [ first ] ]] ) "
+ "[[ for = [ foo ] ]] baz? ( ) [[ for = [ baz ] ]] ) [[ for = [ bar ] ]]");
+ }
+ } test_annotations;
}
diff --git a/paludis/repositories/e/dep_spec_pretty_printer.cc b/paludis/repositories/e/dep_spec_pretty_printer.cc
index 232de62..95b4b6a 100644
--- a/paludis/repositories/e/dep_spec_pretty_printer.cc
+++ b/paludis/repositories/e/dep_spec_pretty_printer.cc
@@ -23,9 +23,11 @@
#include <paludis/formatter.hh>
#include <paludis/util/save.hh>
#include <paludis/util/visitor-impl.hh>
+#include <paludis/util/visitor_cast.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/fs_entry.hh>
+#include <paludis/util/set.hh>
#include <paludis/environment.hh>
#include <paludis/selection.hh>
#include <paludis/generator.hh>
@@ -173,7 +175,7 @@ namespace
}
void
-DepSpecPrettyPrinter::visit_sequence(const AllDepSpec &,
+DepSpecPrettyPrinter::visit_sequence(const AllDepSpec & a,
GenericSpecTree::ConstSequenceIterator cur,
GenericSpecTree::ConstSequenceIterator end)
{
@@ -208,6 +210,9 @@ DepSpecPrettyPrinter::visit_sequence(const AllDepSpec &,
else if (_imp->need_space)
_imp->s << " ";
_imp->s << ")";
+
+ do_annotations(a);
+
if (_imp->use_newlines)
_imp->s << _imp->formatter.newline();
else
@@ -216,7 +221,7 @@ DepSpecPrettyPrinter::visit_sequence(const AllDepSpec &,
}
void
-DepSpecPrettyPrinter::visit_sequence(const AnyDepSpec &,
+DepSpecPrettyPrinter::visit_sequence(const AnyDepSpec & a,
GenericSpecTree::ConstSequenceIterator cur,
GenericSpecTree::ConstSequenceIterator end)
{
@@ -244,6 +249,9 @@ DepSpecPrettyPrinter::visit_sequence(const AnyDepSpec &,
else if (_imp->need_space)
_imp->s << " ";
_imp->s << ")";
+
+ do_annotations(a);
+
if (_imp->use_newlines)
_imp->s << _imp->formatter.newline();
else
@@ -284,6 +292,9 @@ DepSpecPrettyPrinter::visit_sequence(const ConditionalDepSpec & a,
else if (_imp->need_space)
_imp->s << " ";
_imp->s << ")";
+
+ do_annotations(a);
+
if (_imp->use_newlines)
_imp->s << _imp->formatter.newline();
else
@@ -312,6 +323,8 @@ DepSpecPrettyPrinter::visit_leaf(const PackageDepSpec & p)
else
_imp->s << _imp->formatter.format(p, format::Plain());
+ do_annotations(p);
+
if (_imp->use_newlines)
_imp->s << _imp->formatter.newline();
else
@@ -328,6 +341,8 @@ DepSpecPrettyPrinter::visit_leaf(const PlainTextDepSpec & p)
_imp->s << _imp->formatter.format(p, format::Plain());
+ do_annotations(p);
+
if (_imp->use_newlines)
_imp->s << _imp->formatter.newline();
else
@@ -344,6 +359,8 @@ DepSpecPrettyPrinter::visit_leaf(const NamedSetDepSpec & p)
_imp->s << _imp->formatter.format(p, format::Plain());
+ do_annotations(p);
+
if (_imp->use_newlines)
_imp->s << _imp->formatter.newline();
else
@@ -368,6 +385,8 @@ DepSpecPrettyPrinter::visit_leaf(const LicenseDepSpec & p)
else
_imp->s << _imp->formatter.format(p, format::Plain());
+ do_annotations(p);
+
if (_imp->use_newlines)
_imp->s << _imp->formatter.newline();
else
@@ -384,6 +403,8 @@ DepSpecPrettyPrinter::visit_leaf(const FetchableURIDepSpec & p)
_imp->s << _imp->formatter.format(p, format::Plain());
+ do_annotations(p);
+
if (_imp->use_newlines)
_imp->s << _imp->formatter.newline();
else
@@ -400,6 +421,8 @@ DepSpecPrettyPrinter::visit_leaf(const SimpleURIDepSpec & p)
_imp->s << _imp->formatter.format(p, format::Plain());
+ do_annotations(p);
+
if (_imp->use_newlines)
_imp->s << _imp->formatter.newline();
else
@@ -416,6 +439,8 @@ DepSpecPrettyPrinter::visit_leaf(const BlockDepSpec & b)
_imp->s << _imp->formatter.format(b, format::Plain());
+ do_annotations(b);
+
if (_imp->use_newlines)
_imp->s << _imp->formatter.newline();
else
@@ -438,6 +463,8 @@ DepSpecPrettyPrinter::visit_leaf(const URILabelsDepSpec & l)
_imp->s << _imp->formatter.format(l, format::Plain());
+ do_annotations(l);
+
if (_imp->use_newlines)
_imp->s << _imp->formatter.newline();
else
@@ -466,6 +493,8 @@ DepSpecPrettyPrinter::visit_leaf(const DependencyLabelsDepSpec & l)
_imp->s << _imp->formatter.format(l, format::Plain());
+ do_annotations(l);
+
if (_imp->use_newlines)
_imp->s << _imp->formatter.newline();
else
@@ -478,3 +507,21 @@ DepSpecPrettyPrinter::visit_leaf(const DependencyLabelsDepSpec & l)
}
}
+void
+DepSpecPrettyPrinter::do_annotations(const DepSpec & p)
+{
+ if (p.annotations_key() && (p.annotations_key()->begin_metadata() != p.annotations_key()->end_metadata()))
+ {
+ _imp->s << " [[ ";
+ for (MetadataSectionKey::MetadataConstIterator k(p.annotations_key()->begin_metadata()), k_end(p.annotations_key()->end_metadata()) ;
+ k != k_end ; ++k)
+ {
+ const MetadataValueKey<std::string> * r(visitor_cast<const MetadataValueKey<std::string> >(**k));
+ if (! r)
+ throw InternalError(PALUDIS_HERE, "annotations must be string keys");
+ _imp->s << (*k)->raw_name() << " = [" << (r->value().empty() ? " " : " " + r->value() + " ") << "] ";
+ }
+ _imp->s << "]]";
+ }
+}
+
diff --git a/paludis/repositories/e/dep_spec_pretty_printer.hh b/paludis/repositories/e/dep_spec_pretty_printer.hh
index a75117d..cb73c50 100644
--- a/paludis/repositories/e/dep_spec_pretty_printer.hh
+++ b/paludis/repositories/e/dep_spec_pretty_printer.hh
@@ -48,6 +48,9 @@ namespace paludis
{
friend std::ostream & operator<< (std::ostream &, const DepSpecPrettyPrinter &);
+ private:
+ void do_annotations(const DepSpec &);
+
public:
///\name Basic operations
///\{