ShParser.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #ifndef SHPARSER_HPP
00021 #define SHPARSER_HPP
00022 
00023 #include <stack>
00024 #include "ShDllExport.hpp"
00025 #include "ShCtrlGraph.hpp"
00026 #include "ShToken.hpp"
00027 
00028 namespace SH {
00029 
00034 class
00035 SH_DLLEXPORT ShParser {
00036 public:
00038   static ShParser* instance();
00039 
00042   void parse(ShCtrlGraphNodePtr& head, ShCtrlGraphNodePtr& tail, ShBlockListPtr blocks);
00043   
00044 private:
00045   // This class is a singleton
00046   ShParser() {}
00047 
00048   void parseBlock(ShCtrlGraphNodePtr& head, ShCtrlGraphNodePtr& tail, ShBasicBlockPtr block);
00049   void parseStmts(ShCtrlGraphNodePtr& head, ShCtrlGraphNodePtr& tail, ShBlockListPtr blocks);
00050   void parseIf(ShCtrlGraphNodePtr& head, ShCtrlGraphNodePtr& tail, ShBlockListPtr blocks);
00051   void parseFor(ShCtrlGraphNodePtr& head, ShCtrlGraphNodePtr& tail, ShBlockListPtr blocks);
00052   void parseWhile(ShCtrlGraphNodePtr& head, ShCtrlGraphNodePtr& tail, ShBlockListPtr blocks);
00053   void parseDo(ShCtrlGraphNodePtr& head, ShCtrlGraphNodePtr& tail, ShBlockListPtr blocks);
00054   void parseSection(ShCtrlGraphNodePtr& head, ShCtrlGraphNodePtr& tail, ShBlockListPtr blocks);
00055   void parse_break(ShCtrlGraphNodePtr& head, ShCtrlGraphNodePtr& tail, ShBlockListPtr blocks);
00056   void parse_continue(ShCtrlGraphNodePtr& head, ShCtrlGraphNodePtr& tail, ShBlockListPtr blocks);
00057 
00059   ShTokenPtr popToken(ShBlockListPtr blocks);
00061   ShTokenPtr popToken(ShBlockListPtr blocks, ShTokenType expectedType, unsigned int expectedArgs=0);
00062 
00064   void push_scope(ShCtrlGraphNodePtr& break_node, ShCtrlGraphNodePtr& continue_node);
00066   void pop_scope();
00067 
00068   // Stacks that keep track of the current scope
00069   std::stack<ShCtrlGraphNodePtr> m_break_node;    // for SH_BREAK
00070   std::stack<ShCtrlGraphNodePtr> m_continue_node; // for SH_CONTINUE
00071 
00072   // NOT IMPLEMENTED
00073   ShParser(const ShParser&);
00074 };
00075  
00076 }
00077 
00078 #endif

Generated on Wed Nov 9 15:29:38 2005 for Sh by  doxygen 1.4.5