82 lines
2.2 KiB
C++
82 lines
2.2 KiB
C++
#include "ast_basic.h"
|
|
#include <QDebug>
|
|
|
|
using namespace ast_basic;
|
|
using namespace lib_token;
|
|
using namespace lib_syntax;
|
|
|
|
ExpressionElement::ExpressionElement(std::shared_ptr<const ExpressionRule> bind) : _expr_rule(bind) {}
|
|
|
|
std::shared_ptr<const ExpressionRule> ExpressionElement::definedRule() const {
|
|
return _expr_rule;
|
|
}
|
|
|
|
QString ExpressionElement::filePath() const {
|
|
if(!tokens_bind.size())
|
|
throw new SyntaxException(u8"InternalError[0x0002]Ò»¸ö¿ÕµÄ·Ç·¨ÎÞЧ½Úµã");
|
|
|
|
return tokens_bind.first()->file();
|
|
}
|
|
|
|
void ExpressionElement::tokensReset(const QList<std::shared_ptr<const IToken>>& list) {
|
|
this->tokens_bind = list;
|
|
}
|
|
|
|
void ExpressionElement::addToken(std::shared_ptr<const IToken> token_inst) {
|
|
this->tokens_bind.append(token_inst);
|
|
}
|
|
|
|
QList<std::shared_ptr<const Expression>> ExpressionElement::children() const {
|
|
return this->children_store;
|
|
}
|
|
|
|
void ExpressionElement::addChild(std::shared_ptr<const Expression> inst) {
|
|
this->children_store.append(inst);
|
|
}
|
|
|
|
QList<std::shared_ptr<const IToken>> ExpressionElement::tokens() const {
|
|
return this->tokens_bind;
|
|
}
|
|
|
|
ExpressionContext::ExpressionContext() {}
|
|
|
|
void ExpressionContext::setCurrentFile(const QString& path) { this->current_file_path = path; }
|
|
|
|
QString ExpressionContext::currentFile() const { return this->current_file_path; }
|
|
|
|
std::shared_ptr<Expression> ExpressionContext::currentInst() const
|
|
{
|
|
if(expression_stack.size())
|
|
return expression_stack.last();
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
void ExpressionContext::pushInst(std::shared_ptr<Expression> current_inst)
|
|
{
|
|
if(!expression_stack.size() || expression_stack.last() != current_inst)
|
|
expression_stack.append(current_inst);
|
|
}
|
|
|
|
std::shared_ptr<Expression> ExpressionContext::popInst()
|
|
{
|
|
auto lastx = expression_stack.takeLast();
|
|
return lastx;
|
|
}
|
|
|
|
std::shared_ptr<const BaseRule> ExpressionContext::currentExpressionRule() const {
|
|
if(rule_stack.size())
|
|
return rule_stack.last();
|
|
return nullptr;
|
|
}
|
|
|
|
void ExpressionContext::pushExpressionRule(std::shared_ptr<const BaseRule> inst) {
|
|
if(!rule_stack.size() || rule_stack.last() != inst)
|
|
rule_stack.append(inst);
|
|
}
|
|
|
|
std::shared_ptr<const BaseRule> ExpressionContext::popExpressionRule()
|
|
{
|
|
return rule_stack.takeLast();
|
|
}
|