r230495 - Add support for inserting ArrayRef<FixItHint> into DiagnosticBuilder.

David Blaikie dblaikie at gmail.com
Wed Feb 25 09:39:13 PST 2015


On Wed, Feb 25, 2015 at 6:40 AM, Alexander Kornienko <alexfh at google.com>
wrote:

> Author: alexfh
> Date: Wed Feb 25 08:40:56 2015
> New Revision: 230495
>
> URL: http://llvm.org/viewvc/llvm-project?rev=230495&view=rev
> Log:
> Add support for inserting ArrayRef<FixItHint> into DiagnosticBuilder.
>
> This is going to be needed in clang-tidy as more checks add complex fixits.
>
> Modified:
>     cfe/trunk/include/clang/Basic/Diagnostic.h
>     cfe/trunk/lib/Sema/SemaChecking.cpp
>
> Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=230495&r1=230494&r2=230495&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
> +++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Feb 25 08:40:56 2015
> @@ -991,7 +991,8 @@ public:
>
>    void AddFixItHint(const FixItHint &Hint) const {
>      assert(isActive() && "Clients must not add to cleared diagnostic!");
> -    DiagObj->DiagFixItHints.push_back(Hint);
> +    if (!Hint.isNull())
>

Why is this null check required/used? (it'd be nicer to hold the invariant
that the FixItHints can't be null, if possible/reasonable)

(also, if we do need FixItHints to have a null state, perhaps they should
be boolean testable with an explicit operator bool)


> +      DiagObj->DiagFixItHints.push_back(Hint);
>    }
>
>    void addFlagValue(StringRef V) const { DiagObj->FlagValue = V; }
> @@ -1095,7 +1096,13 @@ inline const DiagnosticBuilder &operator
>
>  inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
>                                             const FixItHint &Hint) {
> -  if (!Hint.isNull())
> +  DB.AddFixItHint(Hint);
> +  return DB;
> +}
> +
> +inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
> +                                           ArrayRef<FixItHint> Hints) {
> +  for (const FixItHint &Hint : Hints)
>      DB.AddFixItHint(Hint);
>    return DB;
>  }
>
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=230495&r1=230494&r2=230495&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Feb 25 08:40:56 2015
> @@ -3152,10 +3152,7 @@ void CheckFormatHandler::EmitFormatDiagn
>    if (InFunctionCall) {
>      const Sema::SemaDiagnosticBuilder &D = S.Diag(Loc, PDiag);
>      D << StringRange;
> -    for (ArrayRef<FixItHint>::iterator I = FixIt.begin(), E = FixIt.end();
> -         I != E; ++I) {
> -      D << *I;
> -    }
> +    D << FixIt;
>    } else {
>      S.Diag(IsStringLocation ? ArgumentExpr->getExprLoc() : Loc, PDiag)
>        << ArgumentExpr->getSourceRange();
> @@ -3165,10 +3162,7 @@ void CheckFormatHandler::EmitFormatDiagn
>               diag::note_format_string_defined);
>
>      Note << StringRange;
> -    for (ArrayRef<FixItHint>::iterator I = FixIt.begin(), E = FixIt.end();
> -         I != E; ++I) {
> -      Note << *I;
> -    }
> +    Note << FixIt;
>    }
>  }
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150225/0183bd23/attachment.html>


More information about the cfe-commits mailing list