| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#ifndef REPLACE_CALL_EXPR_H |
| 12 |
#define REPLACE_CALL_EXPR_H |
| 13 |
|
| 14 |
#include <string> |
| 15 |
#include <vector> |
| 16 |
#include <utility> |
| 17 |
#include "llvm/ADT/SmallVector.h" |
| 18 |
#include "llvm/ADT/DenseMap.h" |
| 19 |
#include "Transformation.h" |
| 20 |
|
| 21 |
namespace clang { |
| 22 |
class DeclGroupRef; |
| 23 |
class ASTContext; |
| 24 |
class FunctionDecl; |
| 25 |
class CallExpr; |
| 26 |
class DeclRefExpr; |
| 27 |
class ReturnStmt; |
| 28 |
class Expr; |
| 29 |
class ParmVarDecl; |
| 30 |
} |
| 31 |
|
| 32 |
class ReplaceCallExprVisitor; |
| 33 |
|
| 34 |
class ReplaceCallExpr : public Transformation { |
| 35 |
friend class ReplaceCallExprVisitor; |
| 36 |
|
| 37 |
public: |
| 38 |
|
| 39 |
ReplaceCallExpr(const char *TransName, const char *Desc) |
| 40 |
: Transformation(TransName, Desc), |
| 41 |
CollectionVisitor(NULL), |
| 42 |
TheCallExpr(NULL), |
| 43 |
TheReturnStmt(NULL), |
| 44 |
CurrentFD(NULL) |
| 45 |
{ } |
| 46 |
|
| 47 |
~ReplaceCallExpr(void); |
| 48 |
|
| 49 |
private: |
| 50 |
|
| 51 |
typedef llvm::SmallVector<clang::ReturnStmt *, 5> ReturnStmtsVector; |
| 52 |
|
| 53 |
typedef llvm::SmallVector<const clang::DeclRefExpr *, 5> ParmRefsVector; |
| 54 |
|
| 55 |
typedef llvm::SmallVector<unsigned int, 10> ParameterPosVector; |
| 56 |
|
| 57 |
virtual void Initialize(clang::ASTContext &context); |
| 58 |
|
| 59 |
virtual void HandleTranslationUnit(clang::ASTContext &Ctx); |
| 60 |
|
| 61 |
void addOneReturnStmt(clang::ReturnStmt *RS); |
| 62 |
|
| 63 |
void addOneParmRef(clang::ReturnStmt *RS, const clang::DeclRefExpr *DE); |
| 64 |
|
| 65 |
void replaceCallExpr(void); |
| 66 |
|
| 67 |
void getNewParmRefStr(const clang::DeclRefExpr *DE, |
| 68 |
std::string &ParmRefStr); |
| 69 |
|
| 70 |
void replaceParmRefs(std::string &RetStr, const clang::Expr *RetE, |
| 71 |
llvm::DenseMap<const clang::DeclRefExpr *, std::string> &ParmRefToStrMap); |
| 72 |
|
| 73 |
void insertParmRef( |
| 74 |
std::vector< std::pair<const clang::DeclRefExpr *, int> > &SortedParmRefs, |
| 75 |
const clang::DeclRefExpr *ParmRef, int Off); |
| 76 |
|
| 77 |
void sortParmRefsByOffs(const char *StartBuf, |
| 78 |
llvm::DenseMap<const clang::DeclRefExpr *, std::string> &ParmRefToStrMap, |
| 79 |
std::vector<std::pair<const clang::DeclRefExpr *, int> > &SortedParmRefs); |
| 80 |
|
| 81 |
void doAnalysis(void); |
| 82 |
|
| 83 |
void getParmPosVector(ParameterPosVector &PosVector, |
| 84 |
clang::ReturnStmt *RS, clang::CallExpr *CE); |
| 85 |
|
| 86 |
bool hasBadEffect(const ParameterPosVector &PosVector, |
| 87 |
clang::ReturnStmt *RS, clang::CallExpr *CE); |
| 88 |
|
| 89 |
bool hasUnmatchedParmArg(const ParameterPosVector &PosVector, |
| 90 |
clang::CallExpr *CE); |
| 91 |
|
| 92 |
ReplaceCallExprVisitor *CollectionVisitor; |
| 93 |
|
| 94 |
llvm::DenseMap<clang::FunctionDecl *, ReturnStmtsVector *> FuncToReturnStmts; |
| 95 |
|
| 96 |
llvm::DenseMap<clang::ReturnStmt *, ParmRefsVector *> ReturnStmtToParmRefs; |
| 97 |
|
| 98 |
llvm::SmallVector<clang::CallExpr *, 10> AllCallExprs; |
| 99 |
|
| 100 |
clang::CallExpr *TheCallExpr; |
| 101 |
|
| 102 |
clang::ReturnStmt *TheReturnStmt; |
| 103 |
|
| 104 |
clang::FunctionDecl *CurrentFD; |
| 105 |
|
| 106 |
|
| 107 |
ReplaceCallExpr(void); |
| 108 |
|
| 109 |
ReplaceCallExpr(const ReplaceCallExpr &); |
| 110 |
|
| 111 |
void operator=(const ReplaceCallExpr &); |
| 112 |
}; |
| 113 |
#endif |