#include "ast_foundation.h" using namespace Ast; ASTLeaf::ASTLeaf(ASTTree *parent, Lex::Token *inst) : _store(inst), parent_ins(parent) {} ASTLeaf::~ASTLeaf() { delete _store; } const ASTTree *ASTLeaf::parent() const { return parent_ins; } uint ASTLeaf::depth() const { auto depth_value = 0; const ASTTree *temp_node = this; while (temp_node->parent()) { depth_value++; temp_node = temp_node->parent(); } return depth_value; } QList ASTLeaf::children() const { return QList(); } uint ASTLeaf::count() const { return 0; } ASTTree *ASTLeaf::child(uint) const { return nullptr; } QString ASTLeaf::toString() const { return _store->content(); } Lex::Token *ASTLeaf::tokenIns() const { return _store; } ASTList::ASTList(ASTTree *parent) : parent_ins(parent) {} ASTList::~ASTList() { for (auto &it : _store) delete it; } void ASTList::resetChildren(const QList &tokens) { _store = tokens; } const ASTTree *ASTList::parent() const { return parent_ins; } uint ASTList::depth() const { auto depth_value = 0; const ASTTree *temp_node = this; while (temp_node->parent()) { depth_value++; temp_node = temp_node->parent(); } return depth_value; } QList ASTList::children() const { return _store; } uint ASTList::count() const { return _store.count(); } ASTTree *ASTList::child(uint index) const { if (index >= count()) return nullptr; return _store[index]; } void ASTList::insert(uint idx, ASTTree *child) { this->_store.insert(idx, child); } QString ASTList::toString() const { QString content; for (auto &it : _store) content += it->toString() + " "; return content; }