masters-thesis/op-finder/OperationFinderAstVisitor.hpp
Erki 83ca2deb0e Better branch detection model
For loops are now broken up into 2 branches: 1 (init) and 2 (cond + inc).
2021-03-07 13:02:14 +02:00

49 lines
1.2 KiB
C++

//
// Created by erki on 02.03.21.
//
#ifndef C_ANALYZER_OPERATIONFINDERASTVISITOR_HPP
#define C_ANALYZER_OPERATIONFINDERASTVISITOR_HPP
#include <clang/AST/RecursiveASTVisitor.h>
class OperationFinder;
class OperationFinderAstVisitor
: public clang::RecursiveASTVisitor<OperationFinderAstVisitor>
{
public:
explicit OperationFinderAstVisitor(OperationFinder* op_finder);
void NewContext(clang::ASTContext* context);
bool VisitForStmt(clang::ForStmt* stmt);
bool VisitBinaryOperator(clang::BinaryOperator* op);
bool VisitUnaryOperator(clang::UnaryOperator* op);
bool VisitCallExpr(clang::CallExpr* call);
bool VisitArraySubscriptExpr(clang::ArraySubscriptExpr* subscript);
bool dataTraverseStmtPre(clang::Stmt* stmt);
bool dataTraverseStmtPost(clang::Stmt* stmt);
private:
clang::ASTContext* _context;
OperationFinder* _op_finder;
struct _LoopHeaderStateMachine
{
bool in_loop_header = false;
clang::Stmt* init = nullptr;
clang::Stmt* header_start = nullptr;
clang::Stmt* header_end = nullptr;
};
_LoopHeaderStateMachine _loop_header;
std::vector<clang::Stmt*> _branch_stack;
clang::Stmt* _isBranchEntry(clang::Stmt* stmt);
};
#endif //C_ANALYZER_OPERATIONFINDERASTVISITOR_HPP