1 //===--- USRFindingAction.h - Clang refactoring library -------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// Provides an action to find all relevant USRs at a point.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDING_ACTION_H
16 #define LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDING_ACTION_H
17 
18 #include "clang/Basic/LLVM.h"
19 #include "llvm/ADT/ArrayRef.h"
20 
21 #include <string>
22 #include <vector>
23 
24 namespace clang {
25 class ASTConsumer;
26 class ASTContext;
27 class CompilerInstance;
28 class NamedDecl;
29 
30 namespace tooling {
31 
32 /// Returns the canonical declaration that best represents a symbol that can be
33 /// renamed.
34 ///
35 /// The following canonicalization rules are currently used:
36 ///
37 /// - A constructor is canonicalized to its class.
38 /// - A destructor is canonicalized to its class.
39 const NamedDecl *getCanonicalSymbolDeclaration(const NamedDecl *FoundDecl);
40 
41 /// Returns the set of USRs that correspond to the given declaration.
42 std::vector<std::string> getUSRsForDeclaration(const NamedDecl *ND,
43                                                ASTContext &Context);
44 
45 struct USRFindingAction {
USRFindingActionUSRFindingAction46   USRFindingAction(ArrayRef<unsigned> SymbolOffsets,
47                    ArrayRef<std::string> QualifiedNames, bool Force)
48       : SymbolOffsets(SymbolOffsets), QualifiedNames(QualifiedNames),
49         ErrorOccurred(false), Force(Force) {}
50   std::unique_ptr<ASTConsumer> newASTConsumer();
51 
getUSRSpellingsUSRFindingAction52   ArrayRef<std::string> getUSRSpellings() { return SpellingNames; }
getUSRListUSRFindingAction53   ArrayRef<std::vector<std::string>> getUSRList() { return USRList; }
errorOccurredUSRFindingAction54   bool errorOccurred() { return ErrorOccurred; }
55 
56 private:
57   std::vector<unsigned> SymbolOffsets;
58   std::vector<std::string> QualifiedNames;
59   std::vector<std::string> SpellingNames;
60   std::vector<std::vector<std::string>> USRList;
61   bool ErrorOccurred;
62   bool Force;
63 };
64 
65 } // end namespace tooling
66 } // end namespace clang
67 
68 #endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDING_ACTION_H
69