mirror of https://github.com/microsoft/clang.git
Implement diagnostic stream operator for ParsedAttr.
As a part of attempting to clean up the way attributes are printed, this patch adds an operator << to the diagnostics/ partialdiagnostics so that ParsedAttr can be sent directly. This patch also rewrites a large amount* of the times when ParsedAttr was printed using its IdentifierInfo object instead of being printed itself. *"a large amount" == "All I could find". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339344 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ff80b2b617
commit
b97894a1b6
|
@ -16,6 +16,7 @@
|
||||||
#define LLVM_CLANG_SEMA_ATTRIBUTELIST_H
|
#define LLVM_CLANG_SEMA_ATTRIBUTELIST_H
|
||||||
|
|
||||||
#include "clang/Basic/AttrSubjectMatchRules.h"
|
#include "clang/Basic/AttrSubjectMatchRules.h"
|
||||||
|
#include "clang/Basic/Diagnostic.h"
|
||||||
#include "clang/Basic/SourceLocation.h"
|
#include "clang/Basic/SourceLocation.h"
|
||||||
#include "clang/Basic/TargetInfo.h"
|
#include "clang/Basic/TargetInfo.h"
|
||||||
#include "clang/Sema/Ownership.h"
|
#include "clang/Sema/Ownership.h"
|
||||||
|
@ -939,6 +940,34 @@ enum AttributeDeclKind {
|
||||||
ExpectedFunctionWithProtoType,
|
ExpectedFunctionWithProtoType,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
|
||||||
|
const ParsedAttr &At) {
|
||||||
|
DB.AddTaggedVal(reinterpret_cast<intptr_t>(At.getName()),
|
||||||
|
DiagnosticsEngine::ak_identifierinfo);
|
||||||
|
return DB;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
|
||||||
|
const ParsedAttr &At) {
|
||||||
|
PD.AddTaggedVal(reinterpret_cast<intptr_t>(At.getName()),
|
||||||
|
DiagnosticsEngine::ak_identifierinfo);
|
||||||
|
return PD;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
|
||||||
|
const ParsedAttr *At) {
|
||||||
|
DB.AddTaggedVal(reinterpret_cast<intptr_t>(At->getName()),
|
||||||
|
DiagnosticsEngine::ak_identifierinfo);
|
||||||
|
return DB;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
|
||||||
|
const ParsedAttr *At) {
|
||||||
|
PD.AddTaggedVal(reinterpret_cast<intptr_t>(At->getName()),
|
||||||
|
DiagnosticsEngine::ak_identifierinfo);
|
||||||
|
return PD;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace clang
|
} // namespace clang
|
||||||
|
|
||||||
#endif // LLVM_CLANG_SEMA_ATTRIBUTELIST_H
|
#endif // LLVM_CLANG_SEMA_ATTRIBUTELIST_H
|
||||||
|
|
|
@ -2456,11 +2456,11 @@ public:
|
||||||
unsigned AttrSpellingListIndex);
|
unsigned AttrSpellingListIndex);
|
||||||
OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, SourceRange Range,
|
OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, SourceRange Range,
|
||||||
unsigned AttrSpellingListIndex);
|
unsigned AttrSpellingListIndex);
|
||||||
InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, SourceRange Range,
|
InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL);
|
||||||
IdentifierInfo *Ident,
|
InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D,
|
||||||
unsigned AttrSpellingListIndex);
|
const InternalLinkageAttr &AL);
|
||||||
CommonAttr *mergeCommonAttr(Decl *D, SourceRange Range, IdentifierInfo *Ident,
|
CommonAttr *mergeCommonAttr(Decl *D, const ParsedAttr &AL);
|
||||||
unsigned AttrSpellingListIndex);
|
CommonAttr *mergeCommonAttr(Decl *D, const CommonAttr &AL);
|
||||||
|
|
||||||
void mergeDeclAttributes(NamedDecl *New, Decl *Old,
|
void mergeDeclAttributes(NamedDecl *New, Decl *Old,
|
||||||
AvailabilityMergeKind AMK = AMK_Redeclaration);
|
AvailabilityMergeKind AMK = AMK_Redeclaration);
|
||||||
|
|
|
@ -2474,14 +2474,9 @@ static bool mergeDeclAttribute(Sema &S, NamedDecl *D,
|
||||||
else if (const auto *OA = dyn_cast<OptimizeNoneAttr>(Attr))
|
else if (const auto *OA = dyn_cast<OptimizeNoneAttr>(Attr))
|
||||||
NewAttr = S.mergeOptimizeNoneAttr(D, OA->getRange(), AttrSpellingListIndex);
|
NewAttr = S.mergeOptimizeNoneAttr(D, OA->getRange(), AttrSpellingListIndex);
|
||||||
else if (const auto *InternalLinkageA = dyn_cast<InternalLinkageAttr>(Attr))
|
else if (const auto *InternalLinkageA = dyn_cast<InternalLinkageAttr>(Attr))
|
||||||
NewAttr = S.mergeInternalLinkageAttr(
|
NewAttr = S.mergeInternalLinkageAttr(D, *InternalLinkageA);
|
||||||
D, InternalLinkageA->getRange(),
|
|
||||||
&S.Context.Idents.get(InternalLinkageA->getSpelling()),
|
|
||||||
AttrSpellingListIndex);
|
|
||||||
else if (const auto *CommonA = dyn_cast<CommonAttr>(Attr))
|
else if (const auto *CommonA = dyn_cast<CommonAttr>(Attr))
|
||||||
NewAttr = S.mergeCommonAttr(D, CommonA->getRange(),
|
NewAttr = S.mergeCommonAttr(D, *CommonA);
|
||||||
&S.Context.Idents.get(CommonA->getSpelling()),
|
|
||||||
AttrSpellingListIndex);
|
|
||||||
else if (isa<AlignedAttr>(Attr))
|
else if (isa<AlignedAttr>(Attr))
|
||||||
// AlignedAttrs are handled separately, because we need to handle all
|
// AlignedAttrs are handled separately, because we need to handle all
|
||||||
// such attributes on a declaration at the same time.
|
// such attributes on a declaration at the same time.
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -56,8 +56,7 @@ static Attr *handleFallThroughAttr(Sema &S, Stmt *St, const ParsedAttr &A,
|
||||||
static Attr *handleSuppressAttr(Sema &S, Stmt *St, const ParsedAttr &A,
|
static Attr *handleSuppressAttr(Sema &S, Stmt *St, const ParsedAttr &A,
|
||||||
SourceRange Range) {
|
SourceRange Range) {
|
||||||
if (A.getNumArgs() < 1) {
|
if (A.getNumArgs() < 1) {
|
||||||
S.Diag(A.getLoc(), diag::err_attribute_too_few_arguments)
|
S.Diag(A.getLoc(), diag::err_attribute_too_few_arguments) << A << 1;
|
||||||
<< A.getName() << 1;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,8 +283,7 @@ static Attr *handleOpenCLUnrollHint(Sema &S, Stmt *St, const ParsedAttr &A,
|
||||||
unsigned NumArgs = A.getNumArgs();
|
unsigned NumArgs = A.getNumArgs();
|
||||||
|
|
||||||
if (NumArgs > 1) {
|
if (NumArgs > 1) {
|
||||||
S.Diag(A.getLoc(), diag::err_attribute_too_many_arguments) << A.getName()
|
S.Diag(A.getLoc(), diag::err_attribute_too_many_arguments) << A << 1;
|
||||||
<< 1;
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,7 +295,7 @@ static Attr *handleOpenCLUnrollHint(Sema &S, Stmt *St, const ParsedAttr &A,
|
||||||
|
|
||||||
if (!E->isIntegerConstantExpr(ArgVal, S.Context)) {
|
if (!E->isIntegerConstantExpr(ArgVal, S.Context)) {
|
||||||
S.Diag(A.getLoc(), diag::err_attribute_argument_type)
|
S.Diag(A.getLoc(), diag::err_attribute_argument_type)
|
||||||
<< A.getName() << AANT_ArgumentIntegerConstant << E->getSourceRange();
|
<< A << AANT_ArgumentIntegerConstant << E->getSourceRange();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,7 +304,7 @@ static Attr *handleOpenCLUnrollHint(Sema &S, Stmt *St, const ParsedAttr &A,
|
||||||
if (Val <= 0) {
|
if (Val <= 0) {
|
||||||
S.Diag(A.getRange().getBegin(),
|
S.Diag(A.getRange().getBegin(),
|
||||||
diag::err_attribute_requires_positive_integer)
|
diag::err_attribute_requires_positive_integer)
|
||||||
<< A.getName();
|
<< A;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
UnrollFactor = Val;
|
UnrollFactor = Val;
|
||||||
|
|
|
@ -5815,8 +5815,8 @@ static void HandleAddressSpaceTypeAttribute(QualType &Type,
|
||||||
|
|
||||||
// Check the attribute arguments.
|
// Check the attribute arguments.
|
||||||
if (Attr.getNumArgs() != 1) {
|
if (Attr.getNumArgs() != 1) {
|
||||||
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
|
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << Attr
|
||||||
<< Attr.getName() << 1;
|
<< 1;
|
||||||
Attr.setInvalid();
|
Attr.setInvalid();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -5951,8 +5951,8 @@ static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state,
|
||||||
S.getSourceManager().getImmediateExpansionRange(AttrLoc).getBegin();
|
S.getSourceManager().getImmediateExpansionRange(AttrLoc).getBegin();
|
||||||
|
|
||||||
if (!attr.isArgIdent(0)) {
|
if (!attr.isArgIdent(0)) {
|
||||||
S.Diag(AttrLoc, diag::err_attribute_argument_type)
|
S.Diag(AttrLoc, diag::err_attribute_argument_type) << attr
|
||||||
<< attr.getName() << AANT_ArgumentString;
|
<< AANT_ArgumentString;
|
||||||
attr.setInvalid();
|
attr.setInvalid();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -6122,14 +6122,14 @@ static bool handleObjCGCTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
|
||||||
// Check the attribute arguments.
|
// Check the attribute arguments.
|
||||||
if (!attr.isArgIdent(0)) {
|
if (!attr.isArgIdent(0)) {
|
||||||
S.Diag(attr.getLoc(), diag::err_attribute_argument_type)
|
S.Diag(attr.getLoc(), diag::err_attribute_argument_type)
|
||||||
<< attr.getName() << AANT_ArgumentString;
|
<< attr << AANT_ArgumentString;
|
||||||
attr.setInvalid();
|
attr.setInvalid();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Qualifiers::GC GCAttr;
|
Qualifiers::GC GCAttr;
|
||||||
if (attr.getNumArgs() > 1) {
|
if (attr.getNumArgs() > 1) {
|
||||||
S.Diag(attr.getLoc(), diag::err_attribute_wrong_number_arguments)
|
S.Diag(attr.getLoc(), diag::err_attribute_wrong_number_arguments) << attr
|
||||||
<< attr.getName() << 1;
|
<< 1;
|
||||||
attr.setInvalid();
|
attr.setInvalid();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -6338,11 +6338,9 @@ static bool handleMSPointerTypeQualifierAttr(TypeProcessingState &State,
|
||||||
// pointer-to-member types.
|
// pointer-to-member types.
|
||||||
if (!isa<PointerType>(Desugared)) {
|
if (!isa<PointerType>(Desugared)) {
|
||||||
if (Type->isMemberPointerType())
|
if (Type->isMemberPointerType())
|
||||||
S.Diag(Attr.getLoc(), diag::err_attribute_no_member_pointers)
|
S.Diag(Attr.getLoc(), diag::err_attribute_no_member_pointers) << Attr;
|
||||||
<< Attr.getName();
|
|
||||||
else
|
else
|
||||||
S.Diag(Attr.getLoc(), diag::err_attribute_pointers_only)
|
S.Diag(Attr.getLoc(), diag::err_attribute_pointers_only) << Attr << 0;
|
||||||
<< Attr.getName() << 0;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6906,8 +6904,8 @@ static void HandleVectorSizeAttr(QualType &CurType, const ParsedAttr &Attr,
|
||||||
Sema &S) {
|
Sema &S) {
|
||||||
// Check the attribute arguments.
|
// Check the attribute arguments.
|
||||||
if (Attr.getNumArgs() != 1) {
|
if (Attr.getNumArgs() != 1) {
|
||||||
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
|
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << Attr
|
||||||
<< Attr.getName() << 1;
|
<< 1;
|
||||||
Attr.setInvalid();
|
Attr.setInvalid();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -6943,8 +6941,8 @@ static void HandleExtVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
|
||||||
Sema &S) {
|
Sema &S) {
|
||||||
// check the attribute arguments.
|
// check the attribute arguments.
|
||||||
if (Attr.getNumArgs() != 1) {
|
if (Attr.getNumArgs() != 1) {
|
||||||
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
|
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << Attr
|
||||||
<< Attr.getName() << 1;
|
<< 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7032,14 +7030,14 @@ static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
|
||||||
Sema &S, VectorType::VectorKind VecKind) {
|
Sema &S, VectorType::VectorKind VecKind) {
|
||||||
// Target must have NEON
|
// Target must have NEON
|
||||||
if (!S.Context.getTargetInfo().hasFeature("neon")) {
|
if (!S.Context.getTargetInfo().hasFeature("neon")) {
|
||||||
S.Diag(Attr.getLoc(), diag::err_attribute_unsupported) << Attr.getName();
|
S.Diag(Attr.getLoc(), diag::err_attribute_unsupported) << Attr;
|
||||||
Attr.setInvalid();
|
Attr.setInvalid();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check the attribute arguments.
|
// Check the attribute arguments.
|
||||||
if (Attr.getNumArgs() != 1) {
|
if (Attr.getNumArgs() != 1) {
|
||||||
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
|
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << Attr
|
||||||
<< Attr.getName() << 1;
|
<< 1;
|
||||||
Attr.setInvalid();
|
Attr.setInvalid();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -7049,8 +7047,8 @@ static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
|
||||||
if (numEltsExpr->isTypeDependent() || numEltsExpr->isValueDependent() ||
|
if (numEltsExpr->isTypeDependent() || numEltsExpr->isValueDependent() ||
|
||||||
!numEltsExpr->isIntegerConstantExpr(numEltsInt, S.Context)) {
|
!numEltsExpr->isIntegerConstantExpr(numEltsInt, S.Context)) {
|
||||||
S.Diag(Attr.getLoc(), diag::err_attribute_argument_type)
|
S.Diag(Attr.getLoc(), diag::err_attribute_argument_type)
|
||||||
<< Attr.getName() << AANT_ArgumentIntegerConstant
|
<< Attr << AANT_ArgumentIntegerConstant
|
||||||
<< numEltsExpr->getSourceRange();
|
<< numEltsExpr->getSourceRange();
|
||||||
Attr.setInvalid();
|
Attr.setInvalid();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -7256,7 +7254,7 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
|
||||||
// A C++11 attribute on a declarator chunk must appertain to a type.
|
// A C++11 attribute on a declarator chunk must appertain to a type.
|
||||||
if (attr.isCXX11Attribute() && TAL == TAL_DeclChunk) {
|
if (attr.isCXX11Attribute() && TAL == TAL_DeclChunk) {
|
||||||
state.getSema().Diag(attr.getLoc(), diag::err_attribute_not_type_attr)
|
state.getSema().Diag(attr.getLoc(), diag::err_attribute_not_type_attr)
|
||||||
<< attr.getName();
|
<< attr;
|
||||||
attr.setUsedAsTypeAttr();
|
attr.setUsedAsTypeAttr();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -3335,7 +3335,7 @@ static std::string GenerateAppertainsTo(const Record &Attr, raw_ostream &OS) {
|
||||||
SS << (Warn ? "warn_attribute_wrong_decl_type_str" :
|
SS << (Warn ? "warn_attribute_wrong_decl_type_str" :
|
||||||
"err_attribute_wrong_decl_type_str");
|
"err_attribute_wrong_decl_type_str");
|
||||||
SS << ")\n";
|
SS << ")\n";
|
||||||
SS << " << Attr.getName() << ";
|
SS << " << Attr << ";
|
||||||
SS << CalculateDiagnostic(*SubjectObj) << ";\n";
|
SS << CalculateDiagnostic(*SubjectObj) << ";\n";
|
||||||
SS << " return false;\n";
|
SS << " return false;\n";
|
||||||
SS << " }\n";
|
SS << " }\n";
|
||||||
|
|
Loading…
Reference in New Issue