#pragma once #include #include "ast_node.hpp" namespace ast { class Ast { public: Ast() = default; Ast(const Ast&) = delete; Ast(Ast&& other) { this->root = other.root; other.root = nullptr; this->items = std::move(other.items); } AstVisitable* root; void traverse(AstVisitor& visitor) { root->accept(visitor); } template T* create(Args&&... args) { auto node = new T(std::forward(args)...); items.push_back(std::unique_ptr(node)); return node; } private: // basically a gc vector that destroys all ast nodes once this object is // destroyed. parser generator is written in c and works only with raw // pointers so this is what makes it leak free after the parser finishes // parsing without using shared pointers std::vector items; }; }