Debian Codegraph @

clang_delta/RenameCXXMethod.h

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