Skip to content

Commit 50be107

Browse files
committed
[clang] Unify SourceLocation and IdentifierInfo* pair-like data structures to IdentifierLoc
Signed-off-by: yronglin <[email protected]>
1 parent 04b6f54 commit 50be107

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+387
-374
lines changed

clang/include/clang/AST/OpenACCClause.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ inline bool operator!=(const OpenACCBindClause &LHS,
258258
return !(LHS == RHS);
259259
}
260260

261-
using DeviceTypeArgument = std::pair<IdentifierInfo *, SourceLocation>;
261+
using DeviceTypeArgument = IdentifierLoc;
262262
/// A 'device_type' or 'dtype' clause, takes a list of either an 'asterisk' or
263263
/// an identifier. The 'asterisk' means 'the rest'.
264264
class OpenACCDeviceTypeClause final
@@ -302,7 +302,7 @@ class OpenACCDeviceTypeClause final
302302
}
303303
bool hasAsterisk() const {
304304
return getArchitectures().size() > 0 &&
305-
getArchitectures()[0].first == nullptr;
305+
getArchitectures()[0].getIdentifierInfo() == nullptr;
306306
}
307307

308308
ArrayRef<DeviceTypeArgument> getArchitectures() const {

clang/include/clang/Basic/IdentifierTable.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ inline bool isReservedInAllContexts(ReservedIdentifierStatus Status) {
7676
Status != ReservedIdentifierStatus::StartsWithUnderscoreAndIsExternC;
7777
}
7878

79-
/// A simple pair of identifier info and location.
80-
using IdentifierLocPair = std::pair<IdentifierInfo *, SourceLocation>;
81-
8279
/// IdentifierInfo and other related classes are aligned to
8380
/// 8 bytes so that DeclarationName can use the lower 3 bits
8481
/// of a pointer to one of these classes.

clang/include/clang/Basic/SourceLocation.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ template <typename T, typename Enable> struct FoldingSetTrait;
3131

3232
namespace clang {
3333

34+
class IdentifierInfo;
3435
class SourceManager;
3536

3637
/// An opaque identifier used by SourceManager which refers to a
@@ -466,6 +467,29 @@ class FullSourceLoc : public SourceLocation {
466467
}
467468
};
468469

470+
/// A simple pair of identifier info and location.
471+
class IdentifierLoc {
472+
SourceLocation Loc;
473+
IdentifierInfo *II = nullptr;
474+
475+
public:
476+
IdentifierLoc() = default;
477+
IdentifierLoc(SourceLocation L, IdentifierInfo *Ident) : Loc(L), II(Ident) {}
478+
479+
void setLoc(SourceLocation L) { Loc = L; }
480+
void setIdentifierInfo(IdentifierInfo *Ident) { II = Ident; }
481+
SourceLocation getLoc() const { return Loc; }
482+
IdentifierInfo *getIdentifierInfo() const { return II; }
483+
484+
bool operator==(const IdentifierLoc &X) const {
485+
return Loc == X.Loc && II == X.II;
486+
}
487+
488+
bool operator!=(const IdentifierLoc &X) const {
489+
return Loc != X.Loc || II != X.II;
490+
}
491+
};
492+
469493
} // namespace clang
470494

