改进context实现名称
This commit is contained in:
parent
eeafd5fef8
commit
c2c6f0a083
|
@ -34,13 +34,13 @@ QList<std::shared_ptr<const IToken>> ExpressionElement::tokens() const {
|
||||||
return this->tokens_bind;
|
return this->tokens_bind;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpressionContext::ExpressionContext() {}
|
ExprsContext::ExprsContext() {}
|
||||||
|
|
||||||
void ExpressionContext::setCurrentFile(const QString& path) { this->current_file_path = path; }
|
void ExprsContext::setCurrentFile(const QString& path) { this->current_file_path = path; }
|
||||||
|
|
||||||
QString ExpressionContext::currentFile() const { return this->current_file_path; }
|
QString ExprsContext::currentFile() const { return this->current_file_path; }
|
||||||
|
|
||||||
std::shared_ptr<IExprInst> ExpressionContext::currentExprInst() const
|
std::shared_ptr<IExprInst> ExprsContext::currentExprInst() const
|
||||||
{
|
{
|
||||||
if (expression_stack.size())
|
if (expression_stack.size())
|
||||||
return expression_stack.last();
|
return expression_stack.last();
|
||||||
|
@ -48,39 +48,39 @@ std::shared_ptr<IExprInst> ExpressionContext::currentExprInst() const
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpressionContext::pushExprInst(std::shared_ptr<IExprInst> current_inst)
|
void ExprsContext::pushExprInst(std::shared_ptr<IExprInst> current_inst)
|
||||||
{
|
{
|
||||||
if (!expression_stack.size() || expression_stack.last() != current_inst)
|
if (!expression_stack.size() || expression_stack.last() != current_inst)
|
||||||
expression_stack.append(current_inst);
|
expression_stack.append(current_inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<IExprInst> ExpressionContext::popExprInst()
|
std::shared_ptr<IExprInst> ExprsContext::popExprInst()
|
||||||
{
|
{
|
||||||
auto lastx = expression_stack.takeLast();
|
auto lastx = expression_stack.takeLast();
|
||||||
return lastx;
|
return lastx;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<const IBasicRule> ExpressionContext::currentExprRule() const {
|
std::shared_ptr<const IBasicRule> ExprsContext::currentExprRule() const {
|
||||||
if (rule_stack.size())
|
if (rule_stack.size())
|
||||||
return rule_stack.last();
|
return rule_stack.last();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpressionContext::pushExprRule(std::shared_ptr<const IBasicRule> inst) {
|
void ExprsContext::pushExprRule(std::shared_ptr<const IBasicRule> inst) {
|
||||||
if (!rule_stack.size() || rule_stack.last() != inst)
|
if (!rule_stack.size() || rule_stack.last() != inst)
|
||||||
rule_stack.append(inst);
|
rule_stack.append(inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<const IBasicRule> ExpressionContext::popExprRule()
|
std::shared_ptr<const IBasicRule> ExprsContext::popExprRule()
|
||||||
{
|
{
|
||||||
return rule_stack.takeLast();
|
return rule_stack.takeLast();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpressionContext::appendParseErrors(const QString& file_path, int start, const QString& e) {
|
void ExprsContext::appendParseErrors(const QString& file_path, int start, const QString& e) {
|
||||||
this->errors_storage.append(std::make_tuple(file_path, start, e));
|
this->errors_storage.append(std::make_tuple(file_path, start, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ExpressionContext::errors() const {
|
QStringList ExprsContext::errors() const {
|
||||||
QStringList values;
|
QStringList values;
|
||||||
for (auto& tp : this->errors_storage)
|
for (auto& tp : this->errors_storage)
|
||||||
values.append(QString(u8"Îļþ£º%1\n\t%2").arg(std::get<0>(tp)).arg(std::get<2>(tp)));
|
values.append(QString(u8"Îļþ£º%1\n\t%2").arg(std::get<0>(tp)).arg(std::get<2>(tp)));
|
||||||
|
@ -88,7 +88,7 @@ QStringList ExpressionContext::errors() const {
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpressionContext::clearErrors(const QString &file_path, int start) {
|
void ExprsContext::clearErrors(const QString &file_path, int start) {
|
||||||
for (int idx = 0; idx < this->errors_storage.size(); ++idx) {
|
for (int idx = 0; idx < this->errors_storage.size(); ++idx) {
|
||||||
auto &tp = errors_storage[idx];
|
auto &tp = errors_storage[idx];
|
||||||
if(std::get<0>(tp) == file_path && std::get<1>(tp) >= start)
|
if(std::get<0>(tp) == file_path && std::get<1>(tp) >= start)
|
||||||
|
@ -96,15 +96,15 @@ void ExpressionContext::clearErrors(const QString &file_path, int start) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<std::shared_ptr<const IBasicRule>> ExpressionContext::currentExprRuleStack() const {
|
QList<std::shared_ptr<const IBasicRule>> ExprsContext::currentExprRuleStack() const {
|
||||||
return rule_stack;
|
return rule_stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ExpressionContext::appendDocInst(std::shared_ptr<ast_basic::IExprInst> inst) {
|
void ExprsContext::appendDocInst(std::shared_ptr<ast_basic::IExprInst> inst) {
|
||||||
this->document_store.append(inst);
|
this->document_store.append(inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<std::shared_ptr<const ast_basic::IExprInst>> ExpressionContext::getDocInsts() const {
|
QList<std::shared_ptr<const ast_basic::IExprInst>> ExprsContext::getDocInsts() const {
|
||||||
return this->document_store;
|
return this->document_store;
|
||||||
}
|
}
|
|
@ -77,7 +77,7 @@ namespace ast_basic {
|
||||||
void addChild(std::shared_ptr<const IExprInst> inst) override;
|
void addChild(std::shared_ptr<const IExprInst> inst) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LIBSYNTAX_EXPORT ExpressionContext : public lib_syntax::IContext, public std::enable_shared_from_this<ExpressionContext> {
|
class LIBSYNTAX_EXPORT ExprsContext : public lib_syntax::IContext, public std::enable_shared_from_this<ExprsContext> {
|
||||||
private:
|
private:
|
||||||
QList<std::shared_ptr<const lib_syntax::IBasicRule>> rule_stack;
|
QList<std::shared_ptr<const lib_syntax::IBasicRule>> rule_stack;
|
||||||
QList<std::shared_ptr<IExprInst>> expression_stack;
|
QList<std::shared_ptr<IExprInst>> expression_stack;
|
||||||
|
@ -86,7 +86,7 @@ namespace ast_basic {
|
||||||
QList<std::tuple<QString, int, QString>> errors_storage;
|
QList<std::tuple<QString, int, QString>> errors_storage;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ExpressionContext();
|
ExprsContext();
|
||||||
|
|
||||||
// ͨ¹ý IContext ¼Ì³Ð
|
// ͨ¹ý IContext ¼Ì³Ð
|
||||||
virtual void setCurrentFile(const QString& path);
|
virtual void setCurrentFile(const QString& path);
|
||||||
|
|
|
@ -102,7 +102,7 @@ namespace ast_gen
|
||||||
/**
|
/**
|
||||||
* @brief ¸ùÔªËØ¶¨Òå
|
* @brief ¸ùÔªËØ¶¨Òå
|
||||||
*/
|
*/
|
||||||
class LIBSYNTAX_EXPORT GlobalElement : public SyntaxElement, public ast_basic::ExpressionContext {
|
class LIBSYNTAX_EXPORT GlobalElement : public SyntaxElement, public ast_basic::ExprsContext {
|
||||||
private:
|
private:
|
||||||
QString names_store;
|
QString names_store;
|
||||||
QHash<QString, std::shared_ptr<const SyntaxElement>> node_cache;
|
QHash<QString, std::shared_ptr<const SyntaxElement>> node_cache;
|
||||||
|
|
Loading…
Reference in New Issue