File indexing completed on 2024-04-28 15:54:22

0001 /* This file is part of kdev-pg-qt
0002    Copyright (C) 2010 Jonathan Schmidt-Dominé <devel@the-user.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KDEV_PG_BNF_VISITOR_H
0021 #define KDEV_PG_BNF_VISITOR_H
0022 
0023 #include "kdev-pg-default-visitor.h"
0024 
0025 #include "kdev-pg.h"
0026 
0027 #include <QHash>
0028 
0029 namespace KDevPG
0030 {
0031 
0032 class BnfVisitor : public DefaultVisitor
0033 {
0034 public:
0035   static bool isInternal(Model::Node* item);
0036 private:
0037   static KDevPG::Allocator<char> localMemoryPool;
0038   
0039   static QHash<Model::OperatorItem*, Model::Node*> mOpStuff;
0040   static QHash<Model::StarItem*, Model::Node*> mStarStuff;
0041   static QHash<Model::PlusItem*, Model::Node*> mPlusStuff;
0042   
0043   template <class _Tp>
0044   inline _Tp *localCreateNode();
0045   
0046   template <class _Tp>
0047   inline _Tp *createArray(qint64 size);
0048   
0049   template <class _Tp>
0050   inline _Tp * getSubArray(void *mem, qint64 s);
0051     
0052 protected:
0053   void visitInlinedNonTerminal(Model::InlinedNonTerminalItem *node) override;
0054   void visitNonTerminal(Model::NonTerminalItem *node) override;
0055   void visitPlus(Model::PlusItem *node) override;
0056   void visitStar(Model::StarItem *node) override;
0057   void visitOperator(Model::OperatorItem *node) override;
0058   void visitTryCatch(Model::TryCatchItem *node) override;
0059   void visitAnnotation(Model::AnnotationItem *node) override;
0060   void visitCondition(Model::ConditionItem *node) override;
0061   void visitEvolve(Model::EvolveItem *node) override;
0062   void visitAction(Model::ActionItem *node) override;
0063 
0064   /// Should be reimplemented by first- and follow-set-generators
0065   virtual void copy(Model::Node *from, Model::Node *to)
0066   {
0067     Q_UNUSED(from);
0068     Q_UNUSED(to);
0069   }
0070   virtual void preCopy(Model::Node *from, Model::Node *to)
0071   {
0072     Q_UNUSED(from);
0073     Q_UNUSED(to);
0074   }
0075   
0076   virtual void finished();
0077   ~BnfVisitor() override
0078   {
0079     finished();
0080   }
0081 };
0082 
0083 }
0084 
0085 #endif