[PATCH] Add missing const in tooling::applyAllReplacements().

David Blaikie dblaikie at gmail.com
Wed Jul 17 10:42:16 PDT 2013


Seems simple enough that I'm OK signing off on it. Please commit.

(if Manuel has an issue with it that's probably fine to deal with post-commit)

On Wed, Jul 17, 2013 at 10:34 AM, Guillaume Papin
<guillaume.papin at epitech.eu> wrote:
> Hi klimek,
>
> Now when calling applyAllReplacements() it's possible to pass 'non-lvalue'
> replacements.
>
> I haven't found a reason why the 'const' was missing, I assume it was an
> oversight.
>
> http://llvm-reviews.chandlerc.com/D1169
>
> Files:
>   include/clang/Tooling/Refactoring.h
>   lib/Tooling/Refactoring.cpp
>
> Index: include/clang/Tooling/Refactoring.h
> ===================================================================
> --- include/clang/Tooling/Refactoring.h
> +++ include/clang/Tooling/Refactoring.h
> @@ -124,13 +124,13 @@
>  /// other applications.
>  ///
>  /// \returns true if all replacements apply. false otherwise.
> -bool applyAllReplacements(Replacements &Replaces, Rewriter &Rewrite);
> +bool applyAllReplacements(const Replacements &Replaces, Rewriter &Rewrite);
>
>  /// \brief Applies all replacements in \p Replaces to \p Code.
>  ///
>  /// This completely ignores the path stored in each replacement. If one or more
>  /// replacements cannot be applied, this returns an empty \c string.
> -std::string applyAllReplacements(StringRef Code, Replacements &Replaces);
> +std::string applyAllReplacements(StringRef Code, const Replacements &Replaces);
>
>  /// \brief Calculates how a code \p Position is shifted when \p Replaces are
>  /// applied.
> Index: lib/Tooling/Refactoring.cpp
> ===================================================================
> --- lib/Tooling/Refactoring.cpp
> +++ lib/Tooling/Refactoring.cpp
> @@ -123,7 +123,7 @@
>                          getRangeSize(Sources, Range), ReplacementText);
>  }
>
> -bool applyAllReplacements(Replacements &Replaces, Rewriter &Rewrite) {
> +bool applyAllReplacements(const Replacements &Replaces, Rewriter &Rewrite) {
>    bool Result = true;
>    for (Replacements::const_iterator I = Replaces.begin(),
>                                      E = Replaces.end();
> @@ -137,7 +137,7 @@
>    return Result;
>  }
>
> -std::string applyAllReplacements(StringRef Code, Replacements &Replaces) {
> +std::string applyAllReplacements(StringRef Code, const Replacements &Replaces) {
>    FileManager Files((FileSystemOptions()));
>    DiagnosticsEngine Diagnostics(
>        IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),
> @@ -152,8 +152,8 @@
>    SourceMgr.overrideFileContents(Entry, Buf);
>    FileID ID =
>        SourceMgr.createFileID(Entry, SourceLocation(), clang::SrcMgr::C_User);
> -  for (Replacements::iterator I = Replaces.begin(), E = Replaces.end(); I != E;
> -       ++I) {
> +  for (Replacements::const_iterator I = Replaces.begin(), E = Replaces.end();
> +       I != E; ++I) {
>      Replacement Replace("<stdin>", I->getOffset(), I->getLength(),
>                          I->getReplacementText());
>      if (!Replace.apply(Rewrite))
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>



More information about the cfe-commits mailing list