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

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

Issue 2246263002: Skip parameter replacements where old text != old name. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Self-review. Created 4 years, 4 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
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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 335
336 return true; 336 return true;
337 } 337 }
338 338
339 bool GetNameForDecl(const clang::VarDecl& decl, 339 bool GetNameForDecl(const clang::VarDecl& decl,
340 const clang::ASTContext& context, 340 const clang::ASTContext& context,
341 std::string& name) { 341 std::string& name) {
342 StringRef original_name = decl.getName(); 342 StringRef original_name = decl.getName();
343 343
344 // Nothing to do for unnamed parameters. 344 // Nothing to do for unnamed parameters.
345 if (clang::isa<clang::ParmVarDecl>(decl) && original_name.empty()) 345 if (clang::isa<clang::ParmVarDecl>(decl)) {
346 return false; 346 if (original_name.empty())
347 return false;
348
349 // Check if |decl| really covers text of |original_name|. This might not be
350 // true when specializing a templatized class that had an unnamed parameter
351 // in one of method declarations.
dcheng 2016/08/25 04:08:51 Let's file an upstream bug for this with the test
Łukasz Anforowicz 2016/08/25 23:32:33 Done: https://llvm.org/bugs/show_bug.cgi?id=29145
352 clang::SourceLocation loc = decl.getLocation();
353 clang::CharSourceRange range = clang::CharSourceRange::getTokenRange(loc);
354 StringRef old_text = clang::Lexer::getSourceText(
355 range, context.getSourceManager(), context.getLangOpts());
356 if (!loc.isMacroID() && old_text != original_name) {
dcheng 2016/08/25 04:08:52 Add a comment why we want to ignore SourceLocation
Łukasz Anforowicz 2016/08/25 23:32:33 I've started using spelling location in the latest
357 return false;
358 }
359 }
347 360
348 // static class members match against VarDecls. Blink style dictates that 361 // static class members match against VarDecls. Blink style dictates that
349 // these should be prefixed with `s_`, so strip that off. Also check for `m_` 362 // these should be prefixed with `s_`, so strip that off. Also check for `m_`
350 // and strip that off too, for code that accidentally uses the wrong prefix. 363 // and strip that off too, for code that accidentally uses the wrong prefix.
351 if (original_name.startswith(kBlinkStaticMemberPrefix)) 364 if (original_name.startswith(kBlinkStaticMemberPrefix))
352 original_name = original_name.substr(strlen(kBlinkStaticMemberPrefix)); 365 original_name = original_name.substr(strlen(kBlinkStaticMemberPrefix));
353 else if (original_name.startswith(kBlinkFieldPrefix)) 366 else if (original_name.startswith(kBlinkFieldPrefix))
354 original_name = original_name.substr(strlen(kBlinkFieldPrefix)); 367 original_name = original_name.substr(strlen(kBlinkFieldPrefix));
355 368
356 bool is_const = IsProbablyConst(decl, context); 369 bool is_const = IsProbablyConst(decl, context);
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 for (const auto& r : replacements) { 892 for (const auto& r : replacements) {
880 std::string replacement_text = r.getReplacementText().str(); 893 std::string replacement_text = r.getReplacementText().str();
881 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 894 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
882 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 895 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
883 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 896 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
884 } 897 }
885 llvm::outs() << "==== END EDITS ====\n"; 898 llvm::outs() << "==== END EDITS ====\n";
886 899
887 return 0; 900 return 0;
888 } 901 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698