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

This PR reland https://github.com/llvm/llvm-project/pull/135808, fixed
some missed changes in LLDB.
I found this issue when I working on
https://github.com/llvm/llvm-project/pull/107168.

Currently we have many similiar data structures like:
- std::pair<IdentifierInfo *, SourceLocation>.
- Element type of ModuleIdPath.
- IdentifierLocPair.
- IdentifierLoc.

This PR unify these data structures to IdentifierLoc, moved
IdentifierLoc definition to SourceLocation.h, and deleted other similer
data structures.

---------

Signed-off-by: yronglin <yronglin777@gmail.com>
This commit is contained in:
yronglin 2025-04-17 22:40:47 +08:00 committed by GitHub
parent 78857e7263
commit d83b639b4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
47 changed files with 411 additions and 395 deletions

View File

@ -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());

View File

@ -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
@ -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>());
@ -302,7 +302,7 @@ public:
}
bool hasAsterisk() const {
return getArchitectures().size() > 0 &&
getArchitectures()[0].first == nullptr;
getArchitectures()[0].getIdentifierInfo() == nullptr;
}
ArrayRef<DeviceTypeArgument> getArchitectures() const {

View File

@ -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"
@ -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.
@ -1165,6 +1163,28 @@ public:
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 {

View File

@ -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"
@ -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 {

View File

@ -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"

View File

@ -327,7 +327,7 @@ private:
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;
@ -622,7 +622,7 @@ private:
/// 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.
@ -1998,8 +1998,7 @@ public:
/// 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;
}
@ -2007,7 +2006,7 @@ public:
/// 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

View File

@ -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 {

View File

@ -1725,8 +1725,8 @@ private:
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,
@ -3818,8 +3818,7 @@ private:
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,
@ -3951,10 +3950,8 @@ private:
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]

View File

@ -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'
@ -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 *>;

View File

@ -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;

View File

@ -193,8 +193,7 @@ public:
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);

View File

@ -307,11 +307,11 @@ public:
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,

View File

@ -212,7 +212,7 @@ public:
} 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

View File

@ -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 << ")";
}

View File

@ -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;

View File

