File indexing completed on 2024-04-14 04:31:33

0001 /* This file is part of kdev-pg-qt
0002    Copyright (C) 2005 Roberto Raggi <roberto@kdevelop.org>
0003    Copyright (C) 2006 Jakob Petsovits <jpetso@gmx.at>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #include "kdev-pg-clone-tree.h"
0022 #include "kdev-pg.h"
0023 
0024 namespace KDevPG
0025 {
0026 
0027 void CloneTree::visitZero(Model::ZeroItem *node)
0028 {
0029   mTemps.push(node);
0030 }
0031 
0032 void CloneTree::visitSymbol(Model::SymbolItem *node)
0033 {
0034   mTemps.push(node);
0035 }
0036 
0037 void CloneTree::visitTerminal(Model::TerminalItem *node)
0038 {
0039   mTemps.push(node);
0040 }
0041 
0042 void CloneTree::visitNonTerminal(Model::NonTerminalItem *node)
0043 {
0044   mTemps.push(KDevPG::nonTerminal(node->mSymbol, node->mArguments));
0045 }
0046 
0047 void CloneTree::visitInlinedNonTerminal(Model::InlinedNonTerminalItem* node)
0048 {
0049   mTemps.push(KDevPG::inlinedNonTerminal(node->mSymbol));
0050 }
0051 
0052 void CloneTree::visitPlus(Model::PlusItem *node)
0053 {
0054   visitNode(node->mItem);
0055 
0056   Model::Node *item = mTemps.top();
0057   mTemps.pop();
0058 
0059   mTemps.push(KDevPG::plus(item));
0060 }
0061 
0062 void CloneTree::visitStar(Model::StarItem *node)
0063 {
0064   visitNode(node->mItem);
0065 
0066   Model::Node *item = mTemps.top();
0067   mTemps.pop();
0068 
0069   mTemps.push(KDevPG::star(item));
0070 }
0071 
0072 void CloneTree::visitAction(Model::ActionItem *node)
0073 {
0074   visitNode(node->mItem);
0075 
0076   Model::Node *item = mTemps.top();
0077   mTemps.pop();
0078 
0079   mTemps.push(KDevPG::action(item, node->mCode));
0080 }
0081 
0082 void CloneTree::visitAlternative(Model::AlternativeItem *node)
0083 {
0084   visitNode(node->mLeft);
0085 
0086   Model::Node *left = mTemps.top();
0087   mTemps.pop();
0088 
0089   visitNode(node->mRight);
0090 
0091   Model::Node *right = mTemps.top();
0092   mTemps.pop();
0093 
0094   mTemps.push(KDevPG::alternative(left, right));
0095 }
0096 
0097 void CloneTree::visitCons(Model::ConsItem *node)
0098 {
0099   visitNode(node->mLeft);
0100 
0101   Model::Node *left = mTemps.top();
0102   mTemps.pop();
0103 
0104   visitNode(node->mRight);
0105 
0106   Model::Node *right = mTemps.top();
0107   mTemps.pop();
0108 
0109   mTemps.push(KDevPG::cons(left, right));
0110 }
0111 
0112 void CloneTree::visitEvolve(Model::EvolveItem *node)
0113 {
0114   visitNode(node->mItem);
0115 
0116   Model::Node *item = mTemps.top();
0117   mTemps.pop();
0118 
0119   mTemps.push(KDevPG::evolve(item, node->mSymbol, node->mDeclarations, node->mCode));
0120 }
0121 
0122 void CloneTree::visitTryCatch(Model::TryCatchItem *node)
0123 {
0124   visitNode(node->mTryItem);
0125 
0126   Model::Node *try_item = mTemps.top();
0127   mTemps.pop();
0128 
0129   Model::Node *catch_item = nullptr;
0130 
0131   if (node->mCatchItem)
0132     {
0133       visitNode(node->mCatchItem);
0134 
0135       catch_item = mTemps.top();
0136       mTemps.pop();
0137     }
0138 
0139   mTemps.push(KDevPG::tryCatch(try_item, catch_item));
0140 }
0141 
0142 void CloneTree::visitAlias(Model::AliasItem *node)
0143 {
0144   Q_UNUSED(node);
0145   Q_ASSERT(0); // ### not implemented yet
0146 }
0147 
0148 void CloneTree::visitAnnotation(Model::AnnotationItem *node)
0149 {
0150   visitNode(node->mItem);
0151 
0152   Model::Node *item = mTemps.top();
0153   mTemps.pop();
0154 
0155   mTemps.push(KDevPG::annotation(node->mDeclaration->mName, item,
0156                                node->mDeclaration->mIsSequence,
0157                                node->mDeclaration->mStorageType));
0158 }
0159 
0160 void CloneTree::visitOperator(Model::OperatorItem *node)
0161 {
0162   // Should not be relevant if it gets really copied
0163   mTemps.push(node);
0164 }
0165 
0166 Model::Node *CloneTree::clone(Model::Node *node)
0167 {
0168   mTemps = QStack<Model::Node*>();
0169   visitNode(node);
0170   Model::Node *n = mTemps.top();
0171   mTemps.pop();
0172   Q_ASSERT(mTemps.empty());
0173   return n;
0174 }
0175 
0176 }