summaryrefslogtreecommitdiff
path: root/src/ast/expr_ptr.hpp
blob: cae519ccc3a381bbb89e9f17cd27268d298035c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
  * MRustC - Mutabah's Rust Compiler
 * - By John Hodge (Mutabah/thePowersGang)
 *
 * ast/expr_ptr.hpp
 * - Pointer type wrapping AST::ExprNode (prevents need to know the full definition)
 */
#include <memory>

namespace AST {

class ExprNode;
class NodeVisitor;

typedef ::std::unique_ptr<AST::ExprNode>    ExprNodeP;
extern ::std::ostream& operator<<(::std::ostream& os, const ExprNode& node);

class Expr
{
    ::std::shared_ptr<ExprNode> m_node;
public:
    Expr(unique_ptr<ExprNode> node);
    Expr(ExprNode* node);
    Expr();

    bool is_valid() const { return m_node.get() != nullptr; }
    const ExprNode& node() const { assert(m_node.get()); return *m_node; }
          ExprNode& node()       { assert(m_node.get()); return *m_node; }
    ::std::shared_ptr<ExprNode> take_node() { assert(m_node.get()); return ::std::move(m_node); }
    void visit_nodes(NodeVisitor& v);
    void visit_nodes(NodeVisitor& v) const;

    Expr clone() const;

    friend ::std::ostream& operator<<(::std::ostream& os, const Expr& pat);
};

}