1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
//===----------------------------------------------------------------------===//
//
// Copyright (c) 2012, 2013, 2014 The University of Utah
// All rights reserved.
//
// This file is distributed under the University of Illinois Open Source
// License. See the file COPYING for details.
//
//===----------------------------------------------------------------------===//
#ifndef RENAME_CXX_METHOD_H
#define RENAME_CXX_METHOD_H
#include <string>
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "Transformation.h"
namespace clang {
class DeclGroupRef;
class ASTContext;
class FunctionDecl;
class CXXMethodDecl;
class CXXRecordDecl;
class Expr;
class CallExpr;
class OverloadExpr;
class CXXDependentScopeMemberExpr;
class DeclarationName;
class FunctionTemplateDecl;
class TemplateArgument;
class ClassTemplateSpecializationDecl;
}
namespace llvm {
class StringRef;
}
class RenameCXXMethodCollectionVisitor;
class RenameCXXMethodVisitor;
class RenameCXXMethod : public Transformation {
friend class RenameCXXMethodCollectionVisitor;
friend class RenameCXXMethodVisitor;
public:
RenameCXXMethod(const char *TransName, const char *Desc)
: Transformation(TransName, Desc),
MethodCollectionVisitor(NULL),
RenameVisitor(NULL),
CurrentFD(NULL),
ClassInstantiation(false),
FunctionInstantiation(false),
DoRenaming(false),
MethodNamePrefix("m_fn"),
NumRenamedMethods(0)
{ }
~RenameCXXMethod();
virtual bool skipCounter() {
return true;
}
private:
typedef llvm::DenseMap<const clang::CXXMethodDecl *, std::string>
CXXMethodDeclToNameMap;
typedef llvm::DenseMap<const clang::CXXRecordDecl *, unsigned int>
CXXRecordDeclToNumMap;
typedef llvm::SmallPtrSet<const clang::CXXRecordDecl *, 10> CXXRecordDeclSet;
typedef llvm::SmallPtrSet<const clang::CXXMethodDecl *, 10> CXXMethodDeclSet;
typedef llvm::SmallVector<const clang::ClassTemplateSpecializationDecl*, 5>
ClassSpecDeclVector;
virtual void Initialize(clang::ASTContext &context);
virtual bool HandleTopLevelDecl(clang::DeclGroupRef D);
virtual void HandleTranslationUnit(clang::ASTContext &Ctx);
void handleOneCXXRecordDecl(const clang::CXXRecordDecl *RD);
void addOneMethodName(const clang::CXXMethodDecl *MD, unsigned int Num);
void addOneInheritedName(const clang::CXXMethodDecl *MD,
const clang::CXXMethodDecl *BaseMD);
bool isSpecialCXXMethod(const clang::CXXMethodDecl *MD);
unsigned int getNumInheritedFunctions(const clang::CXXRecordDecl *RD);
void handleOneMemberTemplateFunction(const clang::CXXMethodDecl *MD);
void rewriteDependentExpr(const clang::Expr *E);
void rewriteOverloadExpr(const clang::OverloadExpr *OE);
void rewriteFunctionTemplateExplicitInstantiation(
const clang::FunctionDecl *FD);
void rewriteCXXDependentScopeMemberExpr(
const clang::CXXDependentScopeMemberExpr *DE);
bool getMethodNewName(const clang::CXXMethodDecl *MD, std::string &NewName);
bool hasValidMethods();
bool isExplicit(const clang::CXXMethodDecl *MD);
const clang::FunctionDecl* getFunctionDecl(
const clang::CXXDependentScopeMemberExpr *DE);
const clang::CXXMethodDecl* getCXXMethodFromMemberFunction(
const clang::CXXMethodDecl *MD);
const clang::FunctionDecl* getFunctionDeclFromType(
const clang::Type *Ty, clang::DeclarationName &DName);
const clang::FunctionDecl* getFunctionDeclFromOverloadExpr(
const clang::OverloadExpr *OE);
const clang::FunctionDecl* getFunctionDeclFromReturnType(
const clang::CallExpr *CE, clang::DeclarationName &DName);
const clang::FunctionDecl* getFunctionDeclFromOverloadTemplate(
const clang::CallExpr *CE, const clang::OverloadExpr *OE,
clang::DeclarationName &DName);
bool isValidName(const llvm::StringRef &Name);
void setClassInstantiationFlag(const clang::RecordDecl *RD);
void clearClassInstantiationFlag(void) {
ClassInstantiation = false;
}
void setFunctionInstantiationFlag(const clang::FunctionDecl *FD);
void clearFunctionInstantiationFlag(void) {
FunctionInstantiation = false;
}
RenameCXXMethodCollectionVisitor *MethodCollectionVisitor;
RenameCXXMethodVisitor *RenameVisitor;
const clang::FunctionDecl *CurrentFD;
bool ClassInstantiation;
bool FunctionInstantiation;
bool DoRenaming;
const std::string MethodNamePrefix;
int NumRenamedMethods;
CXXRecordDeclSet VisitedCXXRecordDecls;
CXXMethodDeclSet VisitedSpecializedMethods;
CXXMethodDeclToNameMap NewMethodNames;
CXXRecordDeclToNumMap NumMemberFunctions;
ClassSpecDeclVector InstantiationQueue;
// Unimplemented
RenameCXXMethod();
RenameCXXMethod(const RenameCXXMethod &);
void operator=(const RenameCXXMethod &);
};
#endif
|