source: trunk/tools/porting/src/rpptreewalker.cpp@ 497

Last change on this file since 497 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 5.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the qt3to4 porting application of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "rpptreewalker.h"
43
44QT_BEGIN_NAMESPACE
45
46namespace Rpp {
47
48void RppTreeWalker::evaluateItem(const Item *item)
49{
50 if(!item)
51 return;
52 if (Source *source = item->toSource())
53 evaluateSource(source);
54 else if (Directive *directive = item->toDirective())
55 evaluateDirective(directive);
56 else if (IfSection *ifSection = item->toIfSection())
57 evaluateIfSection(ifSection);
58 else if (Text *text = item->toText())
59 evaluateText(text);
60}
61
62void RppTreeWalker::evaluateItemComposite(const ItemComposite *itemComposite)
63{
64 if (!itemComposite)
65 return;
66 for (int i = 0; i < itemComposite->count(); ++i) {
67 evaluateItem(itemComposite->item(i));
68 }
69}
70
71void RppTreeWalker::evaluateSource(const Source *source)
72{
73 evaluateItemComposite(source->toItemComposite());
74}
75
76void RppTreeWalker::evaluateDirective(const Directive *directive)
77{
78 if (!directive)
79 return;
80 if (EmptyDirective *dir = directive->toEmptyDirective())
81 evaluateEmptyDirective(dir);
82 else if (ErrorDirective *dir = directive->toErrorDirective())
83 evaluateErrorDirective(dir);
84 else if (PragmaDirective *dir = directive->toPragmaDirective())
85 evaluatePragmaDirective(dir);
86 else if (IncludeDirective *dir = directive->toIncludeDirective())
87 evaluateIncludeDirective(dir);
88 else if (DefineDirective *dir = directive->toDefineDirective())
89 evaluateDefineDirective(dir);
90 else if (UndefDirective *dir = directive->toUndefDirective())
91 evaluateUndefDirective(dir);
92 else if (LineDirective *dir = directive->toLineDirective())
93 evaluateLineDirective(dir);
94 else if (NonDirective *dir = directive->toNonDirective())
95 evaluateNonDirective(dir);
96 else if (NonDirective *dir = directive->toNonDirective())
97 evaluateNonDirective(dir);
98 else if (ConditionalDirective *dir = directive->toConditionalDirective())
99 evaluateConditionalDirective(dir);
100}
101
102/*
103 This function evaluates all the branches of an IfSection. You should
104 override it if you want to only evaluate the "correct" branch.
105*/
106void RppTreeWalker::evaluateIfSection(const IfSection *ifSection)
107{
108 if (!ifSection)
109 return;
110 evaluateItemComposite(ifSection->toItemComposite());
111}
112
113void RppTreeWalker::evaluateConditionalDirective(const ConditionalDirective *conditionalDirective)
114{
115 if (!conditionalDirective)
116 return;
117 if (IfdefDirective *dir = conditionalDirective->toIfdefDirective())
118 evaluateIfdefDirective(dir);
119 else if (IfndefDirective *dir = conditionalDirective->toIfndefDirective())
120 evaluateIfndefDirective(dir);
121 else if (IfDirective *dir = conditionalDirective->toIfDirective())
122 evaluateIfDirective(dir);
123 else if (ElifDirective *dir = conditionalDirective->toElifDirective())
124 evaluateElifDirective(dir);
125 else if (ElseDirective *dir = conditionalDirective->toElseDirective())
126 evaluateElseDirective(dir);
127}
128
129void RppTreeWalker::evaluateIfdefDirective(const IfdefDirective *directive)
130{
131 if (!directive)
132 return;
133 evaluateItemComposite(directive->toItemComposite());
134}
135
136void RppTreeWalker::evaluateIfndefDirective(const IfndefDirective *directive)
137{
138 if (!directive)
139 return;
140 evaluateItemComposite(directive->toItemComposite());
141}
142
143void RppTreeWalker::evaluateIfDirective(const IfDirective *directive)
144{
145 if (!directive)
146 return;
147 evaluateItemComposite(directive->toItemComposite());
148}
149
150void RppTreeWalker::evaluateElifDirective(const ElifDirective *directive)
151{
152 if (!directive)
153 return;
154 evaluateItemComposite(directive->toItemComposite());
155}
156
157void RppTreeWalker::evaluateElseDirective(const ElseDirective *directive)
158{
159 if (!directive)
160 return;
161 evaluateItemComposite(directive->toItemComposite());
162}
163
164}
165
166QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.