SymbolOccurrences.cpp 1.4 KB

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