[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:
parent
0eb9e021b1
commit
baabaa4ce9
@ -895,9 +895,6 @@ public:
|
|||||||
void disable() { Active = false; }
|
void disable() { Active = false; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Build a partial diagnostic.
|
|
||||||
PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h
|
|
||||||
|
|
||||||
sema::FunctionScopeInfo *getCurFunction() const {
|
sema::FunctionScopeInfo *getCurFunction() const {
|
||||||
return FunctionScopes.empty() ? nullptr : FunctionScopes.back();
|
return FunctionScopes.empty() ? nullptr : FunctionScopes.back();
|
||||||
}
|
}
|
||||||
|
@ -217,6 +217,9 @@ public:
|
|||||||
/// Emit a partial diagnostic.
|
/// Emit a partial diagnostic.
|
||||||
SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD,
|
SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD,
|
||||||
bool DeferHint = false);
|
bool DeferHint = false);
|
||||||
|
|
||||||
|
/// Build a partial diagnostic.
|
||||||
|
PartialDiagnostic PDiag(unsigned DiagID = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace clang
|
} // namespace clang
|
||||||
|
@ -21,10 +21,6 @@
|
|||||||
|
|
||||||
namespace clang {
|
namespace clang {
|
||||||
|
|
||||||
inline PartialDiagnostic Sema::PDiag(unsigned DiagID) {
|
|
||||||
return PartialDiagnostic(DiagID, Context.getDiagAllocator());
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
FTIHasSingleVoidParameter(const DeclaratorChunk::FunctionTypeInfo &FTI) {
|
FTIHasSingleVoidParameter(const DeclaratorChunk::FunctionTypeInfo &FTI) {
|
||||||
return FTI.NumParams == 1 && !FTI.isVariadic &&
|
return FTI.NumParams == 1 && !FTI.isVariadic &&
|
||||||
|
@ -29,6 +29,10 @@ SemaBase::ImmediateDiagBuilder::~ImmediateDiagBuilder() {
|
|||||||
SemaRef.EmitCurrentDiagnostic(DiagID);
|
SemaRef.EmitCurrentDiagnostic(DiagID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PartialDiagnostic SemaBase::PDiag(unsigned DiagID) {
|
||||||
|
return PartialDiagnostic(DiagID, SemaRef.Context.getDiagAllocator());
|
||||||
|
}
|
||||||
|
|
||||||
const SemaBase::SemaDiagnosticBuilder &
|
const SemaBase::SemaDiagnosticBuilder &
|
||||||
operator<<(const SemaBase::SemaDiagnosticBuilder &Diag,
|
operator<<(const SemaBase::SemaDiagnosticBuilder &Diag,
|
||||||
const PartialDiagnostic &PD) {
|
const PartialDiagnostic &PD) {
|
||||||
|
@ -567,9 +567,8 @@ void SemaObjC::ActOnSuperClassOfClassInterface(
|
|||||||
if (TypoCorrection Corrected = SemaRef.CorrectTypo(
|
if (TypoCorrection Corrected = SemaRef.CorrectTypo(
|
||||||
DeclarationNameInfo(SuperName, SuperLoc), Sema::LookupOrdinaryName,
|
DeclarationNameInfo(SuperName, SuperLoc), Sema::LookupOrdinaryName,
|
||||||
SemaRef.TUScope, nullptr, CCC, Sema::CTK_ErrorRecovery)) {
|
SemaRef.TUScope, nullptr, CCC, Sema::CTK_ErrorRecovery)) {
|
||||||
SemaRef.diagnoseTypo(Corrected,
|
SemaRef.diagnoseTypo(Corrected, PDiag(diag::err_undef_superclass_suggest)
|
||||||
SemaRef.PDiag(diag::err_undef_superclass_suggest)
|
<< SuperName << ClassName);
|
||||||
<< SuperName << ClassName);
|
|
||||||
PrevDecl = Corrected.getCorrectionDeclAs<ObjCInterfaceDecl>();
|
PrevDecl = Corrected.getCorrectionDeclAs<ObjCInterfaceDecl>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1322,9 +1321,9 @@ void SemaObjC::FindProtocolDeclaration(bool WarnOnDeclarations,
|
|||||||
Sema::LookupObjCProtocolName, SemaRef.TUScope,
|
Sema::LookupObjCProtocolName, SemaRef.TUScope,
|
||||||
nullptr, CCC, Sema::CTK_ErrorRecovery);
|
nullptr, CCC, Sema::CTK_ErrorRecovery);
|
||||||
if ((PDecl = Corrected.getCorrectionDeclAs<ObjCProtocolDecl>()))
|
if ((PDecl = Corrected.getCorrectionDeclAs<ObjCProtocolDecl>()))
|
||||||
SemaRef.diagnoseTypo(
|
SemaRef.diagnoseTypo(Corrected,
|
||||||
Corrected, SemaRef.PDiag(diag::err_undeclared_protocol_suggest)
|
PDiag(diag::err_undeclared_protocol_suggest)
|
||||||
<< Pair.first);
|
<< Pair.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PDecl) {
|
if (!PDecl) {
|
||||||
@ -1703,9 +1702,9 @@ void SemaObjC::actOnObjCTypeArgsOrProtocolQualifiers(
|
|||||||
if (corrected) {
|
if (corrected) {
|
||||||
// Did we find a protocol?
|
// Did we find a protocol?
|
||||||
if (auto proto = corrected.getCorrectionDeclAs<ObjCProtocolDecl>()) {
|
if (auto proto = corrected.getCorrectionDeclAs<ObjCProtocolDecl>()) {
|
||||||
SemaRef.diagnoseTypo(
|
SemaRef.diagnoseTypo(corrected,
|
||||||
corrected, SemaRef.PDiag(diag::err_undeclared_protocol_suggest)
|
PDiag(diag::err_undeclared_protocol_suggest)
|
||||||
<< identifiers[i]);
|
<< identifiers[i]);
|
||||||
lookupKind = Sema::LookupObjCProtocolName;
|
lookupKind = Sema::LookupObjCProtocolName;
|
||||||
protocols[i] = proto;
|
protocols[i] = proto;
|
||||||
++numProtocolsResolved;
|
++numProtocolsResolved;
|
||||||
@ -1715,7 +1714,7 @@ void SemaObjC::actOnObjCTypeArgsOrProtocolQualifiers(
|
|||||||
// Did we find a type?
|
// Did we find a type?
|
||||||
if (auto typeDecl = corrected.getCorrectionDeclAs<TypeDecl>()) {
|
if (auto typeDecl = corrected.getCorrectionDeclAs<TypeDecl>()) {
|
||||||
SemaRef.diagnoseTypo(corrected,
|
SemaRef.diagnoseTypo(corrected,
|
||||||
SemaRef.PDiag(diag::err_unknown_typename_suggest)
|
PDiag(diag::err_unknown_typename_suggest)
|
||||||
<< identifiers[i]);
|
<< identifiers[i]);
|
||||||
lookupKind = Sema::LookupOrdinaryName;
|
lookupKind = Sema::LookupOrdinaryName;
|
||||||
typeDecls[i] = typeDecl;
|
typeDecls[i] = typeDecl;
|
||||||
@ -1725,10 +1724,9 @@ void SemaObjC::actOnObjCTypeArgsOrProtocolQualifiers(
|
|||||||
|
|
||||||
// Did we find an Objective-C class?
|
// Did we find an Objective-C class?
|
||||||
if (auto objcClass = corrected.getCorrectionDeclAs<ObjCInterfaceDecl>()) {
|
if (auto objcClass = corrected.getCorrectionDeclAs<ObjCInterfaceDecl>()) {
|
||||||
SemaRef.diagnoseTypo(
|
SemaRef.diagnoseTypo(corrected,
|
||||||
corrected,
|
PDiag(diag::err_unknown_type_or_class_name_suggest)
|
||||||
SemaRef.PDiag(diag::err_unknown_type_or_class_name_suggest)
|
<< identifiers[i] << true);
|
||||||
<< identifiers[i] << true);
|
|
||||||
lookupKind = Sema::LookupOrdinaryName;
|
lookupKind = Sema::LookupOrdinaryName;
|
||||||
typeDecls[i] = objcClass;
|
typeDecls[i] = objcClass;
|
||||||
++numTypeDeclsResolved;
|
++numTypeDeclsResolved;
|
||||||
@ -2009,10 +2007,9 @@ ObjCImplementationDecl *SemaObjC::ActOnStartClassImplementation(
|
|||||||
// Suggest the (potentially) correct interface name. Don't provide a
|
// Suggest the (potentially) correct interface name. Don't provide a
|
||||||
// code-modification hint or use the typo name for recovery, because
|
// code-modification hint or use the typo name for recovery, because
|
||||||
// this is just a warning. The program may actually be correct.
|
// this is just a warning. The program may actually be correct.
|
||||||
SemaRef.diagnoseTypo(Corrected,
|
SemaRef.diagnoseTypo(
|
||||||
SemaRef.PDiag(diag::warn_undef_interface_suggest)
|
Corrected, PDiag(diag::warn_undef_interface_suggest) << ClassName,
|
||||||
<< ClassName,
|
/*ErrorRecovery*/ false);
|
||||||
/*ErrorRecovery*/ false);
|
|
||||||
} else {
|
} else {
|
||||||
Diag(ClassLoc, diag::warn_undef_interface) << ClassName;
|
Diag(ClassLoc, diag::warn_undef_interface) << ClassName;
|
||||||
}
|
}
|
||||||
@ -5439,8 +5436,7 @@ ObjCInterfaceDecl *SemaObjC::getObjCInterfaceDecl(const IdentifierInfo *&Id,
|
|||||||
if (TypoCorrection C = SemaRef.CorrectTypo(
|
if (TypoCorrection C = SemaRef.CorrectTypo(
|
||||||
DeclarationNameInfo(Id, IdLoc), Sema::LookupOrdinaryName,
|
DeclarationNameInfo(Id, IdLoc), Sema::LookupOrdinaryName,
|
||||||
SemaRef.TUScope, nullptr, CCC, Sema::CTK_ErrorRecovery)) {
|
SemaRef.TUScope, nullptr, CCC, Sema::CTK_ErrorRecovery)) {
|
||||||
SemaRef.diagnoseTypo(C, SemaRef.PDiag(diag::err_undef_interface_suggest)
|
SemaRef.diagnoseTypo(C, PDiag(diag::err_undef_interface_suggest) << Id);
|
||||||
<< Id);
|
|
||||||
IDecl = C.getCorrectionDeclAs<ObjCInterfaceDecl>();
|
IDecl = C.getCorrectionDeclAs<ObjCInterfaceDecl>();
|
||||||
Id = IDecl->getIdentifier();
|
Id = IDecl->getIdentifier();
|
||||||
}
|
}
|
||||||
@ -5544,7 +5540,7 @@ void SemaObjC::SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation) {
|
|||||||
SemaRef.MarkFunctionReferenced(Field->getLocation(), Destructor);
|
SemaRef.MarkFunctionReferenced(Field->getLocation(), Destructor);
|
||||||
SemaRef.CheckDestructorAccess(
|
SemaRef.CheckDestructorAccess(
|
||||||
Field->getLocation(), Destructor,
|
Field->getLocation(), Destructor,
|
||||||
SemaRef.PDiag(diag::err_access_dtor_ivar)
|
PDiag(diag::err_access_dtor_ivar)
|
||||||
<< Context.getBaseElementType(Field->getType()));
|
<< Context.getBaseElementType(Field->getType()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2134,7 +2134,7 @@ ExprResult SemaObjC::HandleExprPropertyRefExpr(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SemaRef.diagnoseTypo(Corrected,
|
SemaRef.diagnoseTypo(Corrected,
|
||||||
SemaRef.PDiag(diag::err_property_not_found_suggest)
|
PDiag(diag::err_property_not_found_suggest)
|
||||||
<< MemberName << QualType(OPT, 0));
|
<< MemberName << QualType(OPT, 0));
|
||||||
return HandleExprPropertyRefExpr(OPT, BaseExpr, OpLoc,
|
return HandleExprPropertyRefExpr(OPT, BaseExpr, OpLoc,
|
||||||
TypoResult, MemberLoc,
|
TypoResult, MemberLoc,
|
||||||
@ -2369,15 +2369,15 @@ SemaObjC::getObjCMessageKind(Scope *S, IdentifierInfo *Name,
|
|||||||
if (Corrected.isKeyword()) {
|
if (Corrected.isKeyword()) {
|
||||||
// If we've found the keyword "super" (the only keyword that would be
|
// If we've found the keyword "super" (the only keyword that would be
|
||||||
// returned by CorrectTypo), this is a send to super.
|
// returned by CorrectTypo), this is a send to super.
|
||||||
SemaRef.diagnoseTypo(
|
SemaRef.diagnoseTypo(Corrected, PDiag(diag::err_unknown_receiver_suggest)
|
||||||
Corrected, SemaRef.PDiag(diag::err_unknown_receiver_suggest) << Name);
|
<< Name);
|
||||||
return ObjCSuperMessage;
|
return ObjCSuperMessage;
|
||||||
} else if (ObjCInterfaceDecl *Class =
|
} else if (ObjCInterfaceDecl *Class =
|
||||||
Corrected.getCorrectionDeclAs<ObjCInterfaceDecl>()) {
|
Corrected.getCorrectionDeclAs<ObjCInterfaceDecl>()) {
|
||||||
// If we found a declaration, correct when it refers to an Objective-C
|
// If we found a declaration, correct when it refers to an Objective-C
|
||||||
// class.
|
// class.
|
||||||
SemaRef.diagnoseTypo(
|
SemaRef.diagnoseTypo(Corrected, PDiag(diag::err_unknown_receiver_suggest)
|
||||||
Corrected, SemaRef.PDiag(diag::err_unknown_receiver_suggest) << Name);
|
<< Name);
|
||||||
QualType T = Context.getObjCInterfaceType(Class);
|
QualType T = Context.getObjCInterfaceType(Class);
|
||||||
TypeSourceInfo *TSInfo = Context.getTrivialTypeSourceInfo(T, NameLoc);
|
TypeSourceInfo *TSInfo = Context.getTrivialTypeSourceInfo(T, NameLoc);
|
||||||
ReceiverType = SemaRef.CreateParsedType(T, TSInfo);
|
ReceiverType = SemaRef.CreateParsedType(T, TSInfo);
|
||||||
|
@ -3074,11 +3074,11 @@ ExprResult SemaOpenMP::ActOnOpenMPIdExpression(Scope *CurScope,
|
|||||||
if (TypoCorrection Corrected =
|
if (TypoCorrection Corrected =
|
||||||
SemaRef.CorrectTypo(Id, Sema::LookupOrdinaryName, CurScope, nullptr,
|
SemaRef.CorrectTypo(Id, Sema::LookupOrdinaryName, CurScope, nullptr,
|
||||||
CCC, Sema::CTK_ErrorRecovery)) {
|
CCC, Sema::CTK_ErrorRecovery)) {
|
||||||
SemaRef.diagnoseTypo(
|
SemaRef.diagnoseTypo(Corrected,
|
||||||
Corrected,
|
PDiag(Lookup.empty()
|
||||||
SemaRef.PDiag(Lookup.empty() ? diag::err_undeclared_var_use_suggest
|
? diag::err_undeclared_var_use_suggest
|
||||||
: diag::err_omp_expected_var_arg_suggest)
|
: diag::err_omp_expected_var_arg_suggest)
|
||||||
<< Id.getName());
|
<< Id.getName());
|
||||||
VD = Corrected.getCorrectionDeclAs<VarDecl>();
|
VD = Corrected.getCorrectionDeclAs<VarDecl>();
|
||||||
} else {
|
} else {
|
||||||
Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use
|
Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use
|
||||||
@ -7915,9 +7915,9 @@ SemaOpenMP::checkOpenMPDeclareVariantFunction(SemaOpenMP::DeclGroupPtrTy DG,
|
|||||||
PartialDiagnostic::NullDiagnostic()),
|
PartialDiagnostic::NullDiagnostic()),
|
||||||
PartialDiagnosticAt(
|
PartialDiagnosticAt(
|
||||||
VariantRef->getExprLoc(),
|
VariantRef->getExprLoc(),
|
||||||
SemaRef.PDiag(diag::err_omp_declare_variant_doesnt_support)),
|
PDiag(diag::err_omp_declare_variant_doesnt_support)),
|
||||||
PartialDiagnosticAt(VariantRef->getExprLoc(),
|
PartialDiagnosticAt(VariantRef->getExprLoc(),
|
||||||
SemaRef.PDiag(diag::err_omp_declare_variant_diff)
|
PDiag(diag::err_omp_declare_variant_diff)
|
||||||
<< FD->getLocation()),
|
<< FD->getLocation()),
|
||||||
/*TemplatesSupported=*/true, /*ConstexprSupported=*/false,
|
/*TemplatesSupported=*/true, /*ConstexprSupported=*/false,
|
||||||
/*CLinkageMayDiffer=*/true))
|
/*CLinkageMayDiffer=*/true))
|
||||||
@ -23695,7 +23695,7 @@ NamedDecl *SemaOpenMP::lookupOpenMPDeclareTargetName(
|
|||||||
SemaRef.CorrectTypo(Id, Sema::LookupOrdinaryName, CurScope, nullptr,
|
SemaRef.CorrectTypo(Id, Sema::LookupOrdinaryName, CurScope, nullptr,
|
||||||
CCC, Sema::CTK_ErrorRecovery)) {
|
CCC, Sema::CTK_ErrorRecovery)) {
|
||||||
SemaRef.diagnoseTypo(Corrected,
|
SemaRef.diagnoseTypo(Corrected,
|
||||||
SemaRef.PDiag(diag::err_undeclared_var_use_suggest)
|
PDiag(diag::err_undeclared_var_use_suggest)
|
||||||
<< Id.getName());
|
<< Id.getName());
|
||||||
checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl());
|
checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user