Chromium Code Reviews| 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 // instantiation of the template and see if they are all compile-time | 283 // instantiation of the template and see if they are all compile-time |
| 284 // isEvaluable(). | 284 // isEvaluable(). |
| 285 if (initializer->isInstantiationDependent()) | 285 if (initializer->isInstantiationDependent()) |
| 286 return false; | 286 return false; |
| 287 | 287 |
| 288 // If the expression can be evaluated at compile time, then it should have a | 288 // If the expression can be evaluated at compile time, then it should have a |
| 289 // kFoo style name. Otherwise, not. | 289 // kFoo style name. Otherwise, not. |
| 290 return initializer->isEvaluatable(context); | 290 return initializer->isEvaluatable(context); |
| 291 } | 291 } |
| 292 | 292 |
| 293 AST_MATCHER_P(clang::QualType, hasString, std::string, ExpectedString) { | |
| 294 return ExpectedString == Node.getAsString(); | |
| 295 } | |
| 296 | |
| 293 bool GetNameForDecl(const clang::FunctionDecl& decl, | 297 bool GetNameForDecl(const clang::FunctionDecl& decl, |
| 294 clang::ASTContext& context, | 298 clang::ASTContext& context, |
| 295 std::string& name) { | 299 std::string& name) { |
| 296 name = decl.getName().str(); | 300 name = decl.getName().str(); |
| 297 name[0] = clang::toUppercase(name[0]); | 301 name[0] = clang::toUppercase(name[0]); |
| 298 | 302 |
| 299 // https://crbug.com/582312: Prepend "Get" if method name conflicts with type. | 303 // https://crbug.com/582312: Prepend "Get" if method name conflicts with type. |
| 300 const clang::IdentifierInfo* return_type = | 304 auto type_with_same_name_as_function = qualType( |
| 301 decl.getReturnType().getBaseTypeIdentifier(); | 305 anyOf(hasDeclaration(namedDecl(hasName(name))), hasString(name))); |
|
Łukasz Anforowicz
2016/09/07 23:14:28
Without |hasString| we wouldn't properly handle th
danakj
2016/09/08 23:30:40
Can you leave a comment here saying that hasName()
Łukasz Anforowicz
2016/09/09 00:20:35
Done.
| |
| 302 if (return_type && return_type->getName() == name) | 306 auto type_containing_same_name_as_function = |
| 307 qualType(anyOf(type_with_same_name_as_function, | |
| 308 hasDescendant(type_with_same_name_as_function))); | |
|
Łukasz Anforowicz
2016/09/07 23:14:28
|hasDescendant| helps catch the RefPtr<SameNameAsF
| |
| 309 auto conflict_matcher = | |
| 310 functionDecl(returns(type_containing_same_name_as_function)); | |
| 311 if (!match(conflict_matcher, decl, context).empty()) | |
| 303 name = "Get" + name; | 312 name = "Get" + name; |
| 304 | 313 |
| 305 return true; | 314 return true; |
| 306 } | 315 } |
| 307 | 316 |
| 308 bool GetNameForDecl(const clang::EnumConstantDecl& decl, | 317 bool GetNameForDecl(const clang::EnumConstantDecl& decl, |
| 309 clang::ASTContext& context, | 318 clang::ASTContext& context, |
| 310 std::string& name) { | 319 std::string& name) { |
| 311 StringRef original_name = decl.getName(); | 320 StringRef original_name = decl.getName(); |
| 312 | 321 |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 for (const auto& r : replacements) { | 941 for (const auto& r : replacements) { |
| 933 std::string replacement_text = r.getReplacementText().str(); | 942 std::string replacement_text = r.getReplacementText().str(); |
| 934 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); | 943 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); |
| 935 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() | 944 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() |
| 936 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; | 945 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; |
| 937 } | 946 } |
| 938 llvm::outs() << "==== END EDITS ====\n"; | 947 llvm::outs() << "==== END EDITS ====\n"; |
| 939 | 948 |
| 940 return 0; | 949 return 0; |
| 941 } | 950 } |
| OLD | NEW |