diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-09-29 11:40:46 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-09-29 11:40:46 +0000 |
commit | 6743e0469914b34322efed11617574b394c91705 (patch) | |
tree | 69a104efe1f0507201f003bf061c217fdf08704e /clang/lib/AST/CommentSema.cpp | |
parent | 903790eff54f473fca8fbf6915713751a070b5df (diff) | |
download | bcm5719-llvm-6743e0469914b34322efed11617574b394c91705.tar.gz bcm5719-llvm-6743e0469914b34322efed11617574b394c91705.zip |
Move the 'find macro by spelling' infrastructure to the Preprocessor class and
use it to suggest appropriate macro for __attribute__((deprecated)) in
-Wdocumentation-deprecated-sync.
llvm-svn: 164892
Diffstat (limited to 'clang/lib/AST/CommentSema.cpp')
-rw-r--r-- | clang/lib/AST/CommentSema.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp index 4f9f1f241c8..dd746ad1196 100644 --- a/clang/lib/AST/CommentSema.cpp +++ b/clang/lib/AST/CommentSema.cpp @@ -13,7 +13,9 @@ #include "clang/AST/Decl.h" #include "clang/AST/DeclTemplate.h" #include "clang/Basic/SourceManager.h" +#include "clang/Lex/Preprocessor.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/ADT/SmallString.h" namespace clang { namespace comments { @@ -23,9 +25,10 @@ namespace { } // unnamed namespace Sema::Sema(llvm::BumpPtrAllocator &Allocator, const SourceManager &SourceMgr, - DiagnosticsEngine &Diags, CommandTraits &Traits) : + DiagnosticsEngine &Diags, CommandTraits &Traits, + const Preprocessor *PP) : Allocator(Allocator), SourceMgr(SourceMgr), Diags(Diags), Traits(Traits), - ThisDeclInfo(NULL), BriefCommand(NULL), ReturnsCommand(NULL) { + PP(PP), ThisDeclInfo(NULL), BriefCommand(NULL), ReturnsCommand(NULL) { } void Sema::setDecl(const Decl *D) { @@ -527,10 +530,25 @@ void Sema::checkDeprecatedCommand(const BlockCommandComment *Command) { FD->doesThisDeclarationHaveABody()) return; + StringRef AttributeSpelling = "__attribute__((deprecated))"; + if (PP) { + TokenValue Tokens[] = { + tok::kw___attribute, tok::l_paren, tok::l_paren, + PP->getIdentifierInfo("deprecated"), + tok::r_paren, tok::r_paren + }; + StringRef MacroName = PP->getLastMacroWithSpelling(FD->getLocation(), + Tokens); + if (!MacroName.empty()) + AttributeSpelling = MacroName; + } + + SmallString<64> TextToInsert(" "); + TextToInsert += AttributeSpelling; Diag(FD->getLocEnd(), diag::note_add_deprecation_attr) << FixItHint::CreateInsertion(FD->getLocEnd().getLocWithOffset(1), - " __attribute__((deprecated))"); + TextToInsert); } } |