OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Changes Blink-style names to Chrome-style names. Currently transforms: | 5 // Changes Blink-style names to Chrome-style names. Currently transforms: |
6 // fields: | 6 // fields: |
7 // int m_operationCount => int operation_count_ | 7 // int m_operationCount => int operation_count_ |
8 // variables (including parameters): | 8 // variables (including parameters): |
9 // int mySuperVariable => int my_super_variable | 9 // int mySuperVariable => int my_super_variable |
10 // constants: | 10 // constants: |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 if (decl.getParent()->getQualifiedNameAsString() == class_name) | 200 if (decl.getParent()->getQualifiedNameAsString() == class_name) |
201 return true; | 201 return true; |
202 for (auto it = decl.begin_overridden_methods(); | 202 for (auto it = decl.begin_overridden_methods(); |
203 it != decl.end_overridden_methods(); ++it) { | 203 it != decl.end_overridden_methods(); ++it) { |
204 if (IsMethodOverrideOf(**it, class_name)) | 204 if (IsMethodOverrideOf(**it, class_name)) |
205 return true; | 205 return true; |
206 } | 206 } |
207 return false; | 207 return false; |
208 } | 208 } |
209 | 209 |
210 bool IsBlacklistedFunction(const clang::FunctionDecl& decl) { | 210 bool IsBlacklistedFunctionOrInstanceOrStaticMethodName(llvm::StringRef name) { |
dcheng
2016/12/27 20:30:40
I find the naming of this helper to be a bit confu
Łukasz Anforowicz
2016/12/27 22:42:43
Done.
| |
211 // swap() functions should match the signature of std::swap for ADL tricks. | 211 // https://crbug.com/677166: Have to avoid renaming |hash| -> |Hash| to avoid |
212 return decl.getName() == "swap"; | 212 // colliding with a struct already named |Hash|. |
213 return name == "hash"; | |
213 } | 214 } |
214 | 215 |
215 bool IsBlacklistedMethodName(llvm::StringRef name) { | 216 bool IsBlacklistedFunctionName(llvm::StringRef name) { |
217 // swap() functions should match the signature of std::swap for ADL tricks. | |
218 return name == "swap"; | |
dcheng
2016/12/27 20:30:40
And call this "IsBlacklistedFreeFunctionName" (sin
Łukasz Anforowicz
2016/12/27 22:42:43
Done.
| |
219 } | |
220 | |
221 bool IsBlacklistedInstanceMethodName(llvm::StringRef name) { | |
222 if (IsBlacklistedFunctionOrInstanceOrStaticMethodName(name)) | |
223 return true; | |
224 | |
216 static const char* kBlacklistedNames[] = { | 225 static const char* kBlacklistedNames[] = { |
217 "hash", | 226 // We should avoid renaming the method names listed below, because |
218 "lock", "unlock", "try_lock", | 227 // 1. They are used in templated code (e.g. in <algorithms>) |
219 "begin", "end", "rbegin", "rend", | 228 // 2. They (begin+end) are used in range-based for syntax sugar |
229 // - for (auto x : foo) { ... } // <- foo.begin() will be called. | |
230 "begin", "end", "rbegin", "rend", "lock", "unlock", "try_lock", | |
220 }; | 231 }; |
221 for (const auto& b : kBlacklistedNames) { | 232 for (const auto& b : kBlacklistedNames) { |
222 if (name == b) | 233 if (name == b) |
223 return true; | 234 return true; |
224 } | 235 } |
225 return false; | 236 return false; |
226 } | 237 } |
227 | 238 |
239 bool IsBlacklistedStaticMethodName(llvm::StringRef name) { | |
240 return IsBlacklistedFunctionOrInstanceOrStaticMethodName(name); | |
241 } | |
242 | |
243 bool IsBlacklistedMethodName(llvm::StringRef name) { | |
244 return IsBlacklistedStaticMethodName(name) || | |
245 IsBlacklistedInstanceMethodName(name); | |
246 } | |
247 | |
248 bool IsBlacklistedFunction(const clang::FunctionDecl& decl) { | |
249 clang::StringRef name = decl.getName(); | |
250 return IsBlacklistedFunctionOrInstanceOrStaticMethodName(name) || | |
251 IsBlacklistedFunctionName(name); | |
252 } | |
253 | |
228 bool IsBlacklistedMethod(const clang::CXXMethodDecl& decl) { | 254 bool IsBlacklistedMethod(const clang::CXXMethodDecl& decl) { |
255 clang::StringRef name = decl.getName(); | |
229 if (decl.isStatic()) | 256 if (decl.isStatic()) |
230 return false; | 257 return IsBlacklistedStaticMethodName(name); |
231 | 258 |
232 clang::StringRef name = decl.getName(); | 259 if (IsBlacklistedInstanceMethodName(name)) |
233 if (IsBlacklistedMethodName(name)) | 260 return true; |
234 return true; | |
235 | 261 |
236 // Subclasses of InspectorAgent will subclass "disable()" from both blink and | 262 // Subclasses of InspectorAgent will subclass "disable()" from both blink and |
237 // from gen/, which is problematic, but DevTools folks don't want to rename | 263 // from gen/, which is problematic, but DevTools folks don't want to rename |
238 // it or split this up. So don't rename it at all. | 264 // it or split this up. So don't rename it at all. |
239 if (name.equals("disable") && | 265 if (name.equals("disable") && |
240 IsMethodOverrideOf(decl, "blink::InspectorAgent")) | 266 IsMethodOverrideOf(decl, "blink::InspectorAgent")) |
241 return true; | 267 return true; |
242 | 268 |
243 return false; | 269 return false; |
244 } | 270 } |
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1294 for (const auto& r : replacements) { | 1320 for (const auto& r : replacements) { |
1295 std::string replacement_text = r.getReplacementText().str(); | 1321 std::string replacement_text = r.getReplacementText().str(); |
1296 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); | 1322 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); |
1297 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() | 1323 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() |
1298 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; | 1324 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; |
1299 } | 1325 } |
1300 llvm::outs() << "==== END EDITS ====\n"; | 1326 llvm::outs() << "==== END EDITS ====\n"; |
1301 | 1327 |
1302 return 0; | 1328 return 0; |
1303 } | 1329 } |
OLD | NEW |