This is the first change as part of developing a clang-query based search and replace tool.
Details
- Reviewers
klimek ioeric jbangert bkramer sbenza - Commits
- rGfc9213e0e518: Add ASTMatchRefactorer and ReplaceNodeWithTemplate to RefactoringCallbacks
rC302624: Add ASTMatchRefactorer and ReplaceNodeWithTemplate to RefactoringCallbacks
rL302624: Add ASTMatchRefactorer and ReplaceNodeWithTemplate to RefactoringCallbacks
Diff Detail
- Repository
- rL LLVM
Event Timeline
| lib/Tooling/RefactoringCallbacks.cpp | ||
|---|---|---|
| 42 ↗ | (On Diff #87372) | Could you add a comment here explaining why the replacements in callbacks need to be cleared? |
| 165 ↗ | (On Diff #87372) | Just use if since there is a continue? |
| 170 ↗ | (On Diff #87372) | You might want to use llvm_unreachable instead so that it also bails out in non-assertion build. |
| 211 ↗ | (On Diff #87372) | Looks like you are using clang-format with Google-style. Please reformat your changes with LLVM style. |
| include/clang/Tooling/RefactoringCallbacks.h | ||
|---|---|---|
| 61 ↗ | (On Diff #87372) | Why emplace_back instead of push_back? |
| lib/Tooling/RefactoringCallbacks.cpp | ||
| 160 ↗ | (On Diff #87372) | We should do the parsing in the constructor, instead of on each match. |
| 174 ↗ | (On Diff #87372) | This is making two lookups into the map when one is enough. |
| 192 ↗ | (On Diff #87372) | X += instead of X = X + |
Thank you for the initial feedback!
| include/clang/Tooling/RefactoringCallbacks.h | ||
|---|---|---|
| 61 ↗ | (On Diff #87372) | Changed to push_back. Is there ever an advantage to using push_back over emplace_back (the latter falls back to a copy constructor). |
Fixed the test -- I am still getting used to the different ninja test targets.
| lib/Tooling/RefactoringCallbacks.cpp | ||
|---|---|---|
| 160 ↗ | (On Diff #87579) | Now it is. |
Looks good. Could you also add test cases where ReplaceNodeWithTemplate::create fails to parse templates?
| include/clang/Tooling/RefactoringCallbacks.h | ||
|---|---|---|
| 61 ↗ | (On Diff #87372) | push_back and emplace_back are equivalent when the value you are passing is already a T. std::vector<std::vector<int>> v; ... many lines below ... v.push_back(1); // fails v.emplace_back(1); // works, but it didn't add a 1 to the vector. |
| lib/Tooling/RefactoringCallbacks.cpp | ||
|---|---|---|
| 213 ↗ | (On Diff #87879) | I don't know if stderr is the best place for this error output. |
| 214 ↗ | (On Diff #87879) | I don't think this is ok. |
| 227 ↗ | (On Diff #87879) | Same as above. This error can be triggered from user input. |
| lib/Tooling/RefactoringCallbacks.cpp | ||
|---|---|---|
| 213 ↗ | (On Diff #87879) | There's a FIXME: above that addresses the need for better error handling, and this one just duplicated their workaround. |
| 214 ↗ | (On Diff #87879) | Using llvm::report_fatal_error for now. See the above for better error handling. |
| unittests/Tooling/RefactoringCallbacksTest.cpp | ||
|---|---|---|
| 101 ↗ | (On Diff #87579) | ninja check-clang-tools works. |
Still LGTM. Please run ninja check-clang and fix the warning. I'll land this patch for you afterwards.
| lib/Tooling/RefactoringCallbacks.cpp | ||
|---|---|---|
| 222 ↗ | (On Diff #94282) | ninja check-clang RefactoringCallbacks.cpp:222:5: warning: default label in switch which covers all enumeration values [-Wcovered-switch-default] Please remove the default. |