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