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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 return false; | 207 return false; |
208 } | 208 } |
209 | 209 |
210 bool IsBlacklistedFunctionName(llvm::StringRef name) { | 210 bool IsBlacklistedFunctionName(llvm::StringRef name) { |
211 // https://crbug.com/672902: Method names with an underscore are typically | 211 // https://crbug.com/672902: Method names with an underscore are typically |
212 // mimicked after std library / are typically not originating from Blink. | 212 // mimicked after std library / are typically not originating from Blink. |
213 // Do not rewrite such names (like push_back, emplace_back, etc.). | 213 // Do not rewrite such names (like push_back, emplace_back, etc.). |
214 if (name.find('_') != llvm::StringRef::npos) | 214 if (name.find('_') != llvm::StringRef::npos) |
215 return true; | 215 return true; |
216 | 216 |
217 // https://crbug.com/677166: Have to avoid renaming |hash| -> |Hash| to avoid | 217 return false; |
218 // colliding with a struct already named |Hash|. | |
219 return name == "hash"; | |
220 } | 218 } |
221 | 219 |
222 bool IsBlacklistedFreeFunctionName(llvm::StringRef name) { | 220 bool IsBlacklistedFreeFunctionName(llvm::StringRef name) { |
223 // swap() functions should match the signature of std::swap for ADL tricks. | 221 // swap() functions should match the signature of std::swap for ADL tricks. |
224 return name == "swap"; | 222 return name == "swap"; |
225 } | 223 } |
226 | 224 |
227 bool IsBlacklistedInstanceMethodName(llvm::StringRef name) { | 225 bool IsBlacklistedInstanceMethodName(llvm::StringRef name) { |
228 static const char* kBlacklistedNames[] = { | 226 static const char* kBlacklistedNames[] = { |
229 // We should avoid renaming the method names listed below, because | 227 // We should avoid renaming the method names listed below, because |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 // If the expression can be evaluated at compile time, then it should have a | 349 // If the expression can be evaluated at compile time, then it should have a |
352 // kFoo style name. Otherwise, not. | 350 // kFoo style name. Otherwise, not. |
353 return initializer->isEvaluatable(context); | 351 return initializer->isEvaluatable(context); |
354 } | 352 } |
355 | 353 |
356 AST_MATCHER_P(clang::QualType, hasString, std::string, ExpectedString) { | 354 AST_MATCHER_P(clang::QualType, hasString, std::string, ExpectedString) { |
357 return ExpectedString == Node.getAsString(); | 355 return ExpectedString == Node.getAsString(); |
358 } | 356 } |
359 | 357 |
360 bool ShouldPrefixFunctionName(const std::string& old_method_name) { | 358 bool ShouldPrefixFunctionName(const std::string& old_method_name) { |
361 // Methods that are named similarily to a type - they should be prefixed | 359 // Methods that are named similarily to a type - they should be prefixed |
danakj
2017/01/04 18:44:51
Can you fix this comment - "Method" is incorrect h
nasko
2017/01/04 19:03:02
Done.
| |
362 // with a "get" prefix. | 360 // with a "get" prefix. |
363 static const char* kConflictingMethods[] = { | 361 static const char* kConflictingMethods[] = { |
364 "animationWorklet", | 362 "animationWorklet", |
365 "audioWorklet", | 363 "audioWorklet", |
366 "binaryType", | 364 "binaryType", |
367 "blob", | 365 "blob", |
368 "channelCountMode", | 366 "channelCountMode", |
369 "color", | 367 "color", |
370 "counterDirectives", | 368 "counterDirectives", |
371 "document", | 369 "document", |
372 "emptyChromeClient", | 370 "emptyChromeClient", |
373 "emptyEditorClient", | 371 "emptyEditorClient", |
374 "emptySpellCheckerClient", | 372 "emptySpellCheckerClient", |
375 "entryType", | 373 "entryType", |
376 "error", | 374 "error", |
377 "fileUtilities", | 375 "fileUtilities", |
378 "font", | 376 "font", |
379 "frame", | 377 "frame", |
380 "frameBlameContext", | 378 "frameBlameContext", |
379 "frontend", | |
380 "hash", | |
381 "heapObjectHeader", | |
381 "iconURL", | 382 "iconURL", |
382 "inputMethodController", | 383 "inputMethodController", |
383 "inputType", | 384 "inputType", |
384 "layout", | 385 "layout", |
385 "layoutBlock", | 386 "layoutBlock", |
386 "layoutObject", | 387 "layoutObject", |
387 "layoutSize", | 388 "layoutSize", |
388 "length", | 389 "length", |
389 "lineCap", | 390 "lineCap", |
391 "lineEndings", | |
390 "lineJoin", | 392 "lineJoin", |
393 "listItems", | |
391 "matchedProperties", | 394 "matchedProperties", |
395 "midpointState", | |
396 "mouseEvent", | |
392 "name", | 397 "name", |
393 "navigationType", | 398 "navigationType", |
394 "node", | 399 "node", |
395 "outcome", | 400 "outcome", |
396 "pagePopup", | 401 "pagePopup", |
397 "paintWorklet", | 402 "paintWorklet", |
398 "path", | 403 "path", |
399 "processingInstruction", | 404 "processingInstruction", |
400 "readyState", | 405 "readyState", |
406 "relList", | |
407 "resource", | |
401 "response", | 408 "response", |
402 "sandboxSupport", | 409 "sandboxSupport", |
403 "screenInfo", | 410 "screenInfo", |
404 "scrollAnimator", | 411 "scrollAnimator", |
405 "settings", | 412 "settings", |
406 "signalingState", | 413 "signalingState", |
407 "state", | 414 "state", |
408 "string", | 415 "string", |
416 "styleSheet", | |
409 "text", | 417 "text", |
410 "textAlign", | 418 "textAlign", |
411 "textBaseline", | 419 "textBaseline", |
412 "theme", | 420 "theme", |
421 "thread", | |
413 "timing", | 422 "timing", |
414 "topLevelBlameContext", | 423 "topLevelBlameContext", |
424 "vector", | |
415 "widget", | 425 "widget", |
426 "wordBoundaries", | |
427 "wrapperTypeInfo", | |
416 }; | 428 }; |
417 for (const auto& conflicting_method : kConflictingMethods) { | 429 for (const auto& conflicting_method : kConflictingMethods) { |
418 if (old_method_name == conflicting_method) | 430 if (old_method_name == conflicting_method) |
419 return true; | 431 return true; |
420 } | 432 } |
421 | 433 |
422 return false; | 434 return false; |
423 } | 435 } |
424 | 436 |
425 AST_MATCHER(clang::FunctionDecl, shouldPrefixFunctionName) { | 437 AST_MATCHER(clang::FunctionDecl, shouldPrefixFunctionName) { |
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1392 for (const auto& r : replacements) { | 1404 for (const auto& r : replacements) { |
1393 std::string replacement_text = r.getReplacementText().str(); | 1405 std::string replacement_text = r.getReplacementText().str(); |
1394 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); | 1406 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); |
1395 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() | 1407 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() |
1396 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; | 1408 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; |
1397 } | 1409 } |
1398 llvm::outs() << "==== END EDITS ====\n"; | 1410 llvm::outs() << "==== END EDITS ====\n"; |
1399 | 1411 |
1400 return 0; | 1412 return 0; |
1401 } | 1413 } |
OLD | NEW |