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 <string.h> | |
16 #include <algorithm> | 17 #include <algorithm> |
17 #include <fstream> | 18 #include <fstream> |
18 #include <memory> | 19 #include <memory> |
19 #include <string> | 20 #include <string> |
20 #include <unordered_map> | 21 #include <unordered_map> |
21 #include <unordered_set> | 22 #include <unordered_set> |
22 | 23 |
24 #if defined(_WIN32) | |
25 #include <windows.h> | |
26 #else | |
27 #include <sys/file.h> | |
28 #include <unistd.h> | |
29 #endif | |
30 | |
23 #include "clang/AST/ASTContext.h" | 31 #include "clang/AST/ASTContext.h" |
24 #include "clang/ASTMatchers/ASTMatchFinder.h" | 32 #include "clang/ASTMatchers/ASTMatchFinder.h" |
25 #include "clang/ASTMatchers/ASTMatchers.h" | 33 #include "clang/ASTMatchers/ASTMatchers.h" |
26 #include "clang/ASTMatchers/ASTMatchersMacros.h" | 34 #include "clang/ASTMatchers/ASTMatchersMacros.h" |
27 #include "clang/Basic/CharInfo.h" | 35 #include "clang/Basic/CharInfo.h" |
28 #include "clang/Basic/SourceManager.h" | 36 #include "clang/Basic/SourceManager.h" |
29 #include "clang/Frontend/FrontendActions.h" | 37 #include "clang/Frontend/FrontendActions.h" |
30 #include "clang/Lex/Lexer.h" | 38 #include "clang/Lex/Lexer.h" |
31 #include "clang/Tooling/CommonOptionsParser.h" | 39 #include "clang/Tooling/CommonOptionsParser.h" |
32 #include "clang/Tooling/Refactoring.h" | 40 #include "clang/Tooling/Refactoring.h" |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
504 &replacements); | 512 &replacements); |
505 match_finder.addMatcher(constructor_initializer_matcher, | 513 match_finder.addMatcher(constructor_initializer_matcher, |
506 &constructor_initializer_rewriter); | 514 &constructor_initializer_rewriter); |
507 | 515 |
508 std::unique_ptr<clang::tooling::FrontendActionFactory> factory = | 516 std::unique_ptr<clang::tooling::FrontendActionFactory> factory = |
509 clang::tooling::newFrontendActionFactory(&match_finder); | 517 clang::tooling::newFrontendActionFactory(&match_finder); |
510 int result = tool.run(factory.get()); | 518 int result = tool.run(factory.get()); |
511 if (result != 0) | 519 if (result != 0) |
512 return result; | 520 return result; |
513 | 521 |
522 #if defined(_WIN32) | |
523 OFSTRUCT lockfd_out; | |
524 HFILE lockfd = OpenFile("rewrite-sym.lock", &lockfd_out, OF_CREATE); | |
525 OVERLAPPED lock_out; | |
526 memset(&lock_out, 0, sizeof(lock_out)); | |
dcheng
2016/01/22 00:31:30
OVERLAPPED lock_out = {};
then you can skip the m
danakj
2016/01/22 23:33:36
Fancy~
| |
527 LockFileEx(lockfd, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &lock_out); | |
528 #else | |
529 int lockfd = open("rewrite-sym.lock", O_RDWR | O_CREAT, 0666); | |
530 while (flock(lockfd, LOCK_EX)) { // :D | |
dcheng
2016/01/22 00:31:30
Do we need to worry about contention here? Is ther
danakj
2016/01/22 23:33:36
I think it's okay, it takes like ~20min to run the
| |
531 } | |
532 #endif | |
533 | |
514 std::ofstream replacement_db_file("rewrite-sym.txt", | 534 std::ofstream replacement_db_file("rewrite-sym.txt", |
515 std::ios_base::out | std::ios_base::app); | 535 std::ios_base::out | std::ios_base::app); |
516 for (const auto& p : field_decl_rewriter.replacement_names()) | 536 for (const auto& p : field_decl_rewriter.replacement_names()) |
517 replacement_db_file << "var:" << p.first << ":" << p.second << "\n"; | 537 replacement_db_file << "var:" << p.first << ":" << p.second << "\n"; |
518 for (const auto& p : var_decl_rewriter.replacement_names()) | 538 for (const auto& p : var_decl_rewriter.replacement_names()) |
519 replacement_db_file << "var:" << p.first << ":" << p.second << "\n"; | 539 replacement_db_file << "var:" << p.first << ":" << p.second << "\n"; |
520 for (const auto& p : function_decl_rewriter.replacement_names()) | 540 for (const auto& p : function_decl_rewriter.replacement_names()) |
521 replacement_db_file << "fun:" << p.first << ":" << p.second << "\n"; | 541 replacement_db_file << "fun:" << p.first << ":" << p.second << "\n"; |
522 for (const auto& p : method_decl_rewriter.replacement_names()) | 542 for (const auto& p : method_decl_rewriter.replacement_names()) |
523 replacement_db_file << "fun:" << p.first << ":" << p.second << "\n"; | 543 replacement_db_file << "fun:" << p.first << ":" << p.second << "\n"; |
524 replacement_db_file.close(); | 544 replacement_db_file.close(); |
525 | 545 |
546 #if defined(_WIN32) | |
547 UnlockFile(lockfd, 0, 0, 1, 0); | |
548 CloseHandle(lockfd); | |
549 #else | |
550 flock(lockfd, LOCK_UN); | |
551 close(lockfd); | |
552 #endif | |
553 | |
526 // Serialization format is documented in tools/clang/scripts/run_tool.py | 554 // Serialization format is documented in tools/clang/scripts/run_tool.py |
527 llvm::outs() << "==== BEGIN EDITS ====\n"; | 555 llvm::outs() << "==== BEGIN EDITS ====\n"; |
528 for (const auto& r : replacements) { | 556 for (const auto& r : replacements) { |
529 std::string replacement_text = r.getReplacementText().str(); | 557 std::string replacement_text = r.getReplacementText().str(); |
530 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); | 558 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); |
531 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() | 559 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() |
532 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; | 560 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; |
533 } | 561 } |
534 llvm::outs() << "==== END EDITS ====\n"; | 562 llvm::outs() << "==== END EDITS ====\n"; |
535 | 563 |
536 return 0; | 564 return 0; |
537 } | 565 } |
OLD | NEW |