[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the qt3to4 porting application of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 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 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "rpptreewalker.h"
|
---|
| 43 |
|
---|
| 44 | QT_BEGIN_NAMESPACE
|
---|
| 45 |
|
---|
| 46 | namespace Rpp {
|
---|
| 47 |
|
---|
| 48 | void 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 |
|
---|
| 62 | void 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 |
|
---|
| 71 | void RppTreeWalker::evaluateSource(const Source *source)
|
---|
| 72 | {
|
---|
| 73 | evaluateItemComposite(source->toItemComposite());
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | void 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 | */
|
---|
| 106 | void RppTreeWalker::evaluateIfSection(const IfSection *ifSection)
|
---|
| 107 | {
|
---|
| 108 | if (!ifSection)
|
---|
| 109 | return;
|
---|
| 110 | evaluateItemComposite(ifSection->toItemComposite());
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | void 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 |
|
---|
| 129 | void RppTreeWalker::evaluateIfdefDirective(const IfdefDirective *directive)
|
---|
| 130 | {
|
---|
| 131 | if (!directive)
|
---|
| 132 | return;
|
---|
| 133 | evaluateItemComposite(directive->toItemComposite());
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | void RppTreeWalker::evaluateIfndefDirective(const IfndefDirective *directive)
|
---|
| 137 | {
|
---|
| 138 | if (!directive)
|
---|
| 139 | return;
|
---|
| 140 | evaluateItemComposite(directive->toItemComposite());
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | void RppTreeWalker::evaluateIfDirective(const IfDirective *directive)
|
---|
| 144 | {
|
---|
| 145 | if (!directive)
|
---|
| 146 | return;
|
---|
| 147 | evaluateItemComposite(directive->toItemComposite());
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | void RppTreeWalker::evaluateElifDirective(const ElifDirective *directive)
|
---|
| 151 | {
|
---|
| 152 | if (!directive)
|
---|
| 153 | return;
|
---|
| 154 | evaluateItemComposite(directive->toItemComposite());
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | void RppTreeWalker::evaluateElseDirective(const ElseDirective *directive)
|
---|
| 158 | {
|
---|
| 159 | if (!directive)
|
---|
| 160 | return;
|
---|
| 161 | evaluateItemComposite(directive->toItemComposite());
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | QT_END_NAMESPACE
|
---|