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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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|. See also | |
350 // https://llvm.org/bugs/show_bug.cgi?id=29145 | |
dcheng
2016/08/26 20:28:02
Perhaps describe the actual bug a bit here: a meth
Łukasz Anforowicz
2016/08/26 22:39:51
Done.
| |
351 clang::SourceLocation loc = | |
352 context.getSourceManager().getSpellingLoc(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 (old_text != original_name) | |
357 return false; | |
358 } | |
347 | 359 |
348 // static class members match against VarDecls. Blink style dictates that | 360 // 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_` | 361 // 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. | 362 // and strip that off too, for code that accidentally uses the wrong prefix. |
351 if (original_name.startswith(kBlinkStaticMemberPrefix)) | 363 if (original_name.startswith(kBlinkStaticMemberPrefix)) |
352 original_name = original_name.substr(strlen(kBlinkStaticMemberPrefix)); | 364 original_name = original_name.substr(strlen(kBlinkStaticMemberPrefix)); |
353 else if (original_name.startswith(kBlinkFieldPrefix)) | 365 else if (original_name.startswith(kBlinkFieldPrefix)) |
354 original_name = original_name.substr(strlen(kBlinkFieldPrefix)); | 366 original_name = original_name.substr(strlen(kBlinkFieldPrefix)); |
355 | 367 |
356 bool is_const = IsProbablyConst(decl, context); | 368 bool is_const = IsProbablyConst(decl, context); |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
879 for (const auto& r : replacements) { | 891 for (const auto& r : replacements) { |
880 std::string replacement_text = r.getReplacementText().str(); | 892 std::string replacement_text = r.getReplacementText().str(); |
881 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); | 893 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); |
882 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() | 894 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() |
883 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; | 895 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; |
884 } | 896 } |
885 llvm::outs() << "==== END EDITS ====\n"; | 897 llvm::outs() << "==== END EDITS ====\n"; |
886 | 898 |
887 return 0; | 899 return 0; |
888 } | 900 } |
OLD | NEW |