[clang] Use SourceLocation as key in std::map, NFCI

SourceLocation implements `operator<`, so `SourceLocation`-s can be used
as keys in `std::map` directly, there is no need to extract the internal
representation.

Since the `operator<` simply compares the internal representations of
its operands, this patch does not introduce any functional changes.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D89705
This commit is contained in:
Mikhail Maltsev 2020-10-19 18:30:51 +01:00
parent 3cbdae22b9
commit a3c16039b3
2 changed files with 21 additions and 25 deletions

View File

@ -65,7 +65,7 @@ class PropertiesRewriter {
}; };
typedef SmallVector<PropData, 2> PropsTy; typedef SmallVector<PropData, 2> PropsTy;
typedef std::map<unsigned, PropsTy> AtPropDeclsTy; typedef std::map<SourceLocation, PropsTy> AtPropDeclsTy;
AtPropDeclsTy AtProps; AtPropDeclsTy AtProps;
llvm::DenseMap<IdentifierInfo *, PropActionKind> ActionOnProp; llvm::DenseMap<IdentifierInfo *, PropActionKind> ActionOnProp;
@ -76,13 +76,13 @@ public:
static void collectProperties(ObjCContainerDecl *D, AtPropDeclsTy &AtProps, static void collectProperties(ObjCContainerDecl *D, AtPropDeclsTy &AtProps,
AtPropDeclsTy *PrevAtProps = nullptr) { AtPropDeclsTy *PrevAtProps = nullptr) {
for (auto *Prop : D->instance_properties()) { for (auto *Prop : D->instance_properties()) {
if (Prop->getAtLoc().isInvalid()) SourceLocation Loc = Prop->getAtLoc();
if (Loc.isInvalid())
continue; continue;
unsigned RawLoc = Prop->getAtLoc().getRawEncoding();
if (PrevAtProps) if (PrevAtProps)
if (PrevAtProps->find(RawLoc) != PrevAtProps->end()) if (PrevAtProps->find(Loc) != PrevAtProps->end())
continue; continue;
PropsTy &props = AtProps[RawLoc]; PropsTy &props = AtProps[Loc];
props.push_back(Prop); props.push_back(Prop);
} }
} }
@ -113,8 +113,7 @@ public:
ObjCIvarDecl *ivarD = implD->getPropertyIvarDecl(); ObjCIvarDecl *ivarD = implD->getPropertyIvarDecl();
if (!ivarD || ivarD->isInvalidDecl()) if (!ivarD || ivarD->isInvalidDecl())
continue; continue;
unsigned rawAtLoc = propD->getAtLoc().getRawEncoding(); AtPropDeclsTy::iterator findAtLoc = AtProps.find(propD->getAtLoc());
AtPropDeclsTy::iterator findAtLoc = AtProps.find(rawAtLoc);
if (findAtLoc == AtProps.end()) if (findAtLoc == AtProps.end())
continue; continue;
@ -130,7 +129,7 @@ public:
for (AtPropDeclsTy::iterator for (AtPropDeclsTy::iterator
I = AtProps.begin(), E = AtProps.end(); I != E; ++I) { I = AtProps.begin(), E = AtProps.end(); I != E; ++I) {
SourceLocation atLoc = SourceLocation::getFromRawEncoding(I->first); SourceLocation atLoc = I->first;
PropsTy &props = I->second; PropsTy &props = I->second;
if (!getPropertyType(props)->isObjCRetainableType()) if (!getPropertyType(props)->isObjCRetainableType())
continue; continue;

View File

@ -44,13 +44,13 @@ class InclusionRewriter : public PPCallbacks {
bool ShowLineMarkers; ///< Show #line markers. bool ShowLineMarkers; ///< Show #line markers.
bool UseLineDirectives; ///< Use of line directives or line markers. bool UseLineDirectives; ///< Use of line directives or line markers.
/// Tracks where inclusions that change the file are found. /// Tracks where inclusions that change the file are found.
std::map<unsigned, IncludedFile> FileIncludes; std::map<SourceLocation, IncludedFile> FileIncludes;
/// Tracks where inclusions that import modules are found. /// Tracks where inclusions that import modules are found.
std::map<unsigned, const Module *> ModuleIncludes; std::map<SourceLocation, const Module *> ModuleIncludes;
/// Tracks where inclusions that enter modules (in a module build) are found. /// Tracks where inclusions that enter modules (in a module build) are found.
std::map<unsigned, const Module *> ModuleEntryIncludes; std::map<SourceLocation, const Module *> ModuleEntryIncludes;
/// Tracks where #if and #elif directives get evaluated and whether to true. /// Tracks where #if and #elif directives get evaluated and whether to true.
std::map<unsigned, bool> IfConditions; std::map<SourceLocation, bool> IfConditions;
/// Used transitively for building up the FileIncludes mapping over the /// Used transitively for building up the FileIncludes mapping over the
/// various \c PPCallbacks callbacks. /// various \c PPCallbacks callbacks.
SourceLocation LastInclusionLocation; SourceLocation LastInclusionLocation;
@ -65,8 +65,8 @@ public:
void detectMainFileEOL(); void detectMainFileEOL();
void handleModuleBegin(Token &Tok) { void handleModuleBegin(Token &Tok) {
assert(Tok.getKind() == tok::annot_module_begin); assert(Tok.getKind() == tok::annot_module_begin);
ModuleEntryIncludes.insert({Tok.getLocation().getRawEncoding(), ModuleEntryIncludes.insert(
(Module *)Tok.getAnnotationValue()}); {Tok.getLocation(), (Module *)Tok.getAnnotationValue()});
} }
private: private:
void FileChanged(SourceLocation Loc, FileChangeReason Reason, void FileChanged(SourceLocation Loc, FileChangeReason Reason,
@ -164,7 +164,7 @@ void InclusionRewriter::FileChanged(SourceLocation Loc,
return; return;
FileID Id = FullSourceLoc(Loc, SM).getFileID(); FileID Id = FullSourceLoc(Loc, SM).getFileID();
auto P = FileIncludes.insert( auto P = FileIncludes.insert(
std::make_pair(LastInclusionLocation.getRawEncoding(), std::make_pair(LastInclusionLocation,
IncludedFile(Id, NewFileType, PP.GetCurDirLookup()))); IncludedFile(Id, NewFileType, PP.GetCurDirLookup())));
(void)P; (void)P;
assert(P.second && "Unexpected revisitation of the same include directive"); assert(P.second && "Unexpected revisitation of the same include directive");
@ -199,8 +199,7 @@ void InclusionRewriter::InclusionDirective(SourceLocation HashLoc,
const Module *Imported, const Module *Imported,
SrcMgr::CharacteristicKind FileType){ SrcMgr::CharacteristicKind FileType){
if (Imported) { if (Imported) {
auto P = ModuleIncludes.insert( auto P = ModuleIncludes.insert(std::make_pair(HashLoc, Imported));
std::make_pair(HashLoc.getRawEncoding(), Imported));
(void)P; (void)P;
assert(P.second && "Unexpected revisitation of the same include directive"); assert(P.second && "Unexpected revisitation of the same include directive");
} else } else
@ -209,8 +208,7 @@ void InclusionRewriter::InclusionDirective(SourceLocation HashLoc,
void InclusionRewriter::If(SourceLocation Loc, SourceRange ConditionRange, void InclusionRewriter::If(SourceLocation Loc, SourceRange ConditionRange,
ConditionValueKind ConditionValue) { ConditionValueKind ConditionValue) {
auto P = IfConditions.insert( auto P = IfConditions.insert(std::make_pair(Loc, ConditionValue == CVK_True));
std::make_pair(Loc.getRawEncoding(), ConditionValue == CVK_True));
(void)P; (void)P;
assert(P.second && "Unexpected revisitation of the same if directive"); assert(P.second && "Unexpected revisitation of the same if directive");
} }
@ -218,8 +216,7 @@ void InclusionRewriter::If(SourceLocation Loc, SourceRange ConditionRange,
void InclusionRewriter::Elif(SourceLocation Loc, SourceRange ConditionRange, void InclusionRewriter::Elif(SourceLocation Loc, SourceRange ConditionRange,
ConditionValueKind ConditionValue, ConditionValueKind ConditionValue,
SourceLocation IfLoc) { SourceLocation IfLoc) {
auto P = IfConditions.insert( auto P = IfConditions.insert(std::make_pair(Loc, ConditionValue == CVK_True));
std::make_pair(Loc.getRawEncoding(), ConditionValue == CVK_True));
(void)P; (void)P;
assert(P.second && "Unexpected revisitation of the same elif directive"); assert(P.second && "Unexpected revisitation of the same elif directive");
} }
@ -228,7 +225,7 @@ void InclusionRewriter::Elif(SourceLocation Loc, SourceRange ConditionRange,
/// an inclusion directive) in the map of inclusion information, FileChanges. /// an inclusion directive) in the map of inclusion information, FileChanges.
const InclusionRewriter::IncludedFile * const InclusionRewriter::IncludedFile *
InclusionRewriter::FindIncludeAtLocation(SourceLocation Loc) const { InclusionRewriter::FindIncludeAtLocation(SourceLocation Loc) const {
const auto I = FileIncludes.find(Loc.getRawEncoding()); const auto I = FileIncludes.find(Loc);
if (I != FileIncludes.end()) if (I != FileIncludes.end())
return &I->second; return &I->second;
return nullptr; return nullptr;
@ -238,7 +235,7 @@ InclusionRewriter::FindIncludeAtLocation(SourceLocation Loc) const {
/// an inclusion directive) in the map of module inclusion information. /// an inclusion directive) in the map of module inclusion information.
const Module * const Module *
InclusionRewriter::FindModuleAtLocation(SourceLocation Loc) const { InclusionRewriter::FindModuleAtLocation(SourceLocation Loc) const {
const auto I = ModuleIncludes.find(Loc.getRawEncoding()); const auto I = ModuleIncludes.find(Loc);
if (I != ModuleIncludes.end()) if (I != ModuleIncludes.end())
return I->second; return I->second;
return nullptr; return nullptr;
@ -248,14 +245,14 @@ InclusionRewriter::FindModuleAtLocation(SourceLocation Loc) const {
/// an inclusion directive) in the map of module entry information. /// an inclusion directive) in the map of module entry information.
const Module * const Module *
InclusionRewriter::FindEnteredModule(SourceLocation Loc) const { InclusionRewriter::FindEnteredModule(SourceLocation Loc) const {
const auto I = ModuleEntryIncludes.find(Loc.getRawEncoding()); const auto I = ModuleEntryIncludes.find(Loc);
if (I != ModuleEntryIncludes.end()) if (I != ModuleEntryIncludes.end())
return I->second; return I->second;
return nullptr; return nullptr;
} }
bool InclusionRewriter::IsIfAtLocationTrue(SourceLocation Loc) const { bool InclusionRewriter::IsIfAtLocationTrue(SourceLocation Loc) const {
const auto I = IfConditions.find(Loc.getRawEncoding()); const auto I = IfConditions.find(Loc);
if (I != IfConditions.end()) if (I != IfConditions.end())
return I->second; return I->second;
return false; return false;