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

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

Issue 1644803002: rewrite_to_chrome_style: Don't put a trailing _ on static consts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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/constants-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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 return false; 149 return false;
150 150
151 // static class members match against VarDecls. Blink style dictates that 151 // static class members match against VarDecls. Blink style dictates that
152 // these should be prefixed with `s_`, so strip that off. Also check for `m_` 152 // these should be prefixed with `s_`, so strip that off. Also check for `m_`
153 // and strip that off too, for code that accidentally uses the wrong prefix. 153 // and strip that off too, for code that accidentally uses the wrong prefix.
154 if (original_name.startswith(kBlinkStaticMemberPrefix)) 154 if (original_name.startswith(kBlinkStaticMemberPrefix))
155 original_name = original_name.substr(strlen(kBlinkStaticMemberPrefix)); 155 original_name = original_name.substr(strlen(kBlinkStaticMemberPrefix));
156 else if (original_name.startswith(kBlinkFieldPrefix)) 156 else if (original_name.startswith(kBlinkFieldPrefix))
157 original_name = original_name.substr(strlen(kBlinkFieldPrefix)); 157 original_name = original_name.substr(strlen(kBlinkFieldPrefix));
158 158
159 if (IsProbablyConst(decl, context)) { 159 bool is_const = IsProbablyConst(decl, context);
160 if (is_const) {
160 // Don't try to rename constants that already conform to Chrome style. 161 // Don't try to rename constants that already conform to Chrome style.
161 if (original_name.size() >= 2 && original_name[0] == 'k' && 162 if (original_name.size() >= 2 && original_name[0] == 'k' &&
162 clang::isUppercase(original_name[1])) 163 clang::isUppercase(original_name[1]))
163 return false; 164 return false;
164 name = 'k'; 165 name = 'k';
165 name.append(original_name.data(), original_name.size()); 166 name.append(original_name.data(), original_name.size());
166 name[1] = clang::toUppercase(name[1]); 167 name[1] = clang::toUppercase(name[1]);
167 } else { 168 } else {
168 name = CamelCaseToUnderscoreCase(original_name); 169 name = CamelCaseToUnderscoreCase(original_name);
169 } 170 }
170 171
171 if (decl.isStaticDataMember()) { 172 // Static members end with _ just like other members, but constants should
173 // not.
174 if (!is_const && decl.isStaticDataMember()) {
172 name += '_'; 175 name += '_';
173 } 176 }
174 177
175 return true; 178 return true;
176 } 179 }
177 180
178 template <typename Type> 181 template <typename Type>
179 struct TargetNodeTraits; 182 struct TargetNodeTraits;
180 183
181 template <> 184 template <>
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 for (const auto& r : replacements) { 558 for (const auto& r : replacements) {
556 std::string replacement_text = r.getReplacementText().str(); 559 std::string replacement_text = r.getReplacementText().str();
557 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 560 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
558 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 561 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
559 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 562 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
560 } 563 }
561 llvm::outs() << "==== END EDITS ====\n"; 564 llvm::outs() << "==== END EDITS ====\n";
562 565
563 return 0; 566 return 0;
564 } 567 }
OLDNEW
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/constants-expected.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698