// // Created by erki on 02.03.21. // #include "OperationFinderAstVisitor.hpp" #include "OperationFinder.hpp" #include "ASTHelpers.hpp" OperationFinderAstVisitor::OperationFinderAstVisitor(OperationFinder* op_finder) : _context(nullptr) , _op_finder(op_finder) { } void OperationFinderAstVisitor::NewContext(clang::ASTContext* context) { _context = context; } bool OperationFinderAstVisitor::VisitForStmt(clang::ForStmt* stmt) { assert(_context); return true; } bool OperationFinderAstVisitor::VisitBinaryOperator(clang::BinaryOperator* op) { assert(_context); if (!op->isCompoundAssignmentOp()) _op_finder->processArithmetic(op, _context->getSourceManager()); return true; } bool OperationFinderAstVisitor::VisitUnaryOperator(clang::UnaryOperator* op) { assert(_context); _op_finder->processUnaryArithmetic(op, _context->getSourceManager()); return true; } bool OperationFinderAstVisitor::VisitCallExpr(clang::CallExpr* call) { assert(_context); _op_finder->processFunctionCall(call, _context->getSourceManager()); return true; } bool OperationFinderAstVisitor::dataTraverseStmtPre(clang::Stmt* stmt) { assert(_context); if (auto* loop = clang::dyn_cast(stmt)) { if (loop->getInit()) { _loop_init = loop->getInit(); _op_finder->fallthroughBranchEntered(); } else { _op_finder->forLoopEntered(); } } return true; } bool OperationFinderAstVisitor::dataTraverseStmtPost(clang::Stmt* stmt) { assert(_context); if (_loop_init && _loop_init == stmt) { _op_finder->forLoopEntered(); _op_finder->fallthroughBranchExited(); _loop_init = nullptr; } else if (clang::dyn_cast(stmt)) { _op_finder->forLoopExited(); } return true; }