USRFindingAction.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- USRFindingAction.h - Clang refactoring library -------------------===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. ///
  14. /// \file
  15. /// Provides an action to find all relevant USRs at a point.
  16. ///
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_TOOLING_REFACTORING_RENAME_USRFINDINGACTION_H
  19. #define LLVM_CLANG_TOOLING_REFACTORING_RENAME_USRFINDINGACTION_H
  20. #include "clang/Basic/LLVM.h"
  21. #include "llvm/ADT/ArrayRef.h"
  22. #include <string>
  23. #include <vector>
  24. namespace clang {
  25. class ASTConsumer;
  26. class ASTContext;
  27. class NamedDecl;
  28. namespace tooling {
  29. /// Returns the canonical declaration that best represents a symbol that can be
  30. /// renamed.
  31. ///
  32. /// The following canonicalization rules are currently used:
  33. ///
  34. /// - A constructor is canonicalized to its class.
  35. /// - A destructor is canonicalized to its class.
  36. const NamedDecl *getCanonicalSymbolDeclaration(const NamedDecl *FoundDecl);
  37. /// Returns the set of USRs that correspond to the given declaration.
  38. std::vector<std::string> getUSRsForDeclaration(const NamedDecl *ND,
  39. ASTContext &Context);
  40. struct USRFindingAction {
  41. USRFindingAction(ArrayRef<unsigned> SymbolOffsets,
  42. ArrayRef<std::string> QualifiedNames, bool Force)
  43. : SymbolOffsets(SymbolOffsets), QualifiedNames(QualifiedNames),
  44. ErrorOccurred(false), Force(Force) {}
  45. std::unique_ptr<ASTConsumer> newASTConsumer();
  46. ArrayRef<std::string> getUSRSpellings() { return SpellingNames; }
  47. ArrayRef<std::vector<std::string>> getUSRList() { return USRList; }
  48. bool errorOccurred() { return ErrorOccurred; }
  49. private:
  50. std::vector<unsigned> SymbolOffsets;
  51. std::vector<std::string> QualifiedNames;
  52. std::vector<std::string> SpellingNames;
  53. std::vector<std::vector<std::string>> USRList;
  54. bool ErrorOccurred;
  55. bool Force;
  56. };
  57. } // end namespace tooling
  58. } // end namespace clang
  59. #endif // LLVM_CLANG_TOOLING_REFACTORING_RENAME_USRFINDINGACTION_H
  60. #ifdef __GNUC__
  61. #pragma GCC diagnostic pop
  62. #endif