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

Guillaume Papin guillaume.papin at epitech.eu
Wed Jul 17 10:34:14 PDT 2013


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))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1169.1.patch
Type: text/x-patch
Size: 2333 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130717/db713bbd/attachment.bin>


More information about the cfe-commits mailing list