clang 8.0.0

SymbolOccurrences.h
Go to the documentation of this file.
1 //===--- SymbolOccurrences.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 #ifndef LLVM_CLANG_TOOLING_REFACTOR_RENAME_SYMBOL_OCCURRENCES_H
11 #define LLVM_CLANG_TOOLING_REFACTOR_RENAME_SYMBOL_OCCURRENCES_H
12
13 #include "clang/Basic/LLVM.h"
14 #include "clang/Basic/SourceLocation.h"
15 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/ADT/StringRef.h"
17 #include <vector>
18
19 namespace clang {
20 namespace tooling {
21
22 class SymbolName;
23
24 /// An occurrence of a symbol in the source.
25 ///
26 /// Occurrences can have difference kinds, that describe whether this occurrence
27 /// is an exact semantic match, or whether this is a weaker textual match that's
28 /// not guaranteed to represent the exact declaration.
29 ///
30 /// A single occurrence of a symbol can span more than one source range. For
31 /// example, Objective-C selectors can contain multiple argument labels:
32 ///
33 /// \code
34 /// [object selectorPiece1: ... selectorPiece2: ...];
35 /// // ^~~ range 0 ~~ ^~~ range 1 ~~
36 /// \endcode
37 ///
38 /// We have to replace the text in both range 0 and range 1 when renaming the
39 /// Objective-C method 'selectorPiece1:selectorPiece2'.
40 class SymbolOccurrence {
41 public:
42 enum OccurrenceKind {
43 /// This occurrence is an exact match and can be renamed automatically.
44 ///
45 /// Note:
46 /// Symbol occurrences in macro arguments that expand to different
47 /// declarations get marked as exact matches, and thus the renaming engine
48 /// will rename them e.g.:
49 ///
50 /// \code
51 /// #define MACRO(x) x + ns::x
52 /// int foo(int var) {
53 /// return MACRO(var); // var is renamed automatically here when
54 /// // either var or ns::var is renamed.
55 /// };
56 /// \endcode
57 ///
58 /// The user will have to fix their code manually after performing such a
59 /// rename.
60 /// FIXME: The rename verifier should notify user about this issue.
61 MatchingSymbol
62 };
63
64 SymbolOccurrence(const SymbolName &Name, OccurrenceKind Kind,
65 ArrayRef<SourceLocation> Locations);
66
67 SymbolOccurrence(SymbolOccurrence &&) = default;
68 SymbolOccurrence &operator=(SymbolOccurrence &&) = default;
69
70 OccurrenceKind getKind() const { return Kind; }
71
72 ArrayRef<SourceRange> getNameRanges() const {
73 if (MultipleRanges) {
74 return llvm::makeArrayRef(MultipleRanges.get(),
75 RangeOrNumRanges.getBegin().getRawEncoding());
76 }
77 return RangeOrNumRanges;
78 }
79
80 private:
81 OccurrenceKind Kind;
82 std::unique_ptr<SourceRange[]> MultipleRanges;
83 SourceRange RangeOrNumRanges;
84 };
85
86 using SymbolOccurrences = std::vector<SymbolOccurrence>;
87
88 } // end namespace tooling
89 } // end namespace clang
90
91 #endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_SYMBOL_OCCURRENCES_H
clang::tooling::SymbolName
A name of a symbol.
Definition: SymbolName.h:30
clang::SourceLocation::getRawEncoding
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
Definition: SourceLocation.h:146
clang::tooling::SymbolOccurrence::MatchingSymbol
This occurrence is an exact match and can be renamed automatically.
Definition: SymbolOccurrences.h:61
LLVM.h
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
clang::tooling::SymbolOccurrence
An occurrence of a symbol in the source.
Definition: SymbolOccurrences.h:40
llvm::ArrayRef
Definition: LLVM.h:32
Kind
Kind
Definition: ChrootChecker.cpp:29
clang::tooling::SymbolOccurrence::SymbolOccurrence
SymbolOccurrence(const SymbolName &Name, OccurrenceKind Kind, ArrayRef< SourceLocation > Locations)
Definition: SymbolOccurrences.cpp:17
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::tooling::SymbolOccurrence::getNameRanges
ArrayRef< SourceRange > getNameRanges() const
Definition: SymbolOccurrences.h:72
clang::tooling::SymbolOccurrence::OccurrenceKind
OccurrenceKind
Definition: SymbolOccurrences.h:42
clang::tooling::SymbolOccurrences
std::vector< SymbolOccurrence > SymbolOccurrences
Definition: SymbolOccurrences.h:86
SourceLocation.h
Defines the clang::SourceLocation class and associated facilities.
clang::tooling::SymbolOccurrence::operator=
SymbolOccurrence & operator=(SymbolOccurrence &&)=default
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:198
clang::SourceRange::getBegin
SourceLocation getBegin() const
Definition: SourceLocation.h:207
clang::tooling::SymbolOccurrence::getKind
OccurrenceKind getKind() const
Definition: SymbolOccurrences.h:70