Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp

Issue 1839573002: rewrite_to_chrome_style: making globals great again. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: And we'll let the translation units pay for it. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/variables-expected.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 translation unit or
danakj 2016/03/28 18:28:33 update this then
dcheng 2016/03/28 19:50:54 Done.
380 // namespace scope get prefixed with `g_' to reduce the likelihood of a
381 // naming collision.
382 const clang::DeclContext* decl_context = decl.getDeclContext();
383 if (name.find("g_") != 0 && decl.hasGlobalStorage() &&
384 decl_context->isNamespace())
danakj 2016/03/28 18:28:33 OK can you have global storage and not be isNamesp
dcheng 2016/03/28 19:50:54 Yeah, static locals inside functions.
danakj 2016/03/28 19:54:06 ooh, cool
385 name.insert(0, "g_");
378 } 386 }
379 387
380 // Static members end with _ just like other members, but constants should 388 // Static members end with _ just like other members, but constants should
381 // not. 389 // not.
382 if (!is_const && decl.isStaticDataMember()) { 390 if (!is_const && decl.isStaticDataMember()) {
383 name += '_'; 391 name += '_';
384 } 392 }
385 393
386 return true; 394 return true;
387 } 395 }
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 for (const auto& r : replacements) { 850 for (const auto& r : replacements) {
843 std::string replacement_text = r.getReplacementText().str(); 851 std::string replacement_text = r.getReplacementText().str();
844 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 852 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
845 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 853 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
846 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 854 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
847 } 855 }
848 llvm::outs() << "==== END EDITS ====\n"; 856 llvm::outs() << "==== END EDITS ====\n";
849 857
850 return 0; 858 return 0;
851 } 859 }
OLDNEW
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/variables-expected.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698