|
|
|||
File indexing completed on 2026-05-10 08:37:11
0001 //===--- SymbolOccurrences.h - Clang refactoring library ------------------===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLVM_CLANG_TOOLING_REFACTORING_RENAME_SYMBOLOCCURRENCES_H 0010 #define LLVM_CLANG_TOOLING_REFACTORING_RENAME_SYMBOLOCCURRENCES_H 0011 0012 #include "clang/Basic/LLVM.h" 0013 #include "clang/Basic/SourceLocation.h" 0014 #include "llvm/ADT/ArrayRef.h" 0015 #include "llvm/ADT/StringRef.h" 0016 #include <vector> 0017 0018 namespace clang { 0019 namespace tooling { 0020 0021 class SymbolName; 0022 0023 /// An occurrence of a symbol in the source. 0024 /// 0025 /// Occurrences can have difference kinds, that describe whether this occurrence 0026 /// is an exact semantic match, or whether this is a weaker textual match that's 0027 /// not guaranteed to represent the exact declaration. 0028 /// 0029 /// A single occurrence of a symbol can span more than one source range. For 0030 /// example, Objective-C selectors can contain multiple argument labels: 0031 /// 0032 /// \code 0033 /// [object selectorPiece1: ... selectorPiece2: ...]; 0034 /// // ^~~ range 0 ~~ ^~~ range 1 ~~ 0035 /// \endcode 0036 /// 0037 /// We have to replace the text in both range 0 and range 1 when renaming the 0038 /// Objective-C method 'selectorPiece1:selectorPiece2'. 0039 class SymbolOccurrence { 0040 public: 0041 enum OccurrenceKind { 0042 /// This occurrence is an exact match and can be renamed automatically. 0043 /// 0044 /// Note: 0045 /// Symbol occurrences in macro arguments that expand to different 0046 /// declarations get marked as exact matches, and thus the renaming engine 0047 /// will rename them e.g.: 0048 /// 0049 /// \code 0050 /// #define MACRO(x) x + ns::x 0051 /// int foo(int var) { 0052 /// return MACRO(var); // var is renamed automatically here when 0053 /// // either var or ns::var is renamed. 0054 /// }; 0055 /// \endcode 0056 /// 0057 /// The user will have to fix their code manually after performing such a 0058 /// rename. 0059 /// FIXME: The rename verifier should notify user about this issue. 0060 MatchingSymbol 0061 }; 0062 0063 SymbolOccurrence(const SymbolName &Name, OccurrenceKind Kind, 0064 ArrayRef<SourceLocation> Locations); 0065 0066 SymbolOccurrence(SymbolOccurrence &&) = default; 0067 SymbolOccurrence &operator=(SymbolOccurrence &&) = default; 0068 0069 OccurrenceKind getKind() const { return Kind; } 0070 0071 ArrayRef<SourceRange> getNameRanges() const { 0072 if (MultipleRanges) 0073 return llvm::ArrayRef(MultipleRanges.get(), NumRanges); 0074 return SingleRange; 0075 } 0076 0077 private: 0078 OccurrenceKind Kind; 0079 std::unique_ptr<SourceRange[]> MultipleRanges; 0080 union { 0081 SourceRange SingleRange; 0082 unsigned NumRanges; 0083 }; 0084 }; 0085 0086 using SymbolOccurrences = std::vector<SymbolOccurrence>; 0087 0088 } // end namespace tooling 0089 } // end namespace clang 0090 0091 #endif // LLVM_CLANG_TOOLING_REFACTORING_RENAME_SYMBOLOCCURRENCES_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|