Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

small change for FindVisitor #1294

Merged
merged 1 commit into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 deletions src/visitor/FindVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,111 +9,111 @@ namespace graph {

void FindVisitor::visit(TypeCastingExpression* expr) {
findInCurrentExpr(expr);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
expr->operand()->accept(this);
}

void FindVisitor::visit(UnaryExpression* expr) {
findInCurrentExpr(expr);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
expr->operand()->accept(this);
}

void FindVisitor::visit(FunctionCallExpression* expr) {
findInCurrentExpr(expr);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
for (const auto& arg : expr->args()->args()) {
arg->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
}
}

void FindVisitor::visit(AggregateExpression* expr) {
findInCurrentExpr(expr);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
expr->arg()->accept(this);
}

void FindVisitor::visit(ListExpression* expr) {
findInCurrentExpr(expr);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
for (const auto& item : expr->items()) {
item->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
}
}

void FindVisitor::visit(SetExpression* expr) {
findInCurrentExpr(expr);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
for (const auto& item : expr->items()) {
item->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
}
}

void FindVisitor::visit(MapExpression* expr) {
findInCurrentExpr(expr);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
for (const auto& pair : expr->items()) {
pair.second->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
}
}

void FindVisitor::visit(CaseExpression* expr) {
findInCurrentExpr(expr);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;

if (expr->hasCondition()) {
expr->condition()->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
}
if (expr->hasDefault()) {
expr->defaultResult()->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
}
for (const auto& whenThen : expr->cases()) {
whenThen.when->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
whenThen.then->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
}
}

void FindVisitor::visit(PredicateExpression* expr) {
findInCurrentExpr(expr);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;

expr->collection()->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
if (expr->hasFilter()) {
expr->filter()->accept(this);
}
}

void FindVisitor::visit(ReduceExpression* expr) {
findInCurrentExpr(expr);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;

expr->initial()->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
expr->collection()->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
expr->mapping()->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
}

void FindVisitor::visit(ListComprehensionExpression* expr) {
findInCurrentExpr(expr);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;

expr->collection()->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;

if (expr->hasFilter()) {
expr->filter()->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
}

if (expr->hasMapping()) {
Expand Down Expand Up @@ -183,9 +183,9 @@ void FindVisitor::visit(LabelExpression* expr) {

void FindVisitor::visit(LabelAttributeExpression *expr) {
findInCurrentExpr(expr);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
expr->left()->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
expr->right()->accept(this);
}

Expand All @@ -204,33 +204,32 @@ void FindVisitor::visit(ColumnExpression* expr) {

void FindVisitor::visit(SubscriptRangeExpression* expr) {
findInCurrentExpr(expr);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;

expr->list()->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;

if (expr->lo() != nullptr) {
expr->lo()->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
}

if (expr->hi() != nullptr) {
expr->hi()->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
}
}

void FindVisitor::visitBinaryExpr(BinaryExpression* expr) {
findInCurrentExpr(expr);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
expr->left()->accept(this);
if (!needFindAll_ && found_) return;
if (!needFindAll_ && !foundExprs_.empty()) return;
expr->right()->accept(this);
}

void FindVisitor::findInCurrentExpr(Expression* expr) {
if (finder_(expr)) {
found_ = true;
foundExprs_.emplace_back(expr);
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/visitor/FindVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class FindVisitor final : public ExprVisitorImpl {
}

bool found() const {
return found_;
return !foundExprs_.empty();
}

std::vector<const Expression*> results() const {
Expand All @@ -53,7 +53,6 @@ class FindVisitor final : public ExprVisitorImpl {
void visit(CaseExpression* expr) override;
void visit(PredicateExpression* expr) override;
void visit(ReduceExpression* expr) override;

void visit(ConstantExpression* expr) override;
void visit(EdgePropertyExpression* expr) override;
void visit(TagPropertyExpression* expr) override;
Expand All @@ -77,14 +76,11 @@ class FindVisitor final : public ExprVisitorImpl {
void visit(SubscriptRangeExpression* expr) override;

void visitBinaryExpr(BinaryExpression* expr) override;

void findInCurrentExpr(Expression* expr);

private:
Finder finder_;
bool needFindAll_;

bool found_{false};
std::vector<const Expression*> foundExprs_;
};

Expand Down