@ -35,6 +35,7 @@
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Sema/CodeCompleteConsumer.h"
#include "clang/Sema/ParsedAttr.h"
#include "clang/Sema/Sema.h"
#include "clang/Serialization/ASTReader.h"
#include "clang/Serialization/GlobalModuleIndex.h"
@ -2009,8 +2010,8 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
Module::NameVisibilityKind Visibility,
bool IsInclusionDirective) {
// Determine what file we're searching from.
StringRef ModuleName = Path[0].first->getName();
SourceLocation ModuleNameLoc = Path[0].second;
StringRef ModuleName = Path[0].getIdentifierInfo()->getName();
SourceLocation ModuleNameLoc = Path[0].getLoc();
// If we've already handled this import, just return the cached result.
// This one-element cache is important to eliminate redundant diagnostics
@ -2026,7 +2027,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
// If we don't already have information on this module, load the module now.
Module *Module = nullptr;
ModuleMap &MM = getPreprocessor().getHeaderSearchInfo().getModuleMap();
if (auto MaybeModule = MM.getCachedModuleLoad(*Path[0].first)) {
if (auto MaybeModule = MM.getCachedModuleLoad(*Path[0].getIdentifierInfo())) {
// Use the cached result, which may be nullptr.
Module = *MaybeModule;
// Config macros are already checked before building a module, but they need
@ -2046,7 +2047,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
// * `Preprocessor::HandleHeaderIncludeOrImport` will never call this
// function as the `#include` or `#import` is textual.
MM.cacheModuleLoad(*Path[0].first, Module);
MM.cacheModuleLoad(*Path[0].getIdentifierInfo(), Module);
} else {
ModuleLoadResult Result = findOrCompileModuleAndReadAST(
ModuleName, ImportLoc, ModuleNameLoc, IsInclusionDirective);
@ -2055,7 +2056,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
if (!Result)
DisableGeneratingGlobalModuleIndex = true;
Module = Result;
MM.cacheModuleLoad(*Path[0].first, Module);
MM.cacheModuleLoad(*Path[0].getIdentifierInfo(), Module);
}
// If we never found the module, fail. Otherwise, verify the module and link
@ -2067,7 +2068,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
// a submodule.
bool MapPrivateSubModToTopLevel = false;
for (unsigned I = 1, N = Path.size(); I != N; ++I) {
StringRef Name = Path[I].first->getName();
StringRef Name = Path[I].getIdentifierInfo()->getName();
clang::Module *Sub = Module->findSubmodule(Name);
// If the user is requesting Foo.Private and it doesn't exist, try to
@ -2078,10 +2079,10 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
SmallString<128> PrivateModule(Module->Name);
PrivateModule.append("_Private");
SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> PrivPath;
SmallVector<IdentifierLoc, 2> PrivPath;
auto &II = PP->getIdentifierTable().get(
PrivateModule, PP->getIdentifierInfo(Module->Name)->getTokenID());
PrivPath.push_back(std::make_pair(&II, Path[0].second));
PrivPath.emplace_back(Path[0].getLoc(), &II);
std::string FileName;
// If there is a modulemap module or prebuilt module, load it.
@ -2095,11 +2096,12 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
PP->markClangModuleAsAffecting(Module);
if (!getDiagnostics().isIgnored(
diag::warn_no_priv_submodule_use_toplevel, ImportLoc)) {
getDiagnostics().Report(Path[I].second,
getDiagnostics().Report(Path[I].getLoc(),
diag::warn_no_priv_submodule_use_toplevel)
<< Path[I].first << Module->getFullModuleName() << PrivateModule
<< SourceRange(Path[0].second, Path[I].second)
<< FixItHint::CreateReplacement(SourceRange(Path[0].second),
<< Path[I].getIdentifierInfo() << Module->getFullModuleName()
<< PrivateModule
<< SourceRange(Path[0].getLoc(), Path[I].getLoc())
<< FixItHint::CreateReplacement(SourceRange(Path[0].getLoc()),
PrivateModule);
getDiagnostics().Report(Sub->DefinitionLoc,
diag::note_private_top_level_defined);
@ -2128,10 +2130,11 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
// If there was a clear winner, user it.
if (Best.size() == 1) {
getDiagnostics().Report(Path[I].second, diag::err_no_submodule_suggest)
<< Path[I].first << Module->getFullModuleName() << Best[0]
<< SourceRange(Path[0].second, Path[I - 1].second)
<< FixItHint::CreateReplacement(SourceRange(Path[I].second),
getDiagnostics().Report(Path[I].getLoc(),
diag::err_no_submodule_suggest)
<< Path[I].getIdentifierInfo() << Module->getFullModuleName()
<< Best[0] << SourceRange(Path[0].getLoc(), Path[I - 1].getLoc())
<< FixItHint::CreateReplacement(SourceRange(Path[I].getLoc()),
Best[0]);
Sub = Module->findSubmodule(Best[0]);
@ -2141,9 +2144,9 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
if (!Sub) {
// No submodule by this name. Complain, and don't look for further
// submodules.
getDiagnostics().Report(Path[I].second, diag::err_no_submodule)
<< Path[I].first << Module->getFullModuleName()
<< SourceRange(Path[0].second, Path[I - 1].second);
getDiagnostics().Report(Path[I].getLoc(), diag::err_no_submodule)
<< Path[I].getIdentifierInfo() << Module->getFullModuleName()
<< SourceRange(Path[0].getLoc(), Path[I - 1].getLoc());
break;
}
@ -2161,8 +2164,8 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
// FIXME: Should we detect this at module load time? It seems fairly
// expensive (and rare).
getDiagnostics().Report(ImportLoc, diag::warn_missing_submodule)
<< Module->getFullModuleName()
<< SourceRange(Path.front().second, Path.back().second);
<< Module->getFullModuleName()
<< SourceRange(Path.front().getLoc(), Path.back().getLoc());
return ModuleLoadResult(Module, ModuleLoadResult::MissingExpected);
}
@ -2171,7 +2174,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
if (Preprocessor::checkModuleIsAvailable(getLangOpts(), getTarget(),
*Module, getDiagnostics())) {
getDiagnostics().Report(ImportLoc, diag::note_module_import_here)
<< SourceRange(Path.front().second, Path.back().second);
<< SourceRange(Path.front().getLoc(), Path.back().getLoc());
LastModuleImportLoc = ImportLoc;
LastModuleImportResult = ModuleLoadResult();
return ModuleLoadResult();
@ -2296,9 +2299,9 @@ GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex(
Module *TheModule = I->second;
OptionalFileEntryRef Entry = TheModule->getASTFile();
if (!Entry) {
SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path;
Path.push_back(std::make_pair(
getPreprocessor().getIdentifierInfo(TheModule->Name), TriggerLoc));
SmallVector<IdentifierLoc, 2> Path;
Path.emplace_back(TriggerLoc,
getPreprocessor().getIdentifierInfo(TheModule->Name));
std::reverse(Path.begin(), Path.end());
// Load a module as hidden. This also adds it to the global index.
loadModule(TheModule->DefinitionLoc, Path, Module::Hidden, false);

View File

@ -1216,9 +1216,9 @@ void GetDependenciesByModuleNameAction::ExecuteAction() {
SourceManager &SM = PP.getSourceManager();
FileID MainFileID = SM.getMainFileID();
SourceLocation FileStart = SM.getLocForStartOfFile(MainFileID);
SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path;
SmallVector<IdentifierLoc, 2> Path;
IdentifierInfo *ModuleID = PP.getIdentifierInfo(ModuleName);
Path.push_back(std::make_pair(ModuleID, FileStart));
Path.emplace_back(FileStart, ModuleID);
auto ModResult = CI.loadModule(FileStart, Path, Module::Hidden, false);
PPCallbacks *CB = PP.getPPCallbacks();
CB->moduleImport(SourceLocation(), Path, ModResult);

View File

@ -1916,15 +1916,15 @@ void Preprocessor::EnterAnnotationToken(SourceRange Range,
/// Produce a diagnostic informing the user that a #include or similar
/// was implicitly treated as a module import.
static void diagnoseAutoModuleImport(
Preprocessor &PP, SourceLocation HashLoc, Token &IncludeTok,
ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> Path,
SourceLocation PathEnd) {
static void diagnoseAutoModuleImport(Preprocessor &PP, SourceLocation HashLoc,
Token &IncludeTok,
ArrayRef<IdentifierLoc> Path,
SourceLocation PathEnd) {
SmallString<128> PathString;
for (size_t I = 0, N = Path.size(); I != N; ++I) {
if (I)
PathString += '.';
PathString += Path[I].first->getName();
PathString += Path[I].getIdentifierInfo()->getName();
}
int IncludeKind = 0;
@ -2273,12 +2273,12 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
SourceLocation StartLoc = IsImportDecl ? IncludeTok.getLocation() : HashLoc;
// Complain about attempts to #include files in an audit pragma.
if (PragmaARCCFCodeAuditedInfo.second.isValid()) {
if (PragmaARCCFCodeAuditedInfo.getLoc().isValid()) {
Diag(StartLoc, diag::err_pp_include_in_arc_cf_code_audited) << IsImportDecl;
Diag(PragmaARCCFCodeAuditedInfo.second, diag::note_pragma_entered_here);
Diag(PragmaARCCFCodeAuditedInfo.getLoc(), diag::note_pragma_entered_here);
// Immediately leave the pragma.
PragmaARCCFCodeAuditedInfo = {nullptr, SourceLocation()};
PragmaARCCFCodeAuditedInfo = IdentifierLoc();
}
// Complain about attempts to #include files in an assume-nonnull pragma.
@ -2403,10 +2403,10 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
// Compute the module access path corresponding to this module.
// FIXME: Should we have a second loadModule() overload to avoid this
// extra lookup step?
SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path;
SmallVector<IdentifierLoc, 2> Path;
for (Module *Mod = ModuleToImport; Mod; Mod = Mod->Parent)
Path.push_back(std::make_pair(getIdentifierInfo(Mod->Name),
FilenameTok.getLocation()));
Path.emplace_back(FilenameTok.getLocation(),
getIdentifierInfo(Mod->Name));
std::reverse(Path.begin(), Path.end());
// Warn that we're replacing the include/import with a module import.

View File

@ -409,13 +409,13 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) {
// Complain about reaching a true EOF within arc_cf_code_audited.
// We don't want to complain about reaching the end of a macro
// instantiation or a _Pragma.
if (PragmaARCCFCodeAuditedInfo.second.isValid() && !isEndOfMacro &&
if (PragmaARCCFCodeAuditedInfo.getLoc().isValid() && !isEndOfMacro &&
!(CurLexer && CurLexer->Is_PragmaLexer)) {
Diag(PragmaARCCFCodeAuditedInfo.second,
Diag(PragmaARCCFCodeAuditedInfo.getLoc(),
diag::err_pp_eof_in_arc_cf_code_audited);
// Recover by leaving immediately.
PragmaARCCFCodeAuditedInfo = {nullptr, SourceLocation()};
PragmaARCCFCodeAuditedInfo = IdentifierLoc();
}
// Complain about reaching a true EOF within assume_nonnull.

View File

@ -763,20 +763,19 @@ void Preprocessor::HandlePragmaIncludeAlias(Token &Tok) {
// Lex a component of a module name: either an identifier or a string literal;
// for components that can be expressed both ways, the two forms are equivalent.
static bool LexModuleNameComponent(
Preprocessor &PP, Token &Tok,
std::pair<IdentifierInfo *, SourceLocation> &ModuleNameComponent,
bool First) {
static bool LexModuleNameComponent(Preprocessor &PP, Token &Tok,
IdentifierLoc &ModuleNameComponent,
bool First) {
PP.LexUnexpandedToken(Tok);
if (Tok.is(tok::string_literal) && !Tok.hasUDSuffix()) {
StringLiteralParser Literal(Tok, PP);
if (Literal.hadError)
return true;
ModuleNameComponent = std::make_pair(
PP.getIdentifierInfo(Literal.GetString()), Tok.getLocation());
ModuleNameComponent = IdentifierLoc(
Tok.getLocation(), PP.getIdentifierInfo(Literal.GetString()));
} else if (!Tok.isAnnotation() && Tok.getIdentifierInfo()) {
ModuleNameComponent =
std::make_pair(Tok.getIdentifierInfo(), Tok.getLocation());
IdentifierLoc(Tok.getLocation(), Tok.getIdentifierInfo());
} else {
PP.Diag(Tok.getLocation(), diag::err_pp_expected_module_name) << First;
return true;
@ -784,12 +783,10 @@ static bool LexModuleNameComponent(
return false;
}
static bool LexModuleName(
Preprocessor &PP, Token &Tok,
llvm::SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>>
&ModuleName) {
static bool LexModuleName(Preprocessor &PP, Token &Tok,
llvm::SmallVectorImpl<IdentifierLoc> &ModuleName) {
while (true) {
std::pair<IdentifierInfo*, SourceLocation> NameComponent;
IdentifierLoc NameComponent;
if (LexModuleNameComponent(PP, Tok, NameComponent, ModuleName.empty()))
return true;
ModuleName.push_back(NameComponent);
@ -803,10 +800,10 @@ static bool LexModuleName(
void Preprocessor::HandlePragmaModuleBuild(Token &Tok) {
SourceLocation Loc = Tok.getLocation();
std::pair<IdentifierInfo *, SourceLocation> ModuleNameLoc;
IdentifierLoc ModuleNameLoc;
if (LexModuleNameComponent(*this, Tok, ModuleNameLoc, true))
return;
IdentifierInfo *ModuleName = ModuleNameLoc.first;
IdentifierInfo *ModuleName = ModuleNameLoc.getIdentifierInfo();
LexUnexpandedToken(Tok);
if (Tok.isNot(tok::eod)) {
@ -1109,17 +1106,17 @@ struct PragmaDebugHandler : public PragmaHandler {
PP.Diag(MacroName, diag::warn_pragma_debug_missing_argument)
<< II->getName();
} else if (II->isStr("module_map")) {
llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 8>
ModuleName;
llvm::SmallVector<IdentifierLoc, 8> ModuleName;
if (LexModuleName(PP, Tok, ModuleName))
return;
ModuleMap &MM = PP.getHeaderSearchInfo().getModuleMap();
Module *M = nullptr;
for (auto IIAndLoc : ModuleName) {
M = MM.lookupModuleQualified(IIAndLoc.first->getName(), M);
M = MM.lookupModuleQualified(IIAndLoc.getIdentifierInfo()->getName(),
M);
if (!M) {
PP.Diag(IIAndLoc.second, diag::warn_pragma_debug_unknown_module)
<< IIAndLoc.first->getName();
PP.Diag(IIAndLoc.getLoc(), diag::warn_pragma_debug_unknown_module)
<< IIAndLoc.getIdentifierInfo()->getName();
return;
}
}
@ -1707,8 +1704,7 @@ struct PragmaModuleImportHandler : public PragmaHandler {
SourceLocation ImportLoc = Tok.getLocation();
// Read the module name.
llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 8>
ModuleName;
llvm::SmallVector<IdentifierLoc, 8> ModuleName;
if (LexModuleName(PP, Tok, ModuleName))
return;
@ -1723,7 +1719,7 @@ struct PragmaModuleImportHandler : public PragmaHandler {
return;
PP.makeModuleVisible(Imported, ImportLoc);
PP.EnterAnnotationToken(SourceRange(ImportLoc, ModuleName.back().second),
PP.EnterAnnotationToken(SourceRange(ImportLoc, ModuleName.back().getLoc()),
tok::annot_module_include, Imported);
if (auto *CB = PP.getPPCallbacks())
CB->moduleImport(ImportLoc, ModuleName, Imported);
@ -1744,8 +1740,7 @@ struct PragmaModuleBeginHandler : public PragmaHandler {
SourceLocation BeginLoc = Tok.getLocation();
// Read the module name.
llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 8>
ModuleName;
llvm::SmallVector<IdentifierLoc, 8> ModuleName;
if (LexModuleName(PP, Tok, ModuleName))
return;
@ -1754,10 +1749,11 @@ struct PragmaModuleBeginHandler : public PragmaHandler {
// We can only enter submodules of the current module.
StringRef Current = PP.getLangOpts().CurrentModule;
if (ModuleName.front().first->getName() != Current) {
PP.Diag(ModuleName.front().second, diag::err_pp_module_begin_wrong_module)
<< ModuleName.front().first << (ModuleName.size() > 1)
<< Current.empty() << Current;
if (ModuleName.front().getIdentifierInfo()->getName() != Current) {
PP.Diag(ModuleName.front().getLoc(),
diag::err_pp_module_begin_wrong_module)
<< ModuleName.front().getIdentifierInfo() << (ModuleName.size() > 1)
<< Current.empty() << Current;
return;
}
@ -1765,17 +1761,19 @@ struct PragmaModuleBeginHandler : public PragmaHandler {
// be loaded or implicitly loadable.
auto &HSI = PP.getHeaderSearchInfo();
auto &MM = HSI.getModuleMap();
Module *M = HSI.lookupModule(Current, ModuleName.front().second);
Module *M = HSI.lookupModule(Current, ModuleName.front().getLoc());
if (!M) {
PP.Diag(ModuleName.front().second,
diag::err_pp_module_begin_no_module_map) << Current;
PP.Diag(ModuleName.front().getLoc(),
diag::err_pp_module_begin_no_module_map)
<< Current;
return;
}
for (unsigned I = 1; I != ModuleName.size(); ++I) {
auto *NewM = MM.findOrInferSubmodule(M, ModuleName[I].first->getName());
auto *NewM = MM.findOrInferSubmodule(
M, ModuleName[I].getIdentifierInfo()->getName());
if (!NewM) {
PP.Diag(ModuleName[I].second, diag::err_pp_module_begin_no_submodule)
<< M->getFullModuleName() << ModuleName[I].first;
PP.Diag(ModuleName[I].getLoc(), diag::err_pp_module_begin_no_submodule)
<< M->getFullModuleName() << ModuleName[I].getIdentifierInfo();
return;
}
M = NewM;
@ -1791,7 +1789,7 @@ struct PragmaModuleBeginHandler : public PragmaHandler {
// Enter the scope of the submodule.
PP.EnterSubmodule(M, BeginLoc, /*ForPragma*/true);
PP.EnterAnnotationToken(SourceRange(BeginLoc, ModuleName.back().second),
PP.EnterAnnotationToken(SourceRange(BeginLoc, ModuleName.back().getLoc()),
tok::annot_module_begin, M);
}
};
@ -1835,8 +1833,7 @@ struct PragmaModuleLoadHandler : public PragmaHandler {
SourceLocation Loc = Tok.getLocation();
// Read the module name.
llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 8>
ModuleName;
llvm::SmallVector<IdentifierLoc, 8> ModuleName;
if (LexModuleName(PP, Tok, ModuleName))
return;
@ -1901,7 +1898,7 @@ struct PragmaARCCFCodeAuditedHandler : public PragmaHandler {
PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
// The start location of the active audit.
SourceLocation BeginLoc = PP.getPragmaARCCFCodeAuditedInfo().second;
SourceLocation BeginLoc = PP.getPragmaARCCFCodeAuditedInfo().getLoc();
// The start location we want after processing this.
SourceLocation NewLoc;

View File

@ -1159,8 +1159,8 @@ bool Preprocessor::LexAfterModuleImport(Token &Result) {
if (Result.is(tok::colon) && ModuleDeclState.isNamedModule()) {
std::string Name = ModuleDeclState.getPrimaryName().str();
Name += ":";
NamedModuleImportPath.push_back(
{getIdentifierInfo(Name), Result.getLocation()});
NamedModuleImportPath.emplace_back(Result.getLocation(),
getIdentifierInfo(Name));
CurLexerCallback = CLK_LexAfterModuleImport;
return true;
}
@ -1258,8 +1258,8 @@ bool Preprocessor::LexAfterModuleImport(Token &Result) {
if (ModuleImportExpectsIdentifier && Result.getKind() == tok::identifier) {
// We expected to see an identifier here, and we did; continue handling
// identifiers.
NamedModuleImportPath.push_back(
std::make_pair(Result.getIdentifierInfo(), Result.getLocation()));
NamedModuleImportPath.emplace_back(Result.getLocation(),
Result.getIdentifierInfo());
ModuleImportExpectsIdentifier = false;
CurLexerCallback = CLK_LexAfterModuleImport;
return true;
@ -1302,12 +1302,12 @@ bool Preprocessor::LexAfterModuleImport(Token &Result) {
// If the FlatModuleName ends with colon, it implies it is a partition.
if (!FlatModuleName.empty() && FlatModuleName.back() != ':')
FlatModuleName += ".";
FlatModuleName += Piece.first->getName();
FlatModuleName += Piece.getIdentifierInfo()->getName();
}
SourceLocation FirstPathLoc = NamedModuleImportPath[0].second;
SourceLocation FirstPathLoc = NamedModuleImportPath[0].getLoc();
NamedModuleImportPath.clear();
NamedModuleImportPath.push_back(
std::make_pair(getIdentifierInfo(FlatModuleName), FirstPathLoc));
NamedModuleImportPath.emplace_back(FirstPathLoc,
getIdentifierInfo(FlatModuleName));
}
Module *Imported = nullptr;

View File

@ -432,9 +432,8 @@ static bool attributeParsedArgsUnevaluated(const IdentifierInfo &II,
IdentifierLoc *Parser::ParseIdentifierLoc() {
assert(Tok.is(tok::identifier) && "expected an identifier");
IdentifierLoc *IL = IdentifierLoc::create(Actions.Context,
Tok.getLocation(),
Tok.getIdentifierInfo());
IdentifierLoc *IL = new (Actions.Context)
IdentifierLoc(Tok.getLocation(), Tok.getIdentifierInfo());
ConsumeToken();
return IL;
}
@ -1353,20 +1352,21 @@ void Parser::ParseAvailabilityAttribute(
return;
}
IdentifierLoc *Platform = ParseIdentifierLoc();
if (const IdentifierInfo *const Ident = Platform->Ident) {
if (const IdentifierInfo *const Ident = Platform->getIdentifierInfo()) {
// Disallow xrOS for availability attributes.
if (Ident->getName().contains("xrOS") || Ident->getName().contains("xros"))
Diag(Platform->Loc, diag::warn_availability_unknown_platform) << Ident;
Diag(Platform->getLoc(), diag::warn_availability_unknown_platform)
<< Ident;
// Canonicalize platform name from "macosx" to "macos".
else if (Ident->getName() == "macosx")
Platform->Ident = PP.getIdentifierInfo("macos");
Platform->setIdentifierInfo(PP.getIdentifierInfo("macos"));
// Canonicalize platform name from "macosx_app_extension" to
// "macos_app_extension".
else if (Ident->getName() == "macosx_app_extension")
Platform->Ident = PP.getIdentifierInfo("macos_app_extension");
Platform->setIdentifierInfo(PP.getIdentifierInfo("macos_app_extension"));
else
Platform->Ident = PP.getIdentifierInfo(
AvailabilityAttr::canonicalizePlatformName(Ident->getName()));
Platform->setIdentifierInfo(PP.getIdentifierInfo(
AvailabilityAttr::canonicalizePlatformName(Ident->getName())));
}
// Parse the ',' following the platform name.
@ -1418,8 +1418,8 @@ void Parser::ParseAvailabilityAttribute(
continue;
}
if (Keyword == Ident_deprecated && Platform->Ident &&
Platform->Ident->isStr("swift")) {
if (Keyword == Ident_deprecated && Platform->getIdentifierInfo() &&
Platform->getIdentifierInfo()->isStr("swift")) {
// For swift, we deprecate for all versions.
if (Changes[Deprecated].KeywordLoc.isValid()) {
Diag(KeywordLoc, diag::err_availability_redundant)
@ -1436,7 +1436,7 @@ void Parser::ParseAvailabilityAttribute(
if (Keyword == Ident_environment) {
if (EnvironmentLoc != nullptr) {
Diag(KeywordLoc, diag::err_availability_redundant)
<< Keyword << SourceRange(EnvironmentLoc->Loc);
<< Keyword << SourceRange(EnvironmentLoc->getLoc());
}
}
@ -1792,8 +1792,8 @@ void Parser::ParseSwiftNewTypeAttribute(
return;
}
auto *SwiftType = IdentifierLoc::create(Actions.Context, Tok.getLocation(),
Tok.getIdentifierInfo());
auto *SwiftType = new (Actions.Context)
IdentifierLoc(Tok.getLocation(), Tok.getIdentifierInfo());
ConsumeToken();
// Closing ')'

View File

@ -4006,19 +4006,20 @@ std::optional<AvailabilitySpec> Parser::ParseAvailabilitySpec() {
if (Version.empty())
return std::nullopt;
StringRef GivenPlatform = PlatformIdentifier->Ident->getName();
StringRef GivenPlatform =
PlatformIdentifier->getIdentifierInfo()->getName();
StringRef Platform =
AvailabilityAttr::canonicalizePlatformName(GivenPlatform);
if (AvailabilityAttr::getPrettyPlatformName(Platform).empty() ||
(GivenPlatform.contains("xros") || GivenPlatform.contains("xrOS"))) {
Diag(PlatformIdentifier->Loc,
Diag(PlatformIdentifier->getLoc(),
diag::err_avail_query_unrecognized_platform_name)
<< GivenPlatform;
return std::nullopt;
}
return AvailabilitySpec(Version, Platform, PlatformIdentifier->Loc,
return AvailabilitySpec(Version, Platform, PlatformIdentifier->getLoc(),
VersionRange.getEnd());
}
}

View File

@ -115,7 +115,7 @@ static void fixSeparateAttrArgAndNumber(StringRef ArgStr, SourceLocation ArgLoc,
<< FixedArg
<< FixItHint::CreateReplacement(SourceRange(ArgLoc, EndNumLoc), FixedArg);
ArgsUnion &Slot = ArgExprs.back();
Slot = IdentifierLoc::create(Ctx, ArgLoc, PP.getIdentifierInfo(FixedArg));
Slot = new (Ctx) IdentifierLoc(ArgLoc, PP.getIdentifierInfo(FixedArg));
}
void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs,

View File

@ -261,7 +261,7 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
// case, LAngleLoc will be valid and ProtocolIdents will capture the
// protocol references (that have not yet been resolved).
SourceLocation LAngleLoc, EndProtoLoc;
SmallVector<IdentifierLocPair, 8> ProtocolIdents;
SmallVector<IdentifierLoc, 8> ProtocolIdents;
ObjCTypeParamList *typeParameterList = nullptr;
ObjCTypeParamListScope typeParamScope(Actions, getCurScope());
if (Tok.is(tok::less))
@ -361,8 +361,8 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
if (!ProtocolIdents.empty()) {
// We already parsed the protocols named when we thought we had a
// type parameter list. Translate them into actual protocol references.
for (const auto &pair : ProtocolIdents) {
protocolLocs.push_back(pair.second);
for (const auto &Loc : ProtocolIdents) {
protocolLocs.push_back(Loc.getLoc());
}
Actions.ObjC().FindProtocolDeclaration(/*WarnOnDeclarations=*/true,
/*ForObjCContainer=*/true,
@ -459,8 +459,8 @@ static void addContextSensitiveTypeNullability(Parser &P,
/// \param rAngleLoc The location of the ending '>'.
ObjCTypeParamList *Parser::parseObjCTypeParamListOrProtocolRefs(
ObjCTypeParamListScope &Scope, SourceLocation &lAngleLoc,
SmallVectorImpl<IdentifierLocPair> &protocolIdents,
SourceLocation &rAngleLoc, bool mayBeProtocolList) {
SmallVectorImpl<IdentifierLoc> &protocolIdents, SourceLocation &rAngleLoc,
bool mayBeProtocolList) {
assert(Tok.is(tok::less) && "Not at the beginning of a type parameter list");
// Within the type parameter list, don't treat '>' as an operator.
@ -474,7 +474,8 @@ ObjCTypeParamList *Parser::parseObjCTypeParamListOrProtocolRefs(
for (const auto &pair : protocolIdents) {
DeclResult typeParam = Actions.ObjC().actOnObjCTypeParam(
getCurScope(), ObjCTypeParamVariance::Invariant, SourceLocation(),
index++, pair.first, pair.second, SourceLocation(), nullptr);
index++, pair.getIdentifierInfo(), pair.getLoc(), SourceLocation(),
nullptr);
if (typeParam.isUsable())
typeParams.push_back(typeParam.get());
}
@ -546,7 +547,7 @@ ObjCTypeParamList *Parser::parseObjCTypeParamListOrProtocolRefs(
} else if (mayBeProtocolList) {
// If this could still be a protocol list, just capture the identifier.
// We don't want to turn it into a parameter.
protocolIdents.push_back(std::make_pair(paramName, paramLoc));
protocolIdents.emplace_back(paramLoc, paramName);
continue;
}
@ -606,7 +607,7 @@ ObjCTypeParamList *Parser::parseObjCTypeParamListOrProtocolRefs(
/// Parse an objc-type-parameter-list.
ObjCTypeParamList *Parser::parseObjCTypeParamList() {
SourceLocation lAngleLoc;
SmallVector<IdentifierLocPair, 1> protocolIdents;
SmallVector<IdentifierLoc, 1> protocolIdents;
SourceLocation rAngleLoc;
ObjCTypeParamListScope Scope(Actions, getCurScope());
@ -1598,7 +1599,7 @@ ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &Protocols,
LAngleLoc = ConsumeToken(); // the "<"
SmallVector<IdentifierLocPair, 8> ProtocolIdents;
SmallVector<IdentifierLoc, 8> ProtocolIdents;
while (true) {
if (Tok.is(tok::code_completion)) {
@ -1612,8 +1613,7 @@ ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &Protocols,
SkipUntil(tok::greater, StopAtSemi);
return true;
}
ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(),
Tok.getLocation()));
ProtocolIdents.emplace_back(Tok.getLocation(), Tok.getIdentifierInfo());
ProtocolLocs.push_back(Tok.getLocation());
ConsumeToken();
@ -1693,10 +1693,9 @@ void Parser::parseObjCTypeArgsOrProtocolQualifiers(
if (Tok.is(tok::code_completion)) {
// FIXME: Also include types here.
SmallVector<IdentifierLocPair, 4> identifierLocPairs;
SmallVector<IdentifierLoc, 4> identifierLocPairs;
for (unsigned i = 0, n = identifiers.size(); i != n; ++i) {
identifierLocPairs.push_back(IdentifierLocPair(identifiers[i],
identifierLocs[i]));
identifierLocPairs.emplace_back(identifierLocs[i], identifiers[i]);
}
QualType BaseT = Actions.GetTypeFromParser(baseType);
@ -2094,7 +2093,7 @@ Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc,
SourceLocation nameLoc = ConsumeToken();
if (TryConsumeToken(tok::semi)) { // forward declaration of one protocol.
IdentifierLocPair ProtoInfo(protocolName, nameLoc);
IdentifierLoc ProtoInfo(nameLoc, protocolName);
return Actions.ObjC().ActOnForwardProtocolDeclaration(AtLoc, ProtoInfo,
attrs);
}
@ -2102,8 +2101,8 @@ Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc,
CheckNestedObjCContexts(AtLoc);
if (Tok.is(tok::comma)) { // list of forward declarations.
SmallVector<IdentifierLocPair, 8> ProtocolRefs;
ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc));
SmallVector<IdentifierLoc, 8> ProtocolRefs;
ProtocolRefs.emplace_back(nameLoc, protocolName);
// Parse the list of forward declarations.
while (true) {
@ -2112,8 +2111,7 @@ Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc,
SkipUntil(tok::semi);
return nullptr;
}
ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(),
Tok.getLocation()));
ProtocolRefs.emplace_back(Tok.getLocation(), Tok.getIdentifierInfo());
ConsumeToken(); // the identifier
if (Tok.isNot(tok::comma))
@ -2196,7 +2194,7 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
// permitted here. Parse and diagnose them.
if (Tok.is(tok::less)) {
SourceLocation lAngleLoc, rAngleLoc;
SmallVector<IdentifierLocPair, 8> protocolIdents;
SmallVector<IdentifierLoc, 8> protocolIdents;
SourceLocation diagLoc = Tok.getLocation();
ObjCTypeParamListScope typeParamScope(Actions, getCurScope());
if (parseObjCTypeParamListOrProtocolRefs(typeParamScope, lAngleLoc,

View File

@ -15,6 +15,7 @@
#include "clang/Basic/OpenACCKinds.h"
#include "clang/Parse/Parser.h"
#include "clang/Parse/RAIIObjectsForParser.h"
#include "clang/Sema/ParsedAttr.h"
#include "clang/Sema/SemaOpenACC.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
@ -814,7 +815,7 @@ bool Parser::ParseOpenACCIntExprList(OpenACCDirectiveKind DK,
///
/// The device_type clause may be abbreviated to dtype.
bool Parser::ParseOpenACCDeviceTypeList(
llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>> &Archs) {
llvm::SmallVector<IdentifierLoc> &Archs) {
if (expectIdentifierOrKeyword(*this)) {
SkipUntil(tok::r_paren, tok::annot_pragma_openacc_end,
@ -822,7 +823,7 @@ bool Parser::ParseOpenACCDeviceTypeList(
return true;
}
IdentifierInfo *Ident = getCurToken().getIdentifierInfo();
Archs.emplace_back(Ident, ConsumeToken());
Archs.emplace_back(ConsumeToken(), Ident);
while (!getCurToken().isOneOf(tok::r_paren, tok::annot_pragma_openacc_end)) {
ExpectAndConsume(tok::comma);
@ -833,7 +834,7 @@ bool Parser::ParseOpenACCDeviceTypeList(
return true;
}
Ident = getCurToken().getIdentifierInfo();
Archs.emplace_back(Ident, ConsumeToken());
Archs.emplace_back(ConsumeToken(), Ident);
}
return false;
}
@ -1154,11 +1155,12 @@ Parser::OpenACCClauseParseResult Parser::ParseOpenACCClauseParams(
}
case OpenACCClauseKind::DType:
case OpenACCClauseKind::DeviceType: {
llvm::SmallVector<std::pair<IdentifierInfo *, SourceLocation>> Archs;
llvm::SmallVector<IdentifierLoc> Archs;
if (getCurToken().is(tok::star)) {
// FIXME: We want to mark that this is an 'everything else' type of
// device_type in Sema.
ParsedClause.setDeviceTypeDetails({{nullptr, ConsumeToken()}});
ParsedClause.setDeviceTypeDetails(
{IdentifierLoc(ConsumeToken(), nullptr)});
} else if (!ParseOpenACCDeviceTypeList(Archs)) {
ParsedClause.setDeviceTypeDetails(std::move(Archs));
} else {

View File

@ -1419,16 +1419,16 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
static_cast<PragmaLoopHintInfo *>(Tok.getAnnotationValue());
IdentifierInfo *PragmaNameInfo = Info->PragmaName.getIdentifierInfo();
Hint.PragmaNameLoc = IdentifierLoc::create(
Actions.Context, Info->PragmaName.getLocation(), PragmaNameInfo);
Hint.PragmaNameLoc = new (Actions.Context)
IdentifierLoc(Info->PragmaName.getLocation(), PragmaNameInfo);
// It is possible that the loop hint has no option identifier, such as
// #pragma unroll(4).
IdentifierInfo *OptionInfo = Info->Option.is(tok::identifier)
? Info->Option.getIdentifierInfo()
: nullptr;
Hint.OptionLoc = IdentifierLoc::create(
Actions.Context, Info->Option.getLocation(), OptionInfo);
Hint.OptionLoc = new (Actions.Context)
IdentifierLoc(Info->Option.getLocation(), OptionInfo);
llvm::ArrayRef<Token> Toks = Info->Toks;
@ -1508,7 +1508,7 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
if (Toks.size() > 2)
Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)
<< PragmaLoopHintString(Info->PragmaName, Info->Option);
Hint.StateLoc = IdentifierLoc::create(Actions.Context, StateLoc, StateInfo);
Hint.StateLoc = new (Actions.Context) IdentifierLoc(StateLoc, StateInfo);
} else if (OptionInfo && OptionInfo->getName() == "vectorize_width") {
PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/false,
/*IsReinject=*/false);
@ -1529,8 +1529,7 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
ConsumeAnyToken();
}
Hint.StateLoc =
IdentifierLoc::create(Actions.Context, StateLoc, StateInfo);
Hint.StateLoc = new (Actions.Context) IdentifierLoc(StateLoc, StateInfo);
ConsumeToken(); // Consume the constant expression eof terminator.
} else {
@ -1554,7 +1553,7 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
Arg2Error = true;
} else
Hint.StateLoc =
IdentifierLoc::create(Actions.Context, StateLoc, StateInfo);
new (Actions.Context) IdentifierLoc(StateLoc, StateInfo);
PP.Lex(Tok); // Identifier
}

View File

@ -2545,9 +2545,9 @@ StmtResult Parser::ParsePragmaLoopHint(StmtVector &Stmts,
ArgsUnion ArgHints[] = {Hint.PragmaNameLoc, Hint.OptionLoc, Hint.StateLoc,
ArgsUnion(Hint.ValueExpr)};
TempAttrs.addNew(Hint.PragmaNameLoc->Ident, Hint.Range, nullptr,
Hint.PragmaNameLoc->Loc, ArgHints, 4,
ParsedAttr::Form::Pragma());
TempAttrs.addNew(Hint.PragmaNameLoc->getIdentifierInfo(), Hint.Range,
/*scopeName=*/nullptr, Hint.PragmaNameLoc->getLoc(),
ArgHints, /*numArgs=*/4, ParsedAttr::Form::Pragma());
}
// Get the next statement.

View File

@ -2541,17 +2541,17 @@ Parser::ParseModuleDecl(Sema::ModuleImportState &ImportState) {
return Actions.ActOnPrivateModuleFragmentDecl(ModuleLoc, PrivateLoc);
}
SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path;
SmallVector<IdentifierLoc, 2> Path;
if (ParseModuleName(ModuleLoc, Path, /*IsImport*/ false))
return nullptr;
// Parse the optional module-partition.
SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Partition;
SmallVector<IdentifierLoc, 2> Partition;
if (Tok.is(tok::colon)) {
SourceLocation ColonLoc = ConsumeToken();
if (!getLangOpts().CPlusPlusModules)
Diag(ColonLoc, diag::err_unsupported_module_partition)
<< SourceRange(ColonLoc, Partition.back().second);
<< SourceRange(ColonLoc, Partition.back().getLoc());
// Recover by ignoring the partition name.
else if (ParseModuleName(ModuleLoc, Partition, /*IsImport*/ false))
return nullptr;
@ -2600,7 +2600,7 @@ Decl *Parser::ParseModuleImport(SourceLocation AtLoc,
SourceLocation ImportLoc = ConsumeToken();
// For C++20 modules, we can have "name" or ":Partition name" as valid input.
SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path;
SmallVector<IdentifierLoc, 2> Path;
bool IsPartition = false;
Module *HeaderUnit = nullptr;
if (Tok.is(tok::header_name)) {
@ -2616,7 +2616,7 @@ Decl *Parser::ParseModuleImport(SourceLocation AtLoc,
SourceLocation ColonLoc = ConsumeToken();
if (!getLangOpts().CPlusPlusModules)
Diag(ColonLoc, diag::err_unsupported_module_partition)
<< SourceRange(ColonLoc, Path.back().second);
<< SourceRange(ColonLoc, Path.back().getLoc());
// Recover by leaving partition empty.
else if (ParseModuleName(ColonLoc, Path, /*IsImport*/ true))
return nullptr;
@ -2718,10 +2718,9 @@ Decl *Parser::ParseModuleImport(SourceLocation AtLoc,
/// module-name-qualifier[opt] identifier
/// module-name-qualifier:
/// module-name-qualifier[opt] identifier '.'
bool Parser::ParseModuleName(
SourceLocation UseLoc,
SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>> &Path,
bool IsImport) {
bool Parser::ParseModuleName(SourceLocation UseLoc,
SmallVectorImpl<IdentifierLoc> &Path,
bool IsImport) {
// Parse the module path.
while (true) {
if (!Tok.is(tok::identifier)) {
@ -2737,7 +2736,7 @@ bool Parser::ParseModuleName(
}
// Record this part of the module path.
Path.push_back(std::make_pair(Tok.getIdentifierInfo(), Tok.getLocation()));
Path.emplace_back(Tok.getLocation(), Tok.getIdentifierInfo());
ConsumeToken();
if (Tok.isNot(tok::period))

View File

@ -23,14 +23,6 @@
using namespace clang;
IdentifierLoc *IdentifierLoc::create(ASTContext &Ctx, SourceLocation Loc,
IdentifierInfo *Ident) {
IdentifierLoc *Result = new (Ctx) IdentifierLoc;
Result->Loc = Loc;
Result->Ident = Ident;
return Result;
}
size_t ParsedAttr::allocated_size() const {
if (IsAvailability) return AttributeFactory::AvailabilityAllocSize;
else if (IsTypeTagForDatatype)

View File

@ -1178,7 +1178,7 @@ void SemaARM::handleBuiltinAliasAttr(Decl *D, const ParsedAttr &AL) {
return;
}
IdentifierInfo *Ident = AL.getArgAsIdent(0)->Ident;
IdentifierInfo *Ident = AL.getArgAsIdent(0)->getIdentifierInfo();
unsigned BuiltinID = Ident->getBuiltinID();
StringRef AliasName = cast<FunctionDecl>(D)->getIdentifier()->getName();

View File

@ -8718,7 +8718,7 @@ static void AddProtocolResults(DeclContext *Ctx, DeclContext *CurContext,
}
void SemaCodeCompletion::CodeCompleteObjCProtocolReferences(
ArrayRef<IdentifierLocPair> Protocols) {
ArrayRef<IdentifierLoc> Protocols) {
ResultBuilder Results(SemaRef, CodeCompleter->getAllocator(),
CodeCompleter->getCodeCompletionTUInfo(),
CodeCompletionContext::CCC_ObjCProtocolName);
@ -8729,9 +8729,9 @@ void SemaCodeCompletion::CodeCompleteObjCProtocolReferences(
// Tell the result set to ignore all of the protocols we have
// already seen.
// FIXME: This doesn't work when caching code-completion results.
for (const IdentifierLocPair &Pair : Protocols)
if (ObjCProtocolDecl *Protocol =
SemaRef.ObjC().LookupProtocol(Pair.first, Pair.second))
for (const IdentifierLoc &Pair : Protocols)
if (ObjCProtocolDecl *Protocol = SemaRef.ObjC().LookupProtocol(
Pair.getIdentifierInfo(), Pair.getLoc()))
Results.Ignore(Protocol);
// Add all protocols.

View File

@ -135,13 +135,13 @@ bool Sema::checkStringLiteralArgumentAttr(const ParsedAttr &AL, unsigned ArgNum,
// Look for identifiers. If we have one emit a hint to fix it to a literal.
if (AL.isArgIdent(ArgNum)) {
IdentifierLoc *Loc = AL.getArgAsIdent(ArgNum);
Diag(Loc->Loc, diag::err_attribute_argument_type)
Diag(Loc->getLoc(), diag::err_attribute_argument_type)
<< AL << AANT_ArgumentString
<< FixItHint::CreateInsertion(Loc->Loc, "\"")
<< FixItHint::CreateInsertion(getLocForEndOfToken(Loc->Loc), "\"");
Str = Loc->Ident->getName();
<< FixItHint::CreateInsertion(Loc->getLoc(), "\"")
<< FixItHint::CreateInsertion(getLocForEndOfToken(Loc->getLoc()), "\"");
Str = Loc->getIdentifierInfo()->getName();
if (ArgLocation)
*ArgLocation = Loc->Loc;
*ArgLocation = Loc->getLoc();
return true;
}
@ -768,7 +768,7 @@ static void handleDiagnoseAsBuiltinAttr(Sema &S, Decl *D,
auto Union = AL.getArg(Index - 1);
if (auto *E = dyn_cast<Expr *>(Union))
return E->getBeginLoc();
return cast<IdentifierLoc *>(Union)->Loc;
return cast<IdentifierLoc *>(Union)->getLoc();
}();
S.Diag(Loc, diag::err_attribute_argument_n_type) << AL << Index << T;
@ -960,10 +960,10 @@ static void handleConsumableAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
if (AL.isArgIdent(0)) {
IdentifierLoc *IL = AL.getArgAsIdent(0);
if (!ConsumableAttr::ConvertStrToConsumedState(IL->Ident->getName(),
DefaultState)) {
S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL
<< IL->Ident;
if (!ConsumableAttr::ConvertStrToConsumedState(
IL->getIdentifierInfo()->getName(), DefaultState)) {
S.Diag(IL->getLoc(), diag::warn_attribute_type_not_supported)
<< AL << IL->getIdentifierInfo();
return;
}
} else {
@ -1005,8 +1005,8 @@ static void handleCallableWhenAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
SourceLocation Loc;
if (AL.isArgIdent(ArgIndex)) {
IdentifierLoc *Ident = AL.getArgAsIdent(ArgIndex);
StateString = Ident->Ident->getName();
Loc = Ident->Loc;
StateString = Ident->getIdentifierInfo()->getName();
Loc = Ident->getLoc();
} else {
if (!S.checkStringLiteralArgumentAttr(AL, ArgIndex, StateString, &Loc))
return;
@ -1030,11 +1030,11 @@ static void handleParamTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
if (AL.isArgIdent(0)) {
IdentifierLoc *Ident = AL.getArgAsIdent(0);
StringRef StateString = Ident->Ident->getName();
StringRef StateString = Ident->getIdentifierInfo()->getName();
if (!ParamTypestateAttr::ConvertStrToConsumedState(StateString,
ParamState)) {
S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported)
S.Diag(Ident->getLoc(), diag::warn_attribute_type_not_supported)
<< AL << StateString;
return;
}
@ -1064,10 +1064,10 @@ static void handleReturnTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
if (AL.isArgIdent(0)) {
IdentifierLoc *IL = AL.getArgAsIdent(0);
if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->Ident->getName(),
ReturnState)) {
S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL
<< IL->Ident;
if (!ReturnTypestateAttr::ConvertStrToConsumedState(
IL->getIdentifierInfo()->getName(), ReturnState)) {
S.Diag(IL->getLoc(), diag::warn_attribute_type_not_supported)
<< AL << IL->getIdentifierInfo();
return;
}
} else {
@ -1111,10 +1111,10 @@ static void handleSetTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
SetTypestateAttr::ConsumedState NewState;
if (AL.isArgIdent(0)) {
IdentifierLoc *Ident = AL.getArgAsIdent(0);
StringRef Param = Ident->Ident->getName();
StringRef Param = Ident->getIdentifierInfo()->getName();
if (!SetTypestateAttr::ConvertStrToConsumedState(Param, NewState)) {
S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL
<< Param;
S.Diag(Ident->getLoc(), diag::warn_attribute_type_not_supported)
<< AL << Param;
return;
}
} else {
@ -1133,10 +1133,10 @@ static void handleTestTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
TestTypestateAttr::ConsumedState TestState;
if (AL.isArgIdent(0)) {
IdentifierLoc *Ident = AL.getArgAsIdent(0);
StringRef Param = Ident->Ident->getName();
StringRef Param = Ident->getIdentifierInfo()->getName();
if (!TestTypestateAttr::ConvertStrToConsumedState(Param, TestState)) {
S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL
<< Param;
S.Diag(Ident->getLoc(), diag::warn_attribute_type_not_supported)
<< AL << Param;
return;
}
} else {
@ -1497,7 +1497,7 @@ static void handleOwnershipAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
return;
}
IdentifierInfo *Module = AL.getArgAsIdent(0)->Ident;
IdentifierInfo *Module = AL.getArgAsIdent(0)->getIdentifierInfo();
StringRef ModuleName = Module->getName();
if (normalizeName(ModuleName)) {
@ -1864,10 +1864,10 @@ static void handleCPUSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
}
IdentifierLoc *CPUArg = AL.getArgAsIdent(ArgNo);
StringRef CPUName = CPUArg->Ident->getName().trim();
StringRef CPUName = CPUArg->getIdentifierInfo()->getName().trim();
if (!S.Context.getTargetInfo().validateCPUSpecificCPUDispatch(CPUName)) {
S.Diag(CPUArg->Loc, diag::err_invalid_cpu_specific_dispatch_value)
S.Diag(CPUArg->getLoc(), diag::err_invalid_cpu_specific_dispatch_value)
<< CPUName << (AL.getKind() == ParsedAttr::AT_CPUDispatch);
return;
}
@ -1880,7 +1880,7 @@ static void handleCPUSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
S.Diag(AL.getLoc(), diag::warn_multiversion_duplicate_entries);
return;
}
CPUs.push_back(CPUArg->Ident);
CPUs.push_back(CPUArg->getIdentifierInfo());
}
FD->setIsMultiVersion(true);
@ -2358,10 +2358,10 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
return;
IdentifierLoc *Platform = AL.getArgAsIdent(0);
IdentifierInfo *II = Platform->Ident;
IdentifierInfo *II = Platform->getIdentifierInfo();
if (AvailabilityAttr::getPrettyPlatformName(II->getName()).empty())
S.Diag(Platform->Loc, diag::warn_availability_unknown_platform)
<< Platform->Ident;
S.Diag(Platform->getLoc(), diag::warn_availability_unknown_platform)
<< Platform->getIdentifierInfo();
auto *ND = dyn_cast<NamedDecl>(D);
if (!ND) // We warned about this already, so just return.
@ -2410,14 +2410,16 @@ static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
IdentifierInfo *IIEnvironment = nullptr;
if (EnvironmentLoc) {
if (S.getLangOpts().HLSL) {
IIEnvironment = EnvironmentLoc->Ident;
IIEnvironment = EnvironmentLoc->getIdentifierInfo();
if (AvailabilityAttr::getEnvironmentType(
EnvironmentLoc->Ident->getName()) ==
EnvironmentLoc->getIdentifierInfo()->getName()) ==
llvm::Triple::EnvironmentType::UnknownEnvironment)
S.Diag(EnvironmentLoc->Loc, diag::warn_availability_unknown_environment)
<< EnvironmentLoc->Ident;
S.Diag(EnvironmentLoc->getLoc(),
diag::warn_availability_unknown_environment)
<< EnvironmentLoc->getIdentifierInfo();
} else {
S.Diag(EnvironmentLoc->Loc, diag::err_availability_unexpected_parameter)
S.Diag(EnvironmentLoc->getLoc(),
diag::err_availability_unexpected_parameter)
<< "environment" << /* C/C++ */ 1;
}
}
@ -3630,7 +3632,7 @@ static void handleEnumExtensibilityAttr(Sema &S, Decl *D,
}
EnumExtensibilityAttr::Kind ExtensibilityKind;
IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo();
if (!EnumExtensibilityAttr::ConvertStrToKind(II->getName(),
ExtensibilityKind)) {
S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
@ -3853,7 +3855,7 @@ static bool handleFormatAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
bool HasImplicitThisParam = isInstanceMethod(D);
Info->NumArgs = getFunctionOrMethodNumParams(D) + HasImplicitThisParam;
Info->Identifier = AL.getArgAsIdent(0)->Ident;
Info->Identifier = AL.getArgAsIdent(0)->getIdentifierInfo();
StringRef Format = Info->Identifier->getName();
if (normalizeName(Format)) {
@ -4017,14 +4019,14 @@ static void handleCallbackAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
if (AL.isArgIdent(I)) {
IdentifierLoc *IdLoc = AL.getArgAsIdent(I);
auto It = NameIdxMapping.find(IdLoc->Ident->getName());
auto It = NameIdxMapping.find(IdLoc->getIdentifierInfo()->getName());
if (It == UnknownName) {
S.Diag(AL.getLoc(), diag::err_callback_attribute_argument_unknown)
<< IdLoc->Ident << IdLoc->Loc;
<< IdLoc->getIdentifierInfo() << IdLoc->getLoc();
return;
}
SR = SourceRange(IdLoc->Loc);
SR = SourceRange(IdLoc->getLoc());
ArgIdx = It->second;
} else if (AL.isArgExpr(I)) {
Expr *IdxExpr = AL.getArgAsExpr(I);
@ -4142,13 +4144,14 @@ LifetimeCaptureByAttr *Sema::ParseLifetimeCaptureByAttr(const ParsedAttr &AL,
}
assert(AL.isArgIdent(I));
IdentifierLoc *IdLoc = AL.getArgAsIdent(I);
if (IdLoc->Ident->getName() == ParamName) {
Diag(IdLoc->Loc, diag::err_capture_by_references_itself) << IdLoc->Loc;
if (IdLoc->getIdentifierInfo()->getName() == ParamName) {
Diag(IdLoc->getLoc(), diag::err_capture_by_references_itself)
<< IdLoc->getLoc();
IsValid = false;
continue;
}
ParamIdents[I] = IdLoc->Ident;
ParamLocs[I] = IdLoc->Loc;
ParamIdents[I] = IdLoc->getIdentifierInfo();
ParamLocs[I] = IdLoc->getLoc();
}
if (!IsValid)
return nullptr;
@ -4754,7 +4757,7 @@ static void handleModeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
return;
}
IdentifierInfo *Name = AL.getArgAsIdent(0)->Ident;
IdentifierInfo *Name = AL.getArgAsIdent(0)->getIdentifierInfo();
S.AddModeAttr(D, AL, Name);
}
@ -5727,8 +5730,8 @@ static void handleArgumentWithTypeTagAttr(Sema &S, Decl *D,
}
D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr(
S.Context, AL, AL.getArgAsIdent(0)->Ident, ArgumentIdx, TypeTagIdx,
IsPointer));
S.Context, AL, AL.getArgAsIdent(0)->getIdentifierInfo(), ArgumentIdx,
TypeTagIdx, IsPointer));
}
static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D,
@ -5748,7 +5751,7 @@ static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D,
return;
}
IdentifierInfo *PointerKind = AL.getArgAsIdent(0)->Ident;
IdentifierInfo *PointerKind = AL.getArgAsIdent(0)->getIdentifierInfo();
TypeSourceInfo *MatchingCTypeLoc = nullptr;
S.GetTypeFromParser(AL.getMatchingCType(), &MatchingCTypeLoc);
assert(MatchingCTypeLoc && "no type source info for attribute argument");
@ -5819,7 +5822,7 @@ static void handleBuiltinAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
return;
}
IdentifierInfo *Ident = AL.getArgAsIdent(0)->Ident;
IdentifierInfo *Ident = AL.getArgAsIdent(0)->getIdentifierInfo();
unsigned BuiltinID = Ident->getBuiltinID();
StringRef AliasName = cast<FunctionDecl>(D)->getIdentifier()->getName();
@ -6585,7 +6588,7 @@ static void handleCFGuardAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
}
CFGuardAttr::GuardArg Arg;
IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo();
if (!CFGuardAttr::ConvertStrToGuardArg(II->getName(), Arg)) {
S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
return;
@ -6687,8 +6690,9 @@ static void handleVTablePointerAuthentication(Sema &S, Decl *D,
if (AL.isArgIdent(0)) {
IdentifierLoc *IL = AL.getArgAsIdent(0);
if (!VTablePointerAuthenticationAttr::ConvertStrToVPtrAuthKeyType(
IL->Ident->getName(), KeyType)) {
S.Diag(IL->Loc, diag::err_invalid_authentication_key) << IL->Ident;
IL->getIdentifierInfo()->getName(), KeyType)) {
S.Diag(IL->getLoc(), diag::err_invalid_authentication_key)
<< IL->getIdentifierInfo();
AL.setInvalid();
}
if (KeyType == VTablePointerAuthenticationAttr::DefaultKey &&
@ -6708,15 +6712,16 @@ static void handleVTablePointerAuthentication(Sema &S, Decl *D,
if (AL.isArgIdent(1)) {
IdentifierLoc *IL = AL.getArgAsIdent(1);
if (!VTablePointerAuthenticationAttr::
ConvertStrToAddressDiscriminationMode(IL->Ident->getName(),
AddressDiversityMode)) {
S.Diag(IL->Loc, diag::err_invalid_address_discrimination) << IL->Ident;
ConvertStrToAddressDiscriminationMode(
IL->getIdentifierInfo()->getName(), AddressDiversityMode)) {
S.Diag(IL->getLoc(), diag::err_invalid_address_discrimination)
<< IL->getIdentifierInfo();
AL.setInvalid();
}
if (AddressDiversityMode ==
VTablePointerAuthenticationAttr::DefaultAddressDiscrimination &&
!S.getLangOpts().PointerAuthCalls) {
S.Diag(IL->Loc, diag::err_no_default_vtable_pointer_auth) << 1;
S.Diag(IL->getLoc(), diag::err_no_default_vtable_pointer_auth) << 1;
AL.setInvalid();
}
} else {
@ -6731,8 +6736,9 @@ static void handleVTablePointerAuthentication(Sema &S, Decl *D,
if (AL.isArgIdent(2)) {
IdentifierLoc *IL = AL.getArgAsIdent(2);
if (!VTablePointerAuthenticationAttr::ConvertStrToExtraDiscrimination(
IL->Ident->getName(), ED)) {
S.Diag(IL->Loc, diag::err_invalid_extra_discrimination) << IL->Ident;
IL->getIdentifierInfo()->getName(), ED)) {
S.Diag(IL->getLoc(), diag::err_invalid_extra_discrimination)
<< IL->getIdentifierInfo();
AL.setInvalid();
}
if (ED == VTablePointerAuthenticationAttr::DefaultExtraDiscrimination &&

View File

@ -1310,24 +1310,26 @@ static bool NestedProtocolHasNoDefinition(ObjCProtocolDecl *PDecl,
/// protocol declarations in its 'Protocols' argument.
void SemaObjC::FindProtocolDeclaration(bool WarnOnDeclarations,
bool ForObjCContainer,
ArrayRef<IdentifierLocPair> ProtocolId,
ArrayRef<IdentifierLoc> ProtocolId,
SmallVectorImpl<Decl *> &Protocols) {
for (const IdentifierLocPair &Pair : ProtocolId) {
ObjCProtocolDecl *PDecl = LookupProtocol(Pair.first, Pair.second);
for (const IdentifierLoc &Pair : ProtocolId) {
ObjCProtocolDecl *PDecl =
LookupProtocol(Pair.getIdentifierInfo(), Pair.getLoc());
if (!PDecl) {
DeclFilterCCC<ObjCProtocolDecl> CCC{};
TypoCorrection Corrected =
SemaRef.CorrectTypo(DeclarationNameInfo(Pair.first, Pair.second),
Sema::LookupObjCProtocolName, SemaRef.TUScope,
nullptr, CCC, Sema::CTK_ErrorRecovery);
TypoCorrection Corrected = SemaRef.CorrectTypo(
DeclarationNameInfo(Pair.getIdentifierInfo(), Pair.getLoc()),
Sema::LookupObjCProtocolName, SemaRef.TUScope, nullptr, CCC,
Sema::CTK_ErrorRecovery);
if ((PDecl = Corrected.getCorrectionDeclAs<ObjCProtocolDecl>()))
SemaRef.diagnoseTypo(Corrected,
PDiag(diag::err_undeclared_protocol_suggest)
<< Pair.first);
<< Pair.getIdentifierInfo());
}
if (!PDecl) {
Diag(Pair.second, diag::err_undeclared_protocol) << Pair.first;
Diag(Pair.getLoc(), diag::err_undeclared_protocol)
<< Pair.getIdentifierInfo();
continue;
}
// If this is a forward protocol declaration, get its definition.
@ -1337,7 +1339,7 @@ void SemaObjC::FindProtocolDeclaration(bool WarnOnDeclarations,
// For an objc container, delay protocol reference checking until after we
// can set the objc decl as the availability context, otherwise check now.
if (!ForObjCContainer) {
(void)SemaRef.DiagnoseUseOfDecl(PDecl, Pair.second);
(void)SemaRef.DiagnoseUseOfDecl(PDecl, Pair.getLoc());
}
// If this is a forward declaration and we are supposed to warn in this
@ -1347,7 +1349,8 @@ void SemaObjC::FindProtocolDeclaration(bool WarnOnDeclarations,
if (WarnOnDeclarations &&
NestedProtocolHasNoDefinition(PDecl, UndefinedProtocol)) {
Diag(Pair.second, diag::warn_undef_protocolref) << Pair.first;
Diag(Pair.getLoc(), diag::warn_undef_protocolref)
<< Pair.getIdentifierInfo();
Diag(UndefinedProtocol->getLocation(), diag::note_protocol_decl_undefined)
<< UndefinedProtocol;
}
@ -1784,17 +1787,17 @@ void SemaObjC::DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
/// ActOnForwardProtocolDeclaration - Handle \@protocol foo;
SemaObjC::DeclGroupPtrTy SemaObjC::ActOnForwardProtocolDeclaration(
SourceLocation AtProtocolLoc, ArrayRef<IdentifierLocPair> IdentList,
SourceLocation AtProtocolLoc, ArrayRef<IdentifierLoc> IdentList,
const ParsedAttributesView &attrList) {
ASTContext &Context = getASTContext();
SmallVector<Decl *, 8> DeclsInGroup;
for (const IdentifierLocPair &IdentPair : IdentList) {
IdentifierInfo *Ident = IdentPair.first;
for (const IdentifierLoc &IdentPair : IdentList) {
IdentifierInfo *Ident = IdentPair.getIdentifierInfo();
ObjCProtocolDecl *PrevDecl = LookupProtocol(
Ident, IdentPair.second, SemaRef.forRedeclarationInCurContext());
Ident, IdentPair.getLoc(), SemaRef.forRedeclarationInCurContext());
ObjCProtocolDecl *PDecl =
ObjCProtocolDecl::Create(Context, SemaRef.CurContext, Ident,
IdentPair.second, AtProtocolLoc, PrevDecl);
IdentPair.getLoc(), AtProtocolLoc, PrevDecl);
SemaRef.PushOnScopeChains(PDecl, SemaRef.TUScope);
CheckObjCDeclScope(PDecl);

View File

@ -1282,8 +1282,8 @@ bool SemaHLSL::handleResourceTypeAttr(QualType T, const ParsedAttr &AL) {
}
IdentifierLoc *Loc = AL.getArgAsIdent(0);
StringRef Identifier = Loc->Ident->getName();
SourceLocation ArgLoc = Loc->Loc;
StringRef Identifier = Loc->getIdentifierInfo()->getName();
SourceLocation ArgLoc = Loc->getLoc();
// Validate resource class value
ResourceClass RC;
@ -1542,8 +1542,8 @@ void SemaHLSL::handleResourceBindingAttr(Decl *TheDecl, const ParsedAttr &AL) {
}
IdentifierLoc *Loc = AL.getArgAsIdent(0);
StringRef Str = Loc->Ident->getName();
SourceLocation ArgLoc = Loc->Loc;
StringRef Str = Loc->getIdentifierInfo()->getName();
SourceLocation ArgLoc = Loc->getLoc();
SourceLocation SpaceArgLoc;
bool SpecifiedSpace = false;
@ -1557,8 +1557,8 @@ void SemaHLSL::handleResourceBindingAttr(Decl *TheDecl, const ParsedAttr &AL) {
}
IdentifierLoc *Loc = AL.getArgAsIdent(1);
Space = Loc->Ident->getName();
SpaceArgLoc = Loc->Loc;
Space = Loc->getIdentifierInfo()->getName();
SpaceArgLoc = Loc->getLoc();
} else {
Slot = Str;
}

View File

@ -15,6 +15,7 @@
#include "clang/AST/ASTMutationListener.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/ParsedAttr.h"
#include "clang/Sema/SemaInternal.h"
#include "llvm/ADT/StringExtras.h"
@ -68,7 +69,7 @@ static std::string stringFromPath(ModuleIdPath Path) {
for (auto &Piece : Path) {
if (!Name.empty())
Name += ".";
Name += Piece.first->getName();
Name += Piece.getIdentifierInfo()->getName();
}
return Name;
}
@ -350,17 +351,18 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc,
// Test the first part of the path to see if it's std[0-9]+ but allow the
// name in a system header.
StringRef FirstComponentName = Path[0].first->getName();
if (!getSourceManager().isInSystemHeader(Path[0].second) &&
StringRef FirstComponentName = Path[0].getIdentifierInfo()->getName();
if (!getSourceManager().isInSystemHeader(Path[0].getLoc()) &&
(FirstComponentName == "std" ||
(FirstComponentName.starts_with("std") &&
llvm::all_of(FirstComponentName.drop_front(3), &llvm::isDigit))))
Diag(Path[0].second, diag::warn_reserved_module_name) << Path[0].first;
Diag(Path[0].getLoc(), diag::warn_reserved_module_name)
<< Path[0].getIdentifierInfo();
// Then test all of the components in the path to see if any of them are
// using another kind of reserved or invalid identifier.
for (auto Part : Path) {
if (DiagReservedModuleName(*this, Part.first, Part.second))
if (DiagReservedModuleName(*this, Part.getIdentifierInfo(), Part.getLoc()))
return nullptr;
}
@ -376,10 +378,10 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc,
// correct.
if (!getLangOpts().CurrentModule.empty() &&
getLangOpts().CurrentModule != ModuleName) {
Diag(Path.front().second, diag::err_current_module_name_mismatch)
<< SourceRange(Path.front().second, IsPartition
? Partition.back().second
: Path.back().second)
Diag(Path.front().getLoc(), diag::err_current_module_name_mismatch)
<< SourceRange(Path.front().getLoc(), IsPartition
? Partition.back().getLoc()
: Path.back().getLoc())
<< getLangOpts().CurrentModule;
return nullptr;
}
@ -394,7 +396,7 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc,
// We can't have parsed or imported a definition of this module or parsed a
// module map defining it already.
if (auto *M = Map.findModule(ModuleName)) {
Diag(Path[0].second, diag::err_module_redefinition) << ModuleName;
Diag(Path[0].getLoc(), diag::err_module_redefinition) << ModuleName;
if (M->DefinitionLoc.isValid())
Diag(M->DefinitionLoc, diag::note_prev_module_definition);
else if (OptionalFileEntryRef FE = M->getASTFile())
@ -417,8 +419,8 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc,
// keyword nor a module-partition implicitly imports the primary
// module interface unit of the module as if by a module-import-
// declaration.
std::pair<IdentifierInfo *, SourceLocation> ModuleNameLoc(
PP.getIdentifierInfo(ModuleName), Path[0].second);
IdentifierLoc ModuleNameLoc(Path[0].getLoc(),
PP.getIdentifierInfo(ModuleName));
// The module loader will assume we're trying to import the module that
// we're building if `LangOpts.CurrentModule` equals to 'ModuleName'.
@ -490,7 +492,7 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc,
// Make the import decl for the interface in the impl module.
ImportDecl *Import = ImportDecl::Create(Context, CurContext, ModuleLoc,
Interface, Path[0].second);
Interface, Path[0].getLoc());
CurContext->addDecl(Import);
// Sequence initialization of the imported module before that of the current
@ -579,7 +581,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
// For a C++20 module name, flatten into a single identifier with the source
// location of the first component.
std::pair<IdentifierInfo *, SourceLocation> ModuleNameLoc;
IdentifierLoc ModuleNameLoc;
std::string ModuleName;
if (IsPartition) {
@ -591,11 +593,13 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
ModuleName = NamedMod->getPrimaryModuleInterfaceName().str();
ModuleName += ":";
ModuleName += stringFromPath(Path);
ModuleNameLoc = {PP.getIdentifierInfo(ModuleName), Path[0].second};
ModuleNameLoc =
IdentifierLoc(Path[0].getLoc(), PP.getIdentifierInfo(ModuleName));
Path = ModuleIdPath(ModuleNameLoc);
} else if (getLangOpts().CPlusPlusModules) {
ModuleName = stringFromPath(Path);
ModuleNameLoc = {PP.getIdentifierInfo(ModuleName), Path[0].second};
ModuleNameLoc =
IdentifierLoc(Path[0].getLoc(), PP.getIdentifierInfo(ModuleName));
Path = ModuleIdPath(ModuleNameLoc);
}
@ -680,7 +684,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
IdentifierLocs.push_back(SourceLocation());
} else if (getLangOpts().CPlusPlusModules && !Mod->Parent) {
// A single identifier for the whole name.
IdentifierLocs.push_back(Path[0].second);
IdentifierLocs.push_back(Path[0].getLoc());
} else {
Module *ModCheck = Mod;
for (unsigned I = 0, N = Path.size(); I != N; ++I) {
@ -690,7 +694,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
break;
ModCheck = ModCheck->Parent;
IdentifierLocs.push_back(Path[I].second);
IdentifierLocs.push_back(Path[I].getLoc());
}
}
@ -707,7 +711,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
if (getLangOpts().CPlusPlusModules && ExportLoc.isValid() &&
Mod->Kind == Module::ModuleKind::ModulePartitionImplementation) {
Diag(ExportLoc, diag::err_export_partition_impl)
<< SourceRange(ExportLoc, Path.back().second);
<< SourceRange(ExportLoc, Path.back().getLoc());
} else if (!ModuleScopes.empty() && !currentModuleIsImplementation()) {
// Re-export the module if the imported module is exported.
// Note that we don't need to add re-exported module to Imports field

View File

@ -1446,10 +1446,8 @@ SemaObjC::ObjCSubscriptKind SemaObjC::CheckSubscriptingKind(Expr *FromE) {
void SemaObjC::AddCFAuditedAttribute(Decl *D) {
ASTContext &Context = getASTContext();
IdentifierInfo *Ident;
SourceLocation Loc;
std::tie(Ident, Loc) = SemaRef.PP.getPragmaARCCFCodeAuditedInfo();
if (!Loc.isValid())
auto IdLoc = SemaRef.PP.getPragmaARCCFCodeAuditedInfo();
if (!IdLoc.getLoc().isValid())
return;
// Don't add a redundant or conflicting attribute.
@ -1457,7 +1455,8 @@ void SemaObjC::AddCFAuditedAttribute(Decl *D) {
D->hasAttr<CFUnknownTransferAttr>())
return;
AttributeCommonInfo Info(Ident, SourceRange(Loc),
AttributeCommonInfo Info(IdLoc.getIdentifierInfo(),
SourceRange(IdLoc.getLoc()),
AttributeCommonInfo::Form::Pragma());
D->addAttr(CFAuditedTransferAttr::CreateImplicit(Context, Info));
}
@ -1642,8 +1641,10 @@ void SemaObjC::handleMethodFamilyAttr(Decl *D, const ParsedAttr &AL) {
IdentifierLoc *IL = AL.getArgAsIdent(0);
ObjCMethodFamilyAttr::FamilyKind F;
if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind(IL->Ident->getName(), F)) {
Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL << IL->Ident;
if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind(
IL->getIdentifierInfo()->getName(), F)) {
Diag(IL->getLoc(), diag::warn_attribute_type_not_supported)
<< AL << IL->getIdentifierInfo();
return;
}
@ -1706,7 +1707,7 @@ void SemaObjC::handleBlocksAttr(Decl *D, const ParsedAttr &AL) {
return;
}
IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo();
BlocksAttr::BlockType type;
if (!BlocksAttr::ConvertStrToBlockType(II->getName(), type)) {
Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
@ -1998,7 +1999,7 @@ void SemaObjC::handleNSErrorDomain(Decl *D, const ParsedAttr &Attr) {
IdentifierLoc *IdentLoc =
Attr.isArgIdent(0) ? Attr.getArgAsIdent(0) : nullptr;
if (!IdentLoc || !IdentLoc->Ident) {
if (!IdentLoc || !IdentLoc->getIdentifierInfo()) {
// Try to locate the argument directly.
SourceLocation Loc = Attr.getLoc();
if (Attr.isArgExpr(0) && Attr.getArgAsExpr(0))
@ -2009,18 +2010,18 @@ void SemaObjC::handleNSErrorDomain(Decl *D, const ParsedAttr &Attr) {
}
// Verify that the identifier is a valid decl in the C decl namespace.
LookupResult Result(SemaRef, DeclarationName(IdentLoc->Ident),
LookupResult Result(SemaRef, DeclarationName(IdentLoc->getIdentifierInfo()),
SourceLocation(),
Sema::LookupNameKind::LookupOrdinaryName);
if (!SemaRef.LookupName(Result, SemaRef.TUScope) ||
!Result.getAsSingle<VarDecl>()) {
Diag(IdentLoc->Loc, diag::err_nserrordomain_invalid_decl)
<< 1 << IdentLoc->Ident;
Diag(IdentLoc->getLoc(), diag::err_nserrordomain_invalid_decl)
<< 1 << IdentLoc->getIdentifierInfo();
return;
}
D->addAttr(::new (getASTContext())
NSErrorDomainAttr(getASTContext(), Attr, IdentLoc->Ident));
D->addAttr(::new (getASTContext()) NSErrorDomainAttr(
getASTContext(), Attr, IdentLoc->getIdentifierInfo()));
}
void SemaObjC::handleBridgeAttr(Decl *D, const ParsedAttr &AL) {
@ -2033,7 +2034,7 @@ void SemaObjC::handleBridgeAttr(Decl *D, const ParsedAttr &AL) {
// Typedefs only allow objc_bridge(id) and have some additional checking.
if (const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
if (!Parm->Ident->isStr("id")) {
if (!Parm->getIdentifierInfo()->isStr("id")) {
Diag(AL.getLoc(), diag::err_objc_attr_typedef_not_id) << AL;
return;
}
@ -2046,8 +2047,8 @@ void SemaObjC::handleBridgeAttr(Decl *D, const ParsedAttr &AL) {
}
}
D->addAttr(::new (getASTContext())
ObjCBridgeAttr(getASTContext(), AL, Parm->Ident));
D->addAttr(::new (getASTContext()) ObjCBridgeAttr(getASTContext(), AL,
Parm->getIdentifierInfo()));
}
void SemaObjC::handleBridgeMutableAttr(Decl *D, const ParsedAttr &AL) {
@ -2058,21 +2059,21 @@ void SemaObjC::handleBridgeMutableAttr(Decl *D, const ParsedAttr &AL) {
return;
}
D->addAttr(::new (getASTContext())
ObjCBridgeMutableAttr(getASTContext(), AL, Parm->Ident));
D->addAttr(::new (getASTContext()) ObjCBridgeMutableAttr(
getASTContext(), AL, Parm->getIdentifierInfo()));
}
void SemaObjC::handleBridgeRelatedAttr(Decl *D, const ParsedAttr &AL) {
IdentifierInfo *RelatedClass =
AL.isArgIdent(0) ? AL.getArgAsIdent(0)->Ident : nullptr;
AL.isArgIdent(0) ? AL.getArgAsIdent(0)->getIdentifierInfo() : nullptr;
if (!RelatedClass) {
Diag(D->getBeginLoc(), diag::err_objc_attr_not_id) << AL << 0;
return;
}
IdentifierInfo *ClassMethod =
AL.getArgAsIdent(1) ? AL.getArgAsIdent(1)->Ident : nullptr;
AL.getArgAsIdent(1) ? AL.getArgAsIdent(1)->getIdentifierInfo() : nullptr;
IdentifierInfo *InstanceMethod =
AL.getArgAsIdent(2) ? AL.getArgAsIdent(2)->Ident : nullptr;
AL.getArgAsIdent(2) ? AL.getArgAsIdent(2)->getIdentifierInfo() : nullptr;
D->addAttr(::new (getASTContext()) ObjCBridgeRelatedAttr(
getASTContext(), AL, RelatedClass, ClassMethod, InstanceMethod));
}

View File

@ -1343,7 +1343,7 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceTypeClause(
// the limitation, since the Dialect requires this.
if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Set &&
Clause.getDeviceTypeArchitectures().size() > 1) {
SemaRef.Diag(Clause.getDeviceTypeArchitectures()[1].second,
SemaRef.Diag(Clause.getDeviceTypeArchitectures()[1].getLoc(),
diag::err_acc_device_type_multiple_archs);
return nullptr;
}
@ -1369,16 +1369,17 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceTypeClause(
bool Diagnosed = false;
auto FilterPred = [&](const DeviceTypeArgument &Arch) {
// The '*' case.
if (!Arch.first)
if (!Arch.getIdentifierInfo())
return false;
return llvm::find_if(ValidValues, [&](StringRef RHS) {
return Arch.first->getName().equals_insensitive(RHS);
return Arch.getIdentifierInfo()->getName().equals_insensitive(RHS);
}) == ValidValues.end();
};
auto Diagnose = [&](const DeviceTypeArgument &Arch) {
Diagnosed = SemaRef.Diag(Arch.second, diag::err_acc_invalid_default_type)
<< Arch.first << Clause.getClauseKind() << ValidValuesString;
Diagnosed = SemaRef.Diag(Arch.getLoc(), diag::err_acc_invalid_default_type)
<< Arch.getIdentifierInfo() << Clause.getClauseKind()
<< ValidValuesString;
};
// There aren't stable enumertor versions of 'for-each-then-erase', so do it

View File

@ -79,9 +79,10 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A,
Expr *ValueExpr = A.getArgAsExpr(3);
StringRef PragmaName =
llvm::StringSwitch<StringRef>(PragmaNameLoc->Ident->getName())
llvm::StringSwitch<StringRef>(
PragmaNameLoc->getIdentifierInfo()->getName())
.Cases("unroll", "nounroll", "unroll_and_jam", "nounroll_and_jam",
PragmaNameLoc->Ident->getName())
PragmaNameLoc->getIdentifierInfo()->getName())
.Default("clang loop");
// This could be handled automatically by adding a Subjects definition in
@ -127,10 +128,10 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A,
SetHints(LoopHintAttr::UnrollAndJam, LoopHintAttr::Enable);
} else {
// #pragma clang loop ...
assert(OptionLoc && OptionLoc->Ident &&
assert(OptionLoc && OptionLoc->getIdentifierInfo() &&
"Attribute must have valid option info.");
Option = llvm::StringSwitch<LoopHintAttr::OptionType>(
OptionLoc->Ident->getName())
OptionLoc->getIdentifierInfo()->getName())
.Case("vectorize", LoopHintAttr::Vectorize)
.Case("vectorize_width", LoopHintAttr::VectorizeWidth)
.Case("interleave", LoopHintAttr::Interleave)
@ -144,12 +145,13 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A,
.Case("distribute", LoopHintAttr::Distribute)
.Default(LoopHintAttr::Vectorize);
if (Option == LoopHintAttr::VectorizeWidth) {
assert((ValueExpr || (StateLoc && StateLoc->Ident)) &&
assert((ValueExpr || (StateLoc && StateLoc->getIdentifierInfo())) &&
"Attribute must have a valid value expression or argument.");
if (ValueExpr && S.CheckLoopHintExpr(ValueExpr, St->getBeginLoc(),
/*AllowZero=*/false))
return nullptr;
if (StateLoc && StateLoc->Ident && StateLoc->Ident->isStr("scalable"))
if (StateLoc && StateLoc->getIdentifierInfo() &&
StateLoc->getIdentifierInfo()->isStr("scalable"))
State = LoopHintAttr::ScalableWidth;
else
State = LoopHintAttr::FixedWidth;
@ -167,14 +169,15 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A,
Option == LoopHintAttr::Unroll ||
Option == LoopHintAttr::Distribute ||
Option == LoopHintAttr::PipelineDisabled) {
assert(StateLoc && StateLoc->Ident && "Loop hint must have an argument");
if (StateLoc->Ident->isStr("disable"))
assert(StateLoc && StateLoc->getIdentifierInfo() &&
"Loop hint must have an argument");
if (StateLoc->getIdentifierInfo()->isStr("disable"))
State = LoopHintAttr::Disable;
else if (StateLoc->Ident->isStr("assume_safety"))
else if (StateLoc->getIdentifierInfo()->isStr("assume_safety"))
State = LoopHintAttr::AssumeSafety;
else if (StateLoc->Ident->isStr("full"))
else if (StateLoc->getIdentifierInfo()->isStr("full"))
State = LoopHintAttr::Full;
else if (StateLoc->Ident->isStr("enable"))
else if (StateLoc->getIdentifierInfo()->isStr("enable"))
State = LoopHintAttr::Enable;
else
llvm_unreachable("bad loop hint argument");
@ -644,8 +647,8 @@ static Attr *handleAtomicAttr(Sema &S, Stmt *St, const ParsedAttr &AL,
}
IdentifierLoc *Ident = AL.getArgAsIdent(ArgIndex);
OptionString = Ident->Ident->getName();
Loc = Ident->Loc;
OptionString = Ident->getIdentifierInfo()->getName();
Loc = Ident->getLoc();
if (!AtomicAttr::ConvertStrToConsumedOption(OptionString, Option)) {
S.Diag(Loc, diag::err_attribute_invalid_atomic_argument) << OptionString;
return nullptr;

View File

@ -148,8 +148,8 @@ void SemaSwift::handleError(Decl *D, const ParsedAttr &AL) {
return true;
S.Diag(AL.getLoc(), diag::err_attr_swift_error_return_type)
<< AL << AL.getArgAsIdent(0)->Ident->getName() << isa<ObjCMethodDecl>(D)
<< /*pointer*/ 1;
<< AL << AL.getArgAsIdent(0)->getIdentifierInfo()->getName()
<< isa<ObjCMethodDecl>(D) << /*pointer*/ 1;
return false;
};
@ -159,8 +159,8 @@ void SemaSwift::handleError(Decl *D, const ParsedAttr &AL) {
return true;
S.Diag(AL.getLoc(), diag::err_attr_swift_error_return_type)
<< AL << AL.getArgAsIdent(0)->Ident->getName() << isa<ObjCMethodDecl>(D)
<< /*integral*/ 0;
<< AL << AL.getArgAsIdent(0)->getIdentifierInfo()->getName()
<< isa<ObjCMethodDecl>(D) << /*integral*/ 0;
return false;
};
@ -169,10 +169,10 @@ void SemaSwift::handleError(Decl *D, const ParsedAttr &AL) {
IdentifierLoc *Loc = AL.getArgAsIdent(0);
SwiftErrorAttr::ConventionKind Convention;
if (!SwiftErrorAttr::ConvertStrToConventionKind(Loc->Ident->getName(),
Convention)) {
if (!SwiftErrorAttr::ConvertStrToConventionKind(
Loc->getIdentifierInfo()->getName(), Convention)) {
Diag(AL.getLoc(), diag::warn_attribute_type_not_supported)
<< AL << Loc->Ident;
<< AL << Loc->getIdentifierInfo();
return;
}
@ -287,10 +287,10 @@ static void checkSwiftAsyncErrorBlock(Sema &S, Decl *D,
void SemaSwift::handleAsyncError(Decl *D, const ParsedAttr &AL) {
IdentifierLoc *IDLoc = AL.getArgAsIdent(0);
SwiftAsyncErrorAttr::ConventionKind ConvKind;
if (!SwiftAsyncErrorAttr::ConvertStrToConventionKind(IDLoc->Ident->getName(),
ConvKind)) {
if (!SwiftAsyncErrorAttr::ConvertStrToConventionKind(
IDLoc->getIdentifierInfo()->getName(), ConvKind)) {
Diag(AL.getLoc(), diag::warn_attribute_type_not_supported)
<< AL << IDLoc->Ident;
<< AL << IDLoc->getIdentifierInfo();
return;
}
@ -643,7 +643,7 @@ void SemaSwift::handleNewType(Decl *D, const ParsedAttr &AL) {
}
SwiftNewTypeAttr::NewtypeKind Kind;
IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo();
if (!SwiftNewTypeAttr::ConvertStrToNewtypeKind(II->getName(), Kind)) {
Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
return;
@ -667,7 +667,7 @@ void SemaSwift::handleAsyncAttr(Decl *D, const ParsedAttr &AL) {
}
SwiftAsyncAttr::Kind Kind;
IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
IdentifierInfo *II = AL.getArgAsIdent(0)->getIdentifierInfo();
if (!SwiftAsyncAttr::ConvertStrToKind(II->getName(), Kind)) {
Diag(AL.getLoc(), diag::err_swift_async_no_access) << AL << II;
return;

View File

@ -14,6 +14,7 @@
#include "clang/AST/ExprObjC.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/ParsedAttr.h"
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/Sema.h"
@ -755,7 +756,7 @@ bool Sema::CheckParameterPacksForExpansion(
bool &RetainExpansion, UnsignedOrNone &NumExpansions) {
ShouldExpand = true;
RetainExpansion = false;
std::pair<IdentifierInfo *, SourceLocation> FirstPack;
IdentifierLoc FirstPack;
bool HaveFirstPack = false;
UnsignedOrNone NumPartialExpansions = std::nullopt;
SourceLocation PartiallySubstitutedPackLoc;
@ -867,8 +868,7 @@ bool Sema::CheckParameterPacksForExpansion(
// This is the first pack we've seen for which we have an argument.
// Record it.
NumExpansions = NewPackSize;
FirstPack.first = Name;
FirstPack.second = ParmPack.second;
FirstPack = IdentifierLoc(ParmPack.second, Name);
HaveFirstPack = true;
continue;
}
@ -905,9 +905,9 @@ bool Sema::CheckParameterPacksForExpansion(
// the same number of arguments specified.
if (HaveFirstPack)
Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict)
<< FirstPack.first << Name << *NumExpansions
<< FirstPack.getIdentifierInfo() << Name << *NumExpansions
<< (LeastNewPackSize != NewPackSize) << LeastNewPackSize
<< SourceRange(FirstPack.second) << SourceRange(ParmPack.second);
<< SourceRange(FirstPack.getLoc()) << SourceRange(ParmPack.second);
else
Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_multilevel)
<< Name << *NumExpansions << (LeastNewPackSize != NewPackSize)

View File

@ -99,8 +99,8 @@ static void diagnoseBadTypeAttribute(Sema &S, const ParsedAttr &attr,
StringRef name = attr.getAttrName()->getName();
// The GC attributes are usually written with macros; special-case them.
IdentifierInfo *II = attr.isArgIdent(0) ? attr.getArgAsIdent(0)->Ident
: nullptr;
IdentifierInfo *II =
attr.isArgIdent(0) ? attr.getArgAsIdent(0)->getIdentifierInfo() : nullptr;
if (useExpansionLoc && loc.isMacroID() && II) {
if (II->isStr("strong")) {
if (S.findMacroSpelling(loc, "__strong")) name = "__strong";
@ -5732,8 +5732,7 @@ static void transferARCOwnershipToDeclaratorChunk(TypeProcessingState &state,
}
IdentifierLoc *Arg = new (S.Context) IdentifierLoc;
Arg->Ident = &S.Context.Idents.get(attrStr);
Arg->Loc = SourceLocation();
Arg->setIdentifierInfo(&S.Context.Idents.get(attrStr));
ArgsUnion Args(Arg);
@ -6633,7 +6632,7 @@ static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state,
return true;
}
IdentifierInfo *II = attr.getArgAsIdent(0)->Ident;
IdentifierInfo *II = attr.getArgAsIdent(0)->getIdentifierInfo();
Qualifiers::ObjCLifetime lifetime;
if (II->isStr("none"))
lifetime = Qualifiers::OCL_ExplicitNone;
@ -6811,7 +6810,7 @@ static bool handleObjCGCTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
return true;
}
IdentifierInfo *II = attr.getArgAsIdent(0)->Ident;
IdentifierInfo *II = attr.getArgAsIdent(0)->getIdentifierInfo();
if (II->isStr("weak"))
GCAttr = Qualifiers::Weak;
else if (II->isStr("strong"))
@ -7541,7 +7540,7 @@ static Attr *getCCTypeAttr(ASTContext &Ctx, ParsedAttr &Attr) {
if (Attr.isArgExpr(0))
Str = cast<StringLiteral>(Attr.getArgAsExpr(0))->getString();
else
Str = Attr.getArgAsIdent(0)->Ident->getName();
Str = Attr.getArgAsIdent(0)->getIdentifierInfo()->getName();
PcsAttr::PCSType Type;
if (!PcsAttr::ConvertStrToPCSType(Str, Type))
llvm_unreachable("already validated the attribute");

View File

@ -12818,7 +12818,7 @@ OpenACCClause *ASTRecordReader::readOpenACCClause() {
for (unsigned I = 0; I < NumArchs; ++I) {
IdentifierInfo *Ident = readBool() ? readIdentifier() : nullptr;
SourceLocation Loc = readSourceLocation();
Archs.emplace_back(Ident, Loc);
Archs.emplace_back(Loc, Ident);
}
return OpenACCDeviceTypeClause::Create(getContext(), ClauseKind, BeginLoc,

View File

@ -8780,10 +8780,10 @@ void ASTRecordWriter::writeOpenACCClause(const OpenACCClause *C) {
writeSourceLocation(DTC->getLParenLoc());
writeUInt32(DTC->getArchitectures().size());
for (const DeviceTypeArgument &Arg : DTC->getArchitectures()) {
writeBool(Arg.first);
if (Arg.first)
AddIdentifierRef(Arg.first);
writeSourceLocation(Arg.second);
writeBool(Arg.getIdentifierInfo());
if (Arg.getIdentifierInfo())
AddIdentifierRef(Arg.getIdentifierInfo());
writeSourceLocation(Arg.getLoc());
}
return;
}

View File

@ -664,7 +664,7 @@ void ModuleDepCollectorPP::moduleImport(SourceLocation ImportLoc,
const Module *Imported) {
if (MDC.ScanInstance.getPreprocessor().isInImportingCXXNamedModules()) {
P1689ModuleInfo RequiredModule;
RequiredModule.ModuleName = Path[0].first->getName().str();
RequiredModule.ModuleName = Path[0].getIdentifierInfo()->getName().str();
RequiredModule.Type = P1689ModuleInfo::ModuleType::NamedCXXModule;
MDC.RequiredStdCXXModules.push_back(RequiredModule);
return;

View File

@ -13,6 +13,7 @@
#include "clang/Basic/Builtins.h"
#include "clang/Basic/DarwinSDKInfo.h"
#include "clang/Basic/DiagnosticIDs.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/Version.h"
@ -135,8 +136,9 @@ public:
SourceModule module;
for (const std::pair<IdentifierInfo *, SourceLocation> &component : path)
module.path.push_back(ConstString(component.first->getName()));
for (const IdentifierLoc &component : path)
module.path.push_back(
ConstString(component.getIdentifierInfo()->getName()));
StreamString error_stream;

View File

@ -8,6 +8,7 @@
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticFrontend.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendActions.h"
@ -334,20 +335,18 @@ bool ClangModulesDeclVendorImpl::AddModule(const SourceModule &module,
return false;
}
llvm::SmallVector<std::pair<clang::IdentifierInfo *, clang::SourceLocation>,
4>
clang_path;
llvm::SmallVector<clang::IdentifierLoc, 4> clang_path;
{
clang::SourceManager &source_manager =
m_compiler_instance->getASTContext().getSourceManager();
for (ConstString path_component : module.path) {
clang_path.push_back(std::make_pair(
&m_compiler_instance->getASTContext().Idents.get(
path_component.GetStringRef()),
clang_path.emplace_back(
source_manager.getLocForStartOfFile(source_manager.getMainFileID())
.getLocWithOffset(m_source_location_index++)));
.getLocWithOffset(m_source_location_index++),
&m_compiler_instance->getASTContext().Idents.get(
path_component.GetStringRef()));
}
}
@ -629,8 +628,8 @@ ClangModulesDeclVendorImpl::DoGetModule(clang::ModuleIdPath path,
const bool is_inclusion_directive = false;
return m_compiler_instance->loadModule(path.front().second, path, visibility,
is_inclusion_directive);
return m_compiler_instance->loadModule(path.front().getLoc(), path,
visibility, is_inclusion_directive);
}
static const char *ModuleImportBufferName = "LLDBModulesMemoryBuffer";