KDevelop API Documentation

ASTFactory.hpp

Go to the documentation of this file.
00001 #ifndef INC_ASTFactory_hpp__
00002 #define INC_ASTFactory_hpp__
00003 
00004 /* ANTLR Translator Generator
00005  * Project led by Terence Parr at http://www.jGuru.com
00006  * Software rights: http://www.antlr.org/RIGHTS.html
00007  *
00008  * $Id: ASTFactory.hpp,v 1.4 2003/11/17 00:52:24 aclu Exp $
00009  */
00010 
00011 #include <antlr/config.hpp>
00012 #include <antlr/AST.hpp>
00013 #include <antlr/ASTArray.hpp>
00014 #include <antlr/ASTPair.hpp>
00015 
00016 #include <utility>
00017 
00018 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00019 namespace antlr {
00020 #endif
00021 
00030 class ANTLR_API ASTFactory {
00031 public:
00032     typedef RefAST (*factory_type)();
00033     typedef ANTLR_USE_NAMESPACE(std)pair< const char*, factory_type > factory_descriptor;
00034     typedef ANTLR_USE_NAMESPACE(std)vector< factory_descriptor* > factory_descriptor_list;
00035 protected:
00036     /* The mapping of AST node type to factory..
00037      */
00038     factory_descriptor default_factory_descriptor;
00039     factory_descriptor_list nodeFactories;
00040 public:
00042     ASTFactory();
00048     ASTFactory( const char* factory_node_name, factory_type factory );
00050     virtual ~ASTFactory();
00051 
00053     void registerFactory( int type, const char* ast_name, factory_type factory );
00055     void setMaxNodeType( int type );
00056 
00058     void addASTChild(ASTPair& currentAST, RefAST child);
00060     virtual RefAST create();
00062     RefAST create(int type);
00064     RefAST create(int type, const ANTLR_USE_NAMESPACE(std)string& txt);
00066     RefAST create(RefAST tr);
00068     RefAST create(RefToken tok);
00070     RefAST create(const ANTLR_USE_NAMESPACE(std)string& txt, ANTLR_USE_NAMESPACE(std)istream& infile );
00074     RefAST dup(RefAST t);
00076     RefAST dupList(RefAST t);
00080     RefAST dupTree(RefAST t);
00087     RefAST make(ANTLR_USE_NAMESPACE(std)vector<RefAST>& nodes);
00092     RefAST make(ASTArray* nodes);
00094     void makeASTRoot(ASTPair& currentAST, RefAST root);
00095 
00103     void setASTNodeFactory( const char* factory_node_name, factory_type factory );
00104 
00105 #ifdef ANTLR_SUPPORT_XML
00110     RefAST LoadAST( ANTLR_USE_NAMESPACE(std)istream& infile );
00111 #endif
00112 protected:
00113     void loadChildren( ANTLR_USE_NAMESPACE(std)istream& infile, RefAST current );
00114     void loadSiblings( ANTLR_USE_NAMESPACE(std)istream& infile, RefAST current );
00115     bool checkCloseTag( ANTLR_USE_NAMESPACE(std)istream& infile );
00116 
00117 #ifdef ANTLR_VECTOR_HAS_AT
00119     inline RefAST getNodeOfType( unsigned int type )
00120     {
00121         return RefAST(nodeFactories.at(type)->second());
00122     }
00124     const char* getASTNodeType( unsigned int type )
00125     {
00126         return nodeFactories.at(type)->first;
00127     }
00129     factory_type getASTNodeFactory( unsigned int type )
00130     {
00131         return nodeFactories.at(type)->second;
00132     }
00133 #else
00134     inline RefAST getNodeOfType( unsigned int type )
00135     {
00136         return RefAST(nodeFactories[type]->second());
00137     }
00139     const char* getASTNodeType( unsigned int type )
00140     {
00141         return nodeFactories[type]->first;
00142     }
00143     factory_type getASTNodeFactory( unsigned int type )
00144     {
00145         return nodeFactories[type]->second;
00146     }
00147 #endif
00148 
00149 private:
00150     // no copying and such..
00151     ASTFactory( const ASTFactory& );
00152     ASTFactory& operator=( const ASTFactory& );
00153 };
00154 
00155 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00156 }
00157 #endif
00158 
00159 #endif //INC_ASTFactory_hpp__
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:34 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003