• Classes
  • Modules
  • Namespaces
  • Files
  • Related Pages
  • File List
  • File Members

MyAST.h

Go to the documentation of this file.
00001 #ifndef __MY_AST_H__
00002 # define __MY_AST_H__
00003 
00004 #include <antlr/CommonAST.hpp>
00005 
00006 class MyAST;
00007 
00008 typedef ANTLR_USE_NAMESPACE(antlr)ASTRefCount<MyAST> RefMyAST;
00009 
00015 class MyAST : public ANTLR_USE_NAMESPACE(antlr)CommonAST {
00016 public:
00017    // copy constructor
00018    MyAST( const MyAST& other )
00019         : CommonAST(other)
00020         , line(other.line)
00021         {
00022         }
00023    // Default constructor
00024    MyAST( void ) : CommonAST(), line(0) {}
00025    virtual ~MyAST( void ) {}
00026    // get the line number of the node (or try to derive it from the child node
00027    virtual int getLine( void ) const
00028    {
00029       // most of the time the line number is not set if the node is a
00030       // imaginary one. Usually this means it has a child. Refer to the
00031       // child line number. Of course this could be extended a bit.
00032       // based on an example by Peter Morling.
00033       if ( line != 0 )
00034          return line;
00035       if( getFirstChild() )
00036          return ( RefMyAST(getFirstChild())->getLine() );
00037       return 0;
00038    }
00039    virtual void setLine( int l )
00040    {
00041       line = l;
00042    }
00048    virtual void initialize(int t, const ANTLR_USE_NAMESPACE(std)string& txt)
00049    {
00050       CommonAST::initialize(t,txt);
00051       line = 0;
00052    }
00053    virtual void initialize( ANTLR_USE_NAMESPACE(antlr)RefToken t )
00054    {
00055       CommonAST::initialize(t);
00056       line = t->getLine();
00057    }
00058    virtual void initialize( RefMyAST ast )
00059    {
00060       CommonAST::initialize(ANTLR_USE_NAMESPACE(antlr)RefAST(ast));
00061       line = ast->getLine();
00062    }
00063    // for convenience will also work without
00064    void addChild( RefMyAST c )
00065    {
00066       BaseAST::addChild( ANTLR_USE_NAMESPACE(antlr)RefAST(c) );
00067    }
00068    // for convenience will also work without
00069    void setNextSibling( RefMyAST c )
00070    {
00071       BaseAST::setNextSibling( ANTLR_USE_NAMESPACE(antlr)RefAST(c) );
00072    }
00073    // provide a clone of the node (no sibling/child pointers are copied)
00074    virtual ANTLR_USE_NAMESPACE(antlr)RefAST clone( void )
00075    {
00076       return ANTLR_USE_NAMESPACE(antlr)RefAST(new MyAST(*this));
00077    }
00078    static ANTLR_USE_NAMESPACE(antlr)RefAST factory( void )
00079    {
00080       return ANTLR_USE_NAMESPACE(antlr)RefAST(RefMyAST(new MyAST()));
00081    }
00082 private:
00083    int line;
00084 };
00085 #endif

Generated on Thu Jan 12 2012 23:13:51 for ACS-10.0 C++ API by  doxygen 1.7.0