53 lines
1.5 KiB
C++
53 lines
1.5 KiB
C++
#include "libparse.h"
|
|
|
|
using namespace lib_parse;
|
|
using namespace ast_gen;
|
|
|
|
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) {}
|
|
|
|
#include <QTime>
|
|
#include <QDebug>
|
|
std::shared_ptr<const ElementAccess> Analyzer::validCheckWith(std::shared_ptr<const ElementAccess> root) const {
|
|
for (auto& v : check_providers){
|
|
QTime time_stamp = QTime::currentTime();
|
|
v->validCheck(root);
|
|
auto current_stamp = QTime::currentTime();
|
|
qDebug().noquote() << QString("%校验器:%2 消耗时间:%1 ms。").arg(time_stamp.msecsTo(current_stamp)).arg(v->name());
|
|
}
|
|
return root;
|
|
}
|
|
|
|
bool VisitEntry::visitWith(std::shared_ptr<const ElementAccess> syntax_elm, std::shared_ptr<TreeVisitor> visitor) {
|
|
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;
|
|
}
|