tipc
A TIP to LLVM compiler
SyntaxTree.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "treetypes/ASTNode.h"
4 
5 #include <memory>
6 
7 // Forward declare the iterator.
8 class Iterator;
9 
16 class SyntaxTree {
17 
18 public:
19  SyntaxTree(std::shared_ptr<ASTNode> node);
21  SyntaxTree(SyntaxTree const &tree);
22  SyntaxTree &operator=(SyntaxTree const &tree);
23 
29  Iterator begin(std::string const &order);
30 
31  Iterator begin(std::string const &order) const;
32 
38  Iterator end(std::string const &order);
39 
43  std::shared_ptr<ASTNode> getRoot() const;
44 
50  void accept(ASTVisitor *visitor);
51 
55  std::vector<SyntaxTree> getSubtrees();
56 
57 private:
58  std::shared_ptr<ASTNode> root;
59 };
Base class for AST visitors.
Definition: ASTVisitor.h:23
The client-facing iterator interface.
Definition: Iterator.h:15
A convenient interface to the AST nodes.
Definition: SyntaxTree.h:16
void accept(ASTVisitor *visitor)
Apply the visitor to the root of the tree.
Definition: SyntaxTree.cpp:38
SyntaxTree(std::shared_ptr< ASTNode > node)
Definition: SyntaxTree.cpp:5
Iterator begin(std::string const &order)
Definition: SyntaxTree.cpp:11
std::shared_ptr< ASTNode > getRoot() const
Return the root of the tree.
Definition: SyntaxTree.cpp:42
SyntaxTree & operator=(SyntaxTree const &tree)
Definition: SyntaxTree.cpp:31
Iterator end(std::string const &order)
Construct an iterator pointing at the end of the tree.
Definition: SyntaxTree.cpp:17
Iterator begin(std::string const &order) const
SyntaxTree(SyntaxTree const &tree)
std::vector< SyntaxTree > getSubtrees()
Return the children of the root as collection of SyntaxTrees.
Definition: SyntaxTree.cpp:22