WsParser_VS/libParse/libparse.cpp

53 lines
1.5 KiB
C++
Raw Permalink Normal View History

2024-03-17 07:58:28 +00:00
#include "libparse.h"
using namespace lib_parse;
2024-06-22 15:19:14 +00:00
using namespace ast_gen;
2024-03-17 07:58:28 +00:00
CheckException::CheckException(const QString& msg) : msg_store(msg) {}
QString CheckException::message() const { return msg_store; }
Analyzer::Analyzer(const QList<std::shared_ptr<const CheckProvider> >& providers) : check_providers(providers) {}
2024-06-15 01:18:33 +00:00
#include <QTime>
#include <QDebug>
2024-06-22 15:19:14 +00:00
std::shared_ptr<const ElementAccess> Analyzer::validCheckWith(std::shared_ptr<const ElementAccess> root) const {
2024-06-15 01:18:33 +00:00
for (auto& v : check_providers){
QTime time_stamp = QTime::currentTime();
2024-03-17 07:58:28 +00:00
v->validCheck(root);
2024-06-15 01:18:33 +00:00
auto current_stamp = QTime::currentTime();
2025-02-15 12:25:51 +00:00
qDebug().noquote() << QString("%校验器:%2 消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp)).arg(v->name());
2024-06-15 01:18:33 +00:00
}
2024-03-17 07:58:28 +00:00
return root;
}
2024-06-22 15:19:14 +00:00
2025-02-15 12:25:51 +00:00
bool VisitEntry::visitWith(std::shared_ptr<const ElementAccess> syntax_elm, std::shared_ptr<TreeVisitor> visitor) {
2024-06-22 15:19:14 +00:00
switch (visitor->mode()) {
case VisitMode::FirstParent: {
if (visitor->visit(syntax_elm)) {
for (auto& e : syntax_elm->children()) {
visitWith(e, visitor);
}
}
return true;
}break;
case VisitMode::LastParent:{
bool exc_continue = true;
for (auto& e : syntax_elm->children()) {
if(!visitWith(e, visitor)){
exc_continue = false;
break;
}
}
if(exc_continue)
visitor->visit(syntax_elm);
return exc_continue;
}break;
default:
break;
}
return false;
2024-06-22 15:19:14 +00:00
}