Clang Project

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