clang 10.0.0git

SymbolOccurrences.cpp
Go to the documentation of this file.
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
9 #include "clang/Tooling/Refactoring/Rename/SymbolOccurrences.h"
10 #include "clang/Tooling/Refactoring/Rename/SymbolName.h"
11 #include "llvm/ADT/STLExtras.h"
12
13 using namespace clang;
14 using namespace tooling;
15
16 SymbolOccurrence::SymbolOccurrence(const SymbolName &Name, OccurrenceKind Kind,
17 ArrayRef<SourceLocation> Locations)
18 : Kind(Kind) {
19 ArrayRef<std::string> NamePieces = Name.getNamePieces();
20 assert(Locations.size() == NamePieces.size() &&
21 "mismatching number of locations and lengths");
22 assert(!Locations.empty() && "no locations");
23 if (Locations.size() == 1) {
24 RangeOrNumRanges = SourceRange(
25 Locations[0], Locations[0].getLocWithOffset(NamePieces[0].size()));
26 return;
27 }
28 MultipleRanges = std::make_unique<SourceRange[]>(Locations.size());
29 RangeOrNumRanges.setBegin(
30 SourceLocation::getFromRawEncoding(Locations.size()));
31 for (const auto &Loc : llvm::enumerate(Locations)) {
32 MultipleRanges[Loc.index()] = SourceRange(
33 Loc.value(),
34 Loc.value().getLocWithOffset(NamePieces[Loc.index()].size()));
35 }
36 }
clang::tooling::SymbolName
A name of a symbol.
Definition: SymbolName.h:29
clang::SourceRange::setBegin
void setBegin(SourceLocation b)
Definition: SourceLocation.h:219
clang::SourceLocation::getFromRawEncoding
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
Definition: SourceLocation.h:150
llvm::ArrayRef
Definition: LLVM.h:31
SymbolName.h
SymbolOccurrences.h
Kind
Kind
Definition: ChrootChecker.cpp:29
clang::tooling::SymbolOccurrence::SymbolOccurrence
SymbolOccurrence(const SymbolName &Name, OccurrenceKind Kind, ArrayRef< SourceLocation > Locations)
Definition: SymbolOccurrences.cpp:16
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::tooling::SymbolOccurrence::OccurrenceKind
OccurrenceKind
Definition: SymbolOccurrences.h:41
clang::tooling::SymbolName::getNamePieces
ArrayRef< std::string > getNamePieces() const
Definition: SymbolName.h:39
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:207