Skip to content

[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

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Sema/SemaBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions clang/include/clang/Sema/SemaInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Sema/SemaBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
38 changes: 17 additions & 21 deletions clang/lib/Sema/SemaDeclObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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()));
}
}
Expand Down
10 changes: 5 additions & 5 deletions clang/lib/Sema/SemaExprObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions clang/lib/Sema/SemaOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down
Loading