[clang][NFC] Move PDiag into SemaBase (#93849)

This patch moves `PDiag` into `SemaBase`, making it readily available
everywhere across `Sema` without `SemaRef`, like the regular `Diag`.
This commit is contained in:
Vlad Serebrennikov 2024-05-30 23:38:46 +04:00 committed by GitHub
parent 0eb9e021b1
commit baabaa4ce9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 37 additions and 41 deletions

View File

@ -895,9 +895,6 @@ public:
void disable() { Active = false; }
};
/// Build a partial diagnostic.
PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h
sema::FunctionScopeInfo *getCurFunction() const {
return FunctionScopes.empty() ? nullptr : FunctionScopes.back();
}

View File

@ -217,6 +217,9 @@ public:
/// Emit a partial diagnostic.
SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD,
bool DeferHint = false);
/// Build a partial diagnostic.
PartialDiagnostic PDiag(unsigned DiagID = 0);
};
} // namespace clang

View File

@ -21,10 +21,6 @@
namespace clang {
inline PartialDiagnostic Sema::PDiag(unsigned DiagID) {
return PartialDiagnostic(DiagID, Context.getDiagAllocator());
}
inline bool
FTIHasSingleVoidParameter(const DeclaratorChunk::FunctionTypeInfo &FTI) {
return FTI.NumParams == 1 && !FTI.isVariadic &&

View File

@ -29,6 +29,10 @@ SemaBase::ImmediateDiagBuilder::~ImmediateDiagBuilder() {
SemaRef.EmitCurrentDiagnostic(DiagID);
}
PartialDiagnostic SemaBase::PDiag(unsigned DiagID) {
return PartialDiagnostic(DiagID, SemaRef.Context.getDiagAllocator());
}
const SemaBase::SemaDiagnosticBuilder &
operator<<(const SemaBase::SemaDiagnosticBuilder &Diag,
const PartialDiagnostic &PD) {

View File

@ -567,8 +567,7 @@ void SemaObjC::ActOnSuperClassOfClassInterface(
if (TypoCorrection Corrected = SemaRef.CorrectTypo(
DeclarationNameInfo(SuperName, SuperLoc), Sema::LookupOrdinaryName,
SemaRef.TUScope, nullptr, CCC, Sema::CTK_ErrorRecovery)) {
SemaRef.diagnoseTypo(Corrected,
SemaRef.PDiag(diag::err_undef_superclass_suggest)
SemaRef.diagnoseTypo(Corrected, PDiag(diag::err_undef_superclass_suggest)
<< SuperName << ClassName);
PrevDecl = Corrected.getCorrectionDeclAs<ObjCInterfaceDecl>();
}
@ -1322,8 +1321,8 @@ void SemaObjC::FindProtocolDeclaration(bool WarnOnDeclarations,
Sema::LookupObjCProtocolName, SemaRef.TUScope,
nullptr, CCC, Sema::CTK_ErrorRecovery);
if ((PDecl = Corrected.getCorrectionDeclAs<ObjCProtocolDecl>()))
SemaRef.diagnoseTypo(
Corrected, SemaRef.PDiag(diag::err_undeclared_protocol_suggest)
SemaRef.diagnoseTypo(Corrected,
PDiag(diag::err_undeclared_protocol_suggest)
<< Pair.first);
}
@ -1703,8 +1702,8 @@ void SemaObjC::actOnObjCTypeArgsOrProtocolQualifiers(
if (corrected) {
// Did we find a protocol?
if (auto proto = corrected.getCorrectionDeclAs<ObjCProtocolDecl>()) {
SemaRef.diagnoseTypo(
corrected, SemaRef.PDiag(diag::err_undeclared_protocol_suggest)
SemaRef.diagnoseTypo(corrected,
PDiag(diag::err_undeclared_protocol_suggest)
<< identifiers[i]);
lookupKind = Sema::LookupObjCProtocolName;
protocols[i] = proto;
@ -1715,7 +1714,7 @@ void SemaObjC::actOnObjCTypeArgsOrProtocolQualifiers(
// Did we find a type?
if (auto typeDecl = corrected.getCorrectionDeclAs<TypeDecl>()) {
SemaRef.diagnoseTypo(corrected,
SemaRef.PDiag(diag::err_unknown_typename_suggest)
PDiag(diag::err_unknown_typename_suggest)
<< identifiers[i]);
lookupKind = Sema::LookupOrdinaryName;
typeDecls[i] = typeDecl;
@ -1725,9 +1724,8 @@ void SemaObjC::actOnObjCTypeArgsOrProtocolQualifiers(
// Did we find an Objective-C class?
if (auto objcClass = corrected.getCorrectionDeclAs<ObjCInterfaceDecl>()) {
SemaRef.diagnoseTypo(
corrected,
SemaRef.PDiag(diag::err_unknown_type_or_class_name_suggest)
SemaRef.diagnoseTypo(corrected,
PDiag(diag::err_unknown_type_or_class_name_suggest)
<< identifiers[i] << true);
lookupKind = Sema::LookupOrdinaryName;
typeDecls[i] = objcClass;
@ -2009,9 +2007,8 @@ ObjCImplementationDecl *SemaObjC::ActOnStartClassImplementation(
// Suggest the (potentially) correct interface name. Don't provide a
// code-modification hint or use the typo name for recovery, because
// this is just a warning. The program may actually be correct.
SemaRef.diagnoseTypo(Corrected,
SemaRef.PDiag(diag::warn_undef_interface_suggest)
<< ClassName,
SemaRef.diagnoseTypo(
Corrected, PDiag(diag::warn_undef_interface_suggest) << ClassName,
/*ErrorRecovery*/ false);
} else {
Diag(ClassLoc, diag::warn_undef_interface) << ClassName;
@ -5439,8 +5436,7 @@ ObjCInterfaceDecl *SemaObjC::getObjCInterfaceDecl(const IdentifierInfo *&Id,
if (TypoCorrection C = SemaRef.CorrectTypo(
DeclarationNameInfo(Id, IdLoc), Sema::LookupOrdinaryName,
SemaRef.TUScope, nullptr, CCC, Sema::CTK_ErrorRecovery)) {
SemaRef.diagnoseTypo(C, SemaRef.PDiag(diag::err_undef_interface_suggest)
<< Id);
SemaRef.diagnoseTypo(C, PDiag(diag::err_undef_interface_suggest) << Id);
IDecl = C.getCorrectionDeclAs<ObjCInterfaceDecl>();
Id = IDecl->getIdentifier();
}
@ -5544,7 +5540,7 @@ void SemaObjC::SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation) {
SemaRef.MarkFunctionReferenced(Field->getLocation(), Destructor);
SemaRef.CheckDestructorAccess(
Field->getLocation(), Destructor,
SemaRef.PDiag(diag::err_access_dtor_ivar)
PDiag(diag::err_access_dtor_ivar)
<< Context.getBaseElementType(Field->getType()));
}
}

View File

@ -2134,7 +2134,7 @@ ExprResult SemaObjC::HandleExprPropertyRefExpr(
}
} else {
SemaRef.diagnoseTypo(Corrected,
SemaRef.PDiag(diag::err_property_not_found_suggest)
PDiag(diag::err_property_not_found_suggest)
<< MemberName << QualType(OPT, 0));
return HandleExprPropertyRefExpr(OPT, BaseExpr, OpLoc,
TypoResult, MemberLoc,
@ -2369,15 +2369,15 @@ SemaObjC::getObjCMessageKind(Scope *S, IdentifierInfo *Name,
if (Corrected.isKeyword()) {
// If we've found the keyword "super" (the only keyword that would be
// returned by CorrectTypo), this is a send to super.
SemaRef.diagnoseTypo(
Corrected, SemaRef.PDiag(diag::err_unknown_receiver_suggest) << Name);
SemaRef.diagnoseTypo(Corrected, PDiag(diag::err_unknown_receiver_suggest)
<< Name);
return ObjCSuperMessage;
} else if (ObjCInterfaceDecl *Class =
Corrected.getCorrectionDeclAs<ObjCInterfaceDecl>()) {
// If we found a declaration, correct when it refers to an Objective-C
// class.
SemaRef.diagnoseTypo(
Corrected, SemaRef.PDiag(diag::err_unknown_receiver_suggest) << Name);
SemaRef.diagnoseTypo(Corrected, PDiag(diag::err_unknown_receiver_suggest)
<< Name);
QualType T = Context.getObjCInterfaceType(Class);
TypeSourceInfo *TSInfo = Context.getTrivialTypeSourceInfo(T, NameLoc);
ReceiverType = SemaRef.CreateParsedType(T, TSInfo);

View File

@ -3074,9 +3074,9 @@ ExprResult SemaOpenMP::ActOnOpenMPIdExpression(Scope *CurScope,
if (TypoCorrection Corrected =
SemaRef.CorrectTypo(Id, Sema::LookupOrdinaryName, CurScope, nullptr,
CCC, Sema::CTK_ErrorRecovery)) {
SemaRef.diagnoseTypo(
Corrected,
SemaRef.PDiag(Lookup.empty() ? diag::err_undeclared_var_use_suggest
SemaRef.diagnoseTypo(Corrected,
PDiag(Lookup.empty()
? diag::err_undeclared_var_use_suggest
: diag::err_omp_expected_var_arg_suggest)
<< Id.getName());
VD = Corrected.getCorrectionDeclAs<VarDecl>();
@ -7915,9 +7915,9 @@ SemaOpenMP::checkOpenMPDeclareVariantFunction(SemaOpenMP::DeclGroupPtrTy DG,
PartialDiagnostic::NullDiagnostic()),
PartialDiagnosticAt(
VariantRef->getExprLoc(),
SemaRef.PDiag(diag::err_omp_declare_variant_doesnt_support)),
PDiag(diag::err_omp_declare_variant_doesnt_support)),
PartialDiagnosticAt(VariantRef->getExprLoc(),
SemaRef.PDiag(diag::err_omp_declare_variant_diff)
PDiag(diag::err_omp_declare_variant_diff)
<< FD->getLocation()),
/*TemplatesSupported=*/true, /*ConstexprSupported=*/false,
/*CLinkageMayDiffer=*/true))
@ -23695,7 +23695,7 @@ NamedDecl *SemaOpenMP::lookupOpenMPDeclareTargetName(
SemaRef.CorrectTypo(Id, Sema::LookupOrdinaryName, CurScope, nullptr,
CCC, Sema::CTK_ErrorRecovery)) {
SemaRef.diagnoseTypo(Corrected,
SemaRef.PDiag(diag::err_undeclared_var_use_suggest)
PDiag(diag::err_undeclared_var_use_suggest)
<< Id.getName());
checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl());
return nullptr;