Skip to content

Reland [clang] Unify SourceLocation and IdentifierInfo* pair-like data structures to IdentifierLoc #136077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,8 @@ void PPCallbacksTracker::appendArgument(const char *Name, ModuleIdPath Value) {
if (I)
SS << ", ";
SS << "{"
<< "Name: " << Value[I].first->getName() << ", "
<< "Loc: " << getSourceLocationString(PP, Value[I].second) << "}";
<< "Name: " << Value[I].getIdentifierInfo()->getName() << ", "
<< "Loc: " << getSourceLocationString(PP, Value[I].getLoc()) << "}";
}
SS << "]";
appendArgument(Name, SS.str());
Expand Down
20 changes: 10 additions & 10 deletions clang/include/clang/AST/OpenACCClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ inline bool operator!=(const OpenACCBindClause &LHS,
return !(LHS == RHS);
}

using DeviceTypeArgument = std::pair<IdentifierInfo *, SourceLocation>;
using DeviceTypeArgument = IdentifierLoc;
/// A 'device_type' or 'dtype' clause, takes a list of either an 'asterisk' or
/// an identifier. The 'asterisk' means 'the rest'.
class OpenACCDeviceTypeClause final
Expand All @@ -280,16 +280,16 @@ class OpenACCDeviceTypeClause final
"Invalid clause kind for device-type");

assert(!llvm::any_of(Archs, [](const DeviceTypeArgument &Arg) {
return Arg.second.isInvalid();
return Arg.getLoc().isInvalid();
}) && "Invalid SourceLocation for an argument");

assert(
(Archs.size() == 1 || !llvm::any_of(Archs,
[](const DeviceTypeArgument &Arg) {
return Arg.first == nullptr;
})) &&
"Only a single asterisk version is permitted, and must be the "
"only one");
assert((Archs.size() == 1 ||
!llvm::any_of(Archs,
[](const DeviceTypeArgument &Arg) {
return Arg.getIdentifierInfo() == nullptr;
})) &&
"Only a single asterisk version is permitted, and must be the "
"only one");

std::uninitialized_copy(Archs.begin(), Archs.end(),
getTrailingObjects<DeviceTypeArgument>());
Expand All @@ -302,7 +302,7 @@ class OpenACCDeviceTypeClause final
}
bool hasAsterisk() const {
return getArchitectures().size() > 0 &&
getArchitectures()[0].first == nullptr;
getArchitectures()[0].getIdentifierInfo() == nullptr;
}

ArrayRef<DeviceTypeArgument> getArchitectures() const {
Expand Down
26 changes: 23 additions & 3 deletions clang/include/clang/Basic/IdentifierTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "clang/Basic/Builtins.h"
#include "clang/Basic/DiagnosticIDs.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/TokenKinds.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/FoldingSet.h"
Expand Down Expand Up @@ -76,9 +77,6 @@ inline bool isReservedInAllContexts(ReservedIdentifierStatus Status) {
Status != ReservedIdentifierStatus::StartsWithUnderscoreAndIsExternC;
}

/// A simple pair of identifier info and location.
using IdentifierLocPair = std::pair<IdentifierInfo *, SourceLocation>;

/// IdentifierInfo and other related classes are aligned to
/// 8 bytes so that DeclarationName can use the lower 3 bits
/// of a pointer to one of these classes.
Expand Down Expand Up @@ -1165,6 +1163,28 @@ class SelectorTable {
static std::string getPropertyNameFromSetterSelector(Selector Sel);
};

/// A simple pair of identifier info and location.
class IdentifierLoc {
SourceLocation Loc;
IdentifierInfo *II = nullptr;

public:
IdentifierLoc() = default;
IdentifierLoc(SourceLocation L, IdentifierInfo *Ident) : Loc(L), II(Ident) {}

void setLoc(SourceLocation L) { Loc = L; }
void setIdentifierInfo(IdentifierInfo *Ident) { II = Ident; }
SourceLocation getLoc() const { return Loc; }
IdentifierInfo *getIdentifierInfo() const { return II; }

bool operator==(const IdentifierLoc &X) const {
return Loc == X.Loc && II == X.II;
}

bool operator!=(const IdentifierLoc &X) const {
return Loc != X.Loc || II != X.II;
}
};
} // namespace clang

