78 lines
1.9 KiB
C++
78 lines
1.9 KiB
C++
#ifndef AST_FOUNDATION_H
|
|
#define AST_FOUNDATION_H
|
|
|
|
#include "lex_foundation.h"
|
|
#include <QList>
|
|
|
|
namespace Ast {
|
|
|
|
class ASTTree {
|
|
public:
|
|
virtual ~ASTTree() = default;
|
|
|
|
virtual const ASTTree *parent() const = 0;
|
|
virtual uint depth() const = 0;
|
|
|
|
virtual QList<ASTTree *> children() const = 0;
|
|
|
|
virtual uint count() const = 0;
|
|
virtual ASTTree *child(uint index) const = 0;
|
|
|
|
virtual QString toString() const = 0;
|
|
};
|
|
|
|
class ASTLeaf : public ASTTree {
|
|
public:
|
|
explicit ASTLeaf(ASTTree *parent, Lex::Token *inst);
|
|
virtual ~ASTLeaf();
|
|
|
|
virtual const ASTTree *parent() const override;
|
|
virtual uint depth() const override;
|
|
|
|
virtual QList<ASTTree *> children() const final;
|
|
virtual uint count() const final;
|
|
virtual ASTTree *child(uint) const final;
|
|
|
|
virtual QString toString() const override;
|
|
|
|
protected:
|
|
Lex::Token *tokenIns() const;
|
|
|
|
private:
|
|
Lex::Token *const _store;
|
|
ASTTree *const parent_ins;
|
|
};
|
|
|
|
class ASTList : public ASTTree {
|
|
public:
|
|
explicit ASTList(ASTTree *parent);
|
|
virtual ~ASTList();
|
|
|
|
virtual void resetChildren(const QList<ASTTree *> &tokens);
|
|
|
|
// ASTTree interface
|
|
public:
|
|
virtual const ASTTree *parent() const override;
|
|
virtual uint depth() const override;
|
|
|
|
virtual QList<ASTTree *> children() const override final;
|
|
virtual uint count() const override final;
|
|
virtual ASTTree *child(uint index) const override final;
|
|
|
|
/**
|
|
* @brief 插入子节点
|
|
* @param child
|
|
*/
|
|
virtual void insert(uint idx, ASTTree *child);
|
|
|
|
virtual QString toString() const override;
|
|
|
|
private:
|
|
QList<ASTTree *> _store;
|
|
ASTTree *const parent_ins;
|
|
};
|
|
|
|
} // namespace Ast
|
|
|
|
#endif // AST_FOUNDATION_H
|