471495
namespace llvm {

clang/include/clang/Lex/ModuleLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class IdentifierInfo;
2929

3030
/// A sequence of identifier/location pairs used to describe a particular
3131
/// module or submodule, e.g., std.vector.
32-
using ModuleIdPath = ArrayRef<std::pair<IdentifierInfo *, SourceLocation>>;
32+
using ModuleIdPath = ArrayRef<IdentifierLoc>;
3333

3434
/// Describes the result of attempting to load a module.
3535
class ModuleLoadResult {

clang/include/clang/Lex/Preprocessor.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ class Preprocessor {
327327
SourceLocation ModuleImportLoc;
328328

329329
/// The import path for named module that we're currently processing.
330-
SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> NamedModuleImportPath;
330+
SmallVector<IdentifierLoc, 2> NamedModuleImportPath;
331331

332332
llvm::DenseMap<FileID, SmallVector<const char *>> CheckPoints;
333333
unsigned CheckPointCounter = 0;
@@ -622,7 +622,7 @@ class Preprocessor {
622622

623623
/// The identifier and source location of the currently-active
624624
/// \#pragma clang arc_cf_code_audited begin.
625-
std::pair<IdentifierInfo *, SourceLocation> PragmaARCCFCodeAuditedInfo;
625+
IdentifierLoc PragmaARCCFCodeAuditedInfo;
626626

627627
/// The source location of the currently-active
628628
/// \#pragma clang assume_nonnull begin.
@@ -1998,16 +1998,15 @@ class Preprocessor {
19981998
/// arc_cf_code_audited begin.
19991999
///
20002000
/// Returns an invalid location if there is no such pragma active.
2001-
std::pair<IdentifierInfo *, SourceLocation>
2002-
getPragmaARCCFCodeAuditedInfo() const {
2001+
IdentifierLoc getPragmaARCCFCodeAuditedInfo() const {
20032002
return PragmaARCCFCodeAuditedInfo;
20042003
}
20052004

20062005
/// Set the location of the currently-active \#pragma clang
20072006
/// arc_cf_code_audited begin. An invalid location ends the pragma.
20082007
void setPragmaARCCFCodeAuditedInfo(IdentifierInfo *Ident,
20092008
SourceLocation Loc) {
2010-
PragmaARCCFCodeAuditedInfo = {Ident, Loc};
2009+
PragmaARCCFCodeAuditedInfo = IdentifierLoc(Loc, Ident);
20112010
}
20122011

20132012
/// The location of the currently-active \#pragma clang

clang/include/clang/Parse/LoopHint.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace clang {
1515

1616
class Expr;
17-
struct IdentifierLoc;
1817

1918
/// Loop optimization hint for loop and unroll pragmas.
2019
struct LoopHint {

clang/include/clang/Parse/Parser.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,8 +1725,8 @@ class Parser : public CodeCompletionHandler {
17251725
ObjCTypeParamList *parseObjCTypeParamList();
17261726
ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
17271727
ObjCTypeParamListScope &Scope, SourceLocation &lAngleLoc,
1728-
SmallVectorImpl<IdentifierLocPair> &protocolIdents,
1729-
SourceLocation &rAngleLoc, bool mayBeProtocolList = true);
1728+
SmallVectorImpl<IdentifierLoc> &protocolIdents, SourceLocation &rAngleLoc,
1729+
bool mayBeProtocolList = true);
17301730

17311731
void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
17321732
SourceLocation atLoc,
@@ -3816,8 +3816,7 @@ class Parser : public CodeCompletionHandler {
38163816
SourceLocation Loc,
38173817
llvm::SmallVectorImpl<Expr *> &IntExprs);
38183818
/// Parses the 'device-type-list', which is a list of identifiers.
3819-
bool ParseOpenACCDeviceTypeList(
3820-
llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>> &Archs);
3819+
bool ParseOpenACCDeviceTypeList(llvm::SmallVector<IdentifierLoc> &Archs);
38213820
/// Parses the 'async-argument', which is an integral value with two
38223821
/// 'special' values that are likely negative (but come from Macros).
38233822
OpenACCIntExprParseResult ParseOpenACCAsyncArgument(OpenACCDirectiveKind DK,
@@ -3949,10 +3948,8 @@ class Parser : public CodeCompletionHandler {
39493948
return false;
39503949
}
39513950

3952-
bool ParseModuleName(
3953-
SourceLocation UseLoc,
3954-
SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>> &Path,
3955-
bool IsImport);
3951+
bool ParseModuleName(SourceLocation UseLoc,
3952+
SmallVectorImpl<IdentifierLoc> &Path, bool IsImport);
39563953

39573954
//===--------------------------------------------------------------------===//
39583955
// C++11/G++: Type Traits [Type-Traits.html in the GCC manual]

clang/include/clang/Sema/ParsedAttr.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class LangOptions;
4040
class Sema;
4141
class Stmt;
4242
class TargetInfo;
43-
struct IdentifierLoc;
4443

4544
/// Represents information about a change in availability for
4645
/// an entity, which is part of the encoding of the 'availability'
@@ -99,15 +98,6 @@ struct PropertyData {
9998

10099
} // namespace detail
101100

102-
/// Wraps an identifier and optional source location for the identifier.
103-
struct IdentifierLoc {
104-
SourceLocation Loc;
105-
IdentifierInfo *Ident;
106-
107-
static IdentifierLoc *create(ASTContext &Ctx, SourceLocation Loc,
108-
IdentifierInfo *Ident);
109-
};
110-
111101
/// A union of the various pointer types that can be passed to an
112102
/// ParsedAttr as an argument.
113103
using ArgsUnion = llvm::PointerUnion<Expr *, IdentifierLoc *>;

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ enum class LangAS : unsigned int;
143143
class LocalInstantiationScope;
144144
class LookupResult;
145145
class MangleNumberingContext;
146-
typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> ModuleIdPath;
146+
typedef ArrayRef<IdentifierLoc> ModuleIdPath;
147147
class ModuleLoader;
148148
class MultiLevelTemplateArgumentList;
149149
struct NormalizedConstraint;

clang/include/clang/Sema/SemaCodeCompletion.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ class SemaCodeCompletion : public SemaBase {
193193
void CodeCompleteObjCForCollection(Scope *S, DeclGroupPtrTy IterationVar);
194194
void CodeCompleteObjCSelector(Scope *S,
195195
ArrayRef<const IdentifierInfo *> SelIdents);
196-
void
197-
CodeCompleteObjCProtocolReferences(ArrayRef<IdentifierLocPair> Protocols);
196+
void CodeCompleteObjCProtocolReferences(ArrayRef<IdentifierLoc> Protocols);
198197
void CodeCompleteObjCProtocolDecl(Scope *S);
199198
void CodeCompleteObjCInterfaceDecl(Scope *S);
200199
void CodeCompleteObjCClassForwardDecl(Scope *S);

0 commit comments

Comments
 (0)