[cfe-commits] r164892 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/AST/CommentSema.h include/clang/AST/RawCommentList.h include/clang/Lex/Preprocessor.h lib/AST/ASTContext.cpp lib/AST/CommentSema.cpp lib/AST/RawCommentList.cpp li

Alexander Kornienko alexfh at google.com
Mon Oct 1 04:34:48 PDT 2012


On Sat, Sep 29, 2012 at 1:40 PM, Dmitri Gribenko <gribozavr at gmail.com>wrote:

> Author: gribozavr
> Date: Sat Sep 29 06:40:46 2012
> New Revision: 164892
>
> URL: http://llvm.org/viewvc/llvm-project?rev=164892&view=rev
> Log:
> 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.
> ...
> Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
> ...

+  /// \brief Return the name of the macro defined before \p Loc that has
> +  /// spelling \p Tokens.  If there are multiple macros with same
> spelling,
> +  /// return the last one defined.
> +  StringRef getLastMacroWithSpelling(SourceLocation Loc,
> +                                     ArrayRef<TokenValue> Tokens) const;
>

Isn't it more convenient to have a default spelling as a parameter of this
method so that callers don't have to check if the result is empty?


> Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp

...

-          std::string AnnotationSpelling = GetSuitableSpelling(
> -              PP, L, Tokens, "[[clang::fallthrough]]");
> +          StringRef AnnotationSpelling = "[[clang::fallthrough]]";
> +          StringRef MacroName = PP.getLastMacroWithSpelling(L, Tokens);
> +          if (!MacroName.empty())
> +            AnnotationSpelling = MacroName;
>
StringRef AnnotationSpelling = PP.getLastMacroWithSpelling(L, Tokens,
    "[[clang::fallthrough]]");
(if you add the DefaultSpelling argument) seems better to me.


> +          SmallString<64> TextToInsert(AnnotationSpelling);
> +          TextToInsert += "; ";
>

Over-optimization? ;)


>            S.Diag(L, diag::note_insert_fallthrough_fixit) <<
>                AnnotationSpelling <<
> -              FixItHint::CreateInsertion(L, AnnotationSpelling + "; ");
> +              FixItHint::CreateInsertion(L, TextToInsert);
>          }
>        }
>        S.Diag(L, diag::note_insert_break_fixit) <<
>
>
-- 
Regards,
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121001/d1673df6/attachment.html>


More information about the cfe-commits mailing list