clang  6.0.0svn
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"
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'.
41 public:
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.
62  };
63 
65  ArrayRef<SourceLocation> Locations);
66 
67  SymbolOccurrence(SymbolOccurrence &&) = default;
69 
70  OccurrenceKind getKind() const { return Kind; }
71 
73  if (MultipleRanges) {
74  return llvm::makeArrayRef(MultipleRanges.get(),
75  RangeOrNumRanges.getBegin().getRawEncoding());
76  }
77  return RangeOrNumRanges;
78  }
79 
80 private:
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
A name of a symbol.
Definition: SymbolName.h:30
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.
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