PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Dependencies/boo/lib/antlr-2.7.5/lib/cpp/antlr/AST.hpp

https://github.com/w4x/boolangstudio
C++ Header | 166 lines | 75 code | 28 blank | 63 comment | 2 complexity | 88f45e868c82509a09a2338676eed9cb MD5 | raw file
Possible License(s): GPL-2.0
  1. #ifndef INC_AST_hpp__
  2. #define INC_AST_hpp__
  3. /* ANTLR Translator Generator
  4. * Project led by Terence Parr at http://www.jGuru.com
  5. * Software rights: http://www.antlr.org/license.html
  6. *
  7. * $Id: //depot/code/org.antlr/release/antlr-2.7.5/lib/cpp/antlr/AST.hpp#1 $
  8. */
  9. #include <antlr/config.hpp>
  10. #include <antlr/ASTRefCount.hpp>
  11. #include <antlr/Token.hpp>
  12. #include <vector>
  13. #include <string>
  14. #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
  15. namespace antlr {
  16. #endif
  17. struct ASTRef;
  18. class ANTLR_API AST {
  19. public:
  20. AST() : ref(0) {}
  21. AST(const AST&) : ref(0) {}
  22. virtual ~AST() {}
  23. /// Return the type name for this AST node. (for XML output)
  24. virtual const char* typeName( void ) const = 0;
  25. /// Clone this AST node.
  26. virtual RefAST clone( void ) const = 0;
  27. /// Is node t equal to this in terms of token type and text?
  28. virtual bool equals(RefAST t) const = 0;
  29. /** Is t an exact structural and equals() match of this tree. The
  30. * 'this' reference is considered the start of a sibling list.
  31. */
  32. virtual bool equalsList(RefAST t) const = 0;
  33. /** Is 't' a subtree of this list? The siblings of the root are NOT ignored.
  34. */
  35. virtual bool equalsListPartial(RefAST t) const = 0;
  36. /** Is tree rooted at 'this' equal to 't'? The siblings of 'this' are
  37. * ignored.
  38. */
  39. virtual bool equalsTree(RefAST t) const = 0;
  40. /** Is 't' a subtree of the tree rooted at 'this'? The siblings of
  41. * 'this' are ignored.
  42. */
  43. virtual bool equalsTreePartial(RefAST t) const = 0;
  44. /** Walk the tree looking for all exact subtree matches. Return
  45. * a vector of RefAST that lets the caller walk the list
  46. * of subtree roots found herein.
  47. */
  48. virtual ANTLR_USE_NAMESPACE(std)vector<RefAST> findAll(RefAST t) = 0;
  49. /** Walk the tree looking for all subtrees. Return
  50. * a vector of RefAST that lets the caller walk the list
  51. * of subtree roots found herein.
  52. */
  53. virtual ANTLR_USE_NAMESPACE(std)vector<RefAST> findAllPartial(RefAST t) = 0;
  54. /// Add a node to the end of the child list for this node
  55. virtual void addChild(RefAST c) = 0;
  56. /// Get the number of children. Returns 0 if the node is a leaf
  57. virtual size_t getNumberOfChildren() const = 0;
  58. /// Get the first child of this node; null if no children
  59. virtual RefAST getFirstChild() const = 0;
  60. /// Get the next sibling in line after this one
  61. virtual RefAST getNextSibling() const = 0;
  62. /// Get the token text for this node
  63. virtual ANTLR_USE_NAMESPACE(std)string getText() const = 0;
  64. /// Get the token type for this node
  65. virtual int getType() const = 0;
  66. /** Various initialization routines. Used by several factories to initialize
  67. * an AST element.
  68. */
  69. virtual void initialize(int t, const ANTLR_USE_NAMESPACE(std)string& txt) = 0;
  70. virtual void initialize(RefAST t) = 0;
  71. virtual void initialize(RefToken t) = 0;
  72. #ifdef ANTLR_SUPPORT_XML
  73. /** initialize this node from the contents of a stream.
  74. * @param in the stream to read the AST attributes from.
  75. */
  76. virtual void initialize( ANTLR_USE_NAMESPACE(std)istream& in ) = 0;
  77. #endif
  78. /// Set the first child of a node.
  79. virtual void setFirstChild(RefAST c) = 0;
  80. /// Set the next sibling after this one.
  81. virtual void setNextSibling(RefAST n) = 0;
  82. /// Set the token text for this node
  83. virtual void setText(const ANTLR_USE_NAMESPACE(std)string& txt) = 0;
  84. /// Set the token type for this node
  85. virtual void setType(int type) = 0;
  86. /// Return this AST node as a string
  87. virtual ANTLR_USE_NAMESPACE(std)string toString() const = 0;
  88. /// Print out a child-sibling tree in LISP notation
  89. virtual ANTLR_USE_NAMESPACE(std)string toStringList() const = 0;
  90. virtual ANTLR_USE_NAMESPACE(std)string toStringTree() const = 0;
  91. #ifdef ANTLR_SUPPORT_XML
  92. /** get attributes of this node to 'out'. Override to customize XML
  93. * output.
  94. * @param out the stream to write the AST attributes to.
  95. * @returns if a explicit closetag should be written
  96. */
  97. virtual bool attributesToStream( ANTLR_USE_NAMESPACE(std)ostream& out ) const = 0;
  98. /** Print a symbol over ostream. Overload this one to customize the XML
  99. * output for AST derived AST-types
  100. * @param output stream
  101. */
  102. virtual void toStream( ANTLR_USE_NAMESPACE(std)ostream &out ) const = 0;
  103. /** Dump AST contents in XML format to output stream.
  104. * Works in conjunction with to_stream method. Overload that one is
  105. * derived classes to customize behaviour.
  106. * @param output stream to write to string to put the stuff in.
  107. * @param ast RefAST object to write.
  108. */
  109. friend ANTLR_USE_NAMESPACE(std)ostream& operator<<( ANTLR_USE_NAMESPACE(std)ostream& output, const RefAST& ast );
  110. #endif
  111. private:
  112. friend struct ASTRef;
  113. ASTRef* ref;
  114. AST(RefAST other);
  115. AST& operator=(const AST& other);
  116. AST& operator=(RefAST other);
  117. };
  118. #ifdef ANTLR_SUPPORT_XML
  119. inline ANTLR_USE_NAMESPACE(std)ostream& operator<<( ANTLR_USE_NAMESPACE(std)ostream& output, const RefAST& ast )
  120. {
  121. ast->toStream(output);
  122. return output;
  123. }
  124. #endif
  125. extern ANTLR_API RefAST nullAST;
  126. extern ANTLR_API AST* const nullASTptr;
  127. #ifdef NEEDS_OPERATOR_LESS_THAN
  128. // RK: apparently needed by MSVC and a SUN CC, up to and including
  129. // 2.7.2 this was undefined ?
  130. inline bool operator<( RefAST l, RefAST r )
  131. {
  132. return nullAST == l ? ( nullAST == r ? false : true ) : l->getType() < r->getType();
  133. }
  134. #endif
  135. #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
  136. }
  137. #endif
  138. #endif //INC_AST_hpp__