for_range.cpp 1021 B

123456789101112131415161718192021222324252627282930
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "migrate_cpp/cpp_refactoring/for_range.h"
  5. #include "clang/ASTMatchers/ASTMatchers.h"
  6. // NOLINTNEXTLINE(readability-identifier-naming)
  7. namespace cam = ::clang::ast_matchers;
  8. namespace Carbon {
  9. static constexpr char Label[] = "ForRange";
  10. void ForRange::Run() {
  11. const auto& stmt = GetNodeAsOrDie<clang::CXXForRangeStmt>(Label);
  12. // Wrap `in` with spaces so that `for (auto i:items)` has valid results.
  13. AddReplacement(clang::CharSourceRange::getTokenRange(stmt.getColonLoc(),
  14. stmt.getColonLoc()),
  15. " in ");
  16. }
  17. void ForRangeFactory::AddMatcher(cam::MatchFinder* finder,
  18. cam::MatchFinder::MatchCallback* callback) {
  19. finder->addMatcher(cam::cxxForRangeStmt().bind(Label), callback);
  20. }
  21. } // namespace Carbon