diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-10-06 21:18:44 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-10-06 21:18:44 +0000 |
commit | c4b35cfdb977f6427fe0d5725bf104e1b425d72e (patch) | |
tree | aaf25a5711f3e07df94084c6934767075fe0a235 /lib | |
parent | 37cf66350cb5a2bb68b0b7c7cca552f7a4867348 (diff) |
Add message to attribute(deprecated).
attribute(unavailable) to do next.
// rdar:// 6734520.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115842 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 46 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 10 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 6 |
3 files changed, 47 insertions, 15 deletions
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 9800db09e3..1376472eec 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -903,12 +903,28 @@ static void HandleDestructorAttr(Decl *d, const AttributeList &Attr, Sema &S) { static void HandleDeprecatedAttr(Decl *d, const AttributeList &Attr, Sema &S) { // check the attribute arguments. - if (Attr.getNumArgs() != 0) { - S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0; - return; + int noArgs = Attr.getNumArgs(); + if (noArgs > 1) { + S.Diag(Attr.getLoc(), + diag::err_attribute_wrong_number_arguments) << "0 or 1"; + return; + } + // Handle the case where deprecated attribute has a text message. + StringLiteral *SE; + if (noArgs == 1) { + Expr *ArgExpr = static_cast<Expr *>(Attr.getArg(0)); + SE = dyn_cast<StringLiteral>(ArgExpr); + if (!SE) { + S.Diag(ArgExpr->getLocStart(), + diag::err_attribute_not_string) << "deprecated"; + return; + } } + else + SE = StringLiteral::CreateEmpty(S.Context, 1); - d->addAttr(::new (S.Context) DeprecatedAttr(Attr.getLoc(), S.Context)); + d->addAttr(::new (S.Context) DeprecatedAttr(Attr.getLoc(), S.Context, + SE->getString())); } static void HandleUnavailableAttr(Decl *d, const AttributeList &Attr, Sema &S) { @@ -2536,20 +2552,30 @@ void Sema::HandleDelayedDeprecationCheck(DelayedDiagnostic &DD, return; DD.Triggered = true; - Diag(DD.Loc, diag::warn_deprecated) - << DD.DeprecationData.Decl->getDeclName(); + if (strlen(DD.DeprecationData.Message)) + Diag(DD.Loc, diag::warn_deprecated_message) + << DD.DeprecationData.Decl->getDeclName() + << DD.DeprecationData.Message; + else + Diag(DD.Loc, diag::warn_deprecated) + << DD.DeprecationData.Decl->getDeclName(); } -void Sema::EmitDeprecationWarning(NamedDecl *D, SourceLocation Loc) { +void Sema::EmitDeprecationWarning(NamedDecl *D, const char * Message, + SourceLocation Loc) { // Delay if we're currently parsing a declaration. if (ParsingDeclDepth) { - DelayedDiagnostics.push_back(DelayedDiagnostic::makeDeprecation(Loc, D)); + DelayedDiagnostics.push_back(DelayedDiagnostic::makeDeprecation(Loc, D, + Message)); return; } // Otherwise, don't warn if our current context is deprecated. if (isDeclDeprecated(cast<Decl>(CurContext))) return; - - Diag(Loc, diag::warn_deprecated) << D->getDeclName(); + if (strlen(Message)) + Diag(Loc, diag::warn_deprecated_message) << D->getDeclName() + << Message; + else + Diag(Loc, diag::warn_deprecated) << D->getDeclName(); } diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 89ae18fc39..09502a4923 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1622,9 +1622,13 @@ Decl *Sema::ActOnMethodDeclaration( // If the interface declared this method, and it was deprecated there, // mark it deprecated here. if (InterfaceMD) - if (Attr *DA = InterfaceMD->getAttr<DeprecatedAttr>()) - ObjCMethod->addAttr(::new (Context) DeprecatedAttr(DA->getLocation(), - Context)); + if (Attr *DA = InterfaceMD->getAttr<DeprecatedAttr>()) { + StringLiteral *SE = StringLiteral::CreateEmpty(Context, 1); + ObjCMethod->addAttr(::new (Context) + DeprecatedAttr(DA->getLocation(), + Context, + SE->getString())); + } return ObjCMethod; } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index ef21a2719b..d54a858221 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -57,8 +57,10 @@ using namespace sema; /// bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) { // See if the decl is deprecated. - if (D->getAttr<DeprecatedAttr>()) { - EmitDeprecationWarning(D, Loc); + if (const DeprecatedAttr *DA = D->getAttr<DeprecatedAttr>()) { + const char *Message = + DA->getMessage().empty() ? "" : DA->getMessage().data(); + EmitDeprecationWarning(D, Message, Loc); } // See if the decl is unavailable |