1/*
2 * Copyright (c) 2015, Intel Corporation
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * * Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Intel Corporation nor the names of its contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** \file
30 * \brief Atomic groups (?>...)
31 */
32#include "ComponentAtomicGroup.h"
33#include "buildstate.h"
34#include "position.h"
35
36#include <algorithm>
37
38using namespace std;
39
40namespace ue2 {
41
42ComponentAtomicGroup *ComponentAtomicGroup::clone() const {
43 return new ComponentAtomicGroup(*this);
44}
45
46Component *ComponentAtomicGroup::accept(ComponentVisitor &v) {
47 Component *c = v.visit(this);
48 if (c != this) {
49 v.post(this);
50 return c;
51 }
52
53 for (auto i = children.begin(), e = children.end(); i != e; ++i) {
54 Component *child = i->get();
55 c = (*i)->accept(v);
56 if (c != child) {
57 // Child has been replaced (new Component pointer) or we've been
58 // instructed to delete it (null).
59 i->reset(c);
60 }
61 }
62
63 // Remove deleted children.
64 children.erase(remove(children.begin(), children.end(), nullptr),
65 children.end());
66
67 v.post(this);
68 return this;
69}
70
71void ComponentAtomicGroup::accept(ConstComponentVisitor &v) const {
72 v.pre(*this);
73 for (auto i = children.begin(), e = children.end(); i != e; ++i) {
74 (*i)->accept(v);
75 if (i + 1 != e) {
76 v.during(*this);
77 }
78 }
79
80 v.post(*this);
81}
82
83void ComponentAtomicGroup::notePositions(GlushkovBuildState &) {
84 assert(0);
85}
86
87void ComponentAtomicGroup::buildFollowSet(GlushkovBuildState &,
88 const vector<PositionInfo> &) {
89 assert(0);
90}
91
92} // namespace
93