1 //===--- SymbolOccurrences.cpp - 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 #include "clang/Tooling/Refactoring/Rename/SymbolOccurrences.h" 11 #include "clang/Tooling/Refactoring/Rename/SymbolName.h" 12 #include "llvm/ADT/STLExtras.h" 13 14 using namespace clang; 15 using namespace tooling; 16 17 SymbolOccurrence::SymbolOccurrence(const SymbolName &Name, OccurrenceKind Kind, 18 ArrayRef<SourceLocation> Locations) 19 : Kind(Kind) { 20 ArrayRef<std::string> NamePieces = Name.getNamePieces(); 21 assert(Locations.size() == NamePieces.size() && 22 "mismatching number of locations and lengths"); 23 assert(!Locations.empty() && "no locations"); 24 if (Locations.size() == 1) { 25 RangeOrNumRanges = SourceRange( 26 Locations[0], Locations[0].getLocWithOffset(NamePieces[0].size())); 27 return; 28 } 29 MultipleRanges = llvm::make_unique<SourceRange[]>(Locations.size()); 30 RangeOrNumRanges.setBegin( 31 SourceLocation::getFromRawEncoding(Locations.size())); 32 for (const auto &Loc : llvm::enumerate(Locations)) { 33 MultipleRanges[Loc.index()] = SourceRange( 34 Loc.value(), 35 Loc.value().getLocWithOffset(NamePieces[Loc.index()].size())); 36 } 37 } 38