xref: /freebsd/contrib/llvm-project/clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
10b57cec5SDimitry Andric //===--- SymbolOccurrences.cpp - Clang refactoring library ----------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "clang/Tooling/Refactoring/Rename/SymbolOccurrences.h"
100b57cec5SDimitry Andric #include "clang/Tooling/Refactoring/Rename/SymbolName.h"
110b57cec5SDimitry Andric #include "llvm/ADT/STLExtras.h"
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric using namespace clang;
140b57cec5SDimitry Andric using namespace tooling;
150b57cec5SDimitry Andric 
SymbolOccurrence(const SymbolName & Name,OccurrenceKind Kind,ArrayRef<SourceLocation> Locations)160b57cec5SDimitry Andric SymbolOccurrence::SymbolOccurrence(const SymbolName &Name, OccurrenceKind Kind,
170b57cec5SDimitry Andric                                    ArrayRef<SourceLocation> Locations)
180b57cec5SDimitry Andric     : Kind(Kind) {
190b57cec5SDimitry Andric   ArrayRef<std::string> NamePieces = Name.getNamePieces();
200b57cec5SDimitry Andric   assert(Locations.size() == NamePieces.size() &&
210b57cec5SDimitry Andric          "mismatching number of locations and lengths");
220b57cec5SDimitry Andric   assert(!Locations.empty() && "no locations");
230b57cec5SDimitry Andric   if (Locations.size() == 1) {
24*e8d8bef9SDimitry Andric     new (&SingleRange) SourceRange(
250b57cec5SDimitry Andric         Locations[0], Locations[0].getLocWithOffset(NamePieces[0].size()));
260b57cec5SDimitry Andric     return;
270b57cec5SDimitry Andric   }
28a7dea167SDimitry Andric   MultipleRanges = std::make_unique<SourceRange[]>(Locations.size());
29*e8d8bef9SDimitry Andric   NumRanges = Locations.size();
300b57cec5SDimitry Andric   for (const auto &Loc : llvm::enumerate(Locations)) {
310b57cec5SDimitry Andric     MultipleRanges[Loc.index()] = SourceRange(
320b57cec5SDimitry Andric         Loc.value(),
330b57cec5SDimitry Andric         Loc.value().getLocWithOffset(NamePieces[Loc.index()].size()));
340b57cec5SDimitry Andric   }
350b57cec5SDimitry Andric }
36