| 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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 const clang::CXXRecordDecl* parent = | 368 const clang::CXXRecordDecl* parent = |
| 369 clang::dyn_cast_or_null<clang::CXXRecordDecl>(decl_context); | 369 clang::dyn_cast_or_null<clang::CXXRecordDecl>(decl_context); |
| 370 if (is_in_wtf && parent && parent->isStruct()) | 370 if (is_in_wtf && parent && parent->isStruct()) |
| 371 return false; | 371 return false; |
| 372 | 372 |
| 373 name = 'k'; | 373 name = 'k'; |
| 374 name.append(original_name.data(), original_name.size()); | 374 name.append(original_name.data(), original_name.size()); |
| 375 name[1] = clang::toUppercase(name[1]); | 375 name[1] = clang::toUppercase(name[1]); |
| 376 } else { | 376 } else { |
| 377 name = CamelCaseToUnderscoreCase(original_name); | 377 name = CamelCaseToUnderscoreCase(original_name); |
| 378 |
| 379 // Non-const variables with static storage duration at namespace scope are |
| 380 // prefixed with `g_' to reduce the likelihood of a naming collision. |
| 381 const clang::DeclContext* decl_context = decl.getDeclContext(); |
| 382 if (name.find("g_") != 0 && decl.hasGlobalStorage() && |
| 383 decl_context->isNamespace()) |
| 384 name.insert(0, "g_"); |
| 378 } | 385 } |
| 379 | 386 |
| 380 // Static members end with _ just like other members, but constants should | 387 // Static members end with _ just like other members, but constants should |
| 381 // not. | 388 // not. |
| 382 if (!is_const && decl.isStaticDataMember()) { | 389 if (!is_const && decl.isStaticDataMember()) { |
| 383 name += '_'; | 390 name += '_'; |
| 384 } | 391 } |
| 385 | 392 |
| 386 return true; | 393 return true; |
| 387 } | 394 } |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 for (const auto& r : replacements) { | 849 for (const auto& r : replacements) { |
| 843 std::string replacement_text = r.getReplacementText().str(); | 850 std::string replacement_text = r.getReplacementText().str(); |
| 844 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); | 851 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); |
| 845 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() | 852 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() |
| 846 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; | 853 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; |
| 847 } | 854 } |
| 848 llvm::outs() << "==== END EDITS ====\n"; | 855 llvm::outs() << "==== END EDITS ====\n"; |
| 849 | 856 |
| 850 return 0; | 857 return 0; |
| 851 } | 858 } |
| OLD | NEW |