namespace llvm {
Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/Lex/ModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifndef LLVM_CLANG_LEX_MODULELOADER_H
#define LLVM_CLANG_LEX_MODULELOADER_H

#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/Module.h"
#include "clang/Basic/SourceLocation.h"
Expand All @@ -29,7 +30,7 @@ class IdentifierInfo;

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

/// Describes the result of attempting to load a module.
class ModuleLoadResult {
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Lex/PPCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define LLVM_CLANG_LEX_PPCALLBACKS_H

#include "clang/Basic/DiagnosticIDs.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/ModuleLoader.h"
Expand Down
9 changes: 4 additions & 5 deletions clang/include/clang/Lex/Preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class Preprocessor {
SourceLocation ModuleImportLoc;

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

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

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

/// The source location of the currently-active
/// \#pragma clang assume_nonnull begin.
Expand Down Expand Up @@ -1998,16 +1998,15 @@ class Preprocessor {
/// arc_cf_code_audited begin.
///
/// Returns an invalid location if there is no such pragma active.
std::pair<IdentifierInfo *, SourceLocation>
getPragmaARCCFCodeAuditedInfo() const {
IdentifierLoc getPragmaARCCFCodeAuditedInfo() const {
return PragmaARCCFCodeAuditedInfo;
}

/// Set the location of the currently-active \#pragma clang
/// arc_cf_code_audited begin. An invalid location ends the pragma.
void setPragmaARCCFCodeAuditedInfo(IdentifierInfo *Ident,
SourceLocation Loc) {
PragmaARCCFCodeAuditedInfo = {Ident, Loc};
PragmaARCCFCodeAuditedInfo = IdentifierLoc(Loc, Ident);
}

/// The location of the currently-active \#pragma clang
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Parse/LoopHint.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#ifndef LLVM_CLANG_PARSE_LOOPHINT_H
#define LLVM_CLANG_PARSE_LOOPHINT_H

#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/SourceLocation.h"

namespace clang {

class Expr;
struct IdentifierLoc;

/// Loop optimization hint for loop and unroll pragmas.
struct LoopHint {
Expand Down
13 changes: 5 additions & 8 deletions clang/include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -1725,8 +1725,8 @@ class Parser : public CodeCompletionHandler {
ObjCTypeParamList *parseObjCTypeParamList();
ObjCTypeParamList *parseObjCTypeParamListOrProtocolRefs(
ObjCTypeParamListScope &Scope, SourceLocation &lAngleLoc,
SmallVectorImpl<IdentifierLocPair> &protocolIdents,
SourceLocation &rAngleLoc, bool mayBeProtocolList = true);
SmallVectorImpl<IdentifierLoc> &protocolIdents, SourceLocation &rAngleLoc,
bool mayBeProtocolList = true);

void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl,
SourceLocation atLoc,
Expand Down Expand Up @@ -3818,8 +3818,7 @@ class Parser : public CodeCompletionHandler {
SourceLocation Loc,
llvm::SmallVectorImpl<Expr *> &IntExprs);
/// Parses the 'device-type-list', which is a list of identifiers.
bool ParseOpenACCDeviceTypeList(
llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>> &Archs);
bool ParseOpenACCDeviceTypeList(llvm::SmallVector<IdentifierLoc> &Archs);
/// Parses the 'async-argument', which is an integral value with two
/// 'special' values that are likely negative (but come from Macros).
OpenACCIntExprParseResult ParseOpenACCAsyncArgument(OpenACCDirectiveKind DK,
Expand Down Expand Up @@ -3951,10 +3950,8 @@ class Parser : public CodeCompletionHandler {
return false;
}

bool ParseModuleName(
SourceLocation UseLoc,
SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>> &Path,
bool IsImport);
bool ParseModuleName(SourceLocation UseLoc,
SmallVectorImpl<IdentifierLoc> &Path, bool IsImport);

//===--------------------------------------------------------------------===//
// C++11/G++: Type Traits [Type-Traits.html in the GCC manual]
Expand Down
10 changes: 0 additions & 10 deletions clang/include/clang/Sema/ParsedAttr.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class LangOptions;
class Sema;
class Stmt;
class TargetInfo;
struct IdentifierLoc;

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

} // namespace detail

/// Wraps an identifier and optional source location for the identifier.
struct IdentifierLoc {
SourceLocation Loc;
IdentifierInfo *Ident;

static IdentifierLoc *create(ASTContext &Ctx, SourceLocation Loc,
IdentifierInfo *Ident);
};

/// A union of the various pointer types that can be passed to an
/// ParsedAttr as an argument.
using ArgsUnion = llvm::PointerUnion<Expr *, IdentifierLoc *>;
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ enum class LangAS : unsigned int;
class LocalInstantiationScope;
class LookupResult;
class MangleNumberingContext;
typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> ModuleIdPath;
typedef ArrayRef<IdentifierLoc> ModuleIdPath;
class ModuleLoader;
class MultiLevelTemplateArgumentList;
struct NormalizedConstraint;
Expand Down
3 changes: 1 addition & 2 deletions clang/include/clang/Sema/SemaCodeCompletion.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ class SemaCodeCompletion : public SemaBase {
void CodeCompleteObjCForCollection(Scope *S, DeclGroupPtrTy IterationVar);
void CodeCompleteObjCSelector(Scope *S,
ArrayRef<const IdentifierInfo *> SelIdents);
void
CodeCompleteObjCProtocolReferences(ArrayRef<IdentifierLocPair> Protocols);
void CodeCompleteObjCProtocolReferences(ArrayRef<IdentifierLoc> Protocols);
void CodeCompleteObjCProtocolDecl(Scope *S);
void CodeCompleteObjCInterfaceDecl(Scope *S);
void CodeCompleteObjCClassForwardDecl(Scope *S);
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/Sema/SemaObjC.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ class SemaObjC : public SemaBase {

DeclGroupPtrTy
ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc,
ArrayRef<IdentifierLocPair> IdentList,
ArrayRef<IdentifierLoc> IdentList,
const ParsedAttributesView &attrList);

void FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer,
ArrayRef<IdentifierLocPair> ProtocolId,
ArrayRef<IdentifierLoc> ProtocolId,
SmallVectorImpl<Decl *> &Protocols);

void DiagnoseTypeArgsAndProtocols(IdentifierInfo *ProtocolId,
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/SemaOpenACC.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class SemaOpenACC : public SemaBase {
} LoopWithoutSeqInfo;

// Redeclaration of the version in OpenACCClause.h.
using DeviceTypeArgument = std::pair<IdentifierInfo *, SourceLocation>;
using DeviceTypeArgument = IdentifierLoc;

/// A type to represent all the data for an OpenACC Clause that has been
/// parsed, but not yet created/semantically analyzed. This is effectively a
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/OpenACCClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,10 +891,10 @@ void OpenACCClausePrinter::VisitDeviceTypeClause(
OS << "(";
llvm::interleaveComma(C.getArchitectures(), OS,
[&](const DeviceTypeArgument &Arch) {
if (Arch.first == nullptr)
if (Arch.getIdentifierInfo() == nullptr)
OS << "*";
else
OS << Arch.first->getName();
OS << Arch.getIdentifierInfo()->getName();
});
OS << ")";
}
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/TextNodeDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,10 @@ void TextNodeDumper::Visit(const OpenACCClause *C) {
llvm::interleaveComma(
cast<OpenACCDeviceTypeClause>(C)->getArchitectures(), OS,
[&](const DeviceTypeArgument &Arch) {
if (Arch.first == nullptr)
if (Arch.getIdentifierInfo() == nullptr)
OS << "*";
else
OS << Arch.first->getName();
OS << Arch.getIdentifierInfo()->getName();
});
OS << ")";
break;
Expand Down
Loading
Loading