matcher.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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. #ifndef MIGRATE_CPP_CPP_REFACTORING_MATCHER_H_
  5. #define MIGRATE_CPP_CPP_REFACTORING_MATCHER_H_
  6. #include "clang/ASTMatchers/ASTMatchFinder.h"
  7. #include "clang/Tooling/Core/Replacement.h"
  8. namespace Carbon {
  9. // This is an abstract class with helpers to make it easier to write matchers.
  10. class Matcher : public clang::ast_matchers::MatchFinder::MatchCallback {
  11. public:
  12. // Alias these to elide the namespaces in subclass headers.
  13. using MatchFinder = clang::ast_matchers::MatchFinder;
  14. using Replacements = clang::tooling::Replacements;
  15. explicit Matcher(std::map<std::string, Replacements>& in_replacements)
  16. : replacements(&in_replacements) {}
  17. protected:
  18. // Replaces the given range with the specified text.
  19. void AddReplacement(const clang::SourceManager& sm,
  20. clang::CharSourceRange range,
  21. llvm::StringRef replacement_text);
  22. private:
  23. std::map<std::string, Replacements>* const replacements;
  24. };
  25. } // namespace Carbon
  26. #endif // MIGRATE_CPP_CPP_REFACTORING_MATCHER_H_