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

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) 2006 Alexander Dymo <adymo@kdevelop.org>
0005    Copyright (C) 2010 Jonathan Schmidt-Dominé <devel@the-user.org>
0006 
0007    This library is free software; you can redistribute it and/or
0008    modify it under the terms of the GNU Library General Public
0009    License as published by the Free Software Foundation; either
0010    version 2 of the License, or (at your option) any later version.
0011 
0012    This library is distributed in the hope that it will be useful,
0013    but WITHOUT ANY WARRANTY; without even the implied warranty of
0014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015    Library General Public License for more details.
0016 
0017    You should have received a copy of the GNU Library General Public License
0018    along with this library; see the file COPYING.LIB.  If not, write to
0019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020    Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #ifndef KDEV_PG_FOLLOW_H
0024 #define KDEV_PG_FOLLOW_H
0025 
0026 #include "kdev-pg.h"
0027 #include "kdev-pg-bnf-visitor.h"
0028 
0029 
0030 
0031 namespace KDevPG
0032 {
0033 
0034 class InitializeFollow: protected DefaultVisitor
0035 {
0036 public:
0037   void operator()(Model::Node *node);
0038 protected:
0039   void visitSymbol(Model::SymbolItem *node) override;
0040 };
0041 
0042 class NextFollow: protected BnfVisitor
0043 {
0044 public:
0045   NextFollow(bool &changed);
0046 
0047   void operator()(Model::Node *node);
0048 
0049 protected:
0050   void merge(Model::Node *__dest, World::NodeSet const &source);
0051   /**adds dependency between rule @p dep whose FIRST set is added to
0052   @p dest FOLLOW set*/
0053   void addFirstToFollowDep(Model::Node *dest, Model::Node *dep);
0054   /**adds dependency between rule @p dep whose FOLLOW set is added to
0055   @p dest FOLLOW set*/
0056   void addFollowToFollowDep(Model::Node *dest, Model::Node *dep);
0057 
0058   void visitNode(Model::Node *node) override;
0059   void visitAlternative(Model::AlternativeItem *node) override;
0060   void visitCons(Model::ConsItem *node) override;
0061   
0062   void preCopy(Model::Node *from, Model::Node *to) override;
0063   void copy(Model::Node *from, Model::Node *to) override;
0064 
0065 private:
0066   bool &mChanged;
0067   Model::SymbolItem *mSymbol;
0068   QSet<Model::Node*> mVisited;
0069 };
0070 
0071 void computeFollow();
0072 
0073 }
0074 
0075 #endif // KDEV_PG_FOLLOW_H