00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 2004-2006 Trolltech ASA. All rights reserved. 00004 ** 00005 ** This file is part of the qt3to4 porting application of the Qt Toolkit. 00006 ** 00007 ** This file may be used under the terms of the GNU General Public 00008 ** License version 2.0 as published by the Free Software Foundation 00009 ** and appearing in the file LICENSE.GPL included in the packaging of 00010 ** this file. Please review the following information to ensure GNU 00011 ** General Public Licensing requirements will be met: 00012 ** http://www.trolltech.com/products/qt/opensource.html 00013 ** 00014 ** If you are unsure which license is appropriate for your use, please 00015 ** review the following information: 00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the 00017 ** sales department at sales@trolltech.com. 00018 ** 00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00021 ** 00022 ****************************************************************************/ 00023 00024 #include "rpptreewalker.h" 00025 00026 namespace Rpp { 00027 00028 void RppTreeWalker::evaluateItem(const Item *item) 00029 { 00030 if(!item) 00031 return; 00032 if (Source *source = item->toSource()) 00033 evaluateSource(source); 00034 else if (Directive *directive = item->toDirective()) 00035 evaluateDirective(directive); 00036 else if (IfSection *ifSection = item->toIfSection()) 00037 evaluateIfSection(ifSection); 00038 else if (Text *text = item->toText()) 00039 evaluateText(text); 00040 } 00041 00042 void RppTreeWalker::evaluateItemComposite(const ItemComposite *itemComposite) 00043 { 00044 if (!itemComposite) 00045 return; 00046 for (int i = 0; i < itemComposite->count(); ++i) { 00047 evaluateItem(itemComposite->item(i)); 00048 } 00049 } 00050 00051 void RppTreeWalker::evaluateSource(const Source *source) 00052 { 00053 evaluateItemComposite(source->toItemComposite()); 00054 } 00055 00056 void RppTreeWalker::evaluateDirective(const Directive *directive) 00057 { 00058 if (!directive) 00059 return; 00060 if (EmptyDirective *dir = directive->toEmptyDirective()) 00061 evaluateEmptyDirective(dir); 00062 else if (ErrorDirective *dir = directive->toErrorDirective()) 00063 evaluateErrorDirective(dir); 00064 else if (PragmaDirective *dir = directive->toPragmaDirective()) 00065 evaluatePragmaDirective(dir); 00066 else if (IncludeDirective *dir = directive->toIncludeDirective()) 00067 evaluateIncludeDirective(dir); 00068 else if (DefineDirective *dir = directive->toDefineDirective()) 00069 evaluateDefineDirective(dir); 00070 else if (UndefDirective *dir = directive->toUndefDirective()) 00071 evaluateUndefDirective(dir); 00072 else if (LineDirective *dir = directive->toLineDirective()) 00073 evaluateLineDirective(dir); 00074 else if (NonDirective *dir = directive->toNonDirective()) 00075 evaluateNonDirective(dir); 00076 else if (NonDirective *dir = directive->toNonDirective()) 00077 evaluateNonDirective(dir); 00078 else if (ConditionalDirective *dir = directive->toConditionalDirective()) 00079 evaluateConditionalDirective(dir); 00080 } 00081 00082 /* 00083 This function evaluates all the branches of an IfSection. You should 00084 override it if you want to only evaluate the "correct" branch. 00085 */ 00086 void RppTreeWalker::evaluateIfSection(const IfSection *ifSection) 00087 { 00088 if (!ifSection) 00089 return; 00090 evaluateItemComposite(ifSection->toItemComposite()); 00091 } 00092 00093 void RppTreeWalker::evaluateConditionalDirective(const ConditionalDirective *conditionalDirective) 00094 { 00095 if (!conditionalDirective) 00096 return; 00097 if (IfdefDirective *dir = conditionalDirective->toIfdefDirective()) 00098 evaluateIfdefDirective(dir); 00099 else if (IfndefDirective *dir = conditionalDirective->toIfndefDirective()) 00100 evaluateIfndefDirective(dir); 00101 else if (IfDirective *dir = conditionalDirective->toIfDirective()) 00102 evaluateIfDirective(dir); 00103 else if (ElifDirective *dir = conditionalDirective->toElifDirective()) 00104 evaluateElifDirective(dir); 00105 else if (ElseDirective *dir = conditionalDirective->toElseDirective()) 00106 evaluateElseDirective(dir); 00107 } 00108 00109 void RppTreeWalker::evaluateIfdefDirective(const IfdefDirective *directive) 00110 { 00111 if (!directive) 00112 return; 00113 evaluateItemComposite(directive->toItemComposite()); 00114 } 00115 00116 void RppTreeWalker::evaluateIfndefDirective(const IfndefDirective *directive) 00117 { 00118 if (!directive) 00119 return; 00120 evaluateItemComposite(directive->toItemComposite()); 00121 } 00122 00123 void RppTreeWalker::evaluateIfDirective(const IfDirective *directive) 00124 { 00125 if (!directive) 00126 return; 00127 evaluateItemComposite(directive->toItemComposite()); 00128 } 00129 00130 void RppTreeWalker::evaluateElifDirective(const ElifDirective *directive) 00131 { 00132 if (!directive) 00133 return; 00134 evaluateItemComposite(directive->toItemComposite()); 00135 } 00136 00137 void RppTreeWalker::evaluateElseDirective(const ElseDirective *directive) 00138 { 00139 if (!directive) 00140 return; 00141 evaluateItemComposite(directive->toItemComposite()); 00142 } 00143 00144 }
1.5.1