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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 } |
OLD | NEW |