Skip to content

Commit baabaa4

Browse files
authored
[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`.
1 parent 0eb9e02 commit baabaa4

File tree

7 files changed

+37
-41
lines changed

7 files changed

+37
-41
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,6 @@ class Sema final : public SemaBase {
895895
void disable() { Active = false; }
896896
};
897897

898-
/// Build a partial diagnostic.
899-
PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h
900-
901898
sema::FunctionScopeInfo *getCurFunction() const {
902899
return FunctionScopes.empty() ? nullptr : FunctionScopes.back();
903900
}

clang/include/clang/Sema/SemaBase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ class SemaBase {
217217
/// Emit a partial diagnostic.
218218
SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD,
219219
bool DeferHint = false);
220+
221+
/// Build a partial diagnostic.
222+
PartialDiagnostic PDiag(unsigned DiagID = 0);
220223
};
221224

222225
} // namespace clang

clang/include/clang/Sema/SemaInternal.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121

2222
namespace clang {
2323

24-
inline PartialDiagnostic Sema::PDiag(unsigned DiagID) {
25-
return PartialDiagnostic(DiagID, Context.getDiagAllocator());
26-
}
27-
2824
inline bool
2925
FTIHasSingleVoidParameter(const DeclaratorChunk::FunctionTypeInfo &FTI) {
3026
return FTI.NumParams == 1 && !FTI.isVariadic &&

clang/lib/Sema/SemaBase.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ SemaBase::ImmediateDiagBuilder::~ImmediateDiagBuilder() {
2929
SemaRef.EmitCurrentDiagnostic(DiagID);
3030
}
3131

32+
PartialDiagnostic SemaBase::PDiag(unsigned DiagID) {
33+
return PartialDiagnostic(DiagID, SemaRef.Context.getDiagAllocator());
34+
}
35+
3236
const SemaBase::SemaDiagnosticBuilder &
3337
operator<<(const SemaBase::SemaDiagnosticBuilder &Diag,
3438
const PartialDiagnostic &PD) {

clang/lib/Sema/SemaDeclObjC.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,8 @@ void SemaObjC::ActOnSuperClassOfClassInterface(
567567
if (TypoCorrection Corrected = SemaRef.CorrectTypo(
568568
DeclarationNameInfo(SuperName, SuperLoc), Sema::LookupOrdinaryName,
569569
SemaRef.TUScope, nullptr, CCC, Sema::CTK_ErrorRecovery)) {
570-
SemaRef.diagnoseTypo(Corrected,
571-
SemaRef.PDiag(diag::err_undef_superclass_suggest)
572-
<< SuperName << ClassName);
570+
SemaRef.diagnoseTypo(Corrected, PDiag(diag::err_undef_superclass_suggest)
571+
<< SuperName << ClassName);
573572
PrevDecl = Corrected.getCorrectionDeclAs<ObjCInterfaceDecl>();
574573
}
575574
}
@@ -1322,9 +1321,9 @@ void SemaObjC::FindProtocolDeclaration(bool WarnOnDeclarations,
13221321
Sema::LookupObjCProtocolName, SemaRef.TUScope,
13231322
nullptr, CCC, Sema::CTK_ErrorRecovery);
13241323
if ((PDecl = Corrected.getCorrectionDeclAs<ObjCProtocolDecl>()))
1325-
SemaRef.diagnoseTypo(
1326-
Corrected, SemaRef.PDiag(diag::err_undeclared_protocol_suggest)
1327-
<< Pair.first);
1324+
SemaRef.diagnoseTypo(Corrected,
1325+
PDiag(diag::err_undeclared_protocol_suggest)
1326+
<< Pair.first);
13281327
}
13291328

13301329
if (!PDecl) {
@@ -1703,9 +1702,9 @@ void SemaObjC::actOnObjCTypeArgsOrProtocolQualifiers(
17031702
if (corrected) {
17041703
// Did we find a protocol?
17051704
if (auto proto = corrected.getCorrectionDeclAs<ObjCProtocolDecl>()) {
1706-
SemaRef.diagnoseTypo(
1707-
corrected, SemaRef.PDiag(diag::err_undeclared_protocol_suggest)
1708-
<< identifiers[i]);
1705+
SemaRef.diagnoseTypo(corrected,
1706+
PDiag(diag::err_undeclared_protocol_suggest)
1707+
<< identifiers[i]);
17091708
lookupKind = Sema::LookupObjCProtocolName;
17101709
protocols[i] = proto;
17111710
++numProtocolsResolved;
@@ -1715,7 +1714,7 @@ void SemaObjC::actOnObjCTypeArgsOrProtocolQualifiers(
17151714
// Did we find a type?
17161715
if (auto typeDecl = corrected.getCorrectionDeclAs<TypeDecl>()) {
17171716
SemaRef.diagnoseTypo(corrected,
1718-
SemaRef.PDiag(diag::err_unknown_typename_suggest)
1717+
PDiag(diag::err_unknown_typename_suggest)
17191718
<< identifiers[i]);
17201719
lookupKind = Sema::LookupOrdinaryName;
17211720
typeDecls[i] = typeDecl;
@@ -1725,10 +1724,9 @@ void SemaObjC::actOnObjCTypeArgsOrProtocolQualifiers(
17251724

17261725
// Did we find an Objective-C class?
17271726
if (auto objcClass = corrected.getCorrectionDeclAs<ObjCInterfaceDecl>()) {
1728-
SemaRef.diagnoseTypo(
1729-
corrected,
1730-
SemaRef.PDiag(diag::err_unknown_type_or_class_name_suggest)
1731-
<< identifiers[i] << true);
1727+
SemaRef.diagnoseTypo(corrected,
1728+
PDiag(diag::err_unknown_type_or_class_name_suggest)
1729+
<< identifiers[i] << true);
17321730
lookupKind = Sema::LookupOrdinaryName;
17331731
typeDecls[i] = objcClass;
17341732
++numTypeDeclsResolved;
@@ -2009,10 +2007,9 @@ ObjCImplementationDecl *SemaObjC::ActOnStartClassImplementation(
20092007
// Suggest the (potentially) correct interface name. Don't provide a
20102008
// code-modification hint or use the typo name for recovery, because
20112009
// this is just a warning. The program may actually be correct.
2012-
SemaRef.diagnoseTypo(Corrected,
2013-
SemaRef.PDiag(diag::warn_undef_interface_suggest)
2014-
<< ClassName,
2015-
/*ErrorRecovery*/ false);
2010+
SemaRef.diagnoseTypo(
2011+
Corrected, PDiag(diag::warn_undef_interface_suggest) << ClassName,
2012+
/*ErrorRecovery*/ false);
20162013
} else {
20172014
Diag(ClassLoc, diag::warn_undef_interface) << ClassName;
20182015
}
@@ -5439,8 +5436,7 @@ ObjCInterfaceDecl *SemaObjC::getObjCInterfaceDecl(const IdentifierInfo *&Id,
54395436
if (TypoCorrection C = SemaRef.CorrectTypo(
54405437
DeclarationNameInfo(Id, IdLoc), Sema::LookupOrdinaryName,
54415438
SemaRef.TUScope, nullptr, CCC, Sema::CTK_ErrorRecovery)) {
5442-
SemaRef.diagnoseTypo(C, SemaRef.PDiag(diag::err_undef_interface_suggest)
5443-
<< Id);
5439+
SemaRef.diagnoseTypo(C, PDiag(diag::err_undef_interface_suggest) << Id);
54445440
IDecl = C.getCorrectionDeclAs<ObjCInterfaceDecl>();
54455441
Id = IDecl->getIdentifier();
54465442
}
@@ -5544,7 +5540,7 @@ void SemaObjC::SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation) {
55445540
SemaRef.MarkFunctionReferenced(Field->getLocation(), Destructor);
55455541
SemaRef.CheckDestructorAccess(
55465542
Field->getLocation(), Destructor,
5547-
SemaRef.PDiag(diag::err_access_dtor_ivar)
5543+
PDiag(diag::err_access_dtor_ivar)
55485544
<< Context.getBaseElementType(Field->getType()));
55495545
}
55505546
}

clang/lib/Sema/SemaExprObjC.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ ExprResult SemaObjC::HandleExprPropertyRefExpr(
21342134
}
21352135
} else {
21362136
SemaRef.diagnoseTypo(Corrected,
2137-
SemaRef.PDiag(diag::err_property_not_found_suggest)
2137+
PDiag(diag::err_property_not_found_suggest)
21382138
<< MemberName << QualType(OPT, 0));
21392139
return HandleExprPropertyRefExpr(OPT, BaseExpr, OpLoc,
21402140
TypoResult, MemberLoc,
@@ -2369,15 +2369,15 @@ SemaObjC::getObjCMessageKind(Scope *S, IdentifierInfo *Name,
23692369
if (Corrected.isKeyword()) {
23702370
// If we've found the keyword "super" (the only keyword that would be
23712371
// returned by CorrectTypo), this is a send to super.
2372-
SemaRef.diagnoseTypo(
2373-
Corrected, SemaRef.PDiag(diag::err_unknown_receiver_suggest) << Name);
2372+
SemaRef.diagnoseTypo(Corrected, PDiag(diag::err_unknown_receiver_suggest)
2373+
<< Name);
23742374
return ObjCSuperMessage;
23752375
} else if (ObjCInterfaceDecl *Class =
23762376
Corrected.getCorrectionDeclAs<ObjCInterfaceDecl>()) {
23772377
// If we found a declaration, correct when it refers to an Objective-C
23782378
// class.
2379-
SemaRef.diagnoseTypo(
2380-
Corrected, SemaRef.PDiag(diag::err_unknown_receiver_suggest) << Name);
2379+
SemaRef.diagnoseTypo(Corrected, PDiag(diag::err_unknown_receiver_suggest)
2380+
<< Name);
23812381
QualType T = Context.getObjCInterfaceType(Class);
23822382
TypeSourceInfo *TSInfo = Context.getTrivialTypeSourceInfo(T, NameLoc);
23832383
ReceiverType = SemaRef.CreateParsedType(T, TSInfo);

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3074,11 +3074,11 @@ ExprResult SemaOpenMP::ActOnOpenMPIdExpression(Scope *CurScope,
30743074
if (TypoCorrection Corrected =
30753075
SemaRef.CorrectTypo(Id, Sema::LookupOrdinaryName, CurScope, nullptr,
30763076
CCC, Sema::CTK_ErrorRecovery)) {
3077-
SemaRef.diagnoseTypo(
3078-
Corrected,
3079-
SemaRef.PDiag(Lookup.empty() ? diag::err_undeclared_var_use_suggest
3080-
: diag::err_omp_expected_var_arg_suggest)
3081-
<< Id.getName());
3077+
SemaRef.diagnoseTypo(Corrected,
3078+
PDiag(Lookup.empty()
3079+
? diag::err_undeclared_var_use_suggest
3080+
: diag::err_omp_expected_var_arg_suggest)
3081+
<< Id.getName());
30823082
VD = Corrected.getCorrectionDeclAs<VarDecl>();
30833083
} else {
30843084
Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use
@@ -7915,9 +7915,9 @@ SemaOpenMP::checkOpenMPDeclareVariantFunction(SemaOpenMP::DeclGroupPtrTy DG,
79157915
PartialDiagnostic::NullDiagnostic()),
79167916
PartialDiagnosticAt(
79177917
VariantRef->getExprLoc(),
7918-
SemaRef.PDiag(diag::err_omp_declare_variant_doesnt_support)),
7918+
PDiag(diag::err_omp_declare_variant_doesnt_support)),
79197919
PartialDiagnosticAt(VariantRef->getExprLoc(),
7920-
SemaRef.PDiag(diag::err_omp_declare_variant_diff)
7920+
PDiag(diag::err_omp_declare_variant_diff)
79217921
<< FD->getLocation()),
79227922
/*TemplatesSupported=*/true, /*ConstexprSupported=*/false,
79237923
/*CLinkageMayDiffer=*/true))
@@ -23695,7 +23695,7 @@ NamedDecl *SemaOpenMP::lookupOpenMPDeclareTargetName(
2369523695
SemaRef.CorrectTypo(Id, Sema::LookupOrdinaryName, CurScope, nullptr,
2369623696
CCC, Sema::CTK_ErrorRecovery)) {
2369723697
SemaRef.diagnoseTypo(Corrected,
23698-
SemaRef.PDiag(diag::err_undeclared_var_use_suggest)
23698+
PDiag(diag::err_undeclared_var_use_suggest)
2369923699
<< Id.getName());
2370023700
checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl());
2370123701
return nullptr;

0 commit comments

Comments
 (0)