Path: blob/main/contrib/llvm-project/clang/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
35295 views
//===--- SymbolOccurrences.cpp - Clang refactoring library ----------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "clang/Tooling/Refactoring/Rename/SymbolOccurrences.h"9#include "clang/Tooling/Refactoring/Rename/SymbolName.h"10#include "llvm/ADT/STLExtras.h"1112using namespace clang;13using namespace tooling;1415SymbolOccurrence::SymbolOccurrence(const SymbolName &Name, OccurrenceKind Kind,16ArrayRef<SourceLocation> Locations)17: Kind(Kind) {18ArrayRef<std::string> NamePieces = Name.getNamePieces();19assert(Locations.size() == NamePieces.size() &&20"mismatching number of locations and lengths");21assert(!Locations.empty() && "no locations");22if (Locations.size() == 1) {23new (&SingleRange) SourceRange(24Locations[0], Locations[0].getLocWithOffset(NamePieces[0].size()));25return;26}27MultipleRanges = std::make_unique<SourceRange[]>(Locations.size());28NumRanges = Locations.size();29for (const auto &Loc : llvm::enumerate(Locations)) {30MultipleRanges[Loc.index()] = SourceRange(31Loc.value(),32Loc.value().getLocWithOffset(NamePieces[Loc.index()].size()));33}34}353637