| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#ifndef RENAME_PARAM_H |
| 12 |
#define RENAME_PARAM_H |
| 13 |
|
| 14 |
#include <string> |
| 15 |
#include <vector> |
| 16 |
#include "llvm/ADT/DenseMap.h" |
| 17 |
#include "llvm/ADT/SmallSet.h" |
| 18 |
#include "Transformation.h" |
| 19 |
|
| 20 |
namespace clang { |
| 21 |
class DeclGroupRef; |
| 22 |
class ASTContext; |
| 23 |
class FunctionDecl; |
| 24 |
class ParmVarDecl; |
| 25 |
} |
| 26 |
|
| 27 |
class ExistingVarCollectionVisitor; |
| 28 |
class RenameParamVisitor; |
| 29 |
|
| 30 |
class RenameParam : public Transformation { |
| 31 |
friend class ExistingVarCollectionVisitor; |
| 32 |
friend class RenameParamVisitor; |
| 33 |
|
| 34 |
public: |
| 35 |
|
| 36 |
RenameParam(const char *TransName, const char *Desc) |
| 37 |
: Transformation(TransName, Desc), |
| 38 |
VarCollectionVisitor(NULL), |
| 39 |
RenameVisitor(NULL), |
| 40 |
ParamNamePrefix("p"), |
| 41 |
HasValidParams(false) |
| 42 |
{ } |
| 43 |
|
| 44 |
~RenameParam(void); |
| 45 |
|
| 46 |
virtual bool skipCounter(void) { |
| 47 |
return true; |
| 48 |
} |
| 49 |
|
| 50 |
private: |
| 51 |
|
| 52 |
typedef llvm::SmallSet<unsigned int, 5> ExistingNumberSet; |
| 53 |
|
| 54 |
virtual void Initialize(clang::ASTContext &context); |
| 55 |
|
| 56 |
virtual void HandleTranslationUnit(clang::ASTContext &Ctx); |
| 57 |
|
| 58 |
void addGlobalVar(clang::VarDecl *VD); |
| 59 |
|
| 60 |
void addLocalVar(clang::VarDecl *VD); |
| 61 |
|
| 62 |
bool getPostfixValue(const std::string &Name, unsigned int &Value); |
| 63 |
|
| 64 |
bool isValidPostfix(ExistingNumberSet *LocalSet, unsigned int Postfix); |
| 65 |
|
| 66 |
unsigned int validatePostfix(clang::FunctionDecl *FD, |
| 67 |
unsigned int CurrPostfix); |
| 68 |
|
| 69 |
void validateParam(clang::ParmVarDecl *PD); |
| 70 |
|
| 71 |
ExistingVarCollectionVisitor *VarCollectionVisitor; |
| 72 |
|
| 73 |
RenameParamVisitor *RenameVisitor; |
| 74 |
|
| 75 |
llvm::DenseMap<clang::FunctionDecl *, ExistingNumberSet *> FunExistingVarsMap; |
| 76 |
|
| 77 |
ExistingNumberSet ExistingGlobalVars; |
| 78 |
|
| 79 |
const std::string ParamNamePrefix; |
| 80 |
|
| 81 |
bool HasValidParams; |
| 82 |
|
| 83 |
|
| 84 |
RenameParam(void); |
| 85 |
|
| 86 |
RenameParam(const RenameParam &); |
| 87 |
|
| 88 |
void operator=(const RenameParam &); |
| 89 |
}; |
| 90 |
#endif |