File indexing completed on 2024-04-28 15:54:30
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 Copyright (C) 2010 Jonathan Schmidt-Dominé <devel@the-user.org> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Library General Public 0008 License as published by the Free Software Foundation; either 0009 version 2 of the License, or (at your option) any later version. 0010 0011 This library is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 Library General Public License for more details. 0015 0016 You should have received a copy of the GNU Library General Public License 0017 along with this library; see the file COPYING.LIB. If not, write to 0018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #include "kdev-pg-visitor-bits-gen.h" 0023 #include "kdev-pg.h" 0024 #include <map> 0025 #include <iostream> 0026 0027 0028 namespace KDevPG 0029 { 0030 0031 void GenerateVisitorBits::operator()() 0032 { 0033 QMap<QString, Model::SymbolItem*>::iterator it = globalSystem.symbols.begin(); 0034 0035 if (globalSystem.visitorTable) 0036 { 0037 out << "Visitor::ParserFuncType Visitor::sParserTable[] = {" << endl; 0038 0039 while (it != globalSystem.symbols.end()) 0040 { 0041 Model::SymbolItem *sym = *it++; 0042 0043 #define O(str) \ 0044 out << "reinterpret_cast<ParserFuncType>(&Visitor::visit" << str << ")"; 0045 0046 if(isOperatorSymbol(sym)) 0047 { 0048 O("Prefix" + sym->mCapitalizedName) 0049 out << ",\n"; 0050 O("Postfix" + sym->mCapitalizedName) 0051 out << ",\n"; 0052 O("Binary" + sym->mCapitalizedName) 0053 out << ",\n"; 0054 O("Ternary" + sym->mCapitalizedName) 0055 out << ",\n0"; 0056 } 0057 else 0058 O(sym->mCapitalizedName) 0059 0060 if (it != globalSystem.symbols.end()) 0061 out << ","; 0062 0063 out << endl; 0064 0065 #undef O 0066 } 0067 0068 out << "}; // sParserTable[]" << endl; 0069 0070 out << "void Visitor::visitNode(AstNode *node) { " 0071 << "if (node) (this->*sParserTable[node->kind - 1000])(node); " 0072 << "}" << endl; 0073 } 0074 else 0075 { 0076 out << "void Visitor::visitNode(AstNode *node) { if(node) {" 0077 "switch(node->kind) {"; 0078 while (it != globalSystem.symbols.end()) 0079 { 0080 Model::SymbolItem *sym = *it++; 0081 0082 #define O(str) \ 0083 out << "case AstNode::" << str << "Kind:\n" \ 0084 "visit" << str << "(reinterpret_cast<" << str << "Ast*>(node)); break;"; 0085 0086 if(isOperatorSymbol(sym)) 0087 { 0088 O("Prefix" + sym->mCapitalizedName) 0089 O("Postfix" + sym->mCapitalizedName) 0090 O("Binary" + sym->mCapitalizedName) 0091 O("Ternary" + sym->mCapitalizedName) 0092 } 0093 else 0094 O(sym->mCapitalizedName) 0095 0096 #undef O 0097 } 0098 0099 out << "default: Q_ASSERT(false); } } }" 0100 << endl; 0101 } 0102 } 0103 0104 } 0105