aboutsummaryrefslogtreecommitdiff
path: root/paludis/dep_list/range_rewriter.cc
blob: 00a4a330cdaac10f8e1b7c6d7ade71a01077a473 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
 *
 * 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 "range_rewriter.hh"
#include <paludis/util/sequence.hh>
#include <libwrapiter/libwrapiter_forward_iterator.hh>
#include <libwrapiter/libwrapiter_output_iterator.hh>

using namespace paludis;

RangeRewriter::RangeRewriter() :
    _invalid(false)
{
}

RangeRewriter::~RangeRewriter()
{
}

void
RangeRewriter::visit_sequence(const AllDepSpec &,
        DependencySpecTree::ConstSequenceIterator cur,
        DependencySpecTree::ConstSequenceIterator end)
{
    if (cur != end)
        _invalid = true;
}

void
RangeRewriter::visit_sequence(const AnyDepSpec &,
        DependencySpecTree::ConstSequenceIterator cur,
        DependencySpecTree::ConstSequenceIterator end)
{
    if (cur != end)
        _invalid = true;
}

void
RangeRewriter::visit_sequence(const UseDepSpec &,
        DependencySpecTree::ConstSequenceIterator,
        DependencySpecTree::ConstSequenceIterator)
{
    _invalid = true;
}

void
RangeRewriter::visit_leaf(const PackageDepSpec & a)
{
    if (_invalid)
        return;

    if (a.use_requirements_ptr() || a.slot_ptr() || a.use_requirements_ptr() || ! a.version_requirements_ptr())
    {
        _invalid = true;
        return;
    }

    if (a.version_requirements_mode() != vr_or && 1 != std::distance(a.version_requirements_ptr()->begin(),
                a.version_requirements_ptr()->end()))
    {
        _invalid = true;
        return;
    }

    if (_spec)
    {
        if ((! a.package_ptr()) || (! _spec->package_ptr()) || (*a.package_ptr() != *_spec->package_ptr()))
        {
            _invalid = true;
            return;
        }

        for (VersionRequirements::Iterator v(a.version_requirements_ptr()->begin()),
                v_end(a.version_requirements_ptr()->end()) ; v != v_end ; ++v)
            _spec->version_requirements_ptr()->push_back(*v);
    }
    else
    {
        _spec.reset(new PackageDepSpec(a));
        _spec->set_version_requirements_mode(vr_or);
    }
}

void
RangeRewriter::visit_leaf(const BlockDepSpec &)
{
    _invalid = true;
}

void
RangeRewriter::visit_leaf(const DependencyLabelDepSpec &)
{
    _invalid = true;
}