Chromium Code Reviews| 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: |
| 11 // const int maxThings => const int kMaxThings | 11 // const int maxThings => const int kMaxThings |
| 12 // free functions and methods: | 12 // free functions and methods: |
| 13 // void doThisThenThat() => void DoThisAndThat() | 13 // void doThisThenThat() => void DoThisAndThat() |
| 14 | 14 |
| 15 #include <assert.h> | 15 #include <assert.h> |
| 16 #include <algorithm> | 16 #include <algorithm> |
| 17 #include <fstream> | 17 #include <fstream> |
| 18 #include <memory> | 18 #include <memory> |
| 19 #include <string> | 19 #include <string> |
| 20 #include <unordered_map> | 20 #include <unordered_map> |
| 21 #include <unordered_set> | 21 #include <unordered_set> |
| 22 | 22 |
| 23 #if defined(_WIN32) | |
| 24 #include <windows.h> | |
| 25 #else | |
| 26 #include <sys/file.h> | |
| 27 #include <unistd.h> | |
| 28 #endif | |
| 29 | |
| 23 #include "clang/AST/ASTContext.h" | 30 #include "clang/AST/ASTContext.h" |
| 24 #include "clang/ASTMatchers/ASTMatchFinder.h" | 31 #include "clang/ASTMatchers/ASTMatchFinder.h" |
| 25 #include "clang/ASTMatchers/ASTMatchers.h" | 32 #include "clang/ASTMatchers/ASTMatchers.h" |
| 26 #include "clang/ASTMatchers/ASTMatchersMacros.h" | 33 #include "clang/ASTMatchers/ASTMatchersMacros.h" |
| 27 #include "clang/Basic/CharInfo.h" | 34 #include "clang/Basic/CharInfo.h" |
| 28 #include "clang/Basic/SourceManager.h" | 35 #include "clang/Basic/SourceManager.h" |
| 29 #include "clang/Frontend/FrontendActions.h" | 36 #include "clang/Frontend/FrontendActions.h" |
| 30 #include "clang/Lex/Lexer.h" | 37 #include "clang/Lex/Lexer.h" |
| 31 #include "clang/Tooling/CommonOptionsParser.h" | 38 #include "clang/Tooling/CommonOptionsParser.h" |
| 32 #include "clang/Tooling/Refactoring.h" | 39 #include "clang/Tooling/Refactoring.h" |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 504 &replacements); | 511 &replacements); |
| 505 match_finder.addMatcher(constructor_initializer_matcher, | 512 match_finder.addMatcher(constructor_initializer_matcher, |
| 506 &constructor_initializer_rewriter); | 513 &constructor_initializer_rewriter); |
| 507 | 514 |
| 508 std::unique_ptr<clang::tooling::FrontendActionFactory> factory = | 515 std::unique_ptr<clang::tooling::FrontendActionFactory> factory = |
| 509 clang::tooling::newFrontendActionFactory(&match_finder); | 516 clang::tooling::newFrontendActionFactory(&match_finder); |
| 510 int result = tool.run(factory.get()); | 517 int result = tool.run(factory.get()); |
| 511 if (result != 0) | 518 if (result != 0) |
| 512 return result; | 519 return result; |
| 513 | 520 |
| 521 #if defined(_WIN32) | |
| 522 OFSTRUCT lockfd_out; | |
| 523 HFILE lockfd = OpenFile("rewrite-sym.lock", &lockfd_out, OF_CREATE); | |
|
dcheng
2016/01/26 07:04:15
It might be slightly more robust to use CreateFile
danakj
2016/01/26 23:34:52
Done. I think.
| |
| 524 OVERLAPPED lock_out = {}; | |
| 525 LockFileEx(lockfd, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &lock_out); | |
| 526 #else | |
| 527 int lockfd = open("rewrite-sym.lock", O_RDWR | O_CREAT, 0666); | |
| 528 while (flock(lockfd, LOCK_EX)) { // :D | |
| 529 } | |
| 530 #endif | |
| 531 | |
| 514 std::ofstream replacement_db_file("rewrite-sym.txt", | 532 std::ofstream replacement_db_file("rewrite-sym.txt", |
| 515 std::ios_base::out | std::ios_base::app); | 533 std::ios_base::out | std::ios_base::app); |
| 516 for (const auto& p : field_decl_rewriter.replacement_names()) | 534 for (const auto& p : field_decl_rewriter.replacement_names()) |
| 517 replacement_db_file << "var:" << p.first << ":" << p.second << "\n"; | 535 replacement_db_file << "var:" << p.first << ":" << p.second << "\n"; |
| 518 for (const auto& p : var_decl_rewriter.replacement_names()) | 536 for (const auto& p : var_decl_rewriter.replacement_names()) |
| 519 replacement_db_file << "var:" << p.first << ":" << p.second << "\n"; | 537 replacement_db_file << "var:" << p.first << ":" << p.second << "\n"; |
| 520 for (const auto& p : function_decl_rewriter.replacement_names()) | 538 for (const auto& p : function_decl_rewriter.replacement_names()) |
| 521 replacement_db_file << "fun:" << p.first << ":" << p.second << "\n"; | 539 replacement_db_file << "fun:" << p.first << ":" << p.second << "\n"; |
| 522 for (const auto& p : method_decl_rewriter.replacement_names()) | 540 for (const auto& p : method_decl_rewriter.replacement_names()) |
| 523 replacement_db_file << "fun:" << p.first << ":" << p.second << "\n"; | 541 replacement_db_file << "fun:" << p.first << ":" << p.second << "\n"; |
| 524 replacement_db_file.close(); | 542 replacement_db_file.close(); |
| 525 | 543 |
| 544 #if defined(_WIN32) | |
| 545 UnlockFile(lockfd, 0, 0, 1, 0); | |
|
dcheng
2016/01/26 07:04:15
Nit: UnlockFileEx for symmetry? The parameters are
danakj
2016/01/26 23:34:52
Done.
| |
| 546 CloseHandle(lockfd); | |
| 547 #else | |
| 548 flock(lockfd, LOCK_UN); | |
| 549 close(lockfd); | |
| 550 #endif | |
| 551 | |
| 526 // Serialization format is documented in tools/clang/scripts/run_tool.py | 552 // Serialization format is documented in tools/clang/scripts/run_tool.py |
| 527 llvm::outs() << "==== BEGIN EDITS ====\n"; | 553 llvm::outs() << "==== BEGIN EDITS ====\n"; |
| 528 for (const auto& r : replacements) { | 554 for (const auto& r : replacements) { |
| 529 std::string replacement_text = r.getReplacementText().str(); | 555 std::string replacement_text = r.getReplacementText().str(); |
| 530 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); | 556 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); |
| 531 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() | 557 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() |
| 532 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; | 558 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; |
| 533 } | 559 } |
| 534 llvm::outs() << "==== END EDITS ====\n"; | 560 llvm::outs() << "==== END EDITS ====\n"; |
| 535 | 561 |
| 536 return 0; | 562 return 0; |
| 537 } | 563 } |
| OLD | NEW |