| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#ifndef RENAME_VAR_H |
| 12 |
#define RENAME_VAR_H |
| 13 |
|
| 14 |
#include <string> |
| 15 |
#include <vector> |
| 16 |
#include "llvm/ADT/SmallVector.h" |
| 17 |
#include "llvm/ADT/DenseMap.h" |
| 18 |
#include "Transformation.h" |
| 19 |
|
| 20 |
namespace clang { |
| 21 |
class DeclGroupRef; |
| 22 |
class ASTContext; |
| 23 |
class VarDecl; |
| 24 |
} |
| 25 |
|
| 26 |
class RNVCollectionVisitor; |
| 27 |
class RenameVarVisitor; |
| 28 |
|
| 29 |
class RenameVar : public Transformation { |
| 30 |
friend class RNVCollectionVisitor; |
| 31 |
friend class RenameVarVisitor; |
| 32 |
|
| 33 |
public: |
| 34 |
|
| 35 |
RenameVar(const char *TransName, const char *Desc) |
| 36 |
: Transformation(TransName, Desc), |
| 37 |
VarCollectionVisitor(NULL), |
| 38 |
RenameVisitor(NULL), |
| 39 |
RenamePrefix('t') |
| 40 |
{ } |
| 41 |
|
| 42 |
~RenameVar(void); |
| 43 |
|
| 44 |
virtual bool skipCounter(void) { |
| 45 |
return true; |
| 46 |
} |
| 47 |
|
| 48 |
private: |
| 49 |
|
| 50 |
virtual void Initialize(clang::ASTContext &context); |
| 51 |
|
| 52 |
virtual bool HandleTopLevelDecl(clang::DeclGroupRef D); |
| 53 |
|
| 54 |
virtual void HandleTranslationUnit(clang::ASTContext &Ctx); |
| 55 |
|
| 56 |
void addVar(clang::VarDecl *VD); |
| 57 |
|
| 58 |
bool allValidNames(); |
| 59 |
|
| 60 |
void collectVars(void); |
| 61 |
|
| 62 |
RNVCollectionVisitor *VarCollectionVisitor; |
| 63 |
|
| 64 |
RenameVarVisitor *RenameVisitor; |
| 65 |
|
| 66 |
char RenamePrefix; |
| 67 |
|
| 68 |
std::vector<clang::VarDecl *> ValidVars; |
| 69 |
|
| 70 |
llvm::SmallVector<char, 26> AvailableNames; |
| 71 |
|
| 72 |
llvm::DenseMap<clang::VarDecl *, std::string> VarToNameMap; |
| 73 |
|
| 74 |
llvm::SmallPtrSet<clang::DeclRefExpr *, 10> VisitedDREs; |
| 75 |
|
| 76 |
|
| 77 |
RenameVar(void); |
| 78 |
|
| 79 |
RenameVar(const RenameVar &); |
| 80 |
|
| 81 |
void operator=(const RenameVar &); |
| 82 |
}; |
| 83 |
#endif |