clang 8.0.0

SymbolOccurrences.cpp
Go to the documentation of this file.
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 }
clang::tooling::SymbolName
A name of a symbol.
Definition: SymbolName.h:30
clang::SourceRange::setBegin
void setBegin(SourceLocation b)
Definition: SourceLocation.h:210
clang::SourceLocation::getFromRawEncoding
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
Definition: SourceLocation.h:152
llvm::ArrayRef
Definition: LLVM.h:32
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:17
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::tooling::SymbolOccurrence::OccurrenceKind
OccurrenceKind
Definition: SymbolOccurrences.h:42
clang::tooling::SymbolName::getNamePieces
ArrayRef< std::string > getNamePieces() const
Definition: SymbolName.h:40
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:198