-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][NFC] Move PDiag
into SemaBase
#93849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: Vlad Serebrennikov (Endilll) ChangesThis patch moves Full diff: https://github.com/llvm/llvm-project/pull/93849.diff 7 Files Affected:
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index ad4a61d2c8d84..7dea2b6826cfd 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -895,9 +895,6 @@ class Sema final : public SemaBase {
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();
}
diff --git a/clang/include/clang/Sema/SemaBase.h b/clang/include/clang/Sema/SemaBase.h
index 3220f71dd797e..0b05245ab9686 100644
--- a/clang/include/clang/Sema/SemaBase.h
+++ b/clang/include/clang/Sema/SemaBase.h
@@ -217,6 +217,9 @@ class SemaBase {
/// 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
diff --git a/clang/include/clang/Sema/SemaInternal.h b/clang/include/clang/Sema/SemaInternal.h
index 842eec099540c..d994d1819b442 100644
--- a/clang/include/clang/Sema/SemaInternal.h
+++ b/clang/include/clang/Sema/SemaInternal.h
@@ -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 &&
diff --git a/clang/lib/Sema/SemaBase.cpp b/clang/lib/Sema/SemaBase.cpp
index 0442fb2929e3c..a2f12d622e8cc 100644
--- a/clang/lib/Sema/SemaBase.cpp
+++ b/clang/lib/Sema/SemaBase.cpp
@@ -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) {
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index 6d4379283f198..807453400abdd 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -567,9 +567,8 @@ 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)
- << SuperName << ClassName);
+ SemaRef.diagnoseTypo(Corrected, PDiag(diag::err_undef_superclass_suggest)
+ << SuperName << ClassName);
PrevDecl = Corrected.getCorrectionDeclAs<ObjCInterfaceDecl>();
}
}
@@ -1322,9 +1321,9 @@ 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)
- << Pair.first);
+ SemaRef.diagnoseTypo(Corrected,
+ PDiag(diag::err_undeclared_protocol_suggest)
+ << Pair.first);
}
if (!PDecl) {
@@ -1703,9 +1702,9 @@ 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)
- << identifiers[i]);
+ SemaRef.diagnoseTypo(corrected,
+ PDiag(diag::err_undeclared_protocol_suggest)
+ << identifiers[i]);
lookupKind = Sema::LookupObjCProtocolName;
protocols[i] = proto;
++numProtocolsResolved;
@@ -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,10 +1724,9 @@ 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)
- << identifiers[i] << true);
+ SemaRef.diagnoseTypo(corrected,
+ PDiag(diag::err_unknown_type_or_class_name_suggest)
+ << identifiers[i] << true);
lookupKind = Sema::LookupOrdinaryName;
typeDecls[i] = objcClass;
++numTypeDeclsResolved;
@@ -2009,10 +2007,9 @@ 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,
- /*ErrorRecovery*/ false);
+ 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()));
}
}
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 462ab2c952b67..9c423529c80e7 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -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);
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index e74f252f54049..99528c2a4f1f4 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -3074,11 +3074,11 @@ 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
- : diag::err_omp_expected_var_arg_suggest)
- << Id.getName());
+ 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>();
} else {
Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use
@@ -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;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sensible to me, I'm all for it.
This patch moves
PDiag
intoSemaBase
, making it readily available everywhere acrossSema
withoutSemaRef
, like the regularDiag
.